function editSignItemsAction() { $eSigIds = Zend_Json::decode($this->_getParam('electronicSignatureIds')); $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; if (strlen($eSigIds) <= 0) { $msg = __('No selected items to sign.'); WebVista::log($msg); $this->getResponse()->setHttpResponseCode(500); $json->direct(array('error' => $msg)); return; } $eSigIds = explode(',', $eSigIds); $signature = $this->_getParam('signature'); foreach ($eSigIds as $eSigId) { if (strlen($eSigId) <= 0) { continue; } $esig = new ESignature(); $esig->eSignatureId = (int) $eSigId; $esig->populate(); $objectClass = $esig->objectClass; if ($objectClass == 'Medication') { // check for possible eprescribed $medication = new Medication(); $medication->medicationId = (int) $esig->objectId; $medication->populate(); if ($medication->transmit == 'ePrescribe') { $result = $this->_checkCurrentLocation($medication); if ($result !== false) { $this->getResponse()->setHttpResponseCode(500); $json->direct(array('error' => $result)); return; } } } $signedDate = date('Y-m-d H:i:s'); $esig->signedDateTime = $signedDate; $obj = new $esig->objectClass(); $obj->documentId = $esig->objectId; $obj->eSignatureId = $esig->eSignatureId; try { $esig->sign($obj, $signature); } catch (Exception $e) { $this->getResponse()->setHttpResponseCode(500); $json->direct(array('error' => $e->getMessage())); return; } $esig->persist(); $obj->populate(); $obj->eSignatureId = $esig->eSignatureId; $obj->persist(); } }
public static function handlerSSAct(Audit $audit, array $sourceData) { if (!isset($sourceData['_audit']) || $audit->objectClass != 'ESignature') { WebVista::log('unable to send: _audit index does not exists or audit objectClass not ESignature '); return false; } $eSignature = new ESignature(); $eSignature->eSignatureId = $audit->objectId; $eSignature->populate(); if ($eSignature->objectClass != 'Medication' || !strlen($eSignature->signature) > 0) { WebVista::log('unable to send: signature is not signed or objectClass not Medication'); return false; } $medication = new Medication(); $medication->medicationId = (int) $eSignature->objectId; $medication->populate(); $medication->dateTransmitted = date('Y-m-d H:i:s'); $medication->persist(); $patientInfo = $sourceData['Patient']['lastName'] . ', ' . $sourceData['Patient']['firstName'] . ' ' . $sourceData['Patient']['middleName'] . ' MRN#' . $sourceData['Patient']['fileId']; $patientInfo .= ' - ' . $sourceData['Medication']['description'] . ' #' . date('m/d/Y', strtotime($sourceData['Medication']['writtenDate'])); WebVista::log('patient info: ' . $patientInfo); $audit = $sourceData['_audit']; unset($sourceData['_audit']); $messaging = new Messaging(); $messaging->messagingId = $sourceData['messageId']; $messaging->messageType = 'NewRx'; $messaging->populate(); $messaging->objectId = (int) $eSignature->objectId; $messaging->objectClass = $audit->objectClass; $messaging->status = 'Sending'; $messaging->note = 'Sending newRx (' . $patientInfo . ')'; $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(); if ($messaging->resend && $messaging->pharmacyId > 0) { // supersedes pharmacy from messaging $pharmacy = new Pharmacy(); $pharmacy->pharmacyId = $messaging->pharmacyId; $pharmacy->populate(); $pharmacyData = array(); $pharmacyData['NCPDPID'] = $pharmacy->NCPDPID; $pharmacyData['StoreName'] = $pharmacy->StoreName; $pharmacyData['addressLine1'] = $pharmacy->AddressLine1; $pharmacyData['addressLine2'] = $pharmacy->AddressLine2; $pharmacyData['city'] = $pharmacy->City; $pharmacyData['state'] = $pharmacy->State; $pharmacyData['zip'] = $pharmacy->Zip; $pharmacyData['phone'] = $pharmacy->PhonePrimary; $pharmacyData['fax'] = ''; $sourceData['Pharmacy'] = $pharmacyData; } $query = http_build_query(array('data' => $sourceData)); $ch = curl_init(); $ePrescribeURL = Zend_Registry::get('config')->healthcloud->URL; $ePrescribeURL .= 'ss-manager.raw/new-rx?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey; WebVista::log('SS URL: ' . $ePrescribeURL); WebVista::log('URL Query: ' . $query); 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); curl_setopt($ch, CURLOPT_USERPWD, 'admin:ch3!'); $output = curl_exec($ch); $error = ''; $messaging->status = 'Sent'; $messaging->note = 'newRx pending'; $messaging->unresolved = 1; WebVista::log('RESPONSE: ' . $output); if (!curl_errno($ch)) { try { $responseXml = new SimpleXMLElement($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 prescribing new medication, Error code: ' . $errorCode . ' Error Message: ' . $errorMsg, E_USER_NOTICE); } else { if (isset($responseXml->status)) { $messaging->note = 'newRx awaiting confirmation'; if ((string) $responseXml->status->code == '010') { // value 000 is for free standing error? $messaging->status .= ' and Verified'; $messaging->note = 'newRx sent and verified'; $messaging->unresolved = 0; } } else { $error = 'Unrecognized HealthCloud response: ' . $output; } } 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 prescribe new medication. Please try again or contact the system administrator."); trigger_error("There was an error prescribing new medication, the response couldn't be parsed as XML: " . $output, E_USER_NOTICE); } } else { $error = __("There was an error connecting to HealthCloud to prescribe new medication. Please try again or contact the system administrator."); trigger_error("Curl error connecting to healthcare prescribed new medication: " . curl_error($ch), E_USER_NOTICE); } $messaging->note .= ' (' . $patientInfo . ')'; curl_close($ch); $ret = true; if (strlen($error) > 0) { $messaging->status = 'Error'; $patientInfo = $sourceData['Patient']['lastName'] . ', ' . $sourceData['Patient']['firstName'] . ' ' . $sourceData['Patient']['middleName'] . ' MRN#' . $sourceData['Patient']['fileId']; $providerInfo = $sourceData['Prescriber']['lastName'] . ', ' . $sourceData['Prescriber']['firstName'] . ' ' . $sourceData['Prescriber']['middleName']; $medicationInfo = $sourceData['Medication']['description'] . ' #' . date('m/d/Y', strtotime($sourceData['Medication']['writtenDate'])); $messaging->note = $error . ' Patient: ' . $patientInfo . ' Provider: ' . $providerInfo . ' Medication: ' . $medicationInfo; $ret = false; } if ($messaging->resend) { $messaging->resend = 0; } $messaging->retries++; $messaging->dateStatus = date('Y-m-d H:i:s'); $messaging->persist(); return $ret; }
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); }