public function indexAction()
 {
     $personId = (int) $this->_getParam('personId');
     $visitId = (int) $this->_getParam('visitId');
     $identity = Zend_Auth::getInstance()->getIdentity();
     $this->view->providerId = (int) $identity->personId;
     $this->view->personId = $personId;
     $insuredRelationship = new InsuredRelationship();
     $insuredRelationship->personId = $personId;
     $insurancePrograms = array('0' => '');
     foreach ($insuredRelationship->getProgramList() as $key => $value) {
         $insurancePrograms[$key] = $value;
     }
     $this->view->insurancePrograms = $insurancePrograms;
     $visit = new Visit();
     $visit->visitId = $visitId;
     if (!$visit->populate()) {
         $visit->visitId = 0;
         $visit->dateOfTreatment = date('Y-m-d');
     }
     $this->view->visit = $visit;
     $this->view->room = Building::getBuildingDefaultLocation($this->view->providerId, (int) $identity->default_location_id);
     $facilityIterator = new FacilityIterator();
     $this->view->facilityIterator = $facilityIterator;
     $facilityIterator->setFilter(array('Practice'));
     $this->view->practices = $facilityIterator->toArray('practiceId', 'name');
     $provider = new Provider();
     $providerIterator = $provider->getIter();
     $this->view->providers = $providerIterator->toArray('personId', 'displayName');
     $this->render();
 }
 public static function handlerSSSourceData(Audit $audit)
 {
     $data = array();
     if ($audit->objectClass != 'ESignature') {
         return $data;
     }
     $eSignature = new ESignature();
     $eSignature->eSignatureId = $audit->objectId;
     $eSignature->populate();
     if ($eSignature->objectClass != 'Medication' || !strlen($eSignature->signature) > 0) {
         WebVista::log('esignature is not signed or medication');
         return $data;
     }
     // MEDICATION DATA
     $medication = new Medication();
     $medication->medicationId = (int) $eSignature->objectId;
     $medication->populate();
     if ($medication->transmit != 'ePrescribe' || $medication->isScheduled()) {
         WebVista::log('medication is either scheduled or not an eprescribe');
         return $data;
     }
     WebVista::log('generating source data');
     $data['_audit'] = $audit;
     $uuid = NSDR::create_guid();
     $data['messageId'] = str_replace('-', '', $uuid);
     $data['prescriberOrderNumber'] = $medication->medicationId . '_' . $audit->auditId;
     $data['rxReferenceNumber'] = $medication->rxReferenceNumber;
     WebVista::log('messageId:[' . $data['messageId'] . '] prescriberOrderNumber:[' . $data['prescriberOrderNumber'] . '], rxReferenceNumber:[' . $data['rxReferenceNumber'] . ']');
     $medData = array();
     $medData['description'] = $medication->description;
     $medData['strength'] = $medication->dose;
     $qualifiers = Medication::listQuantityQualifiersMapping();
     $medData['strengthUnits'] = $qualifiers[$medication->quantityQualifier];
     // temporarily set to the same with quantity
     $medData['quantity'] = $medication->quantity;
     $medData['quantityUnits'] = $qualifiers[$medication->quantityQualifier];
     $medData['daysSupply'] = $medication->daysSupply;
     $medData['directions'] = $medication->directions;
     $qualifier = 'R';
     if ($medication->prn) {
         $qualifier = 'PRN';
     }
     $medData['refills'] = $medication->refills;
     $medData['refillsUnits'] = $qualifier;
     $medData['substitutions'] = $medication->substitution ? '0' : '1';
     $writtenDate = date('Ymd', strtotime($medication->datePrescribed));
     if ($medication->datePrescribed == '0000-00-00 00:00:00') {
         $writtenDate = '';
     }
     $medData['writtenDate'] = $writtenDate;
     $medData['productCode'] = $medication->hipaaNDC;
     $medData['productQualifier'] = 'ND';
     $medData['dosageForm'] = DataTables::getDosageForm($medication->chmedDose);
     $medData['drugDBCode'] = $medication->pkey;
     $medData['drugDBQualifier'] = '';
     //'pkey'; valid options: "E|G|FG|FS|MC|MD|MG|MM"
     $medData['note'] = $medication->comment;
     $data['Medication'] = $medData;
     WebVista::log('medication data: ' . print_r($medData, true));
     // PHARMACY DATA
     $pharmacy = new Pharmacy();
     $pharmacy->pharmacyId = $medication->pharmacyId;
     $pharmacy->populate();
     $pharmacyData = array();
     $pharmacyData['NCPDPID'] = $pharmacy->NCPDPID;
     $pharmacyData['fileId'] = $pharmacy->pharmacyId;
     $pharmacyData['NPI'] = $pharmacy->NPI;
     $pharmacyData['storeName'] = $pharmacy->StoreName;
     $pharmacyData['storeNumber'] = $pharmacy->StoreNumber;
     $pharmacyData['email'] = $pharmacy->Email;
     $pharmacyData['twentyFourHourFlag'] = $pharmacy->TwentyFourHourFlag;
     $pharmacyData['crossStreet'] = $pharmacy->CrossStreet;
     $pharmacyData['addressLine1'] = $pharmacy->AddressLine1;
     $pharmacyData['addressLine2'] = $pharmacy->AddressLine2;
     $pharmacyData['city'] = $pharmacy->City;
     $pharmacyData['state'] = $pharmacy->State;
     $pharmacyData['zip'] = $pharmacy->Zip;
     $phones = array();
     $phones[] = array('number' => $pharmacy->PhonePrimary, 'type' => 'TE');
     $phones[] = array('number' => $pharmacy->Fax, 'type' => 'FX');
     $phones[] = array('number' => $pharmacy->PhoneAlt1, 'type' => $pharmacy->PhoneAlt1Qualifier);
     $phones[] = array('number' => $pharmacy->PhoneAlt2, 'type' => $pharmacy->PhoneAlt2Qualifier);
     $phones[] = array('number' => $pharmacy->PhoneAlt3, 'type' => $pharmacy->PhoneAlt3Qualifier);
     $phones[] = array('number' => $pharmacy->PhoneAlt4, 'type' => $pharmacy->PhoneAlt4Qualifier);
     $phones[] = array('number' => $pharmacy->PhoneAlt5, 'type' => $pharmacy->PhoneAlt5Qualifier);
     $pharmacyData['phones'] = $phones;
     $data['Pharmacy'] = $pharmacyData;
     WebVista::log('pharmacy data: ' . print_r($pharmacyData, true));
     // PRESCRIBER DATA
     $provider = new Provider();
     $provider->personId = $medication->prescriberPersonId;
     $provider->populate();
     $prescriberData = array();
     $prescriberData['DEANumber'] = $provider->deaNumber;
     // it has conflicts with DEANumber
     //$prescriberData['stateLicenseNumber'] = $provider->stateLicenseNumber;
     $prescriberData['fileId'] = $provider->personId;
     $prescriberData['clinicName'] = '';
     $identifierType = $provider->identifierType;
     if (strlen($identifierType) > 0) {
         //	$prescriberData[$identifierType] = $provider->identifier;
     }
     $prescriberData['lastName'] = $provider->person->lastName;
     $prescriberData['firstName'] = $provider->person->firstName;
     $prescriberData['middleName'] = $provider->person->middleName;
     $prescriberData['suffix'] = $provider->person->suffix;
     $prescriberData['prefix'] = '';
     $prescriberData['email'] = $provider->person->email;
     $prescriberData['specialtyCode'] = $provider->specialty;
     $specialtyQualifier = '';
     if (strlen($provider->specialty) > 0) {
         $specialtyQualifier = 'AM';
     }
     $prescriberData['specialtyQualifier'] = $specialtyQualifier;
     $building = Building::getBuildingDefaultLocation((int) $provider->personId);
     $ePrescriber = new EPrescriber();
     $ePrescriber->providerId = (int) $provider->personId;
     $ePrescriber->buildingId = (int) $building->buildingId;
     $ePrescriber->populateWithBuildingProvider();
     $prescriberData['SPI'] = $ePrescriber->SSID;
     $prescriberData['addressLine1'] = $building->line1;
     $prescriberData['addressLine2'] = $building->line2;
     $prescriberData['city'] = $building->city;
     $prescriberData['state'] = $building->state;
     $prescriberData['zip'] = $building->zipCode;
     $prescriberData['phones'] = $building->phoneNumbers;
     $data['Prescriber'] = $prescriberData;
     WebVista::log('prescriber data: ' . print_r($prescriberData, true));
     // PATIENT DATA
     $patient = new Patient();
     $patient->personId = $medication->personId;
     $patient->populate();
     $patientData = array();
     $patientData['lastName'] = $patient->person->lastName;
     $patientData['firstName'] = $patient->person->firstName;
     $patientData['middleName'] = $patient->person->middleName;
     $patientData['suffix'] = $patient->person->suffix;
     $patientData['prefix'] = '';
     $patientData['email'] = $patient->person->email;
     $patientData['fileId'] = $patient->recordNumber;
     $patientData['medicareNumber'] = '';
     // TODO: to be implemented
     $identifierType = $patient->identifierType;
     if (strlen($identifierType) > 0) {
         $patientData[$identifierType] = $patient->identifier;
     }
     $patientData['gender'] = $patient->person->getDisplayGender();
     $dateOfBirth = date('Ymd', strtotime($patient->person->dateOfBirth));
     if ($patient->person->dateOfBirth == '0000-00-00') {
         $dateOfBirth = '';
     }
     $patientData['dateOfBirth'] = $dateOfBirth;
     $address = new Address();
     $address->personId = $patient->personId;
     $addressIterator = $address->getIteratorByPersonId();
     foreach ($addressIterator as $address) {
         break;
         // retrieves the top address
     }
     $patientData['addressLine1'] = $address->line1;
     $patientData['addressLine2'] = $address->line2;
     $patientData['city'] = $address->city;
     $patientData['state'] = $address->state;
     $patientData['zip'] = $address->zipCode;
     $phoneNumber = new PhoneNumber();
     $phoneNumber->personId = $patient->personId;
     $patientData['phones'] = $phoneNumber->phoneNumbers;
     $data['Patient'] = $patientData;
     WebVista::log('patient data: ' . print_r($patientData, true));
     // CHECK for attending/supervisor
     $attendingId = (int) TeamMember::getAttending($patient->teamId);
     $building = Building::getBuildingDefaultLocation($attendingId);
     $ePrescriber = new EPrescriber();
     $ePrescriber->providerId = $attendingId;
     $ePrescriber->buildingId = (int) $building->buildingId;
     $ePrescriber->populateWithBuildingProvider();
     if ($attendingId > 0 && strlen($ePrescriber->SSID) > 0) {
         // SUPERVISOR
         $provider = new Provider();
         $provider->personId = $attendingId;
         $provider->populate();
         $supervisorData = array();
         $supervisorData['DEANumber'] = $provider->deaNumber;
         $supervisorData['SPI'] = $ePrescriber->SSID;
         // it has conflicts with DEANumber
         //$supervisorData['stateLicenseNumber'] = $provider->stateLicenseNumber;
         $supervisorData['fileId'] = $provider->personId;
         $supervisorData['clinicName'] = '';
         $identifierType = $provider->identifierType;
         if (strlen($identifierType) > 0) {
             //	$prescriberData[$identifierType] = $provider->identifier;
         }
         $phoneNumber = new PhoneNumber();
         $phoneNumber->personId = $provider->personId;
         $supervisorData['phones'] = $phoneNumber->phoneNumbers;
         $supervisorData['lastName'] = $provider->person->lastName;
         $supervisorData['firstName'] = $provider->person->firstName;
         $supervisorData['middleName'] = $provider->person->middleName;
         $supervisorData['suffix'] = $provider->person->suffix;
         $supervisorData['prefix'] = '';
         $supervisorData['email'] = $provider->person->email;
         $supervisorData['specialtyCode'] = $provider->specialty;
         $specialtyQualifier = '';
         if (strlen($provider->specialty) > 0) {
             $specialtyQualifier = 'AM';
         }
         $supervisorData['specialtyQualifier'] = $specialtyQualifier;
         $supervisorData['addressLine1'] = $building->line1;
         $supervisorData['addressLine2'] = $building->line2;
         $supervisorData['city'] = $building->city;
         $supervisorData['state'] = $building->state;
         $supervisorData['zip'] = $building->zipCode;
         $supervisorData['phones'] = $building->phoneNumbers;
         $data['Supervisor'] = $supervisorData;
         WebVista::log('supervisor data: ' . print_r($supervisorData, true));
     }
     return $data;
 }
