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 defaultPatientHeaderAction() { $personId = (int) $this->_getParam('personId'); // e76f18cd-d388-4c53-b940-53cb81b80c5e $referenceId = $this->_getParam('referenceId'); $data = $this->_getAttachmentData($referenceId); $patient = new Patient(); $patient->personId = $personId; $patient->populate(); $person = $patient->person; $picture = ''; if ($person->activePhoto > 0) { $attachment = new Attachment(); $attachment->attachmentId = (int) $person->activePhoto; $attachment->populate(); $picture = base64_encode($attachment->rawData); } $xml = new SimpleXMLElement('<patientHeader/>'); $xmlPatient = $xml->addChild('patient'); $this->_addChild($xmlPatient, 'picture', $picture); $this->_addChild($xmlPatient, 'lastName', $person->lastName); $this->_addChild($xmlPatient, 'firstName', $person->firstName); $this->_addChild($xmlPatient, 'dateOfBirth', $person->dateOfBirth); $this->_addChild($xmlPatient, 'gender', $person->gender); $statistics = PatientStatisticsDefinition::getPatientStatistics($personId); $race = ''; if (isset($statistics['Race'])) { $race = $statistics['Race']; } else { if (isset($statistics['race'])) { $race = $statistics['race']; } } $this->_addChild($xmlPatient, 'race', $race); $this->_addChild($xmlPatient, 'maritalStatus', $person->displayMaritalStatus); $addresses = Address::listAddresses($personId); $phoneNumbers = PhoneNumber::listPhoneNumbers($personId); $address = null; if (isset($addresses[Address::TYPE_BILLING])) { $address = $addresses[Address::TYPE_BILLING]; } else { if (isset($addresses[Address::TYPE_HOME])) { $address = $addresses[Address::TYPE_HOME]; } else { if (isset($addresses[Address::TYPE_MAIN])) { $address = $addresses[Address::TYPE_MAIN]; } else { if (isset($addresses[Address::TYPE_SEC])) { $address = $addresses[Address::TYPE_SEC]; } else { if (isset($addresses[Address::TYPE_OTHER])) { $address = $addresses[Address::TYPE_OTHER]; } } } } } if ($address !== null) { $phone = ''; if (isset($phoneNumbers[PhoneNumber::TYPE_BILLING])) { $phone = $phoneNumbers[PhoneNumber::TYPE_BILLING]->number; } else { if (isset($phoneNumbers[PhoneNumber::TYPE_HOME])) { $phone = $phoneNumbers[PhoneNumber::TYPE_HOME]->number; } else { if (isset($phoneNumbers[PhoneNumber::TYPE_WORK])) { $phone = $phoneNumbers[PhoneNumber::TYPE_WORK]->number; } else { if (isset($phoneNumbers[PhoneNumber::TYPE_HOME_DAY])) { $phone = $phoneNumbers[PhoneNumber::TYPE_HOME_DAY]->number; } else { if (isset($phoneNumbers[PhoneNumber::TYPE_HOME_EVE])) { $phone = $phoneNumbers[PhoneNumber::TYPE_HOME_EVE]->number; } else { if (isset($phoneNumbers[PhoneNumber::TYPE_MOBILE])) { $phone = $phoneNumbers[PhoneNumber::TYPE_MOBILE]->number; } else { if (isset($phoneNumbers[PhoneNumber::TYPE_BEEPER])) { $phone = $phoneNumbers[PhoneNumber::TYPE_BEEPER]->number; } } } } } } } $this->_addChild($xmlPatient, 'billingLine1', $address->line1); $this->_addChild($xmlPatient, 'billingCity', $address->city); $this->_addChild($xmlPatient, 'billingState', $address->state); $this->_addChild($xmlPatient, 'billingZip', $address->postalCode); $this->_addChild($xmlPatient, 'phoneNumber', $phone); } if ($person->primaryPracticeId > 0) { $practice = new Practice(); $practice->practiceId = (int) $person->primaryPracticeId; $practice->populate(); $address = $practice->primaryAddress; $xmlPractice = $xml->addChild('practice'); $this->_addChild($xmlPractice, 'name', $practice->name); $this->_addChild($xmlPractice, 'primaryLine1', $address->line1); $this->_addChild($xmlPractice, 'primaryCity', $address->city); $this->_addChild($xmlPractice, 'primaryState', $address->state); $this->_addChild($xmlPractice, 'primaryZip', $address->postalCode); $this->_addChild($xmlPractice, 'mainPhone', $practice->mainPhone->number); $this->_addChild($xmlPractice, 'faxNumber', $practice->fax->number); } $insuredRelationship = new InsuredRelationship(); $insuredRelationshipIterator = $insuredRelationship->getIteratorByPersonId($personId); $primary = null; $secondary = null; foreach ($insuredRelationshipIterator as $item) { if (!$item->active) { continue; } if ($primary === null) { $primary = $item; } else { if ($secondary === null) { $secondary = $item; } else { break; } } } $xmlPayer = $xml->addChild('payer'); if ($primary !== null) { $this->_addChild($xmlPayer, 'primary', $primary->insuranceProgram->name); } if ($secondary !== null) { $this->_addChild($xmlPayer, 'secondary', $secondary->insuranceProgram->name); } /*$xmlGuarantor = $xml->addChild('guarantor'); $this->_addChild($xmlGuarantor,'lastName',''); $this->_addChild($xmlGuarantor,'firstName',''); $this->_addChild($xmlGuarantor,'dateOfBirth',''); $this->_addChild($xmlGuarantor,'phone','');*/ // get the current visit $xmlProvider = $xml->addChild('provider'); $lastName = ''; $firstName = ''; $dateOfBirth = ''; $phone = ''; $visit = new Visit(); $visit->populateLatestVisit($personId); if ($visit->visitId > 0) { $provider = new Provider(); $provider->personId = $visit->providerId; $provider->populate(); $person = $provider->person; $lastName = $person->lastName; $firstName = $person->firstName; $dateOfBirth = $person->dateOfBirth; $phone = $person->phoneNumber->number; } $this->_addChild($xmlProvider, 'lastName', $lastName); $this->_addChild($xmlProvider, 'firstName', $firstName); $this->_addChild($xmlProvider, 'dateOfBirth', $dateOfBirth); $this->_addChild($xmlProvider, 'phone', $phone); try { $content = ReportBase::mergepdfset($xml, $data); $this->getResponse()->setHeader('Content-Type', 'application/pdf'); } catch (Exception $e) { $content = '<script>alert("' . $e->getMessage() . '")</script>'; } $this->view->content = $content; $this->render('binary-template'); }