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; }
public function processCheckInboundAction() { $inbound = new eFaxInbound(); $inbounds = array(); $ret = 0; //$inbound->checkInbounds(); if ($ret > 0) { $inbounds[] = 'eFax: ' . $ret; } $ret = ePrescribe::pull(); if ($ret > 0) { $inbounds[] = 'ePrescribe: ' . $ret; } if (!isset($inbounds[0])) { $data = 'none'; } else { $data = "\n" . implode("\n", $inbounds); } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }
public function startProcessing($infinite = true) { $infinite = (bool) $infinite; do { $ctr = ePrescribe::pull(); WebVista::log('ePrescribe messages received: ' . $ctr); $this->_populateAudits(); foreach ($this->_audits as $audit) { WebVista::log('start processing auditId:[' . $audit->auditId . '], objectClass:[' . $audit->objectClass . '], objectId:[' . $audit->objectId . ']'); $audit->_persistMode = WebVista_Model_ORM::REPLACE; $audit->_ormPersist = true; if ($audit->startProcessing == '0000-00-00 00:00:00') { $audit->startProcessing = date('Y-m-d H:i:s'); $audit->persist(); } $processResult = true; foreach ($this->_processes as $process) { $process->preProcess($audit); $result = $process->process($audit); $process->postProcess($audit); $processResult &= $result; if ($result) { continue; } } if ($processResult) { $audit->endProcessing = date('Y-m-d H:i:s'); $audit->persist(); } } // invoke extra process that are not dependent on Audits foreach ($this->_processes as $process) { $process->extraProcess(); } sleep($this->_sleepInterval); } while ($infinite); }