Exemple #3
0
 public function populate($patientId, $userId, $visitId)
 {
     $this->_patientId = (int) $patientId;
     $patient = new Patient();
     $patient->personId = $this->_patientId;
     $patient->populate();
     $this->_title = $patient->displayName . ' Healthcare Record';
     $this->patient = $patient;
     $this->_userId = (int) $userId;
     $user = new User();
     $user->personId = $this->_userId;
     $user->populate();
     $this->user = $user;
     $visit = new Visit();
     $visit->visitId = (int) $visitId;
     if ($visit->visitId > 0 && $visit->populate()) {
         $this->visit = $visit;
     }
     $this->building = Building::getBuildingDefaultLocation($this->user->personId);
     $performers = array();
     $problemList = new ProblemList();
     $filters = array();
     $filters['personId'] = $this->_patientId;
     $this->setFiltersDateRange($filters);
     $problems = array();
     $problemListIterator = new ProblemListIterator();
     $problemListIterator->setFilters($filters);
     foreach ($problemListIterator as $problem) {
         $problems[] = $problem;
         $providerId = (int) $problem->providerId;
         if (!isset($performers[$providerId])) {
             $provider = new Provider();
             $provider->personId = $providerId;
             $provider->populate();
             $performers[$providerId] = $provider;
         }
     }
     $this->problemLists = $problems;
     unset($filters['personId']);
     $filters['patientId'] = $this->_patientId;
     $labResults = array();
     $labTests = array();
     $labOrderTests = array();
     $labsIterator = new LabsIterator();
     $labsIterator->setFilters($filters);
     foreach ($labsIterator as $lab) {
         // get the lab order
         $labTestId = (int) $lab->labTestId;
         if (!isset($labTests[$labTestId])) {
             $labTest = new LabTest();
             $labTest->labTestId = (int) $lab->labTestId;
             $labTest->populate();
             $labTests[$labTestId] = $labTest;
         }
         $labTest = $labTests[$labTestId];
         $orderId = (int) $labTest->labOrderId;
         if (!isset($labOrderTests[$orderId])) {
             $orderLabTest = new OrderLabTest();
             $orderLabTest->orderId = $orderId;
             $orderLabTest->populate();
             $labOrderTests[$orderId] = $orderLabTest;
         }
         $orderLabTest = $labOrderTests[$orderId];
         $providerId = (int) $orderLabTest->order->providerId;
         if (!isset($performers[$providerId])) {
             $provider = new Provider();
             $provider->personId = $providerId;
             $provider->populate();
             $performers[$providerId] = $provider;
         }
         if (!isset($labResults[$orderId])) {
             $labResults[$orderId] = array();
             $labResults[$orderId]['results'] = array();
             $labResults[$orderId]['labTest'] = $labTest;
             $labResults[$orderId]['orderLabTest'] = $orderLabTest;
         }
         $labResults[$orderId]['results'][] = $lab;
     }
     $this->labResults = $labResults;
     $this->performers = $performers;
     $this->populateHeader($this->_xml);
     $this->populateBody($this->_xml);
     return $this->_xml->asXML();
 }
 protected function _checkCurrentLocation(Medication $medication)
 {
     $identity = Zend_Auth::getInstance()->getIdentity();
     $personId = (int) $identity->personId;
     $building = Building::getBuildingDefaultLocation($personId);
     $ret = false;
     if ($building->buildingId > 0) {
         $eprescriber = new EPrescriber();
         $eprescriber->populateWithBuildingProvider((int) $building->buildingId, $personId);
         $location = 'for location: ' . $building->practice->name . '->' . $building->name;
         $err = $medication->summary . ' could not be signed because: ';
         if (!strlen($eprescriber->SSID) > 0) {
             $ret = $err . 'Medication will be ePrescribed and you do not have an SPI ' . $location;
         } else {
             $tmp = array();
             $line1Len = strlen($building->line1);
             if (!$line1Len > 0 || $line1Len > 35) {
                 $tmp[] = 'Address line1 field must be supplied and not more than 35 characters';
             }
             $line2Len = strlen($building->line2);
             if ($line2Len > 0 && $line2Len > 35) {
                 $tmp[] = 'Address line2 must not be more than 35 characters';
             }
             $cityLen = strlen($building->city);
             if (!$cityLen > 0 || $cityLen > 35) {
                 $tmp[] = 'Address city field must be supplied and not more than 35 characters';
             }
             if (strlen($building->state) != 2) {
                 $tmp[] = 'Address state field must be supplied and not more than 2 characters';
             }
             $zipCodeLen = strlen($building->zipCode);
             if ($zipCodeLen != 5 && $zipCodeLen != 9) {
                 $tmp[] = 'Address zipcode must be supplied and must be 5 or 9 digit long';
             }
             $phoneNumber = PhoneNumber::autoFixNumber($building->phoneNumber);
             $fax = PhoneNumber::autoFixNumber($building->fax);
             if (strlen($phoneNumber) < 11) {
                 $tmp[] = 'Phone number \'' . $phoneNumber . '\' is invalid';
             }
             $faxLen = strlen($fax);
             if ($faxLen > 0 && $faxLen < 11) {
                 $tmp[] = 'Fax number \'' . $fax . '\' is invalid';
             }
             if (count($tmp) > 0) {
                 $ret = $err . "\n" . implode("\n", $tmp) . ' ' . $location;
             }
         }
     } else {
         $ret = $medication->summary . ' could not be signed because: Medication will be ePrescribed and you do not have a default location.';
     }
     return $ret;
 }
 public static function generateOBR(array $data)
 {
     static $obrCtr = 1;
     $orderLabTest = $data['orderLabTest'];
     $labTest = $data['labTest'];
     $loinc = $data['loinc'];
     $obr = 'OBR|' . $obrCtr++ . '||' . $labTest->filerOrderNum . '^Lab^2.16.840.1.113883.19.3.1.6^ISO|';
     $altIdentifier = '3456543';
     $obr .= $loinc->loincNum . '^' . $loinc->shortname . '^LN^' . $altIdentifier . '^' . $labTest->service . '^99USI|||';
     // concatenated diagnoses ,
     $diagnoses = array();
     $iterator = new PatientDiagnosisIterator();
     $iterator->setFilters(array('patientId' => (int) $orderLabTest->order->patientId));
     foreach ($iterator as $pd) {
         $diagnoses[$pd->code] = $pd->diagnosis;
     }
     $relevantClinicalInfo = implode(',', $diagnoses);
     $obr .= date('YmdHiO', strtotime($labTest->observationTime)) . '||||||' . $relevantClinicalInfo . '|||';
     $provider = $orderLabTest->order->provider;
     $providerId = strlen($provider->identifier) > 0 ? $provider->identifier : $provider->personId;
     $building = Building::getBuildingDefaultLocation($provider->personId);
     if ($provider->personId > 0) {
         $obr .= $providerId . '^' . $provider->person->lastName . '^' . $provider->person->firstName . '^^^^^^' . $building->name . '&2.16.840.1.113883.19.4.6&ISO';
     }
     $obr .= '||||||' . date('YmdHiO', strtotime($labTest->reportTime)) . '|||' . $labTest->status . '||||||';
     $reasonForStudy = array();
     foreach ($diagnoses as $code => $description) {
         $codeSystem = strpos($code, '.') === false ? 'SCT' : 'I9CDX';
         $reasonForStudy[] = $code . '^' . $description . '^' . $codeSystem;
     }
     $obr .= implode('~', $reasonForStudy);
     return $obr;
 }