Ejemplo n.º 1
0
 protected function _edit($groupId = null)
 {
     $groupId = (int) $groupId;
     $claimRule = new ClaimRule();
     $claimRule->event = ClaimRule::EVENT_WARNING;
     $action = 'add';
     if ($groupId > 0) {
         $claimRule->groupId = $groupId;
         $claimRule->populateWithGroupId();
         $claim = new ClaimRule();
         $claim->title = $claimRule->title;
         $claim->message = $claimRule->message;
         $claim->groupId = $claimRule->groupId;
         $claim->event = $claimRule->event;
         $claimRule = $claim;
         // swap, we only need the hidden fields
         $action = 'edit';
     }
     $this->view->action = $action;
     $form = new WebVista_Form(array('name' => 'claimRule'));
     $form->setAction(Zend_Registry::get('baseUrl') . 'claim-rules.raw/process-' . $action);
     $form->loadORM($claimRule, 'claimRule');
     $form->setWindow('windowEditClaimRuleId');
     $this->view->form = $form;
     $this->view->claimRule = $claimRule;
     $modifiers = array('' => '');
     $enumeration = new Enumeration();
     $enumeration->populateByUniqueName('Procedure Modifiers');
     $closure = new EnumerationClosure();
     $descendants = $closure->getAllDescendants($enumeration->enumerationId, 1, true);
     foreach ($descendants as $row) {
         $modifiers[$row->key] = $row->key . ': ' . $row->name;
     }
     $this->view->modifiers = $modifiers;
     $insurancePrograms = array('' => '');
     foreach (InsuranceProgram::getInsurancePrograms() as $key => $value) {
         $insurancePrograms[$key] = $value;
     }
     $this->view->insurancePrograms = $insurancePrograms;
     $this->render('edit');
 }
 public function editInsurerAction()
 {
     $patientId = (int) $this->_getParam('patientId');
     $id = (int) $this->_getParam('id');
     $this->_insurer = new InsuredRelationship();
     $this->_insurer->personId = $patientId;
     if ($id > 0) {
         $this->_insurer->insuredRelationshipId = $id;
         $this->_insurer->populate();
     }
     $this->_form = new WebVista_Form(array('name' => 'edit-insurer'));
     $this->_form->setAction(Zend_Registry::get('baseUrl') . "patient.raw/process-edit-insurer");
     $this->_form->loadORM($this->_insurer, "Insurer");
     $this->_form->setWindow('winEditInsurerId');
     $this->view->form = $this->_form;
     $insuranceProgram = new InsuranceProgram();
     $insurancePrograms = array('' => '');
     foreach (InsuranceProgram::getInsurancePrograms() as $id => $val) {
         $insurancePrograms[$id] = $val;
     }
     $this->view->insurancePrograms = $insurancePrograms;
     $assignings = array('' => '');
     $this->view->assignings = $assignings;
     $subscribers = array('' => '');
     $this->view->subscribers = $subscribers;
     $this->render('edit-insurer');
 }
