public function getAddresses() { $address = new Address(); $address->personId = $this->person_id; return $address->getIteratorByPersonId(); }
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; }
public static function generatePID($patientId) { $patient = new Patient(); $patient->personId = (int) $patientId; $patient->populate(); $phoneHome = ''; $phoneBusiness = ''; $phoneNumber = new PhoneNumber(); $phoneNumber->personId = $patient->personId; $phones = $phoneNumber->getPhoneNumbers(false); foreach ($phones as $phone) { if ($phoneHome == '' && $phone['type'] == 'HP') { $phoneHome = $phone['number']; } if ($phoneBusiness == '' && $phone['type'] == 'TE') { $phoneBusiness = $phone['number']; } } /* most efficient way to create PID? $patientName = $patient->person->lastName.'^'.$patient->person->firstName.'^'.strtoupper(substr($patient->person->middleName,0,1)); $addr = $patient->homeAddress; $address = $addr->line1.'^'.$addr->line2.'^'.$addr->city.'^'.$addr->state.'^'.$addr->zipCode; // reference: http://www.med.mun.ca/tedhoekman/medinfo/hl7/ch300056.htm $data = array(); $data[] = 'PID'; $data[] = ''; // 1: Set ID $data[] = ''; // 2: Patient ID (External) $data[] = $patient->recordNumber; // 3: Patient ID (Internal) $data[] = ''; // 4: Alternate Patient ID $data[] = $patientName; // 5: Patient Name $data[] = ''; // 6: Mother's Maiden Name $data[] = date('Ymd',strtotime($patient->person->dateOfBirth)); // 7: Data/Time of Birth $data[] = $patient->person->gender; // 8: Sex $data[] = ''; // 9: Patient Alias $data[] = ''; // 10: Race $data[] = $address; // 11: Patient Address $data[] = ''; // 12: Country Code $data[] = $phoneHome; // 13: Phone Number (Home) $data[] = $phoneBusiness; // 14: Phone Number (Business) $data[] = ''; // 15: Primary Language $data[] = $patient->person->maritalStatus; // 16: Marital Status $data[] = ''; // 17: Religion $data[] = ''; // 18: Patient Account Number $data[] = $patient->person->identifier; // 19: Patient SSS Number */ $data = array(); $data['mrn'] = $patient->recordNumber; $data['lastName'] = $patient->person->lastName; $data['firstName'] = $patient->person->firstName; $data['middleInitial'] = strtoupper(substr($patient->person->middleName, 0, 1)); $data['dateOfBirth'] = date('Ymd', strtotime($patient->person->dateOfBirth)); $data['gender'] = $patient->person->gender; $address = $patient->homeAddress; // 2.x // fall back for 3.x if (!$address->addressId > 0) { $address = new Address(); $address->personId = $patient->personId; $addressIterator = $address->getIteratorByPersonId(); foreach ($addressIterator as $address) { break; // retrieves the top address } } $data['addressLine1'] = $address->line1; $data['addressLine2'] = $address->line2; $data['addressCity'] = $address->city; $data['addressState'] = $address->state; $data['addressZip'] = $address->zipCode; $data['phoneHome'] = $phoneHome; $data['phoneBusiness'] = $phoneBusiness; $data['ssn'] = $patient->person->identifier; $statistics = PatientStatisticsDefinition::getPatientStatistics((int) $patient->personId); $data['race'] = ''; if (isset($statistics['Race'])) { $data['race'] = $statistics['Race']; } if (isset($statistics['race'])) { $data['race'] = $statistics['race']; } return 'PID|1||' . $data['mrn'] . '||' . $data['lastName'] . '^' . $data['firstName'] . '^' . $data['middleInitial'] . '||' . $data['dateOfBirth'] . '|' . $data['gender'] . '||' . $data['race'] . '|' . $data['addressLine1'] . '^' . $data['addressLine2'] . '^' . $data['addressCity'] . '^' . $data['addressState'] . '^' . $data['addressZip'] . '||' . $data['phoneHome'] . '|' . $data['phoneBusiness'] . '|||||' . $data['ssn']; }
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); }*/ } }
public static function generateORC($provider) { // test#5 does not have this segment if (!$provider instanceof Provider) { $providerId = (int) $provider; $provider = new Provider(); $provider->personId = (int) $providerId; $provider->populate(); } $building = Building::getBuildingDefaultLocation($provider->personId); //$practice = self::$providerBuilding->practice; $practice = $building->practice; $practiceAddr = $practice->primaryAddress; if (!$practiceAddr->addressId > 0) { $practiceAddr = $practice->secondaryAddress; } $practicePhone = $practice->mainPhone; if (!$practicePhone->numberId > 0) { $practicePhone = $practice->secondaryPhone; } $phone = PhoneNumber::autoFixNumber($practicePhone->number); if (substr($phone, 0, 1) == 1) { $phone = substr($phone, 1); } $areaCode = substr($phone, 0, 3); $localNumber = substr($phone, 3); $addr = new Address(); foreach ($addr->getIteratorByPersonId($provider->personId) as $providerAddr) { break; } if (!isset($providerAddr)) { $providerAddr = new Address(); } $orc = 'ORC|RE|||||||||||'; if ($provider->personId > 0) { $providerId = strlen($provider->identifier) > 0 ? $provider->identifier : $provider->personId; $orc .= $providerId . '^' . $provider->person->lastName . '^' . $provider->person->firstName . '^^^^^^' . $building->name . '&2.16.840.1.113883.19.4.6&ISO'; } $orc .= '|||||||||' . $practice->name . '^L^^^^' . $building->name . '&2.16.840.1.113883.19.4.6&ISO^XX^^^' . $practice->identifier . '|' . $practiceAddr->line1 . '^^' . $practiceAddr->city . '^' . $practiceAddr->state . '^' . $practiceAddr->zipCode . '^^B|^^^^^' . $areaCode . '^' . $localNumber; if ($providerAddr->addressId > 0) { $orc .= '|' . $providerAddr->line1 . '^^' . $providerAddr->city . '^' . $providerAddr->state . '^' . $providerAddr->zipCode . '^^B'; } return $orc; }
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); }
public function ssCheck() { $ret = array(); // required SS: Name (last and first), Gender, Date of Birth $person = $this->person; $lastNameLen = strlen($person->lastName); if (!$lastNameLen > 0 || $lastNameLen > 35) { $ret[] = 'Last Name field must be supplied and not more than 35 characters'; } $firstNameLen = strlen($person->firstName); if (!$firstNameLen > 0 || $firstNameLen > 35) { $ret[] = 'First Name field must be supplied and not more than 35 characters'; } $gender = $person->gender; // Gender options = M, F, U $genderList = array('M' => 'Male', 'F' => 'Female', 'U' => 'Unknown', 1 => 'Male', 2 => 'Female', 3 => 'Unknown'); if (!isset($genderList[$gender])) { $ret[] = 'Gender is invalid'; } // Patient DOB must not be future $date = date('Y-m-d'); $dateOfBirth = date('Ymd', strtotime($person->dateOfBirth)); if ($person->dateOfBirth == '0000-00-00' || strtotime($dateOfBirth) > strtotime($date)) { $ret[] = 'Date of birth is invalid'; } // Have appropriate validation on patient address/phone as required by SS docs $address = new Address(); $address->personId = $this->personId; $addressIterator = $address->getIteratorByPersonId(); foreach ($addressIterator as $address) { break; // retrieves the top address } //$address->populateWithType('MAIN'); $line1Len = strlen($address->line1); if (!$line1Len > 0 || $line1Len > 35) { $ret[] = 'Address line1 field must be supplied and not more than 35 characters'; } $line2Len = strlen($address->line2); if ($line2Len > 0 && $line2Len > 35) { $ret[] = 'Address line2 must not be more than 35 characters'; } $cityLen = strlen($address->city); if (!$cityLen > 0 || $cityLen > 35) { $ret[] = 'Address city field must be supplied and not more than 35 characters'; } if (strlen($address->state) != 2) { $ret[] = 'Address state field must be supplied and not more than 2 characters'; } $zipCodeLen = strlen($address->zipCode); if ($zipCodeLen != 5 && $zipCodeLen != 9) { $ret[] = 'Address zipcode must be supplied and must be 5 or 9 digit long'; } $phoneNumber = new PhoneNumber(); $phoneNumber->personId = $person->personId; $phones = $phoneNumber->phoneNumbers; $hasTE = false; foreach ($phones as $phone) { if ($phone['type'] == 'TE') { $hasTE = true; break; } if (strlen($phone['number']) < 11) { $ret[] = 'Phone number \'' . $phone['number'] . '\' is invalid'; } } if (!$hasTE) { $ret[] = 'Phone must have at least one Emergency, Employer or Billing'; } return $ret; }
public static function generatePID($patientId, $raw = false) { $patientId = (int) $patientId; $patient = new Patient(); $patient->personId = $patientId; $patient->populate(); // Patient Statistics $statistics = PatientStatisticsDefinition::getPatientStatistics($patientId); $pid = array('PID'); $pid[1] = ''; // empty $pid[2] = ''; // empty $pid3 = array(); // PID‐3: Patient Identifier List $pid3[1] = $patient->recordNumber; // PID‐3.1: ID Number $pid3[2] = ''; // empty $pid3[3] = ''; // empty $pid34 = array(); // PID-3.4: Assigning Authority $pid34[] = 'MPI'; // PID-3.4.1: Namespace ID $pid34[] = '2.16.840.1.113883.19.3.2.1'; // PID-3.4.2: Universal ID $pid34[] = 'ISO'; // PID-3.4.3: Universal ID Type $pid3[4] = implode('&', $pid34); $pid3[5] = 'MR'; // PID-3.5: ID Number Type $pid[3] = implode('^', $pid3); $pid[4] = ''; // empty $pid5 = array(); $pid51 = array(); // PID-5.1: Family Name $pid51[] = $patient->lastName; // PID-5.1.1: Surname $pid5[] = implode('^', $pid51); $pid5[] = $patient->firstName; // PID-5.2: Given Name $pid[5] = implode('^', $pid5); $pid[6] = ''; // empty $pid7 = array(); $pid7[] = date('Ymd', strtotime($patient->dateOfBirth)); // PID-7.1: Date of Birth $pid[7] = implode('^', $pid7); $pid[8] = $patient->gender; // PID-8: Administrative Sex $pid[9] = ''; // empty $race = ''; $raceCode = 'HL70005'; if (isset($statistics['Race'])) { $race = $statistics['Race']; } if (isset($statistics['race'])) { $race = $statistics['race']; } $raceId = ''; foreach (explode(' ', $race) as $val) { $raceId .= strtoupper(substr($val, 0, 1)); } $pid10 = array(); // PID-10: Race $pid10[] = $raceId; // PID-10.1: Identifier $pid10[] = $race; // PID-10.2: Text $pid10[] = $raceCode; // PID-10.3: Name of Coding System $pid[10] = implode('^', $pid10); $addr = new Address(); foreach ($addr->getIteratorByPersonId($patientId) as $address) { break; } $street = $address->line1; if (strlen($address->line2) > 0) { $street .= ' ' . $address->line2; } $pid11 = array(); // PID-11: Patient Address $pid111 = array(); // PID-11.1: Street Address $pid111[] = $street; // PID-11.1.1: Street or Mailing Address $pid11[] = implode('^', $pid111); // PID-11.1: Street Address $pid11[] = ''; // empty $pid11[] = $address->city; // PID-11.3: City $pid11[] = $address->state; // PID-11.4: State $pid11[] = $address->zipCode; // PID-11.5: Zip Code $pid11[] = 'USA'; // PID-11.6: Country $pid11[] = substr($address->type, 0, 1); // PID-11.7: Address Type $pid[11] = implode('^', $pid11); $pid[12] = ''; // empty $pid13 = array(); // PID-13: Phone Number-Home $pid13[] = ''; // empty $pid13[] = 'PRN'; // PID-13.2: Telecommunication Use Code = PRN? $pid13[] = ''; // empty $pid13[] = ''; // empty $pid13[] = ''; // empty $phoneHome = ''; $phoneBusiness = ''; $phoneNumber = new PhoneNumber(); $phoneNumber->personId = $patient->personId; foreach ($phoneNumber->phoneNumbers as $phone) { if ($phoneHome == '' && $phone['type'] == 'HP') { $phoneHome = $phone['number']; } if ($phoneBusiness == '' && $phone['type'] == 'TE') { $phoneBusiness = $phone['number']; } } if ($phoneHome) { $phone = $phoneHome; } if ($phoneBusiness) { $phone = $phoneBusiness; } if (is_array($phone)) { $phone = $phone['number']; } if (substr($phone, 0, 1) == 1) { $phone = substr($phone, 1); } $areaCode = substr($phone, 0, 3); $localNumber = substr($phone, 3); $pid13[] = $areaCode; // PID-13.6: Area/City Code $pid13[] = $localNumber; // PID-13.7: Local Number $pid[13] = implode('^', $pid13); $pid[14] = ''; // empty $pid[15] = ''; // empty $pid[16] = ''; // empty $pid[17] = ''; // empty $pid[18] = ''; // empty $pid[19] = ''; // empty $pid[20] = ''; // empty $pid[21] = ''; // empty $ethnic = 'Unknown'; $ethnicCode = 'HL70189'; if (isset($statistics['Ethnicity'])) { $ethnic = $statistics['Ethnicity']; } if (isset($statistics['ethnicity'])) { $ethnic = $statistics['ethnicity']; } $ethnicId = substr($ethnic, 0, 1); if ($ethnicId != 'H' && $ethnicId != 'N' && $ethnicId != 'U') { $ethnicId = 'U'; } $pid22 = array(); // PID-22: Ethnic Group $pid22[] = $ethnicId; // PID-22.1: Identifier (H, N, U) $pid22[] = $ethnic; // PID-22.2: Text $pid22[] = $ethnicCode; // PID-22.3: Name of Coding System $pid[22] = implode('^', $pid22); if ($raw) { return $pid; } return implode('|', $pid); }
public function ajaxListAddressesAction() { $patientId = (int) $this->_getParam('patientId'); $rows = array(); $address = new Address(); $addressIterator = $address->getIteratorByPersonId($patientId); foreach ($addressIterator as $addr) { $rows[] = $this->_toJSON($addr, 'addressId', array('name', 'type', 'line1', 'line2', 'city', 'state', 'postal_code', 'notes', 'active')); } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(array('rows' => $rows)); }