public function processSetPonAction() { $messagingId = $this->_getParam('messagingId'); $medicationId = (int) $this->_getParam('medicationId'); $personId = (int) $this->_getParam('personId'); $ret = false; $messaging = new Messaging(); $messaging->messagingId = $messagingId; $messaging->populate(); //if ($medicationId > 0 && strlen($messaging->rawMessage) > 0) { if ($personId > 0 && strlen($messaging->rawMessage) > 0) { $xml = new SimpleXMLElement($messaging->rawMessage); $auditId = Medication::getAuditId($medicationId); if ($medicationId > 0) { $xml->Body->RefillRequest->PrescriberOrderNumber = $medicationId . '_' . $auditId; $messaging->rawMessage = $xml->asXML(); } else { //$xml->Body->RefillRequest->PrescriberOrderNumber = $personId; } $messaging->personId = $personId; $messaging->auditId = $auditId; $messaging->unresolved = 0; $messaging->note = str_replace('Missing PON', 'Missing PON - fixed', $messaging->note); $messaging->persist(); $refillRequest = new MedicationRefillRequest(); $refillRequest->messageId = $messagingId; $refillRequest->populate(); $refillRequest->medicationId = $medicationId; $refillRequest->persist(); $ret = true; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($ret); }
public function send($response, $inputs, $messageId = null) { if ($messageId === null) { $messageId = $this->messageId; } if (!isset($this->_validResponses[$response])) { $response = 'approved'; } $messaging = new Messaging(); $messaging->messagingId = $messageId; if (!$messaging->populate()) { trigger_error(__('Refill request messaging does not exists.'), E_USER_NOTICE); return false; } $refillRequest = new MedicationRefillRequest(); $refillRequest->messageId = $messageId; if (!$refillRequest->populate()) { trigger_error(__('Refill request does not exists.'), E_USER_NOTICE); return false; } $data = array(); //$data['writtenDate'] = date('Ymd',strtotime($inputs['datePrescribed'])) $data['writtenDate'] = date('Ymd'); // should be set to the date the prescriber authorized the renewal of the prescription $data['message'] = $messaging->rawMessage; if ($response == 'approved' && $refillRequest->medication->isScheduled()) { $response = 'denied'; $inputs['note'] = 'This Refill Request is for a controlled substance (Schedule III - V). The approved controlled substance prescription is being faxed to your pharmacy'; $inputs['refills'] = 0; } $arrResponse = array(); switch ($response) { case 'approved': $this->response = 'Approved'; $refills = $messaging->refills; $newRefills = (int) $inputs['refills']; if ($refills != $newRefills) { if ($refills != 0) { $this->response = 'ApprovedWithChanges'; } //else { $data['refills'] = $newRefills; //} } $this->message = $inputs['note']; $arrResponse[$this->response] = array('Note' => $this->message); break; case 'denied': // quantity should be set to zero $data['refills'] = 0; if (isset($inputs['note'])) { $this->response = 'DeniedNewPrescriptionToFollow'; $this->message = $inputs['note']; $arrResponse[$this->response] = array('Note' => $this->message); //$data['medicationId'] = (int)$inputs['medicationId']; } else { $this->response = 'Denied'; //$this->message = $inputs['reasonCode'].':'.$inputs['reason']; // empty reason $this->message = $inputs['reason']; $arrResponse[$this->response] = array('DenialReasonCode' => $inputs['reasonCode'], 'DenialReason' => $inputs['reason']); } break; } $data['response'] = $arrResponse; $data['type'] = 'refill'; $ret = ePrescribe::sendResponse($data, $messaging); if ($ret === true) { $this->dateTime = date('Y-m-d H:i:s'); $this->persist(); $refillRequest->action = $this->_validResponses[$response]; $refillRequest->status = 'RESPONDED'; $refillRequest->persist(); } return $ret; }