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;
 }
 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 buildJSJumpLink($objectId, $signingUserId, $objectClass)
    {
        $objectClass = 'Medications';
        // temporarily hard code objectClass based on MainController::getMainTabs() definitions
        $medication = new Medication();
        $medication->medicationId = $objectId;
        $medication->populate();
        $patientId = $medication->personId;
        $js = parent::buildJSJumpLink($objectId, $patientId, $objectClass);
        $js .= <<<EOL

mainTabbar.setOnTabContentLoaded(function(tabId){
\tloadMedication(objectId);
\topenNewMedicationWindow(objectId);
});

EOL;
        return $js;
    }
Example #4
0
 public static function sendResponse($data, Messaging $messaging)
 {
     $messageInfo = '';
     if (strlen($data['message']) > 0) {
         $xmlMessage = new SimpleXMLElement($data['message']);
         $lastName = (string) $xmlMessage->Body->RefillRequest->Patient->Name->LastName;
         $firstName = (string) $xmlMessage->Body->RefillRequest->Patient->Name->FirstName;
         $messageInfo = $lastName . ', ' . $firstName;
         $description = (string) $xmlMessage->Body->RefillRequest->MedicationPrescribed->DrugDescription;
         $datePrescribed = date('m/d/Y', strtotime((string) $xmlMessage->Body->RefillRequest->MedicationPrescribed->WrittenDate));
         $messageInfo .= ' - ' . $description . ' #' . $datePrescribed;
     }
     $tmpMessaging = $messaging;
     $messaging = new Messaging();
     //		$messaging->messagingId = $messageId;
     //		$messaging->populate();
     $messaging->messageType = 'RefillResponse';
     $messaging->objectId = $tmpMessaging->messagingId;
     $messaging->objectClass = 'MedicationRefillResponse';
     $messaging->status = 'Sending';
     $messaging->note = 'Sending refill response (' . $messageInfo . ')';
     $messaging->dateStatus = date('Y-m-d H:i:s');
     $messaging->auditId = $tmpMessaging->auditId;
     $messaging->persist();
     if (isset($data['medicationId'])) {
         $medicationId = $data['medicationId'];
         unset($data['medicationId']);
         $medication = new Medication();
         $medication->medicationId = $medicationId;
         if ($medication->populate()) {
             $medData = array();
             $medData['description'] = $medication->description;
             $medData['strength'] = $medication->strength;
             $medData['strengthUnits'] = '00';
             //$medication->unit;
             $medData['quantity'] = $medication->quantity;
             $medData['quantityUnits'] = '00';
             $medData['directions'] = $medication->directions;
             $qualifier = 'R';
             if ($medication->prn) {
                 $qualifier = 'PRN';
             }
             $medData['refills'] = $medication->refills;
             $medData['refillsUnits'] = $qualifier;
             $medData['substitutions'] = $medication->substitution;
             $medData['writtenDate'] = date('Ymd', strtotime($medication->datePrescribed));
             $data['Medication'] = $medData;
         }
     }
     $query = http_build_query($data);
     $ch = curl_init();
     $ePrescribeURL = Zend_Registry::get('config')->healthcloud->URL;
     $ePrescribeURL .= 'ss-manager.raw/receive-response?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);
     $error = '';
     $rawMessage = '';
     $messaging->status = 'Sent';
     $messaging->note = 'Refill response pending';
     $messaging->unresolved = 1;
     if (!curl_errno($ch)) {
         try {
             $xml = new SimpleXMLElement($output);
             if (isset($xml->error)) {
                 $errorCode = (string) $xml->error->code;
                 $errorMsg = (string) $xml->error->message;
                 if (isset($xml->error->errorCode)) {
                     $errorCode = (string) $xml->error->errorCode;
                 }
                 if (isset($xml->error->errorMsg)) {
                     $errorMsg = (string) $xml->error->errorMsg;
                 }
                 $error = $errorMsg;
                 trigger_error('There was an error sending refill response, Error code: ' . $errorCode . ' Error Message: ' . $errorMsg, E_USER_NOTICE);
             } else {
                 if (isset($xml->status)) {
                     $messaging->note = 'Refill response awaiting confirmation';
                     if ((string) $xml->status->code == '010') {
                         // value 000 is for free standing error?
                         $messaging->status .= ' and Verified';
                         $messaging->note = 'Refill response sent and verified';
                         $messaging->unresolved = 0;
                     }
                 } else {
                     $error = 'Unrecognized HealthCloud response: ' . $output;
                 }
             }
             if (isset($xml->rawMessage)) {
                 $messaging->rawMessage = base64_decode((string) $xml->rawMessage);
                 $messaging->rawMessageResponse = base64_decode((string) $xml->rawMessageResponse);
             }
         } 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);
     }
     $messaging->note .= ' (' . $messageInfo . ')';
     curl_close($ch);
     $ret = true;
     if (strlen($error) > 0) {
         $messaging->status = 'Error';
         $messaging->note = $error;
         $ret = $error;
     }
     if ($messaging->resend) {
         $messaging->resend = 0;
     }
     $messaging->retries++;
     $messaging->dateStatus = date('Y-m-d H:i:s');
     $messaging->persist();
     return $ret;
 }
 public function newRxAction()
 {
     $medicationId = 1077476;
     $data = array();
     $medication = new Medication();
     $medication->medicationId = $medicationId;
     $medication->populate();
     $data['PrescriberOrderNumber'] = $medication->medicationId;
     $medData = array();
     $medData['DrugDescription'] = $medication->description;
     $medData['Strength'] = $medication->strength;
     $medData['StrengthUnits'] = $medication->unit;
     $medData['Quantity'] = $medication->quantity;
     $medData['Directions'] = $medication->directions;
     $medData['Refills'] = $medication->refills;
     $medData['Substitutions'] = $medication->substitution;
     $medData['WrittenDate'] = date('Ymd', strtotime($medication->datePrescribed));
     $data['medication'] = $medData;
     $pharmacy = new Pharmacy();
     $pharmacy->pharmacyId = $medication->pharmacyId;
     $pharmacy->populate();
     $pharmacyData = array();
     $pharmacyData['NCPDPID'] = $pharmacy->NCPDPID;
     $pharmacyData['StoreName'] = $pharmacy->StoreName;
     $pharmacyData['AddressLine1'] = $pharmacy->AddressLine1 . ' ' . $pharmacy->AddressLine2;
     $pharmacyData['City'] = $pharmacy->City;
     $pharmacyData['State'] = $pharmacy->State;
     $pharmacyData['ZipCode'] = $pharmacy->Zip;
     $pharmacyData['PhoneNumber'] = $pharmacy->PhonePrimary;
     $data['pharmacy'] = $pharmacyData;
     $provider = new Provider();
     $provider->personId = $medication->prescriberPersonId;
     $provider->populate();
     $prescriberData = array();
     $prescriberData['DEANumber'] = $provider->deaNumber;
     $prescriberData['SPI'] = $provider->sureScriptsSPI;
     $prescriberData['ClinicName'] = '';
     $prescriberData['LastName'] = $provider->person->lastName;
     $prescriberData['FirstName'] = $provider->person->firstName;
     $prescriberData['Suffix'] = '';
     $address = new Address();
     $address->personId = $provider->personId;
     $address->populateWithPersonId();
     $prescriberData['AddressLine1'] = $address->line1 . ' ' . $address->line2;
     $prescriberData['City'] = $address->city;
     $prescriberData['State'] = 'AZ';
     //$address->state;
     $prescriberData['ZipCode'] = $address->zipCode;
     $phoneNumber = new PhoneNumber();
     $phoneNumber->personId = $provider->personId;
     $phoneNumber->populateWithPersonId();
     $prescriberData['PhoneNumber'] = $phoneNumber->number;
     $data['prescriber'] = $prescriberData;
     $patient = new Patient();
     $patient->personId = $medication->personId;
     $patient->populate();
     $patientData = array();
     $patientData['LastName'] = $patient->person->lastName;
     $patientData['FirstName'] = $patient->person->firstName;
     $patientData['Gender'] = $patient->person->gender;
     $patientData['DateOfBirth'] = date('Ymd', strtotime($patient->person->dateOfBirth));
     $address = new Address();
     $address->personId = $patient->personId;
     $address->populateWithPersonId();
     $patientData['AddressLine1'] = $address->line1 . ' ' . $address->line2;
     $patientData['City'] = $address->city;
     $patientData['State'] = 'AZ';
     //$address->state;
     $patientData['ZipCode'] = $address->zipCode;
     $phoneNumber = new PhoneNumber();
     $phoneNumber->personId = $patient->personId;
     $phoneNumber->populateWithPersonId();
     $patientData['PhoneNumber'] = $phoneNumber->number;
     $data['patient'] = $patientData;
     $postFields = array();
     foreach ($data as $type => $row) {
         if (is_array($row)) {
             foreach ($row as $field => $value) {
                 $key = $type . '[' . $field . ']';
                 $postFields[$key] = $value;
             }
         } else {
             $postFields[$type] = $row;
         }
     }
     $ch = curl_init();
     $ePrescribeURL = Zend_Registry::get('config')->healthcloud->URL;
     $ePrescribeURL .= 'ss-manager.raw/new-rx?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey;
     curl_setopt($ch, CURLOPT_URL, $ePrescribeURL);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
     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);
     trigger_error('OUTPUT: ' . $output, E_USER_NOTICE);
     $error = "";
     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 prescribing new medication, Error code: ' . $errorCode . ' Error Message: ' . $errorMsg, E_USER_NOTICE);
             }
         } 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 prescribeing 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);
     }
     curl_close($ch);
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     if (strlen($error) > 0) {
         $this->getResponse()->setHttpResponseCode(500);
         $json->direct(array('error' => $error));
         return;
     }
     $json->direct(true);
 }
