Exemplo n.º 1
0
 protected static function _getPatientData($patient, $includeProvider = true, $providerId = null, $roomId = null)
 {
     $maritalStatusMap = array('SEPARATED' => 'A', 'DIVORCED' => 'D', 'MARRIED' => 'M', 'SINGLE' => 'S', 'WIDOWED' => 'W');
     if (!$patient instanceof Patient) {
         $patientId = (int) $patient;
         $patient = new Patient();
         $patient->personId = $patientId;
         $patient->populate();
     }
     $personId = (int) $patient->personId;
     $person = $patient->person;
     $maritalStatus = $person->maritalStatus;
     if (isset($maritalStatusMap[$maritalStatus])) {
         $maritalStatus = $maritalStatusMap[$maritalStatus];
     }
     $ethnicities = array();
     $ethnicities['1'] = 1;
     $ethnicities['Hispanic/Latino'] = 1;
     $ethnicities['2'] = 2;
     $ethnicities['Not Hispanic/Latino'] = 2;
     $ethnicities['3'] = 3;
     $ethnicities['Unreported / Refused to Report'] = 3;
     $races = array();
     $races['A'] = 'A';
     $races['Asian'] = 'A';
     $races['N'] = 'N';
     $races['Native Hawaiian'] = 'N';
     $races['P'] = 'P';
     $races['Other Pacific Islander'] = 'P';
     $races['B'] = 'B';
     $races['Black / African American'] = 'B';
     $races['I'] = 'I';
     $races['American Indian / Alaska Native'] = 'I';
     $races['W'] = 'C';
     $races['White'] = 'C';
     $races['M'] = 'M';
     $races['More than one race'] = 'M';
     $races['E'] = 'E';
     $races['Unreported / Refused to Report'] = 'E';
     $statistics = PatientStatisticsDefinition::getPatientStatistics($personId);
     $race = '';
     if (isset($statistics['Race'])) {
         $race = $statistics['Race'];
     }
     if (isset($statistics['race'])) {
         $race = $statistics['race'];
     }
     $race = isset($races[$race]) ? $races[$race] : 'E';
     $ethnicity = '';
     if (isset($statistics['Ethnicity'])) {
         $ethnicity = $statistics['Ethnicity'];
     }
     if (isset($statistics['ethnicity'])) {
         $ethnicity = $statistics['ethnicity'];
     }
     $ethnicity = isset($ethnicities[$ethnicity]) ? $ethnicities[$ethnicity] : '3';
     $language = '';
     if (isset($statistics['Language'])) {
         $language = $statistics['Language'];
     }
     if (isset($statistics['language'])) {
         $language = $statistics['language'];
     }
     $language = '';
     // temporarily set to empty
     $patientData = array();
     $patientData['recordNumber'] = $patient->recordNumber;
     $patientData['lastName'] = $person->lastName;
     $patientData['firstName'] = $person->firstName;
     $patientData['middleName'] = $person->middleName;
     $patientData['suffix'] = $person->suffix;
     $patientData['dateOfBirth'] = date('Ymd', strtotime($person->dateOfBirth));
     $patientData['gender'] = $person->gender;
     $patientData['race'] = $race;
     $patientData['ethnicity'] = $ethnicity;
     $address = $person->address;
     $patientData['line1'] = $address->line1;
     $patientData['line2'] = $address->line2;
     $patientData['city'] = $address->city;
     $patientData['state'] = $address->state;
     $patientData['zip'] = $address->postalCode;
     $homePhone = '';
     $businessPhone = '';
     $phoneNumber = new PhoneNumber();
     $phoneNumber->personId = $personId;
     $phones = $phoneNumber->getPhoneNumbers(false);
     foreach ($phones as $phone) {
         if ($homePhone == '' && $phone['type'] == 'HP') {
             $homePhone = $phone['number'];
         }
         if ($businessPhone == '' && $phone['type'] == 'TE') {
             $businessPhone = $phone['number'];
         }
         if ($homePhone != '' && $businessPhone != '') {
             break;
         }
     }
     $patientData['homePhone'] = $homePhone;
     $patientData['businessPhone'] = $businessPhone;
     $patientData['language'] = $language;
     $patientData['maritalStatus'] = $maritalStatus;
     $patientData['accountNumber'] = '';
     $patientData['ssn'] = $patient->person->identifierType == 'SSN' ? $patient->identifier : '';
     if (!$includeProvider) {
         return $patientData;
     }
     $data = array();
     $data['patient'] = $patientData;
     if ($providerId === null) {
         $providerId = (int) $patient->defaultProvider;
     }
     $provider = new Provider();
     $provider->personId = $providerId;
     $provider->populate();
     $provider->populate();
     $providerData = array();
     $providerData['id'] = $provider->personId;
     $providerData['lastName'] = $provider->person->lastName;
     $providerData['firstName'] = $provider->person->firstName;
     $providerData['middleName'] = $provider->person->middleName;
     $providerData['suffix'] = $provider->person->suffix;
     $room = new Room();
     if ($roomId !== null && $roomId > 0) {
         $room->roomId = (int) $roomId;
         $room->populate();
         $building = $room->building;
         $practice = $building->practice;
         //trigger_error('room: '.$roomId.':'.$room->name);
     } else {
         $practice = new Practice();
         $building = new Building();
         $practiceId = (int) $patient->person->primaryPracticeId;
         $practice->practiceId = $practiceId;
         $practice->populate();
         //trigger_error('primary practice: '.$practiceId.':'.$practice->name);
     }
     $providerData['practice'] = $practice->name;
     $providerData['building'] = $building->name;
     $providerData['room'] = $room->name;
     $data['provider'] = $providerData;
     return $data;
 }
Exemplo n.º 2
0
 public function populateHeader(SimpleXMLElement $xml)
 {
     $patientName = array();
     $patientName['given'] = $this->patient->person->firstName;
     $patientName['family'] = $this->patient->person->lastName;
     $patientName['suffix'] = $this->patient->person->suffix;
     $providerName = array();
     $providerName['prefix'] = $this->user->person->prefix;
     $providerName['given'] = $this->user->person->firstName;
     $providerName['family'] = $this->user->person->lastName;
     $building = $this->building;
     $buildingName = $building->displayName;
     $realmCode = $xml->addChild('realmCode');
     $realmCode->addAttribute('code', 'US');
     $typeId = $xml->addChild('typeId');
     $typeId->addAttribute('root', '2.16.840.1.113883.1.3');
     $typeId->addAttribute('extension', 'POCD_HD000040');
     $templateId = $xml->addChild('templateId');
     $templateId->addAttribute('root', '2.16.840.1.113883.3.27.1776');
     $templateId->addAttribute('assigningAuthorityName', 'CDA/R2');
     $templateId = $xml->addChild('templateId');
     $templateId->addAttribute('root', '2.16.840.1.113883.10.20.3');
     $templateId->addAttribute('assigningAuthorityName', 'HL7/CDT Header');
     $templateId = $xml->addChild('templateId');
     $templateId->addAttribute('root', '1.3.6.1.4.1.19376.1.5.3.1.1.1');
     $templateId->addAttribute('assigningAuthorityName', 'IHE/PCC');
     $templateId = $xml->addChild('templateId');
     $templateId->addAttribute('root', '2.16.840.1.113883.3.88.11.32.1');
     $templateId->addAttribute('assigningAuthorityName', 'HITSP/C32');
     $id = $xml->addChild('id');
     $id->addAttribute('root', '2.16.840.1.113883.3.72');
     $id->addAttribute('extension', 'HITSP_C32v2.5');
     $id->addAttribute('assigningAuthorityName', 'ClearHealth');
     $code = $xml->addChild('code');
     $code->addAttribute('code', '34133-9');
     $displayName = 'Summarization of episode note';
     $code->addAttribute('displayName', $displayName);
     $code->addAttribute('codeSystem', '2.16.840.1.113883.6.1');
     $code->addAttribute('codeSystemName', 'LOINC');
     $xml->addChild('title', html_convert_entities($this->_title));
     $effectiveTime = $xml->addChild('effectiveTime');
     $dateEffective = self::formatDate();
     $effectiveTime->addAttribute('value', $dateEffective);
     $confidentialityCode = $xml->addChild('confidentialityCode');
     $confidentialityCode->addAttribute('code', 'N');
     //$confidentialityCode->addAttribute('codeSystem','2.16.840.1.113883.5.25');
     $languageCode = $xml->addChild('languageCode');
     $languageCode->addAttribute('code', 'en-US');
     // RECORD TARGET
     $recordTarget = $xml->addChild('recordTarget');
     $patientRole = $recordTarget->addChild('patientRole');
     $id = $patientRole->addChild('id');
     //$id->addAttribute('root','CLINICID');
     $id->addAttribute('root', 'MRN');
     //$id->addAttribute('extension','PatientID');
     $id->addAttribute('extension', html_convert_entities($this->patient->recordNumber));
     // Address
     $address = new Address();
     $address->personId = $this->_patientId;
     $addressIterator = $address->getIteratorByPersonId();
     foreach ($addressIterator as $address) {
         break;
         // retrieves the top address
     }
     $addr = $patientRole->addChild('addr');
     if ($address->addressId > 0) {
         $addr->addAttribute('use', 'HP');
         $addr->addChild('streetAddressLine', html_convert_entities(strlen($address->line2) > 0 ? $address->line1 . ' ' . $address->line2 : $address->line1));
         $addr->addChild('city', html_convert_entities($address->city));
         $addr->addChild('state', html_convert_entities($address->state));
         $addr->addChild('postalCode', html_convert_entities($address->zipCode));
     }
     // Telecom
     $phone = null;
     $phoneNumber = new PhoneNumber();
     $phoneNumber->personId = $this->_patientId;
     foreach ($phoneNumber->getPhoneNumbers(false) as $phone) {
         break;
         // retrieves the top phone
     }
     $telecom = $patientRole->addChild('telecom');
     if ($phone && strlen($phone['number']) > 0) {
         $telecom->addAttribute('use', 'HP');
         $telecom->addAttribute('value', 'tel:' . html_convert_entities($phone['number']));
     }
     // Patient
     $patient = $patientRole->addChild('patient');
     $name = $patient->addChild('name');
     $name->addChild('given', html_convert_entities($patientName['given']));
     $name->addChild('family', html_convert_entities($patientName['family']));
     $name->addChild('suffix', html_convert_entities($patientName['suffix']));
     $genderCode = $patient->addChild('administrativeGenderCode');
     $genderCode->addAttribute('code', html_convert_entities($this->patient->person->gender));
     $genderCode->addAttribute('displayName', html_convert_entities($this->patient->person->displayGender));
     $genderCode->addAttribute('codeSystem', '2.16.840.1.113883.5.1');
     $genderCode->addAttribute('codeSystemName', 'HL7 AdministrativeGender');
     $birthTime = $patient->addChild('birthTime');
     $birthTime->addAttribute('value', date('Ymd', strtotime($this->patient->person->dateOfBirth)));
     /*$maritalStatusCode = $patient->addChild('maritalStatusCode');
     		$maritalStatusCode->addAttribute('code','');
     		$maritalStatusCode->addAttribute('displayName','');
     		$maritalStatusCode->addAttribute('codeSystem','2.16.840.1.113883.5.2');
     		$maritalStatusCode->addAttribute('codeSystemName','HL7 Marital status');*/
     /*$languageCommunication = $patient->addChild('languageCommunication');
     		$templateId = $languageCommunication->addChild('templateId');
     		$templateId->addAttribute('root','2.16.840.1.113883.3.88.11.83.2');
     		$templateId->addAttribute('assigningAuthorityName','HITSP/C83');
     		$templateId = $languageCommunication->addChild('templateId');
     		$templateId->addAttribute('root','1.3.6.1.4.1.19376.1.5.3.1.2.1');
     		$templateId->addAttribute('assigningAuthorityName','IHE/PCC');
     		$languageCode = $languageCommunication->addChild('languageCode');
     		$languageCode->addAttribute('code','en-US');*/
     // AUTHOR
     $author = $xml->addChild('author');
     $time = $author->addChild('time');
     $timeValue = self::formatDate();
     $time->addAttribute('value', $timeValue);
     $assignedAuthor = $author->addChild('assignedAuthor');
     $id = $assignedAuthor->addChild('id');
     $id->addAttribute('root', '20cf14fb-b65c-4c8c-a54d-b0cca834c18c');
     $addr = $assignedAuthor->addChild('addr');
     $addr->addAttribute('use', 'HP');
     $addr->addChild('streetAddressLine', html_convert_entities(strlen($building->line2) > 0 ? $building->line1 . ' ' . $building->line2 : $building->line1));
     $addr->addChild('city', html_convert_entities($building->city));
     $addr->addChild('state', html_convert_entities($building->state));
     $addr->addChild('postalCode', html_convert_entities($building->zipCode));
     $telecom = $assignedAuthor->addChild('telecom');
     if (strlen($building->phoneNumber) > 0) {
         //$telecom->addAttribute('use','HP');
         $telecom->addAttribute('value', 'tel:' . html_convert_entities($building->phoneNumber));
     }
     $assignedPerson = $assignedAuthor->addChild('assignedPerson');
     $name = $assignedPerson->addChild('name');
     $name->addChild('prefix', html_convert_entities($providerName['prefix']));
     $name->addChild('given', html_convert_entities($providerName['given']));
     $name->addChild('family', html_convert_entities($providerName['family']));
     $representedOrg = $assignedAuthor->addChild('representedOrganization');
     $id = $representedOrg->addChild('id');
     $id->addAttribute('root', '2.16.840.1.113883.19.5');
     $representedOrg->addChild('name', html_convert_entities($buildingName));
     $address = $building->practice->primaryAddress;
     $telecom = $representedOrg->addChild('telecom');
     if (strlen($building->practice->mainPhone->number) > 0) {
         //$telecom->addAttribute('use','HP');
         $telecom->addAttribute('value', 'tel:' . html_convert_entities($building->practice->mainPhone->number));
     }
     $addr = $representedOrg->addChild('addr');
     if ($address->addressId > 0) {
         $addr->addAttribute('use', 'HP');
         $addr->addChild('streetAddressLine', html_convert_entities(strlen($address->line2) > 0 ? $address->line1 . ' ' . $address->line2 : $address->line1));
         $addr->addChild('city', html_convert_entities($address->city));
         $addr->addChild('state', html_convert_entities($address->state));
         $addr->addChild('postalCode', html_convert_entities($address->zipCode));
     }
     // CUSTODIAN
     $custodian = $xml->addChild('custodian');
     $assignedCustodian = $custodian->addChild('assignedCustodian');
     $representedOrg = $assignedCustodian->addChild('representedCustodianOrganization');
     $id = $representedOrg->addChild('id');
     $id->addAttribute('root', '2.16.840.1.113883.19.5');
     $representedOrg->addChild('name', 'NIST Registry');
     $telecom = $representedOrg->addChild('telecom');
     $telecom->addAttribute('value', 'tel:+1-301-975-3251');
     $addr = $representedOrg->addChild('addr');
     $addr->addChild('streetAddressLine', '100 Bureau Drive');
     $addr->addChild('city', 'Gaithersburg');
     $addr->addChild('state', 'MD');
     $addr->addChild('postalCode', '20899');
     // PARTICIPANT
     $participant = $xml->addChild('participant');
     $participant->addAttribute('typeCode', 'IND');
     $associatedEntity = $participant->addChild('associatedEntity');
     $associatedEntity->addAttribute('classCode', 'GUAR');
     $id = $associatedEntity->addChild('id');
     $id->addAttribute('root', '4ff51570-83a9-47b7-91f2-93ba30373141');
     $addr = $associatedEntity->addChild('addr');
     //$addr->addChild('streetAddressLine','17 Daws Rd.');
     //$addr->addChild('city','Blue Bell');
     //$addr->addChild('state','MA');
     //$addr->addChild('postalCode','02368');
     $telecom = $associatedEntity->addChild('telecom');
     //$telecom->addAttribute('value','tel:(888)555-1212');
     $associatedPerson = $associatedEntity->addChild('associatedPerson');
     $name = $associatedPerson->addChild('name');
     //$name->addChild('given','Kenneth');
     //$name->addChild('family','Ross');
     // DOCUMENTATION OF
     $documentationOf = $xml->addChild('documentationOf');
     $serviceEvent = $documentationOf->addChild('serviceEvent');
     $serviceEvent->addAttribute('classCode', 'PCPR');
     $effectiveTime = $serviceEvent->addChild('effectiveTime');
     $low = $effectiveTime->addChild('low');
     $lowValue = date('Ymd');
     $low->addAttribute('value', $lowValue);
     $high = $effectiveTime->addChild('high');
     $highValue = date('Ymd', strtotime('+1 month'));
     $high->addAttribute('value', $highValue);
     // Performer
     foreach ($this->performers as $provider) {
         $performer = $serviceEvent->addChild('performer');
         $performer->addAttribute('typeCode', 'PRF');
         $templateId = $performer->addChild('templateId');
         $templateId->addAttribute('root', '2.16.840.1.113883.3.88.11.83.4');
         $templateId->addAttribute('assigningAuthorityName', 'HITSP C83');
         $templateId = $performer->addChild('templateId');
         $templateId->addAttribute('root', '1.3.6.1.4.1.19376.1.5.3.1.2.3');
         $templateId->addAttribute('assigningAuthorityName', 'IHE PCC');
         $functionCode = $performer->addChild('functionCode');
         $functionCode->addAttribute('code', 'PP');
         $functionCode->addAttribute('displayName', 'Primary Care Provider');
         $functionCode->addAttribute('codeSystem', '2.16.840.1.113883.12.443');
         $functionCode->addAttribute('codeSystemName', 'Provider Role');
         $functionCode->addChild('originalText', 'Primary Care Provider');
         $time = $performer->addChild('time');
         $low = $time->addChild('low');
         $lowValue = date('Y');
         $low->addAttribute('value', $lowValue);
         $high = $time->addChild('high');
         $highValue = date('Ymd', strtotime('+1 month'));
         $high->addAttribute('value', $highValue);
         $assignedEntity = $performer->addChild('assignedEntity');
         $id = $assignedEntity->addChild('id');
         $id->addAttribute('extension', 'PseudoMD-' . $provider->personId);
         $id->addAttribute('root', '2.16.840.1.113883.3.72.5.2');
         $id = $assignedEntity->addChild('id');
         $id->addAttribute('extension', '999999999');
         $id->addAttribute('root', '2.16.840.1.113883.4.6');
         // <code code="200000000X" displayName="Allopathic and Osteopathic Physicians" codeSystemName="Provider Codes" codeSystem="2.16.840.1.113883.6.101"/>
         $addr = $assignedEntity->addChild('addr');
         $address = new Address();
         $address->personId = $provider->personId;
         $addressIterator = $address->getIteratorByPersonId();
         foreach ($addressIterator as $address) {
             break;
             // retrieves the top address
         }
         if ($address->addressId > 0) {
             $addr->addAttribute('use', 'HP');
             $addr->addChild('streetAddressLine', html_convert_entities(strlen($address->line2) > 0 ? $address->line1 . ' ' . $address->line2 : $address->line1));
             $addr->addChild('city', html_convert_entities($address->city));
             $addr->addChild('state', html_convert_entities($address->state));
             $addr->addChild('postalCode', html_convert_entities($address->zipCode));
         }
         $telecom = $assignedEntity->addChild('telecom');
         $phoneNumber = new PhoneNumber();
         $phoneNumber->personId = $provider->personId;
         foreach ($phoneNumber->getPhoneNumbers(false) as $phone) {
             break;
             // retrieves the top phone
         }
         if (strlen($phone['number']) > 0) {
             $telecom->addAttribute('use', 'HP');
             $telecom->addAttribute('value', 'tel:' . html_convert_entities($phone['number']));
         }
         $assignedPerson = $assignedEntity->addChild('assignedPerson');
         $name = $assignedPerson->addChild('name');
         $name->addChild('prefix', html_convert_entities($provider->person->prefix));
         $name->addChild('given', html_convert_entities($provider->person->firstName));
         $name->addChild('family', html_convert_entities($provider->person->lastName));
         $representedOrg = $assignedEntity->addChild('representedOrganization');
         $id = $representedOrg->addChild('id');
         $id->addAttribute('root', '2.16.840.1.113883.3.72.5');
         $representedOrg->addChild('name');
         $telecom = $representedOrg->addChild('telecom');
         $addr = $representedOrg->addChild('addr');
         /*$representedOrg->addChild('name',$buildingName);
         		$telecom = $representedOrg->addChild('telecom');
         		if (strlen($building->practice->mainPhone->number) > 0) {
         			$telecom->addAttribute('use','HP');
         			$telecom->addAttribute('value','tel:'.$building->practice->mainPhone->number);
         		}
         		$addr = $representedOrg->addChild('addr');
         		if ($address->addressId > 0) {
         			$addr->addAttribute('use','HP');
         			$addr->addChild('streetAddressLine',(strlen($address->line2) > 0)?$address->line1.' '.$address->line2:$address->line1);
         			$addr->addChild('city',$address->city);
         			$addr->addChild('state',$address->state);
         			$addr->addChild('postalCode',$address->zipCode);
         		}*/
     }
 }
 protected function export2PublicHealth($ids)
 {
     $data = array();
     $data[] = 'FHS|^~\\&';
     $data[] = 'BHS|^~\\&';
     $ctr = count($ids);
     for ($i = 0; $i < $ctr; $i++) {
         $id = (int) $ids[$i];
         if (!isset($this->_session->patientList[$id])) {
             continue;
         }
         $problemList = isset($this->_session->patientList[$id]['problemList']) ? $this->_session->patientList[$id]['problemList'] : array();
         $patient = new Patient();
         $patient->personId = $id;
         $patient->populate();
         $person = $patient->person;
         $dateTime = date('YmdHi');
         $messageDateTime = date('YmdHiO');
         $data[] = 'MSH|^~\\&|CLEARHEALTH||||' . $dateTime . '||ADT^A04|' . $messageDateTime . '|P|2.3.1';
         $dateOfOnset = isset($problemList[0]['dateOfOnset']) ? $problemList[0]['dateOfOnset'] : date('YmdHis');
         $data[] = 'EVN||' . date('YmdHi', strtotime($dateOfOnset));
         // Address
         $address = new Address();
         $address->personId = $id;
         $addressIterator = $address->getIteratorByPersonId();
         foreach ($addressIterator as $address) {
             break;
             // retrieves the top address
         }
         // Telecom
         $phone = null;
         $phoneNumber = new PhoneNumber();
         $phoneNumber->personId = $id;
         foreach ($phoneNumber->getPhoneNumbers(false) as $phone) {
             break;
             // retrieves the top phone
         }
         $telecom = '';
         if ($phone && strlen($phone['number']) > 0) {
             $telecom = $phone['number'];
         }
         $data[] = 'PID|1||' . $patient->recordNumber . '||' . strtoupper($person->lastName) . '^' . strtoupper($person->firstName) . '^' . strtoupper($person->middleName) . '||' . date('Ymd', strtotime($person->dateOfBirth)) . '|' . $person->gender . '||U|' . $address->line1 . '^' . $address->line2 . '^' . $address->city . '^' . $address->state . '^' . $address->zipCode . '^US||' . $telecom;
         $visit = new Visit();
         $visit->patientId = $id;
         $visit->populateLatestVisit();
         $data[] = 'PV1|1|O||R||||||||||||||||||||||||||||||||||||||||' . date('YmdHis', strtotime($visit->dateOfTreatment));
         foreach ($problemList as $key => $problem) {
             $data[] = 'DG1|' . ($key + 1) . '||' . $problem['code'] . '^' . $problem['code'] . ' ' . $problem['codeTextShort'] . '^I9C|||F|||||||||1';
         }
     }
     $data[] = 'BTS|' . $ctr;
     $data[] = 'FTS|1';
     $filename = 'ph_' . uniqid('') . '.er7';
     return array('filename' => $filename, 'data' => $data);
 }