Ejemplo n.º 3
0
 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 processAddProgramAction()
 {
     $params = $this->_getParam('program');
     $program = new InsuranceProgram();
     $program->populateWithArray($params);
     $program->persist();
     $ret = true;
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($ret);
 }
 public function editProgramAction()
 {
     $id = (int) $this->_getParam('id');
     $companyId = (int) $this->_getParam('companyId');
     $this->_program = new InsuranceProgram();
     if ($id > 0) {
         $this->_program->insuranceProgramId = $id;
         $this->_program->populate();
     } else {
         $this->_program->companyId = $companyId;
     }
     $this->_form = new WebVista_Form(array('name' => 'edit-program'));
     $this->_form->setAction(Zend_Registry::get('baseUrl') . 'insurance-manager.raw/process-edit-program');
     $this->_form->loadORM($this->_program, 'program');
     $this->_form->setWindow('winEditProgramId');
     $this->view->form = $this->_form;
     $this->view->buildings = $this->_getBuildings();
     $insurancePrefList = InsuranceProgram::getListInsurancePreferences();
     $payerTypes = array('' => '');
     if (isset($insurancePrefList[InsuranceProgram::INSURANCE_PAYER_TYPE_ENUM_KEY])) {
         foreach ($insurancePrefList[InsuranceProgram::INSURANCE_PAYER_TYPE_ENUM_KEY] as $key => $value) {
             $payerTypes[$key] = $value;
         }
     }
     $this->view->payerTypes = $payerTypes;
     $programTypes = array('' => '');
     if (isset($insurancePrefList[InsuranceProgram::INSURANCE_PROGRAM_TYPE_ENUM_KEY])) {
         foreach ($insurancePrefList[InsuranceProgram::INSURANCE_PROGRAM_TYPE_ENUM_KEY] as $key => $value) {
             $programTypes[$key] = $value;
         }
     }
     $this->view->programTypes = $programTypes;
     $fundsSources = array('' => '');
     if (isset($insurancePrefList[InsuranceProgram::INSURANCE_FUNDS_SOURCE_ENUM_KEY])) {
         foreach ($insurancePrefList[InsuranceProgram::INSURANCE_FUNDS_SOURCE_ENUM_KEY] as $key => $value) {
             $fundsSources[$key] = $value;
         }
     }
     $this->view->fundsSources = $fundsSources;
     $this->view->feeScheduleDisplay = $this->_program->displayFeeSchedule;
     $company = new Company();
     $addressIterator = $company->getAddressIterator($companyId);
     $addresses = array('' => '');
     foreach ($addressIterator as $addr) {
         $addresses[$addr->addressId] = $addr->name;
     }
     $this->view->addresses = $addresses;
     $this->render('edit-program');
 }
 public function listInsuranceProgramsAction()
 {
     $guid = $this->_getParam('fid');
     $fs = new FeeSchedule();
     $fs->guid = $guid;
     $fs->populateByGuid();
     $ids = array();
     foreach (explode(',', $fs->insuranceProgramIds) as $id) {
         $ids[$id] = $id;
     }
     $rows = array();
     foreach (InsuranceProgram::getInsurancePrograms() as $id => $value) {
         $checked = '';
         if (isset($ids[$id])) {
             $checked = '1';
         }
         $rows[] = array('id' => $id, 'data' => array($checked, $value), 'userdata' => array('program' => $value));
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }
Ejemplo n.º 7
0
 public function getAccountDetails()
 {
     $visitId = (int) $this->encounter_id;
     $ret = array('claimFiles' => array('details' => array(), 'totals' => array()), 'charges' => array('details' => array(), 'totals' => array()), 'miscCharges' => array('details' => array(), 'totals' => array()), 'payments' => array('details' => array(), 'totals' => array()), 'writeOffs' => array('details' => array(), 'totals' => array()));
     $totalBilled = 0;
     $totalPaid = 0;
     $totalWO = 0;
     $totalBalance = 0;
     foreach (ClaimFile::listClaims(array('visitId' => $visitId)) as $data) {
         $claimFile = $data['claimFile'];
         $totalBilled += (double) $claimFile->billed;
         $totalPaid += (double) $claimFile->paid;
         $totalWO += (double) $claimFile->writeOff;
         $totalBalance += (double) $claimFile->balance;
         $ret['claimFiles']['details'][] = $data;
     }
     $ret['claimFiles']['totals'] = array('billed' => $totalBilled, 'paid' => $totalPaid, 'writeOff' => $totalWO, 'balance' => $totalBalance);
     $totalBilled = 0;
     if ($this->closed) {
         $iterator = ClaimLine::mostRecentClaims($visitId);
         foreach ($iterator as $claimLine) {
             $totalBilled += (double) $claimLine->baseFee;
             $ret['charges']['details'][] = $claimLine;
         }
     } else {
         $fees = $this->calculateFees();
         $totalBilled += $fees['total'];
         $totalWO += $fees['discounted'];
         $discount = $fees['total'] - $fees['discounted'];
         if ($discount < 0) {
             $discount = 0;
         }
         $claimLine = new ClaimLine();
         $claimLine->baseFee = $fees['total'];
         $claimLine->adjustedFee = $fees['discounted'];
         $claimLine->visitId = $visitId;
         $claimLine->dateTime = $this->date_of_treatment;
         $claimLine->insuranceProgramId = $this->activePayerId;
         $claimLine->enteredBy = $this->getEnteredBy();
         $ret['charges']['details'][] = $claimLine;
         if ($discount > 0) {
             $writeOff = new WriteOff();
             $writeOff->amount = $discount;
             $writeOff->writeOffId = time();
             $writeOff->payerId = InsuranceProgram::lookupSystemId('Discounts');
             // ID of System->Discounts
             $writeOff->timestamp = $this->date_of_treatment;
             $writeOff->userId = $this->last_change_user_id > 0 ? $this->last_change_user_id : $this->created_by_user_id;
             $ret['writeOffs']['details'][] = $writeOff;
         }
     }
     $ret['charges']['totals'] = array('billed' => $totalBilled, 'paid' => 0, 'writeOff' => 0, 'balance' => 0);
     // misc charges
     $miscCharge = new MiscCharge();
     $totalBilled = 0;
     foreach ($miscCharge->getIteratorByVisitId($visitId) as $row) {
         $totalBilled += (double) $row->amount;
         $ret['miscCharges']['details'][] = $row;
     }
     $ret['miscCharges']['totals'] = array('billed' => $totalBilled, 'paid' => 0, 'writeOff' => 0, 'balance' => 0);
     $iterators = ClaimLine::getPaymentHistory(array('visitId' => $visitId, 'unposted' => true));
     $totalPaid = 0;
     $totalWO = 0;
     foreach ($iterators as $iterator) {
         foreach ($iterator as $item) {
             if ($item instanceof PostingJournal) {
                 $totalPaid += (double) $item->amount;
                 $ret['payments']['details'][] = $item;
             } else {
                 if ($item instanceof Payment) {
                     $totalPaid += (double) $item->unallocated;
                     $ret['payments']['details'][] = $item;
                 } else {
                     $totalWO += (double) $item->amount;
                     $ret['writeOffs']['details'][] = $item;
                 }
             }
         }
     }
     // payments
     $ret['payments']['totals'] = array('billed' => 0, 'paid' => $totalPaid, 'writeOff' => 0, 'balance' => 0);
     // writeoffs
     $ret['writeOffs']['totals'] = array('billed' => 0, 'paid' => 0, 'writeOff' => $totalWO, 'balance' => 0);
     return $ret;
 }
Ejemplo n.º 8
0
 public function listPatientAccountDetailsAction()
 {
     $visitId = (int) $this->_getParam('visitId');
     $visit = new Visit();
     $visit->visitId = $visitId;
     $visit->populate();
     $facility = $visit->facility;
     // Facility
     $providerDisplayName = $visit->providerDisplayName;
     // Provider
     $summary = $visit->accountDetails;
     $rows = array();
     foreach ($summary['claimFiles']['details'] as $data) {
         $claimFile = $data['claimFile'];
         $visit = $data['visit'];
         $claimFileId = (int) $claimFile->claimFileId;
         $row = array();
         $row['id'] = $visitId;
         $row['data'] = array();
         $row['data'][] = $claimFileId;
         // Id
         $row['data'][] = InsuranceProgram::getInsuranceProgram($claimFile->payerId);
         // Payer Name
         $row['data'][] = substr($claimFile->dateBilled, 0, 10);
         // Date Billed
         $row['data'][] = substr($claimFile->dateTime, 0, 10);
         // Date
         $row['data'][] = '$' . $claimFile->billed;
         // Billed
         $row['data'][] = '$' . $claimFile->paid;
         // Paid
         $row['data'][] = '$' . $claimFile->writeOff;
         // Write Off
         $row['data'][] = '$' . $claimFile->balance;
         // Balance
         $row['data'][] = '';
         // Chk #
         $row['data'][] = $facility;
         // Facility
         $row['data'][] = $providerDisplayName;
         // Provider
         $row['data'][] = $claimFile->enteredBy;
         // Entered By
         if (!isset($rows[$id])) {
             $rows[$id] = array();
         }
         $rows[$id][] = $row;
     }
     $ctr = 0;
     // charges
     foreach ($summary['charges']['details'] as $row) {
         $amount = (double) $row->baseFee;
         $id = $row->visitId;
         if (!isset($rows[$id])) {
             $rows[$id] = array();
         }
         $rows[$id]['info'][] = array('amount' => $amount, 'type' => 'debit');
         $rows[$id][] = array('id' => $id . '-' . $ctr++, 'data' => array('Charge', InsuranceProgram::getInsuranceProgram($row->insuranceProgramId), substr($row->dateTime, 0, 10), '', '$' . $amount, '', '', '', '', $facility, $providerDisplayName, $row->enteredBy));
     }
     // misc charges
     foreach ($summary['miscCharges']['details'] as $row) {
         $amount = (double) $row->amount;
         $id = $row->miscChargeId;
         if (!isset($rows[$id])) {
             $rows[$id] = array();
         }
         $rows[$id]['info'][] = array('amount' => $amount, 'type' => 'debit');
         $rows[$id][] = array('id' => $id, 'data' => array('Misc Charge', '', substr($row->chargeDate, 0, 10), '', '$' . $amount, '', '', '', '', $facility, $providerDisplayName, $row->enteredBy));
     }
     // payments
     foreach ($summary['payments']['details'] as $row) {
         if ($row instanceof PostingJournal) {
             $amount = (double) $row->amount;
             $id = $row->postingJournalId;
             $datePosted = $row->datePosted;
             $refNum = $row->payment->refNum;
         } else {
             $amount = (double) $row->unallocated;
             $id = $row->paymentId;
             $datePosted = $row->paymentDate;
             $refNum = $row->refNum;
         }
         if (!isset($rows[$id])) {
             $rows[$id] = array();
         }
         $rows[$id]['info'][] = array('amount' => $amount, 'type' => 'credit');
         $rows[$id][] = array('id' => $id, 'data' => array('Payment', InsuranceProgram::getInsuranceProgram($row->payerId), '', substr($datePosted, 0, 10), '', '$' . $amount, '', '', $refNum, $facility, $providerDisplayName, $row->enteredBy));
     }
     // writeoffs
     foreach ($summary['writeOffs']['details'] as $row) {
         $amount = (double) $row->amount;
         $id = $row->writeOffId;
         if (!isset($rows[$id])) {
             $rows[$id] = array();
         }
         $rows[$id]['info'][] = array('amount' => $amount, 'type' => 'credit');
         $rows[$id][] = array('id' => $id, 'data' => array('Write Off', InsuranceProgram::getInsuranceProgram($row->payerId), '', substr($row->timestamp, 0, 10), '', '', '$' . $amount, '', '', $facility, $providerDisplayName, $row->enteredBy));
     }
     ksort($rows);
     $data = array('rows' => array());
     $balance = 0;
     foreach ($rows as $values) {
         $info = $values['info'];
         unset($values['info']);
         foreach ($values as $key => $value) {
             $amount = $info[$key]['amount'];
             if ($info[$key]['type'] == 'debit') {
                 $balance += $amount;
             } else {
                 $balance -= $amount;
             }
             $value['data'][7] = '$' . abs($balance);
             $data['rows'][] = $value;
         }
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
Ejemplo n.º 9
0
 public function getInsuranceDisplay()
 {
     $payerId = (int) $this->payer_id;
     $ret = '';
     if ($payerId > 0) {
         $ret = InsuranceProgram::getInsuranceProgram($payerId);
     }
     return $ret;
 }
Ejemplo n.º 10
0
 public static function listCharges(array $filters)
 {
     $db = Zend_Registry::get('dbAdapter');
     $sqlSelect = $db->select()->from('claimLines')->join('encounter', 'encounter.encounter_id = claimLines.visitId', array('SUM(claimLines.baseFee) AS totalBaseFee', 'SUM(claimLines.adjustedFee) AS totalAdjustedFee'))->order('claimLines.dateTime DESC')->order('claimLines.claimId DESC')->order('encounter.appointmentId')->group('encounter.encounter_id');
     $sqlSelect = $db->select()->from('encounter')->order('encounter.date_of_treatment DESC');
     $mscSelect = $db->select()->from('misc_charge', array('misc_charge.misc_charge_id AS id', 'misc_charge.amount AS billed', 'CONCAT(\'0\') AS paid', 'CONCAT(\'0\') AS writeOff', 'CONCAT(\'Misc Charge\') AS payer', 'encounter.date_of_treatment AS dateOfTreatment', 'misc_charge.charge_date AS dateBilled', 'CONCAT(patient.last_name,\', \',patient.first_name,\' \',patient.middle_name) AS patientName', 'CONCAT(\'\') AS facility', 'CONCAT(provider.last_name,\', \',provider.first_name,\' \',provider.middle_name) AS providerName'))->join('encounter', 'encounter.encounter_id = misc_charge.encounter_id')->join(array('patient' => 'person'), 'patient.person_id = encounter.patient_id')->join(array('provider' => 'person'), 'provider.person_id = encounter.treating_person_id')->order('misc_charge.charge_date DESC');
     foreach ($filters as $key => $value) {
         switch ($key) {
             case 'dateRange':
                 $sqlSelect->where("encounter.date_of_treatment BETWEEN '{$value['start']} 00:00:00' AND '{$value['end']} 23:59:59'");
                 $mscSelect->where("encounter.date_of_treatment BETWEEN '{$value['start']} 00:00:00' AND '{$value['end']} 23:59:59'");
                 break;
             case 'facilities':
                 // practice, building, room
                 if (!is_array($value)) {
                     $value = array($value);
                 }
                 $facilities = array();
                 foreach ($value as $val) {
                     $facilities[] = 'encounter.practice_id = ' . (int) $val['practice'] . ' AND encounter.building_id = ' . (int) $val['building'] . ' AND encounter.room_id = ' . (int) $val['room'];
                 }
                 $sqlSelect->where(implode(' OR ', $facilities));
                 $mscSelect->where(implode(' OR ', $facilities));
                 break;
             case 'payers':
                 $payers = array();
                 foreach ($value as $payerId) {
                     $payers[] = (int) $payerId;
                 }
                 $payers = implode(',', $payers);
                 $sqlSelect->where('encounter.activePayerId IN (' . $payers . ')');
                 $mscSelect->where('encounter.activePayerId IN (' . $payers . ')');
                 break;
             case 'facility':
                 // practice, building, room
                 $sqlSelect->where('encounter.practice_id = ?', (int) $value['practice']);
                 $sqlSelect->where('encounter.building_id = ?', (int) $value['building']);
                 $sqlSelect->where('encounter.room_id = ?', (int) $value['room']);
                 // practice, building, room
                 $mscSelect->where('encounter.practice_id = ?', (int) $value['practice']);
                 $mscSelect->where('encounter.building_id = ?', (int) $value['building']);
                 $mscSelect->where('encounter.room_id = ?', (int) $value['room']);
                 break;
             case 'insurer':
                 $sqlSelect->where('encounter.activePayerId = ?', (int) $value);
                 $mscSelect->where('encounter.activePayerId = ?', (int) $value);
                 break;
             case 'visitId':
                 $sqlSelect->where('encounter.encounter_id = ?', (int) $value);
                 $mscSelect->where('encounter.encounter_id = ?', (int) $value);
                 break;
             case 'provider':
                 $value = array($value);
             case 'providers':
                 $providers = array();
                 foreach ($value as $providerId) {
                     $providers[] = (int) $providerId;
                 }
                 $providers = implode(',', $providers);
                 $sqlSelect->where('encounter.treating_person_id IN (' . $providers . ')');
                 $mscSelect->where('encounter.treating_person_id IN (' . $providers . ')');
                 break;
             case 'closed':
                 $sqlSelect->where('encounter.closed = ?', (int) $value);
                 $mscSelect->where('encounter.closed = ?', (int) $value);
                 break;
             case 'void':
                 $sqlSelect->where('encounter.void = ?', (int) $value);
                 $mscSelect->where('encounter.void = ?', (int) $value);
                 break;
         }
     }
     $rows = array();
     $visits = array();
     $payers = array();
     $facilities = array();
     $patients = array();
     $providers = array();
     $stmt = $db->query($sqlSelect);
     $stmt->setFetchMode(Zend_Db::FETCH_ASSOC);
     while ($row = $stmt->fetch()) {
         $visit = new Visit();
         $visit->populateWithArray($row);
         $visitId = (int) $visit->visitId;
         $acct = $visit->accountSummary;
         $paid = $acct['payment'];
         $writeoff = $acct['writeoff'];
         $total = $acct['total'];
         $billed = $acct['billed'];
         $balance = $acct['balance'];
         $payerId = isset($acct['claimLine']) ? $acct['claimLine']->insuranceProgramId : $visit->activePayerId;
         if (!isset($payers[$payerId])) {
             $payers[$payerId] = InsuranceProgram::getInsuranceProgram($payerId);
         }
         $patientId = (int) $visit->patientId;
         if (!isset($patients[$patientId])) {
             $patient = new Patient();
             $patient->personId = $patientId;
             $patient->populate();
             $patients[$patientId] = $patient;
         }
         $facilityId = (int) $visit->roomId;
         if (!isset($facilities[$facilityId])) {
             $facilities[$facilityId] = $visit->facility;
         }
         $providerId = (int) $visit->providerId;
         if (!isset($providers[$providerId])) {
             $provider = new Provider();
             $provider->personId = $providerId;
             $provider->populate();
             $providers[$providerId] = $provider;
         }
         $tmp = array();
         $tmp['id'] = $visitId;
         $tmp['total'] = $total;
         $tmp['billed'] = $billed;
         $tmp['paid'] = $paid;
         $tmp['writeOff'] = $writeoff;
         $tmp['balance'] = $balance;
         $tmp['payer'] = $payers[$payerId];
         $tmp['dateOfTreatment'] = $visit->dateOfTreatment;
         $tmp['dateBilled'] = isset($acct['claimLine']) ? $acct['claimLine']->dateTime : $visit->dateOfTreatment;
         $patientName = $patients[$patientId]->personId > 0 ? $patients[$patientId]->person->displayName : '';
         $tmp['patientName'] = $patientName;
         $tmp['facility'] = $facilities[$facilityId];
         $providerName = $providers[$providerId]->personId > 0 ? $providers[$providerId]->person->displayName : '';
         $tmp['providerName'] = $providerName;
         $rows[] = $tmp;
     }
     $stmt = $db->query($mscSelect);
     $stmt->setFetchMode(Zend_Db::FETCH_ASSOC);
     while ($row = $stmt->fetch()) {
         $row['balance'] = (double) $row['billed'] - ((double) $row['paid'] + (double) $row['writeOff']);
         $rows[] = $row;
     }
     return $rows;
 }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
 public function processPaymentSendToAction()
 {
     $claimId = (int) $this->_getParam('claimId');
     $payerId = 0;
     $insurance = $this->_getParam('insurance');
     switch ($insurance) {
         case 'Collections':
         case 'Patient Responsibility':
             foreach (InsuranceProgram::getInsurancePrograms() as $key => $value) {
                 if ($value == 'System->' . $insurance) {
                     $payerId = (int) $key;
                     break;
                 }
             }
             break;
     }
     $ret = false;
     if ($claimId > 0 && $payerId > 0) {
         $this->_sendToPayer($claimId, $payerId);
         $ret = true;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($ret);
 }
Ejemplo n.º 13
0
 public function editInsurerAction()
 {
     $patientId = (int) $this->_getParam('patientId');
     $id = (int) $this->_getParam('id');
     $insurer = new InsuredRelationship();
     $insurer->personId = $patientId;
     $time = time();
     $insurer->effectiveStart = date('Y-m-d', $time);
     $insurer->effectiveEnd = date('Y-m-d', strtotime('+1 year', $time));
     if ($id > 0) {
         $insurer->insuredRelationshipId = $id;
         $insurer->populate();
     }
     $this->view->subscriber = $insurer->subscriber;
     $this->view->subscriberPhone = $insurer->subscriber->phoneNumber;
     $this->view->subscriberAddress = $insurer->subscriber->address;
     $this->_form = new WebVista_Form(array('name' => 'edit-insurer'));
     $this->_form->setAction(Zend_Registry::get('baseUrl') . 'patient.raw/process-edit-insurer');
     $this->_form->loadORM($insurer, 'Insurer');
     $this->_form->setWindow('winEditInsurerId');
     $this->view->form = $this->_form;
     $insuranceProgram = new InsuranceProgram();
     $insurancePrograms = array('' => '');
     foreach (InsuranceProgram::getInsurancePrograms() as $id => $val) {
         $insurancePrograms[$id] = $val;
     }
     $this->view->insurancePrograms = $insurancePrograms;
     $assignings = array();
     $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_ASSIGNING_ENUM_KEY) {
             foreach ($rowset as $row) {
                 $assignings[$row->key] = $row->name;
             }
         } else {
             if ($enum->key == InsuranceProgram::INSURANCE_SUBSCRIBER_ENUM_KEY) {
                 foreach ($rowset as $row) {
                     $subscribers[$row->key] = $row->name;
                 }
             }
         }
     }
     $this->view->assignings = $assignings;
     $this->view->subscribers = $subscribers;
     $this->view->listVerified = InsuredRelationship::getVerifiedOptions();
     $this->render('edit-insurer');
 }