Example #1
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;
 }
 public function listClaimLinesAction()
 {
     $visitId = (int) $this->_getParam('visitId');
     $payerId = (int) $this->_getParam('payerId');
     $data = array();
     if ($visitId > 0 || $payerId > 0) {
         $iterator = new ClaimLineIterator();
         $filters = array();
         if ($visitId > 0) {
             $filters['visitId'] = $visitId;
         }
         if ($payerId > 0) {
             $filters['insuranceProgramId'] = $payerId;
         }
         $iterator->setFilters($filters);
         foreach ($iterator as $claimLine) {
             $data[$claimLine->claimLineId] = $claimLine->procedureCode . ' : ' . $claimLine->procedure;
             // Code
         }
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
 public function listClaimLinesAction()
 {
     $claimId = (int) $this->_getParam('claimId');
     $rows = array();
     $iterator = new ClaimLineIterator();
     $iterator->setFilters(array('claimId' => $claimId));
     foreach ($iterator as $claimLine) {
         $row = array();
         $row['id'] = $claimLine->claimLineId;
         $row['data'] = array();
         $row['data'][] = $claimLine->procedureCode . ' : ' . $claimLine->procedure;
         // Code
         //$billed = (float)$claimLine->amountBilled;
         $billed = (double) $claimLine->baseFee;
         $paid = (double) $claimLine->overallPayment;
         $writeOff = (double) $claimLine->overallWriteOff;
         $balance = $billed - ($paid + $writeOff);
         if ($balance < 0) {
             $balance = 0;
         }
         // in the case of rebill
         $row['data'][] = number_format($billed, 2);
         // Amount Billed
         $row['data'][] = number_format($paid, 2);
         // Paid
         $row['data'][] = number_format($writeOff, 2);
         // WriteOff
         $row['data'][] = number_format($balance, 2);
         // Balance
         $rows[] = $row;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }