Beispiel #1
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;
 }
 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));
 }