예제 #1
0
 public function getClaimLine()
 {
     $claimLine = new ClaimLine();
     $claimLine->populateWithPatientProcedure($this, null);
     return $claimLine;
 }
예제 #2
0
 public static function inquire($visitId)
 {
     $claimIds = ClaimLine::listAllMostRecentClaimIds(array($visitId));
     $claimId = isset($claimIds[0]) ? $claimIds[0] : 0;
     $claimFile = self::getClaimFile($claimId);
     $query = array();
     $query['apiKey'] = Zend_Registry::get('config')->healthcloud->apiKey;
     $query['uid'] = $claimFile->claimFileId;
     $ch = curl_init();
     $url = Zend_Registry::get('config')->healthcloud->claimsServerUrl . '/check-status';
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query));
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $output = curl_exec($ch);
     if (!curl_errno($ch)) {
         $data = json_decode($output, true);
         if ($data === null) {
             $response = 'Invalid HC response';
         } else {
             if (array_key_exists('response', $data)) {
                 $response = $data['response'];
             } else {
                 if (array_key_exists('error', $data)) {
                     $response = $data['error'];
                 } else {
                     $response = 'Unknown HC response: ' . print_r($data, true);
                 }
             }
         }
     } else {
         $response = __('There was an error connecting to HealthCloud to check claim status. Please try again or contact the system administrator.');
     }
     curl_close($ch);
     trigger_error($response);
     return $response . '';
 }
예제 #3
0
 public function listAction()
 {
     $posStart = $this->_getParam('posStart');
     if ($posStart < 0) {
         $msg = 'Invalid request';
         trigger_error($msg);
         throw new Exception($msg);
     }
     $sessions = $this->_session->filters;
     $filters = array();
     $filters['dateRange'] = array('start' => $sessions['DateStart'], 'end' => $sessions['DateEnd']);
     if (isset($sessions['facilities']) && count($sessions['facilities']) > 0) {
         // practiceId_buildingId_roomId
         foreach ($sessions['facilities'] as $key => $value) {
             if (!$value) {
                 continue;
             }
             if (!isset($filters['facilities'])) {
                 $filters['facilities'] = array();
             }
             $x = explode('_', $key);
             $practiceId = $x[0];
             $buildingId = $x[1];
             $roomId = $x[2];
             $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;
         }
     }
     if (isset($sessions['providers']) && count($sessions['providers']) > 0) {
         foreach ($sessions['providers'] as $key => $value) {
             if (!$value) {
                 continue;
             }
             if (!isset($filters['providers'])) {
                 $filters['providers'] = array();
             }
             $filters['providers'][] = $key;
         }
     }
     $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;
     $rows = array();
     $appointmentId = 0;
     $totalBilled = 0.0;
     $totalPaid = 0.0;
     $totalWriteoff = 0.0;
     $totalBalance = 0.0;
     $oneDay = 60 * 60 * 24;
     $today = time();
     $aging_0_30 = 0;
     $aging_31_60 = 0;
     $aging_61_90 = 0;
     $aging_91_120 = 0;
     $aging_120_plus = 0;
     $filters['closed'] = 1;
     foreach (ClaimLine::listCharges($filters) as $account) {
         $billed = (double) $account['billed'];
         $paid = (double) $account['paid'];
         $writeoff = (double) $account['writeOff'];
         $balance = (double) $account['balance'];
         $names = array('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;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $balance = abs($balance);
         $totalBilled += $billed;
         $totalPaid += $paid;
         $totalWriteoff += $writeoff;
         $totalBalance += $balance;
         $dateBilled = substr($account['dateBilled'], 0, 10);
         $db = strtotime($dateBilled);
         // calculate aging
         $aging = ($today - $db) / $oneDay;
         if ($aging <= 30) {
             $aging_0_30 += $balance;
         } else {
             if ($aging <= 60) {
                 $aging_31_60 += $balance;
             } else {
                 if ($aging <= 90) {
                     $aging_61_90 += $balance;
                 } else {
                     if ($aging <= 120) {
                         $aging_91_120 += $balance;
                     } else {
                         $aging_120_plus += $balance;
                     }
                 }
             }
         }
         $rows[] = array('id' => $account['id'], 'data' => array(substr($account['dateOfTreatment'], 0, 10), $dateBilled, $account['patientName'], $account['payer'], '$' . $billed, '$' . $paid, '$' . $writeoff, '$' . $balance, $account['facility'], $account['providerName']));
     }
     if (isset($rows[0])) {
         $rows[0]['userdata']['totalBilled'] = $totalBilled;
         trigger_error('total billed: ' . $totalBilled);
         $rows[0]['userdata']['totalPaid'] = $totalPaid;
         trigger_error('total paid: ' . $totalPaid);
         $rows[0]['userdata']['totalWriteoff'] = $totalWriteoff;
         trigger_error('total writeof: ' . $totalWriteoff);
         $rows[0]['userdata']['totalBalance'] = $totalBalance;
         trigger_error('total balance: ' . $totalBalance);
         $rows[0]['userdata']['aging_0_30'] = $aging_0_30;
         trigger_error('total aging 0-30: ' . $aging_0_30);
         $rows[0]['userdata']['aging_31_60'] = $aging_31_60;
         trigger_error('total aging 31-60: ' . $aging_31_60);
         $rows[0]['userdata']['aging_61_90'] = $aging_61_90;
         trigger_error('total aging 61-90: ' . $aging_61_90);
         $rows[0]['userdata']['aging_91_120'] = $aging_91_120;
         trigger_error('total aging 91-120: ' . $aging_91_120);
         $rows[0]['userdata']['aging_120_plus'] = $aging_120_plus;
         trigger_error('total aging 120+: ' . $aging_120_plus);
     }
     $data = array('rows' => $rows);
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
예제 #4
0
 public function getAccountSummary()
 {
     $visitId = (int) $this->visitId;
     $total = 0;
     $billed = 0;
     $writeoff = 0;
     $balance = 0;
     $baseFee = 0;
     $adjustedFee = 0;
     $miscCharge = MiscCharge::total(array('visitId' => $visitId));
     $payment = Payment::total(array('visitId' => $visitId));
     $payment += Payment::unpostedTotal($visitId);
     $writeoff += WriteOff::total(array('visitId' => $visitId));
     if ($this->closed) {
         $iterator = ClaimLine::mostRecentClaims($visitId);
         foreach ($iterator as $claimLine) {
             $baseFee += (double) $claimLine->baseFee;
             $adjustedFee += (double) $claimLine->adjustedFee;
         }
     } else {
         $fees = $this->calculateFees();
         $baseFee += $fees['total'];
         $adjustedFee = $fees['discounted'];
         if (!$writeoff > 0 && $adjustedFee > 0) {
             $writeoff += $baseFee - $adjustedFee;
         }
     }
     $total = $baseFee + $miscCharge;
     $billed = $miscCharge;
     if ($adjustedFee > 0) {
         $billed += $adjustedFee;
     }
     if (!$billed > 0) {
         $billed = $total;
     }
     $balance = abs($total) - ($payment + $writeoff);
     if ($balance == $total) {
         $balance = $billed;
     }
     // use total billed if balance equals to total
     $ret = array();
     $ret['total'] = $total;
     $ret['billed'] = $billed;
     $ret['payment'] = $payment;
     $ret['balance'] = $balance;
     $ret['writeoff'] = $writeoff;
     $ret['baseFee'] = $baseFee;
     $ret['adjustedFee'] = $adjustedFee;
     $ret['miscCharge'] = $miscCharge;
     if (isset($claimLine)) {
         $ret['claimLine'] = $claimLine;
     }
     return $ret;
 }
예제 #5
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;
 }
예제 #6
0
 public function getClaimDetailsAction()
 {
     $claimId = (int) $this->_getParam('claimId');
     $data = array();
     $claimLine = new ClaimLine();
     $claimLine->claimId = $claimId;
     $claimLine->populateByClaimId();
     $visitId = (int) $claimLine->visitId;
     $visit = new Visit();
     $visit->visitId = $visitId;
     $visit->populate();
     $personId = (int) $visit->patientId;
     $data['claimId'] = $claimId;
     $data['dos'] = substr($visit->dateOfTreatment, 0, 10);
     $data['dateBilled'] = substr($claimLine->dateTime, 0, 10);
     $patient = new Patient();
     $patient->personId = $personId;
     $patient->populate();
     $data['patientId'] = $personId;
     $data['patient'] = $patient->displayName;
     $data['payerId'] = $claimLine->insuranceProgramId;
     $data['facility'] = $visit->facility;
     $checkNos = array('' => array('checkNo' => '', 'unallocated' => ''));
     foreach ($claimLine->checkNumbers as $chk) {
         $checkNos[(int) $chk['paymentId']] = array('checkNo' => $chk['checkNo'], 'unallocated' => (double) $chk['unallocated']);
     }
     $data['checkNos'] = $checkNos;
     $insured = new InsuredRelationship();
     $insured->personId = $personId;
     $data['listPayers'] = $insured->programList;
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }