Esempio n. 1
0
 public function listAction()
 {
     $posStart = $this->_getParam('posStart');
     if ($posStart < 0) {
         $msg = 'Invalid request';
         trigger_error($msg);
         throw new Exception($msg);
     }
     $claimList = isset($this->_session->claimList) ? $this->_session->claimList : array();
     $sessions = $this->_session->filters;
     if (!isset($sessions['DOSStart'])) {
         $sessions['DOSStart'] = date('Y-m-d', strtotime('-1 week'));
     }
     if (!isset($sessions['DOSEnd'])) {
         $sessions['DOSEnd'] = date('Y-m-d');
     }
     $filters = array();
     if (isset($sessions['batchHistoryId'])) {
         $claimFile = new ClaimFile();
         $claimFile->claimFileId = (int) $sessions['batchHistoryId'];
         $claimFile->populate();
         $filters['batchHistoryId'] = $claimFile->claimIds;
     } else {
         $filters['dateRange'] = $sessions['DOSStart'] . ':' . $sessions['DOSEnd'];
         if (isset($sessions['facilities']) && count($sessions['facilities']) > 0) {
             // practiceId_buildingId_roomId
             foreach ($sessions['facilities'] as $key => $value) {
                 if (!$value) {
                     continue;
                 }
                 $x = explode('_', $key);
                 $practiceId = $x[0];
                 $buildingId = $x[1];
                 $roomId = $x[2];
                 if (!isset($filters['facilities'])) {
                     $filters['facilities'] = array();
                 }
                 $filters['facilities'][] = array('practice' => $practiceId, 'building' => $buildingId, 'room' => $roomId);
             }
         }
         if (isset($sessions['payers']) && count($sessions['payers']) > 0) {
             foreach ($sessions['payers'] as $key => $value) {
                 if (!$value) {
                     continue;
                 }
                 if (!isset($filters['payers'])) {
                     $filters['payers'] = array();
                 }
                 $filters['payers'][] = $key;
             }
         }
         $filters['total'] = isset($sessions['total']) ? $sessions['total'] : 0;
         $filters['billed'] = isset($sessions['billed']) ? $sessions['billed'] : 0;
         $filters['paid'] = isset($sessions['paid']) ? $sessions['paid'] : 0;
         $filters['writeoff'] = isset($sessions['writeoff']) ? $sessions['writeoff'] : 0;
         $filters['balance'] = isset($sessions['balance']) ? $sessions['balance'] : 0;
         $filters['openClosed'] = isset($sessions['openClosed']) ? (int) $sessions['openClosed'] : 2;
     }
     if (isset($sessions['mrn']) && strlen($sessions['mrn']) > 0) {
         $filters['mrn'] = $sessions['mrn'];
     }
     $rows = array();
     $claimIterator = array();
     $visitIterator = new VisitIterator();
     //$filters['void'] = 0; // exclude void from list
     $visitIterator->setFilters($filters);
     foreach ($visitIterator as $visit) {
         $visitId = (int) $visit->visitId;
         $appointmentId = (int) $visit->appointmentId;
         $acct = $visit->accountSummary;
         $total = $acct['total'];
         $billed = $acct['billed'];
         $writeoff = $acct['writeoff'];
         $paid = $acct['payment'];
         $balance = $acct['balance'];
         $payerId = isset($acct['claimLine']) ? $acct['claimLine']->insuranceProgramId : $visit->activePayerId;
         $names = array('total', 'billed', 'paid', 'writeoff', 'balance');
         foreach ($names as $name) {
             if (!isset($filters[$name]) || !$filters[$name]['active']) {
                 continue;
             }
             $operator = $filters[$name]['operator'];
             $operand1 = $filters[$name]['operand1'];
             $operand2 = $filters[$name]['operand2'];
             if ($operator == '=' && !(${$name} == $operand1)) {
                 continue 2;
             } else {
                 if ($operator == '>' && !(${$name} > $operand1)) {
                     continue 2;
                 } else {
                     if ($operator == '>=' && !(${$name} >= $operand1)) {
                         continue 2;
                     } else {
                         if ($operator == '<' && !(${$name} < $operand1)) {
                             continue 2;
                         } else {
                             if ($operator == '<=' && !(${$name} <= $operand1)) {
                                 continue 2;
                             } else {
                                 if ($operator == 'between' && $operand2 > 0 && !(${$name} >= $operand1 && ${$name} <= $operand2)) {
                                     continue 2;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $paid += $writeoff;
         $dateOfService = substr($visit->dateOfTreatment, 0, 10);
         $personId = (int) $visit->patientId;
         $person = new Person();
         $person->personId = $personId;
         $person->populate();
         $color = '';
         if ($visit->closed) {
             if ($total > 0 && $balance <= 0) {
                 $color = '#82CA9D';
                 // pastel green for fully zeroed claims
             } else {
                 if ($paid > 0) {
                     $color = '#F7977A';
                     // pastel red for claims partly paid or with a denial status
                 }
             }
         }
         if ($color == '') {
             $color = '#FFF79A';
             // pastel yellow for rows transmitted
         }
         $facility = $visit->facility;
         $total = number_format(abs($total), 2, '.', ',');
         $billed = number_format(abs($billed), 2, '.', ',');
         $paid = number_format(abs($paid), 2, '.', ',');
         $balance = number_format(abs($balance), 2, '.', ',');
         $url = $this->view->baseUrl . '/claims.raw/list-claim-files?visitId=' . $visitId;
         if (isset($acct['claimLine'])) {
             $url .= '&claimId=' . $acct['claimLine']->claimId;
         }
         $row = array();
         $row['id'] = $visitId;
         $row['data'] = array();
         $row['data'][] = $url;
         $row['data'][] = $dateOfService;
         $row['data'][] = $person->displayName;
         $row['data'][] = '$' . $total;
         $row['data'][] = '$' . $billed;
         $row['data'][] = '$' . $paid;
         $row['data'][] = '$' . $balance;
         $row['data'][] = InsuranceProgram::getInsuranceProgram($payerId);
         $row['data'][] = $facility;
         $row['data'][] = $visit->displayStatus;
         $row['userdata']['pid'] = $personId;
         $row['userdata']['color'] = $color;
         $rows[] = $row;
         $claimList[$visitId] = array('billed' => $billed, 'paid' => $paid, 'balance' => $balance);
     }
     $this->_session->claimList = $claimList;
     $data = array('rows' => $rows);
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }