public function viewGatewayResponseRawMessageAction() { $messagingId = $this->_getParam('messagingId'); $messaging = new Messaging(); $messaging->messagingId = $messagingId; $messaging->populate(); $this->view->gatewayResponseRawMessage = $messaging->rawMessageResponse; $this->render(); }
public static function handlereFaxAct(Audit $audit, array $sourceData) { if ($audit->objectClass != 'ESignature') { return false; } $eSignature = new ESignature(); $eSignature->eSignatureId = $audit->objectId; $eSignature->populate(); if ($eSignature->objectClass != 'Medication') { return false; } $medication = new Medication(); $medication->medicationId = $eSignature->objectId; $medication->populate(); $audit = $sourceData['_audit']; $messaging = new Messaging(Messaging::TYPE_OUTBOUND_FAX); $messaging->messagingId = (int) $sourceData['transmissionId']; $messaging->transmissionId = $messaging->messagingId; $messaging->populate(); $messaging->objectId = $messaging->messagingId; $messaging->objectClass = $audit->objectClass; $messaging->status = 'Faxed'; $messaging->dateStatus = date('Y-m-d H:i:s'); $messaging->auditId = $audit->auditId; // this must be required for retransmission in case of error $messaging->persist(); $efax = new eFaxOutbound(); $url = Zend_Registry::get('config')->healthcloud->eFax->outboundUrl; $url .= '?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey; $efax->setUrl($url); $efax->setTransmissionId($sourceData['transmissionId']); $efax->setNoDuplicate(eFaxOutbound::NO_DUPLICATE_ENABLE); $efax->setDispositionMethod('POST'); // use the default disposition URL $dispositionUrl = Zend_Registry::get('config')->healthcloud->eFax->dispositionUrl; $efax->setDispositionUrl($dispositionUrl); //$efax->setDispositionMethod('EMAIL'); //$efax->addDispositionEmail('Arthur Layese','*****@*****.**'); foreach ($sourceData['recipients'] as $recipient) { if ($messaging->resend && strlen($messaging->faxNumber) > 9) { // supersedes fax number from messaging $recipient['fax'] = $messaging->faxNumber; } $efax->addRecipient($recipient['fax'], $recipient['name'], $recipient['company']); } foreach ($sourceData['files'] as $file) { $efax->addFile($file['contents'], $file['type']); } $ret = $efax->send(); if (!$ret) { $messaging->status = 'Fax Error'; $messaging->note = implode(PHP_EOL, $efax->getErrors()); } else { $messaging->docid = $efax->getDocId(); $messaging->status = 'Fax Sent'; $messaging->note = ''; } if ($messaging->resend) { $messaging->resend = 0; } $messaging->retries++; $messaging->dateStatus = date('Y-m-d H:i:s'); $messaging->persist(); return true; }
public function getDisplayAction() { $action = ''; switch (strtolower($this->transmit)) { case 'fax': if ($this->eSignatureId > 0) { $action = 'Faxing'; $messaging = new Messaging(); $messaging->messagingId = $this->medicationId; $messaging->populate(); if (strlen($messaging->status) > 0) { $action = $messaging->status; } } else { $action = 'Pending'; } break; } return $action; }
public function getPersonId() { $personId = (int) $this->medication->personId; if (!$personId > 0) { $messaging = new Messaging(); $messaging->messagingId = $this->messageId; $messaging->populate(); $personId = (int) $messaging->personId; } return $personId; }
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 static function activateDownload($daily) { $data = array(); $data['daily'] = (int) $daily; //$data['clinicName'] = $practice->name; $type = 'full'; if ($data['daily']) { $type = 'daily'; } $messaging = new Messaging(); //$messaging->messagingId = ''; $messaging->messageType = 'DirectoryDownload'; $messaging->populate(); //$messaging->objectId = ''; //$messaging->objectClass = ''; $messaging->status = 'Downloading'; $messaging->note = 'Downloading pharmacy (' . $type . ')'; $messaging->dateStatus = date('Y-m-d H:i:s'); //$messaging->auditId = ''; $messaging->persist(); trigger_error($messaging->note, E_USER_NOTICE); $ch = curl_init(); $pharmacyActivateURL = Zend_Registry::get('config')->healthcloud->URL; $pharmacyActivateURL .= 'ss-manager.raw/activate-pharmacy-download?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey; $cookieFile = tempnam(sys_get_temp_dir(), 'ssddcookies_'); trigger_error('URL: ' . $pharmacyActivateURL, E_USER_NOTICE); trigger_error('COOKIEFILE: ' . $cookieFile, E_USER_NOTICE); trigger_error('DATA: ' . print_r($data, true)); curl_setopt($ch, CURLOPT_URL, $pharmacyActivateURL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); curl_setopt($ch, CURLOPT_USERPWD, 'admin:ch3!'); $output = curl_exec($ch); $error = ""; $downloadURL = ""; $messaging->status = 'Downloaded'; $messaging->note = 'Pharmacy downloaded (' . $type . ')'; if (!curl_errno($ch)) { try { $responseXml = simplexml_load_string($output); if (isset($responseXml->error)) { $error = (string) $responseXml->error->messageCode . ': ' . (string) $responseXml->error->message; trigger_error("There was an error activating synchronization of pharmacies, Error code: " . $responseXml->error->code . " Error Message: " . $responseXml->error->message, E_USER_NOTICE); } elseif (isset($responseXml->data->SSDirectoryDownloadUrl)) { $downloadURL = $responseXml->data->SSDirectoryDownloadUrl; trigger_error('DOWNLOAD URL: ' . $downloadURL, E_USER_NOTICE); } if (isset($responseXml->rawMessage)) { $messaging->rawMessage = base64_decode((string) $responseXml->rawMessage); $messaging->rawMessageResponse = base64_decode((string) $responseXml->rawMessageResponse); } } catch (Exception $e) { $error = __("There was an error connecting to HealthCloud to activate synchronization of pharmacies. Please try again or contact the system administrator."); trigger_error("Curl error connecting to healthcloud to activate pharmacy sync: " . curl_error($ch), E_USER_NOTICE); } } else { $error = __("There was an error connecting to HealthCloud to activate synchronization of pharmacies. Please try again or contact the system administrator."); trigger_error("Curl error connecting to healthcloud to activate pharmacy sync: " . curl_error($ch), E_USER_NOTICE); } curl_close($ch); if (strlen($error) > 0) { $messaging->status = 'Error'; $messaging->note .= ' ERROR: ' . $error; $ret = false; } if ($messaging->resend) { $messaging->resend = 0; } $messaging->retries++; $messaging->dateStatus = date('Y-m-d H:i:s'); $messaging->persist(); trigger_error($messaging->note, E_USER_NOTICE); return array('downloadUrl' => $downloadURL, 'cookieFile' => $cookieFile, 'error' => $error); }
public static function pull() { $ch = curl_init(); $ePrescribeURL = Zend_Registry::get('config')->healthcloud->URL; $ePrescribeURL .= 'ss-manager.raw/pull-inbounds?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey; curl_setopt($ch, CURLOPT_URL, $ePrescribeURL); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $output = curl_exec($ch); $error = ''; $ret = 0; if (!curl_errno($ch)) { try { $xml = new SimpleXMLElement($output); foreach ($xml->data as $messages) { foreach ($messages as $key => $message) { $rawMessage = base64_decode((string) $message->rawMessage); if ($key == 'refillRequest') { $messageId = (string) $message->messageId; $rxReferenceNumber = (string) $message->rxReferenceNumber; $prescriberOrderNumber = (string) $message->prescriberOrderNumber; $auditId = 0; $medicationId = 0; $xmlMessage = new SimpleXMLElement($rawMessage); $lastName = (string) $xmlMessage->Body->RefillRequest->Patient->Name->LastName; $firstName = (string) $xmlMessage->Body->RefillRequest->Patient->Name->FirstName; $messageInfo = ' for ' . $lastName . ', ' . $firstName; $description = (string) $xmlMessage->Body->RefillRequest->MedicationPrescribed->DrugDescription; $datePrescribed = date('m/d/Y', strtotime((string) $xmlMessage->Body->RefillRequest->MedicationPrescribed->WrittenDate)); $messageInfo .= ' - ' . $description . ' #' . $datePrescribed; if (strlen($prescriberOrderNumber) > 0) { // currently check for medicationId using the prescriberOrderNumber medication_audit $medAudit = explode('_', $prescriberOrderNumber); $medicationId = (int) $medAudit[0]; $auditId = isset($medAudit[1]) ? (int) $medAudit[1] : 0; } $medication = new Medication(); $medication->medicationId = $medicationId; $medication->populate(); $patientId = (int) $medication->personId; $unresolved = 0; // retrieve providerId using SPI $SPI = (string) $xmlMessage->Body->RefillRequest->Prescriber->Identification->SPI; $eprescriber = new EPrescriber(); $eprescriber->populateBySPI($SPI); $providerId = (int) $eprescriber->providerId; if (!$patientId > 0) { // PON not set or invalid PON, try to automatch based on name, dob, medication and dates in the refreq, if only one match automatically link with correct PON // retrieve pharmacyId using NCPDPID $NCPDPID = (string) $xmlMessage->Body->RefillRequest->Pharmacy->Identification->NCPDPID; $pharmacy = new Pharmacy(); $pharmacy->NCPDPID = $NCPDPID; $pharmacy->populatePharmacyIdWithNCPDPID(); $pharmacyId = (string) $pharmacy->pharmacyId; $gender = (string) $xmlMessage->Body->RefillRequest->Patient->Gender; $dob = (string) $xmlMessage->Body->RefillRequest->Patient->DateOfBirth; // retrieve patientId using LastName, FirstName, Gender and DOB $db = Zend_Registry::get('dbAdapter'); $sqlSelect = $db->select()->from('person', 'person_id')->where('last_name = ?', $lastName)->where('first_name = ?', $firstName)->where('date_of_birth = ?', date('Y-m-d', strtotime($dob)))->limit(1); if ($row = $db->fetchRow($sqlSelect)) { $patientId = $row['person_id']; } //trigger_error($sqlSelect->__toString()); // $qualifiers = Medication::listQuantityQualifiersMapping(); TODO: since qualifier are ambiguous, temporarily not to use this qualifier $quantity = (string) $xmlMessage->Body->RefillRequest->MedicationPrescribed->Quantity->Value; $sqlSelect = $db->select()->from('medications')->where('description = ?', $description)->where('quantity = ?', $quantity)->where('personId = ?', (int) $patientId)->where('prescriberPersonId = ?', (int) $providerId)->where('pharmacyId = ?', (int) $pharmacyId); $writtenDate = (string) $xmlMessage->Body->RefillRequest->MedicationPrescribed->WrittenDate; if (strlen($writtenDate) > 0) { $sqlSelect->where('datePrescribed LIKE ?', date('Y-m-d', strtotime($writtenDate)) . '%'); } $medicationMatched = false; //trigger_error($sqlSelect->__toString()); $rows = $db->fetchAll($sqlSelect); if (count($rows) == 1) { $medication = new Medication(); $medication->populateWithArray($rows[0]); $medicationId = $medication->medicationId; $auditId = Medication::getAuditId($medicationId); if ($auditId > 0) { $xmlMessage->Body->RefillRequest->PrescriberOrderNumber = $medicationId . '_' . $auditId; $rawMessage = $xmlMessage->asXML(); } //trigger_error($sqlSelect->__toString()); $medicationMatched = true; } $messageInfo = ' (Invalid/Missing PON'; if ($patientId > 0 && $medicationMatched) { $patient = new Patient(); $patient->personId = $patientId; $patient->populate(); $messageInfo .= ' - automatched to \'' . $patient->displayName . '\' MRN#' . $patient->recordNumber; } else { $unresolved = 1; } $messageInfo .= ')'; } $refillRequest = new MedicationRefillRequest(); $refillRequest->messageId = $messageId; $refillRequest->medicationId = $medicationId; $refillRequest->action = ''; $refillRequest->status = ''; $refillRequest->dateStart = ''; $refillRequest->details = 'Re: ' . $rxReferenceNumber; $refillRequest->dateTime = date('Y-m-d H:i:s'); // disable audits autoprocess, this was set at CHProcessingDaemon $processedAudits = Audit::$_processedAudits; Audit::$_processedAudits = false; $refillRequest->persist(); Audit::$_processedAudits = $processedAudits; $messaging = new Messaging(); $messaging->messagingId = $messageId; $messaging->populate(); $messaging->messageType = 'RefillRequest'; $messaging->objectId = $refillRequest->messageId; $messaging->objectClass = 'MedicationRefillRequest'; $messaging->note = 'Refill request received - Re:' . $rxReferenceNumber . $messageInfo; $messaging->auditId = $auditId; $messaging->refills = (string) $message->refills; $messaging->personId = $patientId; $messaging->providerId = $providerId; $messaging->unresolved = $unresolved; } else { if ($key == 'status') { $relatesToMessageId = (string) $message->relatesToMessageId; $messageId = (string) $message->messageId; $code = (string) $message->code; $description = (string) $message->description; $messaging = new Messaging(); $messaging->messageType = 'Status'; $messaging->note = 'Status received for unknown messageId: ' . $relatesToMessageId; $tmpMsg = new Messaging(); $tmpMsg->messagingId = $relatesToMessageId; if ($tmpMsg->populate()) { // populate for newRx details $tmpMsg->status = 'Sent and Verified'; $x = explode('(', $tmpMsg->note); $tmpMsg->note = 'newRx'; if ($tmpMsg->objectClass == 'MedicationRefillResponse') { $tmpMsg->note = 'Refill response'; } $tmpMsg->note .= ' sent and verified'; if (isset($x[1])) { unset($x[0]); $tmpMsg->note .= ' (' . implode('(', $x); } $tmpMsg->unresolved = 0; $tmpMsg->persist(); $messaging->auditId = $tmpMsg->auditId; $messaging->objectId = $tmpMsg->objectId; $messaging->objectClass = $tmpMsg->objectClass; $messaging->personId = $tmpMsg->personId; $messaging->providerId = $tmpMsg->providerId; $xmlTmpMessage = new SimpleXMLElement($tmpMsg->rawMessage); $lastName = (string) $xmlTmpMessage->Body->NewRx->Patient->Name->LastName; $firstName = (string) $xmlTmpMessage->Body->NewRx->Patient->Name->FirstName; $messageInfo = $lastName . ', ' . $firstName; $drugDescription = (string) $xmlTmpMessage->Body->NewRx->MedicationPrescribed->DrugDescription; $datePrescribed = date('m/d/Y', strtotime((string) $xmlTmpMessage->Body->NewRx->MedicationPrescribed->WrittenDate)); $messageInfo .= ' - ' . $drugDescription . ' #' . $datePrescribed; $messaging->note = 'Status received for ' . $messageInfo; } $messaging->note .= "\n" . $code . ':' . $description; } else { if ($key == 'error') { $relatesToMessageId = (string) $message->relatesToMessageId; $messageId = (string) $message->messageId; $code = (string) $message->code; $description = (string) $message->description; $messaging = new Messaging(); $messaging->messageType = 'Error'; $messaging->note = 'Error received for unknown messageId: ' . $relatesToMessageId; $tmpMsg = new Messaging(); $tmpMsg->messagingId = $relatesToMessageId; if ($tmpMsg->populate()) { // populate for newRx details $tmpMsg->status = 'Sent and Verified'; $x = explode('(', $tmpMsg->note); $tmpMsg->note = 'newRx'; if ($tmpMsg->objectClass == 'MedicationRefillResponse') { $tmpMsg->note = 'Refill response'; } $tmpMsg->note .= ' sent and verified'; if (isset($x[1])) { unset($x[0]); $tmpMsg->note .= ' (' . implode('(', $x); } $tmpMsg->unresolved = 0; $tmpMsg->persist(); $messaging->auditId = $tmpMsg->auditId; $messaging->objectId = $tmpMsg->objectId; $messaging->objectClass = $tmpMsg->objectClass; $messaging->personId = $tmpMsg->personId; $messaging->providerId = $tmpMsg->providerId; $xmlTmpMessage = new SimpleXMLElement($tmpMsg->rawMessage); $lastName = (string) $xmlTmpMessage->Body->NewRx->Patient->Name->LastName; $firstName = (string) $xmlTmpMessage->Body->NewRx->Patient->Name->FirstName; $messageInfo = $lastName . ', ' . $firstName; $drugDescription = (string) $xmlTmpMessage->Body->NewRx->MedicationPrescribed->DrugDescription; $datePrescribed = date('m/d/Y', strtotime((string) $xmlTmpMessage->Body->NewRx->MedicationPrescribed->WrittenDate)); $messageInfo .= ' - ' . $drugDescription . ' #' . $datePrescribed; $messaging->note = 'Error received for ' . $messageInfo; } $messaging->note .= "\n" . $code . ':' . $description; } else { continue; } } } $messaging->rawMessage = $rawMessage; $messaging->rawMessageResponse = base64_decode((string) $message->rawMessageResponse); $messaging->status = 'Received'; $messaging->dateStatus = date('Y-m-d H:i:s'); $messaging->persist(); $ret++; } } if ($ret > 0) { self::sendPullResponse(); } } catch (Exception $e) { $error = __('There was an error, the response couldn\'t be parsed as XML: ' . $output); trigger_error($error, E_USER_NOTICE); } } else { $error = __('There was an error connecting to HealthCloud. Please try again or contact the system administrator.'); trigger_error('Curl error connecting to healthcare: ' . curl_error($ch), E_USER_NOTICE); } curl_close($ch); return $ret; }
protected function _syncLocation(EPrescriber $ePrescriber) { $ret = true; $dateActiveStart = strtotime($ePrescriber->dateActiveStart); $dateActiveEnd = strtotime($ePrescriber->dateActiveEnd); $serviceLevel = (int) $ePrescriber->serviceLevel; $personId = (int) $ePrescriber->providerId; $provider = new Provider(); $provider->personId = $personId; $provider->populate(); $provider->serviceLevel = $serviceLevel; if ($dateActiveStart > 0 && $dateActiveEnd > 0) { $provider->dateActiveStart = date('Y-m-d H:i:s', $dateActiveStart); $provider->dateActiveEnd = date('Y-m-d H:i:s', $dateActiveEnd); } $person = new Person(); $person->personId = $personId; $person->populate(); $practice = new Practice(); $practice->practiceId = $person->primaryPracticeId; $practice->populate(); $data = array(); $data['deaNumber'] = $provider->deaNumber; $data['stateLicenseNumber'] = $provider->stateLicenseNumber; //$data['portalId'] = Zend_Registry::get('config')->sureScripts->portalId; //$data['accountId'] = Zend_Registry::get('config')->sureScripts->accountId; $data['clinicName'] = '' . $practice->name; $data['lastName'] = $person->lastName; $data['firstName'] = $person->firstName; $address = $ePrescriber->building; $data['addressLine1'] = $address->line1; $data['addressLine2'] = $address->line2; $data['addressCity'] = $address->city; $data['addressState'] = $address->state; $data['addressZipCode'] = $address->zipCode; $data['email'] = $person->email; $data['phones'] = array(array('number' => PhoneNumber::autoFixNumber($address->phoneNumber), 'type' => 'TE'), array('number' => PhoneNumber::autoFixNumber($address->fax), 'type' => 'FX')); $data['specialtyCode'] = $provider->specialty; $specialtyQualifier = ''; if (strlen($provider->specialty) > 0) { $specialtyQualifier = 'AM'; } $data['specialtyQualifier'] = $specialtyQualifier; $data['serviceLevel'] = $provider->serviceLevel; $now = strtotime('now'); $days30 = strtotime('+30 days', $now); $activeStartTime = gmdate("Y-m-d\\TH:i:s.0", $now) . 'Z'; $activeEndTime = gmdate("Y-m-d\\TH:i:s.0", $days30) . 'Z'; $data['activeStartTime'] = $provider->dateActiveStartZ; $data['activeEndTime'] = $provider->dateActiveEndZ; $dateActiveEnd = strtotime(date('Y-m-d', strtotime($provider->dateActiveEndZ))); if ($dateActiveEnd <= strtotime(date('Y-m-d'))) { // to disable a prescriber ActiveEndTime must be set to current date and ServiceLevel must be set to zero. $data['activeEndTime'] = date('Y-m-d'); $data['serviceLevel'] = 0; $provider->serviceLevel = 0; } $provider->persist(); $identifierType = $provider->identifierType; if (strlen($identifierType) > 0) { $data[$identifierType] = $provider->identifier; } $messaging = new Messaging(); //$messaging->messagingId = ''; $type = 'add'; $messaging->messageType = 'AddPrescriber'; if (strlen($ePrescriber->SSID) > 0) { $messaging->messageType = 'UpdatePrescriber'; $data['SPI'] = $ePrescriber->SSID; $type = 'update'; } else { if (strlen($provider->sureScriptsSPI) > 0) { $messaging->messageType = 'AddPrescriberLocation'; $data['SPI'] = substr($provider->sureScriptsSPI, 0, -3); $type = 'addLocation'; } } // backupPortalId must be supplied if type is updateLocation $messaging->populate(); //$messaging->objectId = ''; //$messaging->objectClass = ''; $messaging->status = 'Sending'; $messaging->note = 'Sending prescriber data'; $messaging->dateStatus = date('Y-m-d H:i:s'); //$messaging->auditId = ''; $messaging->persist(); $query = http_build_query(array('type' => $type, 'data' => $data)); $ch = curl_init(); $ePrescribeURL = Zend_Registry::get('config')->healthcloud->URL; $ePrescribeURL .= 'ss-manager.raw/edit-prescriber?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey; curl_setopt($ch, CURLOPT_URL, $ePrescribeURL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $output = curl_exec($ch); trigger_error('OUTPUT: ' . $output, E_USER_NOTICE); $error = ""; $prescriberSPI = ''; $messaging->status = 'Sent'; $messaging->note = 'Prescriber data sent'; if (!curl_errno($ch)) { try { $responseXml = simplexml_load_string($output); if (isset($responseXml->error)) { $errorCode = (string) $responseXml->error->code; $errorMsg = (string) $responseXml->error->message; if (isset($responseXml->error->errorCode)) { $errorCode = (string) $responseXml->error->errorCode; } if (isset($responseXml->error->errorMsg)) { $errorMsg = (string) $responseXml->error->errorMsg; } $error = $errorMsg; trigger_error('There was an error enabling an ePresciber, Error code: ' . $errorCode . ' Error Message: ' . $errorMsg, E_USER_NOTICE); } elseif (isset($responseXml->data)) { $xml = new SimpleXMLElement($responseXml->data); $prescriber = $xml->AddPrescriberResponse->Prescriber; //if ($type == 'addLocation') { if (isset($xml->AddPrescriberLocationResponse)) { $prescriber = $xml->AddPrescriberLocationResponse->Prescriber; } $prescriberSPI = (string) $prescriber->Identification->SPI; if (!strlen($prescriberSPI) > 0) { $error = 'Registration failed for location ' . $ePrescriber->building->name; } } if (isset($responseXml->rawMessage)) { $messaging->rawMessage = base64_decode((string) $responseXml->rawMessage); $messaging->rawMessageResponse = base64_decode((string) $responseXml->rawMessageResponse); } } catch (Exception $e) { $error = __("There was an error connecting to HealthCloud to enable ePrescribing for this provider. Please try again or contact the system administrator."); trigger_error("There was an error enabling an ePresciber, the response couldn't be parsed as XML: " . $output, E_USER_NOTICE); } } else { $error = __("There was an error connecting to HealthCloud to enable ePrescribing for this provider. Please try again or contact the system administrator."); trigger_error("Curl error connecting to healthcare enabled an ePrescribe record: " . curl_error($ch), E_USER_NOTICE); } curl_close($ch); if (strlen($error) > 0) { $messaging->status = 'Error'; $messaging->note = $error; $ret = false; } if ($messaging->resend) { $messaging->resend = 0; } $messaging->retries++; $messaging->dateStatus = date('Y-m-d H:i:s'); $messaging->persist(); if (strlen($error) > 0) { return $error; } if (!strlen($provider->sureScriptsSPI) > 0) { // handler of the first SPI $provider->sureScriptsSPI = $prescriberSPI; $provider->persist(); } if ($type == 'add' || $type == 'addLocation') { $ePrescriber->SSID = $prescriberSPI; $ePrescriber->persist(); } return $ret; }
public function addProcessAction() { $dateActiveStart = strtotime($this->_getParam('dateActiveStart')); $dateActiveEnd = strtotime($this->_getParam('dateActiveEnd')); $serviceLevel = (int) $this->_getParam('serviceLevel'); $personId = (int) $this->_getParam('personId'); $provider = new Provider(); $provider->person_id = $personId; $provider->populate(); $provider->serviceLevel = $serviceLevel; if ($dateActiveStart > 0 && $dateActiveEnd > 0) { $provider->dateActiveStart = date('Y-m-d H:i:s', $dateActiveStart); $provider->dateActiveEnd = date('Y-m-d H:i:s', $dateActiveEnd); } $person = new Person(); $person->person_id = $personId; $person->populate(); $address = new Address(); $address->person_id = $personId; $address->populateWithPersonId($personId); $phoneNumber = new PhoneNumber(); $phoneNumber->person_id = $personId; $phoneNumber->populateWithType(4); $practice = new Practice(); $practice->practiceId = $person->primaryPracticeId; $practice->populate(); $data = array(); $data['deaNumber'] = $provider->deaNumber; $data['stateLicenseNumber'] = $provider->stateLicenseNumber; //$data['portalId'] = Zend_Registry::get('config')->sureScripts->portalId; //$data['accountId'] = Zend_Registry::get('config')->sureScripts->accountId; $data['clinicName'] = '' . $practice->name; $data['lastName'] = $person->last_name; $data['firstName'] = $person->first_name; $address = new Address(); $address->personId = $provider->personId; $address->populateWithType(4); $data['addressLine1'] = $address->line1; $data['addressLine2'] = $address->line2; $data['addressCity'] = $address->city; $data['addressState'] = $address->state; $data['addressZipCode'] = $address->zipCode; $data['email'] = $person->email; $phoneNumber = new PhoneNumber(); $phoneNumber->personId = $provider->personId; /* $phoneNumberIterator = $phoneNumber->getIteratorByPatientId(); $phones = array(); foreach ($phoneNumberIterator as $number) { if (!strlen($number->number) > 0) continue; // SS Type options: BN - Beeper, CP - Cellular, FX - Fax, HP - Home, NP - Night, TE – Telephone*, WP – Work $type = ''; switch ($number->type) { case PhoneNumber::TYPE_HOME: $type = 'HP'; case PhoneNumber::TYPE_WORK: $type = 'WP'; break; case PhoneNumber::TYPE_MOBILE: $type = 'CP'; break; case PhoneNumber::TYPE_FAX: $type = 'FX'; break; case PhoneNumber::TYPE_EMERGENCY: case PhoneNumber::TYPE_EMPLOYER: case PhoneNumber::TYPE_BILLING: $type = 'TE'; break; default: continue; } $phones[$type] = array('number'=>$number->number,'type'=>$type); } $te = null; if (isset($phones['TE'])) { $te = $phones['TE']; unset($phones['TE']); } $fx = null; if (isset($phones['FX'])) { $fx = $phones['FX']; unset($phones['FX']); } if ($te === null) { if (count($phones) > 0) { $te = array_unshift($phones); } else if ($fx !== null) { $te = $fx; } } if ($fx === null) { if (count($phones) > 0) { $fx = array_unshift($phones); } else if ($te !== null) { $fx = $te; } } $data['phones'] = array(); if ($te !== null) { $data['phones'][] = $te; } if ($fx !== null) { $data['phones'][] = $fx; } foreach ($phones as $p) { $data['phones'][] = $p; } */ $data['phones'] = $phoneNumber->phoneNumbers; /*$phoneNumbers = $phoneNumber->phoneNumbers; $fax = ''; if (isset($phoneNumbers['FAX'])) { $fax = $phoneNumbers['FAX']; unset($phoneNumbers['FAX']); } $phone = $fax; if (count($phoneNumbers) > 0) { $phone = array_pop($phoneNumbers); } $data['phoneNumber'] = $phone; $data['faxNumber'] = $fax;*/ $data['specialtyCode'] = $provider->specialty; $specialtyQualifier = ''; if (strlen($provider->specialty) > 0) { $specialtyQualifier = 'AM'; } $data['specialtyQualifier'] = $specialtyQualifier; $data['serviceLevel'] = $provider->serviceLevel; $now = strtotime('now'); $days30 = strtotime('+30 days', $now); $activeStartTime = gmdate("Y-m-d\\TH:i:s.0", $now) . 'Z'; $activeEndTime = gmdate("Y-m-d\\TH:i:s.0", $days30) . 'Z'; $data['activeStartTime'] = $provider->dateActiveStartZ; $data['activeEndTime'] = $provider->dateActiveEndZ; $dateActiveEnd = strtotime(date('Y-m-d', strtotime($provider->dateActiveEndZ))); if ($dateActiveEnd <= strtotime(date('Y-m-d'))) { // to disable a prescriber ActiveEndTime must be set to current date and ServiceLevel must be set to zero. $data['activeEndTime'] = date('Y-m-d'); $data['serviceLevel'] = 0; $provider->serviceLevel = 0; } $provider->persist(); $identifierType = $provider->identifierType; if (strlen($identifierType) > 0) { $data[$identifierType] = $provider->identifier; } /* foreach ($data as $k=>$v) { if (!strlen(trim($v)) > 0) { $tmp = ' '; if ($k == 'addressState') { $tmp = 'AZ'; } if ($k == 'addressZipCode') { $tmp = '12345'; } $data[$k] = $tmp; } }*/ $messaging = new Messaging(); //$messaging->messagingId = ''; $type = 'add'; $messaging->messageType = 'AddPrescriber'; if (strlen($provider->sureScriptsSPI) > 0) { $messaging->messageType = 'UpdatePrescriber'; $data['SPI'] = $provider->sureScriptsSPI; $type = 'update'; } $messaging->populate(); //$messaging->objectId = ''; //$messaging->objectClass = ''; $messaging->status = 'Sending'; $messaging->note = 'Sending prescriber data'; $messaging->dateStatus = date('Y-m-d H:i:s'); //$messaging->auditId = ''; $messaging->persist(); $query = http_build_query(array('type' => $type, 'data' => $data)); $ch = curl_init(); $ePrescribeURL = Zend_Registry::get('config')->healthcloud->URL; $ePrescribeURL .= 'ss-manager.raw/edit-prescriber?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey; curl_setopt($ch, CURLOPT_URL, $ePrescribeURL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $output = curl_exec($ch); trigger_error('OUTPUT: ' . $output, E_USER_NOTICE); $error = ""; $prescriberSPI = ''; $messaging->status = 'Sent'; $messaging->note = 'Prescriber data sent'; if (!curl_errno($ch)) { try { $responseXml = simplexml_load_string($output); if (isset($responseXml->error)) { $errorCode = (string) $responseXml->error->code; $errorMsg = (string) $responseXml->error->message; if (isset($responseXml->error->errorCode)) { $errorCode = (string) $responseXml->error->errorCode; } if (isset($responseXml->error->errorMsg)) { $errorMsg = (string) $responseXml->error->errorMsg; } $error = $errorMsg; trigger_error('There was an error enabling an ePresciber, Error code: ' . $errorCode . ' Error Message: ' . $errorMsg, E_USER_NOTICE); } elseif (isset($responseXml->data)) { $xml = new SimpleXMLElement($responseXml->data); $prescriber = $xml->AddPrescriberResponse->Prescriber; if (isset($xml->AddPrescriberLocationResponse)) { $prescriber = $xml->AddPrescriberLocationResponse->Prescriber; } $prescriberSPI = (string) $prescriber->Identification->SPI; } if (isset($responseXml->rawMessage)) { $messaging->rawMessage = base64_decode((string) $responseXml->rawMessage); $messaging->rawMessageResponse = base64_decode((string) $responseXml->rawMessageResponse); } } catch (Exception $e) { $error = __("There was an error connecting to HealthCloud to enable ePrescribing for this provider. Please try again or contact the system administrator."); trigger_error("There was an error enabling an ePresciber, the response couldn't be parsed as XML: " . $output, E_USER_NOTICE); } } else { $error = __("There was an error connecting to HealthCloud to enable ePrescribing for this provider. Please try again or contact the system administrator."); trigger_error("Curl error connecting to healthcare enabled an ePrescribe record: " . curl_error($ch), E_USER_NOTICE); } curl_close($ch); if (strlen($error) > 0) { $messaging->status = 'Error'; $messaging->note = $error; $ret = false; } if ($messaging->resend) { $messaging->resend = 0; } $messaging->retries++; $messaging->dateStatus = date('Y-m-d H:i:s'); $messaging->persist(); $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $this->view->error = $error; if (strlen($error) > 0) { //$this->getResponse()->setHttpResponseCode(500); $json->direct(array('error' => $error)); return; } if ($type == 'add') { $provider->sureScriptsSPI = trim($prescriberSPI); $provider->persist(); } else { $prescriberSPI = $provider->sureScriptsSPI; } $this->view->message = "ePrescribing Information Saved for Provider, assigned SPI Number: " . $prescriberSPI; $this->view->prescriberSPI = $prescriberSPI; $json->direct(array('message' => $this->view->message, 'prescriberSPI' => $prescriberSPI, 'error' => $error)); }
public function getRxReferenceNumber() { $ret = ''; if (strlen($this->refillRequestId) > 0) { $messaging = new Messaging(); $messaging->messagingId = $this->refillRequestId; $messaging->populate(); $rawMessage = $messaging->rawMessage; if (strlen($rawMessage) > 0) { $xml = new SimpleXMLElement($rawMessage); $ret = (string) $xml->Body->RefillRequest->RxReferenceNumber; } } return $ret; }