Example #6
0
 protected static function _checkMedication(HealthStatusHandler $handler, $patientId, $audit)
 {
     $ret = false;
     if ($audit->objectClass != 'Medication') {
         return $ret;
     }
     $db = Zend_Registry::get('dbAdapter');
     $medication = new Medication();
     $medication->medicationId = (int) $audit->objectId;
     $medication->populate();
     $s = $medication->description;
     if (preg_match('/avandia/i', $s)) {
         $message = 'Patient may be suitable for referral to Diabetes Counseling';
     } else {
         if (preg_match('/hydrochlorothiazide/i', $s)) {
             $message = 'Patient may be suitable for treatment of hypertension with a diuretic such as Hydrochlorothiazide';
         } else {
             if (preg_match('/lipitor/i', $s)) {
                 $message = 'Patient may benefit from hypercholesteremia drug such as Lipitor';
                 $sqlSelect = $db->select()->from('chmed.basemed24', array('md5', 'vaclass'))->where('pkey = ?', $medication->pkey);
                 $hasAllergy = false;
                 if ($row = $db->fetchRow($sqlSelect)) {
                     $personId = (int) $patientId;
                     $md5 = $row['md5'];
                     $vaclass = $row['vaclass'];
                     // check for allergy interactions
                     do {
                         // regular allergies search
                         $interactionIterator = new BaseMed24InteractionIterator();
                         $interactionIterator->setFilters(array('personId' => $personId, 'md5' => $md5));
                         $regularAllergies = $interactionIterator->toJsonArray('hipaa_ndc', array('tradename', 'fda_drugname', 'notice'));
                         $tmpArray = $regularAllergies;
                         $regularAllergies = array();
                         foreach ($tmpArray as $key => $value) {
                             $hasAllergy = true;
                             break 2;
                         }
                         // drug class search
                         $patientAllergyIterator = new PatientAllergyIterator();
                         $patientAllergyIterator->setFilters(array('patientId' => $personId, 'enteredInError' => 0, 'drugAllergy' => $vaclass, 'reactionType' => 'Drug Class Allergy'));
                         $drugClassAllergies = array();
                         foreach ($patientAllergyIterator as $allergy) {
                             $hasAllergy = true;
                             break 2;
                         }
                         // specific drug search
                         $patientAllergyIterator->setFilters(array('patientId' => $personId, 'enteredInError' => 0, 'drugAllergy' => $md5, 'reactionType' => 'Specific Drug Allergy'));
                         $specificDrugAllergies = array();
                         foreach ($patientAllergyIterator as $allergy) {
                             $hasAllergy = true;
                             break 2;
                         }
                     } while (false);
                 }
                 if ($hasAllergy) {
                     $message .= '. NOTE: Consult patients allergies: Lipitor/Atorvastatin';
                 }
             } else {
                 return $ret;
             }
         }
     }
     self::createHSA($handler, $patientId, $message);
     return true;
 }