public function listInsurersAction() { $patientId = (int) $this->_getParam('patientId'); $rows = array(); $insurancePrograms = InsuranceProgram::getInsurancePrograms(); $insuredRelationship = new InsuredRelationship(); $insuredRelationshipIterator = $insuredRelationship->getIteratorByPersonId($patientId); $subscribers = array(); // TODO: get the actual subscribers; foreach ($insuredRelationshipIterator as $item) { $company = ''; $program = ''; if (isset($insurancePrograms[$item->insuranceProgramId])) { $exp = explode('->', $insurancePrograms[$item->insuranceProgramId]); $company = $exp[0]; $program = $exp[1]; } $subscriber = ''; if (isset($subscribers[$item->subscriberId])) { $subscriber = $subscribers[$item->subscriberId]; } $effectiveEnd = date('m/d/Y', strtotime($item->effectiveEnd)); $effective = 'Until'; $effectiveToTime = strtotime($effectiveEnd); if ($effectiveToTime <= strtotime(date('m/d/Y'))) { $effective = 'Ended'; } $effective .= ' ' . $effectiveEnd; $tmp = array(); $tmp['id'] = $item->insuredRelationshipId; $tmp['data'][] = $company; $tmp['data'][] = $program; $tmp['data'][] = $item->groupName; $tmp['data'][] = $item->groupNumber; $tmp['data'][] = $item->copay; $tmp['data'][] = $subscriber; $tmp['data'][] = $effective; $tmp['data'][] = $item->active ? __('Yes') : __('No'); $rows[] = $tmp; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(array('rows' => $rows)); }
public function populatePayers(SimpleXMLElement $xml) { $component = $xml->addChild('component'); $section = $component->addChild('section'); $templateId = $section->addChild('templateId'); $templateId->addAttribute('root', '2.16.840.1.113883.10.20.1.9'); // <!-- Payers section template --> $code = $section->addChild('code'); $code->addAttribute('code', '48768-6'); $code->addAttribute('codeSystem', '2.16.840.1.113883.6.1'); $section->addChild('title', 'Payers'); $rows = array(); $insurancePrograms = InsuranceProgram::getInsurancePrograms(); $insuredRelationship = new InsuredRelationship(); $insuredRelationshipIterator = $insuredRelationship->getIteratorByPersonId($this->_patientId); foreach ($insuredRelationshipIterator as $item) { $company = ''; $program = ''; if (isset($insurancePrograms[$item->insuranceProgramId])) { $exp = explode('->', $insurancePrograms[$item->insuranceProgramId]); $company = html_convert_entities($exp[0]); $program = html_convert_entities($exp[1]); } $rows[] = array('company' => $company, 'program' => $program, 'groupNumber' => html_convert_entities($item->groupNumber)); } $text = $section->addChild('text'); if ($rows) { $table = $text->addChild('table'); $thead = $table->addChild('thead'); $tr = $thead->addChild('tr'); $tr->addChild('th', 'Payer name'); $tr->addChild('th', 'Policy type / Coverage type'); $tr->addChild('th', 'Covered party ID'); $tr->addChild('th', 'Authorization(s)'); $tbody = $table->addChild('tbody'); foreach ($rows as $row) { $tr = $tbody->addChild('tr'); $tr->addChild('td', $row['company']); $tr->addChild('td', $row['program']); $tr->addChild('td', $row['groupNumber']); $tr->addChild('td', ''); } } }
public function listEligibilityAction() { $appointmentId = (int) $this->_getParam('appointmentId'); $rows = array(); $appointment = new Appointment(); $appointment->appointmentId = $appointmentId; $appointment->populate(); $personId = (int) $appointment->patientId; $insuredRelationship = new InsuredRelationship(); $insuredRelationship->personId = $personId; $insuredRelationshipIterator = $insuredRelationship->getActiveEligibility(); foreach ($insuredRelationshipIterator as $item) { $rows[] = $this->_generateEligibilityRowData($item); } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(array('rows' => $rows)); }
public function claimAction() { $visitId = (int) $this->_getParam('visitId'); $insurancePrograms = array(); $insuranceProgramId = 0; if ($visitId > 0) { $visit = new Visit(); $visit->visitId = $visitId; $visit->populate(); $insuredRelationship = new InsuredRelationship(); $insuredRelationship->personId = (int) $visit->patientId; $insurancePrograms = $insuredRelationship->getProgramList(); $insuranceProgramId = (int) $visit->activePayerId; } $this->view->visitId = $visitId; $this->view->insurancePrograms = $insurancePrograms; $this->view->insuranceProgramId = $insuranceProgramId; $this->render(); }
public static function patient($personId) { $newPatient = true; $db = Zend_Registry::get('dbAdapter'); $sqlSelect = $db->select()->from('audits', 'COUNT(*) AS ctr')->where("objectClass = 'Patient' AND objectId = ?", (int) $personId); if (($row = $db->fetchRow($sqlSelect)) && $row['ctr'] > 1) { $newPatient = false; } $data = self::_getPatientData($personId); $subscribersEnum = array(); $enumeration = new Enumeration(); $enumeration->populateByUniqueName(InsuranceProgram::INSURANCE_ENUM_NAME); $enumerationClosure = new EnumerationClosure(); foreach ($enumerationClosure->getAllDescendants($enumeration->enumerationId, 1, true) as $enum) { $rowset = $enumerationClosure->getAllDescendants($enum->enumerationId, 1, true); if ($enum->key != InsuranceProgram::INSURANCE_SUBSCRIBER_ENUM_KEY) { continue; } foreach ($rowset as $row) { $subscribersEnum[$row->key] = $row->name; } } $insuredRelationship = new InsuredRelationship(); $sqlSelect = $db->select()->from($insuredRelationship->_table)->where('person_id = ?', $personId)->where('active = 1')->order('program_order'); $insuredRelationshipIterator = $insuredRelationship->getIterator($sqlSelect); $subscribers = array(); $insurances = array(); $guarantors = array(); foreach ($insuredRelationshipIterator as $item) { $subscriberId = (int) $item->subscriberId; $subscriberToPatientRelationship = $item->subscriberToPatientRelationship; if (!$subscriberId > 0) { $subscriberId = $personId; $subscriberToPatientRelationship = 'SELF'; } if (isset($subscribersEnum[$subscriberToPatientRelationship])) { $subscriberToPatientRelationship = $subscribersEnum[$subscriberToPatientRelationship]; } if (!isset($subscribers[$subscriberId])) { $patient = new Patient(); $patient->personId = $subscriberId; $patient->populate(); $subscribers[$subscriberId] = $patient; } $subscriber = self::_getPatientData($subscribers[$subscriberId], false); $subscriber['relation'] = strtoupper(substr($subscriberToPatientRelationship, 0, 1)); $insuranceProgram = $item->insuranceProgram; $companyId = (int) $insuranceProgram->companyId; $phoneNumber = new PhoneNumber(); $sqlSelect = $db->select()->from(array('cn' => 'company_number'))->join(array('n' => 'number'), 'n.number_id = cn.number_id')->where('n.active = 1')->where('cn.company_id = ?', $companyId)->order('n.displayOrder')->limit(1); $phoneNumber->populateWithSql($sqlSelect->__toString()); $insurance = array(); $insurance['companyId'] = $companyId; $insurance['companyName'] = $insuranceProgram->company->name; $address = $insuranceProgram->address; $insurance['line1'] = $address->line1; $insurance['line2'] = $address->line2; $insurance['city'] = $address->city; $insurance['state'] = $address->state; $insurance['zip'] = $address->postalCode; $insurance['phoneNumber'] = $phoneNumber->number; $insurance['groupNumber'] = $item->groupName; $insurance['groupName'] = ''; $insurance['policyNumber'] = $item->groupNumber; //$insurance['ssn'] = $insuranceProgram->payerIdentifier; $insurances[] = array('subscriber' => $subscriber, 'insurance' => $insurance); $guarantors[] = $subscriber; } $adt = $newPatient ? 'A04' : 'A08'; $t = microtime(); $x = explode(' ', $t); $date = date('YmdHis', $x[1]); $messageId = $date . str_replace('.', '0', $x[0]); $id = 0; $hl7Guarantors = array(); foreach ($guarantors as $key => $guarantor) { $ctr = $key + 1; $hl7Guarantors[] = "GT1|{$ctr}|{$guarantor['recordNumber']}|{$guarantor['lastName']}^{$guarantor['firstName']}^{$guarantor['middleName']}^{$guarantor['suffix']}^^||{$guarantor['line1']}^{$guarantor['line2']}^{$guarantor['city']}^{$guarantor['state']}^{$guarantor['zip']}|{$guarantor['homePhone']}|{$guarantor['businessPhone']}|{$guarantor['dateOfBirth']}|{$guarantor['gender']}||S|{$guarantor['ssn']}|"; } $hl7Insurances = array(); foreach ($insurances as $key => $value) { $ctr = $key + 1; $subscriber = $value['subscriber']; $insurance = $value['insurance']; $hl7Insurances[] = "IN1|{$ctr}|{$insurance['companyId']}^{$insurance['companyName']}|{$insurance['companyId']}|{$insurance['companyName']}|{$insurance['line1']}^{$insurance['line2']}^{$insurance['city']}^{$insurance['state']}^{$insurance['zip']}||{$insurance['phoneNumber']}|{$insurance['groupNumber']}|{$insurance['groupName']}|||||||{$subscriber['lastName']}^{$subscriber['firstName']}^{$subscriber['middleName']}^{$subscriber['suffix']}^^|{$subscriber['relation']}|{$subscriber['dateOfBirth']}|{$subscriber['line1']}^{$subscriber['line2']}^{$subscriber['city']}^{$subscriber['state']}^{$subscriber['zip']}|Y||{$ctr}||||||||||||||{$insurance['policyNumber']}|0||||||{$subscriber['gender']}||||||{$subscriber['ssn']}|"; if (!strlen($subscriber['ssn']) > 0) { continue; } $hl7Insurances[] = "IN2|{$ctr}|{$subscriber['ssn']}"; } $patient = $data['patient']; $provider = $data['provider']; $hl7Message = array(); $hl7Message[] = "MSH|^~\\&|MedMgr|989801|aroeshl7_prod|HEST|{$date}||ADT^{$adt}|{$messageId}|P|2.3|{$id}|"; $hl7Message[] = "EVN|{$adt}|{$date}|||38|"; $hl7Message[] = self::_PID($patient); $hl7Message[] = self::_PV1($provider); foreach ($hl7Guarantors as $hl7Guarantor) { $hl7Message[] = $hl7Guarantor; } foreach ($hl7Insurances as $hl7Insurance) { $hl7Message[] = $hl7Insurance; } $separator = "\r\n"; return implode($separator, $hl7Message); }
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'); }
protected static function _generate4010A1($claimId, array $claim) { static $ctr = 0; static $visits = array(); static $practices = array(); static $insurancePrograms = array(); static $providers = array(); static $patients = array(); $claimId = (int) $claimId; $claimLine = new ClaimLine(); $claimLine->populateByClaimId($claimId); $visitId = (int) $claimLine->visitId; if (!isset($visits[$visitId])) { $visit = new Visit(); $visit->visitId = $visitId; $visit->populate(); $visits[$visitId] = $visit; } $visit = $visits[$visitId]; $patientId = (int) $visit->patientId; if (!isset($patients[$patientId])) { $patient = new Patient(); $patient->personId = $patientId; $patient->populate(); $patients[$patientId] = $patient; } $patient = $patients[$patientId]; $practiceId = (int) $visit->practiceId; if (!isset($practices[$practiceId])) { $practice = new Practice(); $practice->practiceId = $practiceId; $practice->populate(); $practices[$practiceId] = $practice; } $practice = $practices[$practiceId]; $insuranceProgramId = (int) $visit->activePayerId; if (!isset($insurancePrograms[$insuranceProgramId])) { $insurance = new InsuranceProgram(); $insurance->insuranceProgramId = $insuranceProgramId; $insurance->populate(); $insurancePrograms[$insuranceProgramId] = $insurance; } $insuranceProgram = $insurancePrograms[$insuranceProgramId]; $providerId = (int) $visit->treatingPersonId; if (!isset($providers[$providerId])) { $provider = new Provider(); $provider->personId = $providerId; $provider->populate(); $providers[$providerId] = $provider; } $provider = $providers[$providerId]; $billAs = (int) $provider->billAs; if ($billAs > 0) { $providerId = $billAs; if (!isset($providers[$providerId])) { $provider = new Provider(); $provider->personId = $providerId; $provider->populate(); $providers[$providerId] = $provider; } $provider = $providers[$providerId]; } $subscribers = array(); $enumeration = new Enumeration(); $enumeration->populateByUniqueName(InsuranceProgram::INSURANCE_ENUM_NAME); $enumerationClosure = new EnumerationClosure(); foreach ($enumerationClosure->getAllDescendants($enumeration->enumerationId, 1, true) as $enum) { $rowset = $enumerationClosure->getAllDescendants($enum->enumerationId, 1, true); if ($enum->key == InsuranceProgram::INSURANCE_SUBSCRIBER_ENUM_KEY) { foreach ($rowset as $row) { $subscribers[$row->key] = $row->name; } break; } } $insuredRelationship = new InsuredRelationship(); $db = Zend_Registry::get('dbAdapter'); $sqlSelect = $db->select()->from($insuredRelationship->_table)->where('insurance_program_id = ?', (int) $insuranceProgram->insuranceProgramId)->where('person_id = ?', (int) $patientId)->where('active = 1')->order('program_order')->limit(1); if ($row = $db->fetchRow($sqlSelect)) { $insuredRelationship->populateWithArray($row); } $subs = $insuredRelationship->subscriber; $subscriberAddr = $subs->address; $relationship = null; $relationshipCode = $insuredRelationship->subscriberToPatientRelationship; if (isset($subscribers[$relationshipCode])) { $relationship = $subscribers[$relationshipCode]; } if ($relationship === null) { $relationship = 'Self'; $relationshipCode = 18; $subs = new Person(); $subs->personId = $insuredRelationship->personId; $subs->populate(); } $subscriber = array('id' => (int) $subs->personId, 'relationship_code' => $relationshipCode, 'group_number' => $insuredRelationship->groupNumber, 'group_name' => $insuredRelationship->groupName, 'relationship' => $relationship, 'last_name' => $subs->lastName, 'first_name' => $subs->firstName, 'middle_name' => $subs->middleName, 'address' => array('line1' => $subscriberAddr->line1, 'line2' => $subscriberAddr->line2, 'city' => $subscriberAddr->city, 'state' => $subscriberAddr->state, 'zip' => $subscriberAddr->zipCode), 'date_of_birth' => date('Ymd', strtotime($subs->dateOfBirth)), 'gender' => $subs->gender, 'contract_type_code' => '', 'contract_amount' => '', 'contract_percent' => '', 'contract_code' => '', 'contract_discount_percent' => '', 'contract_version' => ''); $practiceAddr = $practice->primaryAddress; $room = new Room(); $room->roomId = (int) $visit->roomId; $room->populate(); $facility = $room->building; $phoneNumber = PhoneNumber::autoFixNumber($practice->mainPhone->number); $phoneLen = strlen($phoneNumber); if ($phoneLen < 10) { $phoneNumber = str_pad($phoneNumber, 10, '0', STR_PAD_LEFT); } else { if ($phoneLen > 10) { $phoneNumber = substr($phoneNumber, -10); } } $identifierType = ''; $identifier = $practice->identifier; if (strlen($identifier) > 0) { $identifierType = 'XX'; } //24'; $data = array('hlCount' => ++$ctr); $data['practice'] = array('name' => $practice->name, 'identifier_type' => $identifierType, 'identifier' => $identifier, 'address' => array('line1' => $practiceAddr->line1, 'line2' => $practiceAddr->line2, 'city' => $practiceAddr->city, 'state' => $practiceAddr->state, 'zip' => $practiceAddr->zipCode), 'phoneNumber' => $phoneNumber); $data['treating_facility'] = array('identifier' => $facility->identifier); $dateOfTreatment = date('Ymd', strtotime($visit->dateOfTreatment)); $payer2Id = $insuranceProgram->insuranceProgramId; if (strlen($payer2Id) < 2) { $payer2Id = str_pad($payer2Id, 2, '0', STR_PAD_LEFT); } $identifierType = ''; $identifier = $provider->person->identifier; if (strlen($identifier) > 0) { $identifierType = 'XX'; } //34'; $claimData = array('claim' => $claim, 'patient' => array('date_of_initial_treatment' => $dateOfTreatment, 'date_of_onset' => $dateOfTreatment, 'comment_type' => '', 'comment' => ''), 'treating_facility' => array('facility_code' => $facility->facilityCodeId, 'name' => $facility->name, 'address' => array('line1' => $facility->line1, 'line2' => $facility->line2, 'city' => $facility->city, 'state' => $facility->state, 'zip' => $facility->zipCode)), 'provider' => array('signature_on_file' => 'Y', 'accepts_assignment' => 'A', 'last_name' => $provider->person->lastName, 'first_name' => $provider->person->firstName, 'identifier_type' => $identifierType, 'identifier' => $identifier, 'identifier_2' => ''), 'billing_facility' => array('clia_number' => ''), 'subscriber' => $subscriber, 'clearing_house' => array('credit_max_amount' => '', 'repricing_method' => '', 'allowed_amount' => '', 'savings_amount' => '', 'identifier' => '', 'rate' => '', 'apg_code' => '', 'apg_amount' => '', 'reject_code' => '', 'compliance_code' => '', 'exception_code' => ''), 'referring_provider' => array('last_name' => '', 'first_name' => '', 'referral_type' => '', 'identifier_type' => '', 'identifier' => '', 'taxonomy_code' => ''), 'supervising_provider' => array('last_name' => '', 'first_name' => '', 'identifier_type' => '', 'identifier' => ''), 'payer2' => array('id' => $payer2Id, 'name' => $insuranceProgram->name)); $clm = array(); $iterator = new ClaimLineIterator(); $iterator->setFilters(array('claimId' => $claimId)); foreach ($iterator as $row) { $baseFee = (double) $row->baseFee; $adjustedFee = (double) $row->adjustedFee; $paid = (double) $row->paid; $billed = $row->totalMiscCharge; if ($baseFee > 0) { $billed += $baseFee - $adjustedFee; } $balance = abs($billed) - $paid; $clm[] = array('claim' => $claimData['claim'], 'patient' => $claimData['patient'], 'claim_line' => array('amount' => $balance, 'diagnosis1' => preg_replace('/[\\.]/', '', $row->diagnosisCode1), 'diagnosis2' => preg_replace('/[\\.]/', '', $row->diagnosisCode2), 'diagnosis3' => preg_replace('/[\\.]/', '', $row->diagnosisCode3), 'diagnosis4' => preg_replace('/[\\.]/', '', $row->diagnosisCode4), 'diagnosis5' => preg_replace('/[\\.]/', '', $row->diagnosisCode5), 'diagnosis6' => preg_replace('/[\\.]/', '', $row->diagnosisCode6), 'diagnosis7' => preg_replace('/[\\.]/', '', $row->diagnosisCode7), 'diagnosis8' => preg_replace('/[\\.]/', '', $row->diagnosisCode8), 'procedure' => $row->procedureCode, 'modifier1' => $row->modifier1, 'modifier2' => $row->modifier2, 'modifier3' => $row->modifier3, 'modifier4' => $row->modifier4, 'units' => str_replace('.00', '', $row->units), 'date_of_treatment' => $dateOfTreatment, 'clia_number' => ''), 'treating_facility' => $claimData['treating_facility'], 'provider' => $claimData['provider'], 'billing_facility' => $claimData['billing_facility'], 'subscriber' => $subscriber, 'clearing_house' => $claimData['clearing_house'], 'referring_provider' => $claimData['referring_provider'], 'supervising_provider' => $claimData['supervising_provider'], 'payer2' => $claimData['payer2']); } $hl2 = array(); $hl2[] = array('hlCount' => $ctr, 'hlCount2' => ++$ctr, 'payer' => array('responsibility' => 'P'), 'subscriber' => $subscriber, 'patient' => array('weight' => '', 'last_name' => $patient->lastName, 'first_name' => $patient->firstName), 'responsible_party' => array('last_name' => '', 'first_name' => '', 'address' => array('line1' => '', 'line2' => '', 'city' => '', 'state' => '', 'zip' => '')), 'CLM' => $clm); $data['HL2'] = $hl2; return $data; }
protected function _populateCMS1500XML(SimpleXMLElement $xml, ClaimLine $claimLine) { $claimId = (int) $claimLine->claimId; $visitId = (int) $claimLine->visitId; $payerId = (int) $claimLine->insuranceProgramId; $visit = new Visit(); $visit->visitId = $visitId; $visit->populate(); $dateOfTreatment = $visit->dateOfTreatment; $patientId = (int) $visit->patientId; $providerId = (int) $visit->treatingPersonId; $insuranceProgram = new InsuranceProgram(); $insuranceProgram->insuranceProgramId = $payerId; $insuranceProgram->populate(); $insuranceAddress = $insuranceProgram->address; $insuredRelationship = InsuredRelationship::filterByPayerPersonIds($payerId, $patientId); $patient = new Patient(); $patient->personId = $patientId; $patient->populate(); $patientAddress = $patient->address; $patientPhone = $patient->phoneNumber; $provider = new Provider(); $provider->personId = $providerId; $provider->populate(); $providerAddress = $provider->person->address; $providerPhone = $provider->phoneNumber; $buildingId = (int) $visit->buildingId; $building = new Building(); $building->buildingId = $buildingId; $building->populate(); $address = $building->practice->primaryAddress; $amountTotal = 0; $claimLines = array(); $iterator = new ClaimLineIterator(); $iterator->setFilters(array('claimId' => $claimId)); foreach ($iterator as $orm) { $amount = (double) $orm->baseFee; $amountTotal += $amount; $row = array(); $row['procedure'] = $orm->procedureCode; $modifiers = array(); for ($i = 1; $i <= 4; $i++) { $field = 'modifier' . $i; $key = $orm->{$field}; if (strlen($key) > 0) { $modifiers[$i] = $key; } } $row['modifier'] = implode(',', $modifiers); $row['amount'] = $amount; $row['units'] = $orm->units; $diagnoses = array(); for ($i = 1; $i <= 8; $i++) { $field = 'diagnosisCode' . $i; $key = $orm->{$field}; if (strlen($key) > 0) { $diagnoses[$key] = $key; } } $row['diagnoses'] = $diagnoses; $row['diagnosis_pointer'] = ''; // TODO: need to resolve on the issue of multiple diagnoses per claimLine $claimLines[] = $row; } $amountPaid = $claimLine->paid; $netAmountTotal = $amountTotal - $amountPaid; if ($payerId > 0) { $xmlPayer = $xml->addChild('payer'); $this->_addChild($xmlPayer, 'name', InsuranceProgram::getInsuranceProgram($payerId)); if ($insuranceAddress->addressId > 0) { $xmlFbaddress = $xmlPayer->addChild('fbaddress'); $this->_addChild($xmlFbaddress, 'line1', $insuranceAddress->line1); $this->_addChild($xmlFbaddress, 'line2', $insuranceAddress->line2); $this->_addChild($xmlFbaddress, 'city', $insuranceAddress->city); $this->_addChild($xmlFbaddress, 'state', $insuranceAddress->state); $this->_addChild($xmlFbaddress, 'zip', $insuranceAddress->zipCode); } } $xmlPatient = $xml->addChild('patient'); $this->_addChild($xmlPatient, 'record_number', $patient->recordNumber); $this->_addChild($xmlPatient, 'last_name', $patient->lastName); $this->_addChild($xmlPatient, 'first_name', $patient->firstName); $this->_addChild($xmlPatient, 'middle_name', $patient->middleName); if ($patientAddress->addressId > 0) { $xmlFbaddress = $xmlPatient->addChild('fbaddress'); $this->_addChild($xmlFbaddress, 'line1', $patientAddress->line1); $this->_addChild($xmlFbaddress, 'line2', $patientAddress->line2); $this->_addChild($xmlFbaddress, 'city', $patientAddress->city); $this->_addChild($xmlFbaddress, 'state', $patientAddress->state); $this->_addChild($xmlFbaddress, 'zip', $patientAddress->zipCode); } $this->_addChild($xmlPatient, 'phone_number', $patientPhone->number); $this->_addChild($xmlPatient, 'date_of_birth', $patient->dateOfBirth); $subscriber = $insuredRelationship->subscriber; $subscriberAddress = $subscriber->address; if ($subscriber->personId > 0) { $xmlSubscriber = $xml->addChild('subscriber'); $this->_addChild($xmlSubscriber, 'phone_number', $subscriber->phoneNumber->number); if ($subscriberAddress->addressId > 0) { $xmlFbaddress = $xmlSubscriber->addChild('fbaddress'); $this->_addChild($xmlFbaddress, 'line1', $subscriberAddress->line1); $this->_addChild($xmlFbaddress, 'line2', $subscriberAddress->line2); $this->_addChild($xmlFbaddress, 'city', $subscriberAddress->city); $this->_addChild($xmlFbaddress, 'state', $subscriberAddress->state); $this->_addChild($xmlFbaddress, 'zip', $subscriberAddress->zipCode); } $this->_addChild($xmlSubscriber, 'last_name', $subscriber->lastName); $this->_addChild($xmlSubscriber, 'first_name', $subscriber->firstName); $this->_addChild($xmlSubscriber, 'middle_name', $subscriber->middleName); $this->_addChild($xmlSubscriber, 'group_number', $insuredRelationship->groupNumber); $this->_addChild($xmlSubscriber, 'gender', $subscriber->gender); $this->_addChild($xmlSubscriber, 'date_of_birth', $subscriber->dateOfBirth); } if ($building->buildingId > 0) { $xmlPractice = $xml->addChild('practice'); $this->_addChild($xmlPractice, 'identifier', $building->practice->identifier); $xmlTreatingFacility = $xml->addChild('treating_facility'); $this->_addChild($xmlTreatingFacility, 'identifier', $building->identifier); $this->_addChild($xmlTreatingFacility, 'name', $building->name); $xmlFbaddress = $xmlTreatingFacility->addChild('fbaddress'); $this->_addChild($xmlFbaddress, 'line1', $building->line1); $this->_addChild($xmlFbaddress, 'line2', $building->line2); $this->_addChild($xmlFbaddress, 'city', $building->city); $this->_addChild($xmlFbaddress, 'state', $building->state); $this->_addChild($xmlFbaddress, 'zip', $building->zipCode); } $xmlProvider = $xml->addChild('provider'); $this->_addChild($xmlProvider, 'identifier', $provider->identifier); $this->_addChild($xmlProvider, 'first_name', $provider->firstName); $this->_addChild($xmlProvider, 'last_name', $provider->lastName); if ($providerAddress->addressId > 0) { $xmlFbaddress = $xmlProvider->addChild('fbaddress'); $this->_addChild($xmlFbaddress, 'line1', $providerAddress->line1); $this->_addChild($xmlFbaddress, 'line2', $providerAddress->line2); $this->_addChild($xmlFbaddress, 'city', $providerAddress->city); $this->_addChild($xmlFbaddress, 'state', $providerAddress->state); $this->_addChild($xmlFbaddress, 'zip', $providerAddress->zipCode); } $xmlDiagnoses = null; foreach ($claimLines as $row) { foreach ($row['diagnoses'] as $diagnosis) { if ($xmlDiagnoses === null) { $xmlDiagnoses = $xml->addChild('diagnoses'); } $this->_addChild($xmlDiagnoses, 'array', $diagnosis); } } $xmlClaimLine = null; $dateOfService = date('m d y', strtotime($dateOfTreatment)); foreach ($claimLines as $row) { if ($xmlClaimLine === null) { $xmlClaimLine = $xml->addChild('claim_lines'); } // 0 - 5 ONLY $xmlClaimLineArr = $xmlClaimLine->addChild('array'); $this->_addChild($xmlClaimLineArr, 'date_of_treatment', $dateOfService); $this->_addChild($xmlClaimLineArr, 'procedure', $row['procedure']); $this->_addChild($xmlClaimLineArr, 'modifier', $row['modifier']); $this->_addChild($xmlClaimLineArr, 'diagnosis_pointer', $row['diagnosis_pointer']); $this->_addChild($xmlClaimLineArr, 'amount', $row['amount']); $this->_addChild($xmlClaimLineArr, 'units', $row['units']); } $xmlClaim = $xml->addChild('claim'); $this->_addChild($xmlClaim, 'amount_total', $amountTotal); $this->_addChild($xmlClaim, 'amount_paid', $amountPaid); $this->_addChild($xmlClaim, 'net_amount_total', $netAmountTotal); //$doc = new DOMDocument(); //$doc->formatOutput = true; //$doc->loadXML($xml->asXML()); //file_put_contents('/tmp/claims.xml',$doc->saveXML()); }
public function processReorderPayersAction() { $from = (int) $this->_getParam('from'); $to = (int) $this->_getParam('to'); $ret = false; if ($from > 0 && $to > 0) { $payerFrom = new InsuredRelationship(); $payerFrom->insuredRelationshipId = $from; $payerFrom->populate(); $payerTo = new InsuredRelationship(); $payerTo->insuredRelationshipId = $to; $payerTo->populate(); $ret = InsuredRelationship::reorder($payerFrom, $payerTo); } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($ret); }