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); }
public function getInsuranceProgram() { return InsuranceProgram::getInsuranceProgram($this->activePayerId); }
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; }
public function getInsuranceDisplay() { $payerId = (int) $this->payer_id; $ret = ''; if ($payerId > 0) { $ret = InsuranceProgram::getInsuranceProgram($payerId); } return $ret; }
public function listPaymentHistoryAction() { $visitId = (int) $this->_getParam('visitId'); $filters = array('visitId' => $visitId, 'unposted' => true); $iterators = ClaimLine::getPaymentHistory($filters); $rows = array(); foreach ($iterators as $iterator) { foreach ($iterator as $item) { $row = array(); $row['data'] = array(); if ($item instanceof PostingJournal) { $row['id'] = $item->postingJournalId; $row['data'][] = $item->datePosted; $row['data'][] = ''; $row['data'][] = $item->amount; $row['data'][] = ''; $row['data'][] = InsuranceProgram::getInsuranceProgram($item->payerId); $row['data'][] = $item->note; $row['data'][] = 'P'; } else { if ($item instanceof Payment) { $row['id'] = $item->paymentId; $row['data'][] = $item->paymentDate; $row['data'][] = ''; $row['data'][] = $item->unallocated; $row['data'][] = ''; $row['data'][] = InsuranceProgram::getInsuranceProgram($item->payerId); $row['data'][] = $item->title; $row['data'][] = 'U'; } else { $row['id'] = $item->writeOffId; $row['data'][] = substr($item->timestamp, 0, 10); $row['data'][] = ''; $row['data'][] = ''; $row['data'][] = $item->amount; $row['data'][] = InsuranceProgram::getInsuranceProgram($item->payerId); $row['data'][] = $item->title; $row['data'][] = 'U'; } } $rows[] = $row; } } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(array('rows' => $rows)); }