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 makePaymentAction()
 {
     $ids = explode(',', $this->_session->ids);
     $data = array('claims' => array(), 'patients' => array(), 'payers' => array(), 'facilities' => array(), 'funds' => array());
     $visits = array();
     foreach ($ids as $id) {
         $visitId = (int) $id;
         if (!$visitId > 0) {
             continue;
         }
         $visit = new Visit();
         $visit->visitId = $visitId;
         if (!$visit->populate()) {
             continue;
         }
         $funds = $visit->unallocatedFunds;
         $claims = $visit->uniqueClaims;
         $data['claimIds'][$visitId] = array('personId' => (int) $visit->patientId, 'unallocatedFunds' => $funds['total'], 'claimIds' => $claims['claimId'], 'payerIds' => $claims['payerId']);
     }
     $this->view->data = $data;
     $payment = new Payment();
     $form = new WebVista_Form(array('name' => 'editPayment'));
     $form->setAction(Zend_Registry::get('baseUrl') . 'claims.raw/process-payments');
     $form->loadORM($payment, 'payment');
     $form->setWindow('windowClaimsMakePaymentId');
     $this->view->form = $form;
     $payers = array('' => '');
     foreach (InsuranceProgram::getInsurancePrograms() as $key => $value) {
         $payers[$key] = $value;
     }
     $this->view->payers = $payers;
     $this->view->visitIds = $ids;
     $this->view->payerSelf = InsuranceProgram::lookupSystemId('Self Pay');
     // ID of System->Self Pay
     $this->render();
 }