public function processDeleteAction() { $data = false; $id = (int) $this->_getParam('id'); $psd = new PatientStatisticsDefinition(); if ($id > 0) { $psd->patientStatisticsDefinitionId = $id; $psd->setPersistMode(WebVista_Model_ORM::DELETE); $psd->persist(); $data = true; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }
public function listStatsAction() { $personId = (int) $this->_getParam('personId'); $psd = new PatientStatisticsDefinition(); $stats = PatientStatisticsDefinition::getPatientStatistics($personId); $psdIterator = $psd->getAllActive(); $rows = array(); foreach ($psdIterator as $row) { $tmp = array(); $tmp['id'] = $row->name; $tmp['data'] = array(); $tmp['data'][] = GrowthChartBase::prettyName($row->name); $tmp['data'][] = isset($stats[$row->name]) ? $stats[$row->name] : ''; $options = array(); if ($row->type == PatientStatisticsDefinition::TYPE_ENUM) { $enumerationClosure = new EnumerationClosure(); $paths = $enumerationClosure->generatePaths($row->value); foreach ($paths as $id => $name) { $options[] = array('key' => $id, 'value' => $name); } } $tmp['userdata']['type'] = $row->type; $tmp['userdata']['options'] = $options; $rows[] = $tmp; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(array('rows' => $rows)); }
public static function generatePID($patient) { if (!$patient instanceof Patient) { $patientId = (int) $patient; $patient = new Patient(); $patient->personId = (int) $patientId; $patient->populate(); } $patientId = (int) $patient->personId; $person = $patient->person; $statistics = PatientStatisticsDefinition::getPatientStatistics($patientId); $raceCode = ''; $race = 'Unknown'; if (isset($statistics['Race'])) { $race = $statistics['Race']; } if (isset($statistics['race'])) { $race = $statistics['race']; } if (strlen($statistics['Race']) > 0) { $race = $statistics['Race']; foreach (PatientStatisticsDefinition::listRaceCodes() as $key => $value) { if (strtolower($value) == strtolower($race)) { $raceCode = $key; break; } } } $addr = new Address(); foreach ($addr->getIteratorByPersonId($patient->personId) as $address) { break; } $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); $ethnic = 'Unknown'; if (isset($statistics['Ethnicity'])) { $ethnic = $statistics['Ethnicity']; } if (isset($statistics['ethnicity'])) { $ethnic = $statistics['ethnicity']; } $ethnicId = strtoupper(substr($ethnic, 0, 1)); if ($ethnicId != 'H' && $ethnicId != 'N' && $ethnicId != 'U') { $ethnicId = 'U'; } return 'PID|||' . $patient->recordNumber . '^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR||' . $person->lastName . '^' . $person->firstName . '||' . date('Ymd', strtotime($person->dateOfBirth)) . '|' . $person->gender . '||' . $raceCode . '^' . $race . '^HL70005|' . $address->line1 . '^^' . $address->city . '^' . $address->state . '^' . $address->zipCode . '^USA^M||^PRN^^^^' . $areaCode . '^' . $localNumber . '|||||||||' . $ethnicId . '^' . $ethnic . '^HL70189'; }
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; }
public function filterDemographicsAction() { $psd = new PatientStatisticsDefinition(); $psdIterator = $psd->getAllActive(); $demographics = array('age' => array('name' => 'Age', 'type' => ''), 'gender' => array('name' => 'Gender', 'type' => PatientStatisticsDefinition::TYPE_ENUM, 'options' => Enumeration::getEnumArray('Gender', 'key')), 'marital_status' => array('name' => 'Marital Status', 'type' => PatientStatisticsDefinition::TYPE_ENUM, 'options' => Enumeration::getEnumArray('Marital Status', 'key'))); foreach ($psdIterator as $row) { $tmp = array(); $tmp['name'] = GrowthChartBase::prettyName($row->name); $options = array(); if ($row->type == PatientStatisticsDefinition::TYPE_ENUM) { $enumerationClosure = new EnumerationClosure(); $options = $enumerationClosure->generatePathsKeyName($row->value); } $tmp['type'] = $row->type; asort($options); $tmp['options'] = $options; $demographics[$row->name] = $tmp; } $this->view->demographics = $demographics; $this->view->filters = $this->_session->filters['demographics']; $operators = array('' => ''); foreach (Claim::balanceOperators() as $key => $value) { $operators[$key] = $value; } $this->view->operators = $operators; $this->render(); }
public function calculateFees($recompute = null) { // pass true or false to override visit.closed checking if ($recompute === null) { $recompute = $this->closed ? false : true; } $visitId = (int) $this->encounter_id; $total = 0; $discounted = 0; $visitFlat = 0; $visitPercentage = 0; $codeFlat = 0; $codePercentage = 0; $discountApplied = array(); if ($recompute) { $insuranceProgramId = (int) $this->activePayerId; $dateOfVisit = date('Y-m-d', strtotime($this->date_of_treatment)); $statistics = PatientStatisticsDefinition::getPatientStatistics((int) $this->patient_id); $familySize = isset($statistics['family_size']) ? $statistics['family_size'] : 0; $monthlyIncome = isset($statistics['monthly_income']) ? $statistics['monthly_income'] : 0; $retDiscount = DiscountTable::checkDiscount($insuranceProgramId, $dateOfVisit, $familySize, $monthlyIncome); if ($retDiscount !== false) { $discount = (double) $retDiscount['discount']; switch ($retDiscount['discountType']) { case DiscountTable::DISCOUNT_TYPE_FLAT_VISIT: $discountApplied[] = 'Flat Visit: $' . $discount; $visitFlat += $discount; break; case DiscountTable::DISCOUNT_TYPE_FLAT_CODE: $discountApplied[] = 'Flat Code: $' . $discount; $codeFlat += $discount; break; case DiscountTable::DISCOUNT_TYPE_PERC_VISIT: $discountApplied[] = 'Percentage Visit: ' . $discount . '%'; $visitPercentage += $discount / 100; break; case DiscountTable::DISCOUNT_TYPE_PERC_CODE: $discountApplied[] = 'Percentage Code: ' . $discount . '%'; $codePercentage += $discount / 100; break; } } } else { $claimLineFees = array(); $iterator = ClaimLine::mostRecentClaims($visitId); foreach ($iterator as $claimLine) { $code = $claimLine->procedureCode; if (!isset($claimLineFees[$code])) { $claimLineFees[$code] = array('baseFee' => 0, 'adjustedFee' => 0); } $claimLineFees[$code]['baseFee'] += (double) $claimLine->baseFee; $claimLineFees[$code]['adjustedFee'] += (double) $claimLine->adjustedFee; } } $details = array(); $iterator = new PatientProcedureIterator(); $iterator->setFilters(array('visitId' => $visitId)); $firstProcedureId = null; foreach ($iterator as $patientProcedure) { $patientProcedureId = (int) $patientProcedure->patientProcedureId; $code = $patientProcedure->code; $quantity = (int) $patientProcedure->quantity; $writeoff = 0; if ($recompute) { $fee = '-.--'; $feeDiscounted = '-.--'; $discountedRate = ''; $retFee = FeeSchedule::checkFee($insuranceProgramId, $dateOfVisit, $code); if ($retFee !== false && (double) $retFee['fee'] != 0) { $fee = (double) $retFee['fee']; $tmpFee = 0; for ($i = 1; $i <= 4; $i++) { $modifier = 'modifier' . $i; if (!strlen($patientProcedure->{$modifier}) > 0) { continue; } switch ($patientProcedure->{$modifier}) { case $retFee['modifier1']: $tmpFee += (double) $retFee['modifier1fee']; break 2; case $retFee['modifier2']: $tmpFee += (double) $retFee['modifier2fee']; break 2; case $retFee['modifier3']: $tmpFee += (double) $retFee['modifier3fee']; break 2; case $retFee['modifier4']: $tmpFee += (double) $retFee['modifier4fee']; break 2; } } if ($tmpFee > 0) { $fee = $tmpFee; } if ($quantity > 0) { $fee *= $quantity; $feeDiscounted *= $quantity; } // calculate discounts if ($codeFlat > 0) { $tmpDiscount = $fee - $codeFlat; if ($tmpDiscount < 0) { $tmpDiscount = 0; } $feeDiscounted += $tmpDiscount; $writeoff = $tmpDiscount; } if ($firstProcedureId !== null && $visitFlat > 0) { $writeoff = $fee; trigger_error('VISIT FLAT: ' . $visitFlat); trigger_error('WRITEOFF: ' . $writeoff); } if ($codePercentage > 0) { $tmpDiscount = $feeDiscounted * $codePercentage; if ($tmpDiscount < 0) { $tmpDiscount = 0; } $feeDiscounted += $tmpDiscount; $writeoff = $tmpDiscount; } } if ($firstProcedureId === null) { $firstProcedureId = $patientProcedureId; } } else { if (isset($claimLineFees[$code])) { $fee = $claimLineFees[$code]['baseFee']; $feeDiscounted = $claimLineFees[$code]['adjustedFee']; } else { $fee = $patientProcedure->baseFee; $feeDiscounted = $patientProcedure->adjustedFee; } if ($quantity > 0) { $fee *= $quantity; $feeDiscounted *= $quantity; } } /*$quantity = (int)$patientProcedure->quantity; if ($quantity > 0) { $fee *= $quantity; $feeDiscounted *= $quantity; }*/ $total += $fee; $discounted += (double) $feeDiscounted; $details[$patientProcedureId] = array(); $details[$patientProcedureId]['orm'] = $patientProcedure; $details[$patientProcedureId]['fee'] = $fee; $details[$patientProcedureId]['feeDiscounted'] = $feeDiscounted; $details[$patientProcedureId]['writeoff'] = $writeoff; } if ($visitFlat > 0) { $discounted += $visitFlat; // update the first procedure if ($firstProcedureId !== null) { $details[$firstProcedureId]['feeDiscounted'] += $visitFlat; $writeoff = $details[$firstProcedureId]['fee'] - $details[$firstProcedureId]['feeDiscounted']; if ($writeoff < 0) { $writeoff = 0; } $details[$firstProcedureId]['writeoff'] = $writeoff; } } if ($visitPercentage > 0) { $discounted += $discounted * $visitPercentage; // update the first procedure if ($firstProcedureId !== null) { $details[$firstProcedureId]['feeDiscounted'] += $details[$firstProcedureId]['feeDiscounted'] * $visitFlat; } } $row = array(); $row['discountApplied'] = $discountApplied; $row['details'] = $details; $row['total'] = $total; $row['discounted'] = $discounted; return $row; }
public function populateXML(SimpleXMLElement $xml = null, $checked = true) { if ($xml === null) { $xml = new SimpleXMLElement('<data/>'); } $personId = (int) $this->person_id; $person = $this->person; $picture = ''; if ($person->activePhoto > 0) { $attachment = new Attachment(); $attachment->attachmentId = (int) $person->activePhoto; $attachment->populate(); $picture = base64_encode($attachment->rawData); } $xmlPatient = $xml->addChild('patient'); $xmlPerson = $xmlPatient->addChild('person'); $this->_addChild($xmlPerson, 'picture', $picture, $checked); $this->_addChild($xmlPerson, 'lastName', $person->lastName, $checked); $this->_addChild($xmlPerson, 'firstName', $person->firstName, $checked); $this->_addChild($xmlPerson, 'middleName', $person->middleName, $checked); $identifier = ''; if ($person->identifierType == 'SSN') { $identifier = $person->identifier; } $this->_addChild($xmlPerson, 'identifier', $identifier, $checked); $this->_addChild($xmlPerson, 'gender', $person->gender, $checked); $dateOfBirth = explode(' ', date('m d Y', strtotime($person->dateOfBirth))); $this->_addChild($xmlPerson, 'dobMonth', $dateOfBirth[0], $checked); $this->_addChild($xmlPerson, 'dobDay', $dateOfBirth[1], $checked); $this->_addChild($xmlPerson, 'dobYear', $dateOfBirth[2], $checked); $statistics = PatientStatisticsDefinition::getPatientStatistics($personId); $race = ''; if (isset($statistics['Race'])) { $race = $statistics['Race']; } else { if (isset($statistics['race'])) { $race = $statistics['race']; } } $this->_addChild($xmlPerson, 'race', $race, $checked); $maritalStatus = $person->maritalStatus ? $person->maritalStatus : 'Other'; $this->_addChild($xmlPerson, 'maritalStatus', $maritalStatus, $checked); $addresses = Address::listAddresses($personId); foreach ($addresses as $address) { switch ($address->type) { case Address::TYPE_MAIN: $type = 'mainAddress'; break; case Address::TYPE_SEC: $type = 'secondaryAddress'; break; case Address::TYPE_HOME: $type = 'homeAddress'; break; case Address::TYPE_EMPLOYER: $type = 'employerAddress'; break; case Address::TYPE_BILLING: $type = 'billingAddress'; break; case Address::TYPE_OTHER: default: $type = 'otherAddress'; break; } $xmlAddress = $xmlPatient->addChild($type); $this->_addChild($xmlAddress, 'line1', $address->line1, $checked); $this->_addChild($xmlAddress, 'city', $address->city, $checked); $this->_addChild($xmlAddress, 'state', $address->state, $checked); $this->_addChild($xmlAddress, 'zip', $address->postalCode, $checked); } $phoneNumbers = PhoneNumber::listPhoneNumbers($personId); foreach ($phoneNumbers as $phoneNumber) { switch ($phoneNumber->type) { case PhoneNumber::TYPE_HOME: $type = 'homePhone'; break; case PhoneNumber::TYPE_WORK: $type = 'workPhone'; break; case PhoneNumber::TYPE_BILLING: $type = 'billingPhone'; break; case PhoneNumber::TYPE_EMPLOYER: $type = 'employerPhone'; break; case PhoneNumber::TYPE_MOBILE: $type = 'mobilePhone'; break; case PhoneNumber::TYPE_EMERGENCY: $type = 'emergencyPhone'; break; case PhoneNumber::TYPE_FAX: $type = 'faxPhone'; break; case PhoneNumber::TYPE_HOME_EVE: $type = 'homeEvePhone'; break; case PhoneNumber::TYPE_HOME_DAY: $type = 'homeDayPhone'; break; case PhoneNumber::TYPE_BEEPER: $type = 'beeperPhone'; break; default: $type = 'otherPhone'; break; } $xmlPhone = $xmlPatient->addChild($type); $this->_addChild($xmlPhone, 'number', $phoneNumber->number, $checked); } if ($person->primaryPracticeId > 0) { $practice = new Practice(); $practice->practiceId = (int) $person->primaryPracticeId; $practice->populate(); $address = $practice->primaryAddress; $xmlPractice = $xmlPatient->addChild('practice'); $this->_addChild($xmlPractice, 'name', $practice->name, $checked); $xmlPrimaryAddress = $xmlPractice->addChild('primaryAddress'); $this->_addChild($xmlPrimaryAddress, 'line1', $address->line1, $checked); $this->_addChild($xmlPrimaryAddress, 'city', $address->city, $checked); $this->_addChild($xmlPrimaryAddress, 'state', $address->state, $checked); $this->_addChild($xmlPrimaryAddress, 'zip', $address->postalCode, $checked); $this->_addChild($xmlPractice, 'mainPhone', $practice->mainPhone->number, $checked); $this->_addChild($xmlPractice, 'faxNumber', $practice->fax->number, $checked); } $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 = $xmlPatient->addChild('payer'); if ($primary !== null) { $this->_addChild($xmlPayer, 'medicareNumber', $primary->insuranceProgram->payerIdentifier, $checked); } if ($secondary !== null) { $this->_addChild($xmlPayer, 'medicaidNumber', $secondary->insuranceProgram->payerIdentifier, $checked); } return $xml; }
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'); }
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); }