From 38c32e6632c2d8b0d9c980865065f6636641b3bf Mon Sep 17 00:00:00 2001 From: Paul Simon Date: Sat, 1 Jan 2011 19:06:02 +0530 Subject: [PATCH] ERA handling is modified. 1)The automatic forwarding to the next level of insurance,after the ERA payment, is added. 2)Also the claim denial code is stored in database for display later. For the first case there is no need to bill again to the secondary.So last_level_billed is updated.In claims table new status=6 is stored. For the second case the denial reason code is stored in claims table with new status=7 and in billing table with bill_process=7. We changed in billing table so that a denial search can be done in the billing manager. We would like you to review the code. Signed-off-by: Paul Simon --- interface/billing/sl_eob_process.php | 34 +++++++++++++++++++++++++++++++--- library/billing.inc | 30 ++++++++++++++++++++++++++---- library/parse_era.inc.php | 5 +++++ library/sl_eob.inc.php | 11 ++++++++--- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/interface/billing/sl_eob_process.php b/interface/billing/sl_eob_process.php index e0a8bd1f3..c8c790bf5 100644 --- a/interface/billing/sl_eob_process.php +++ b/interface/billing/sl_eob_process.php @@ -19,6 +19,7 @@ require_once("claim_status_codes.php"); require_once("adjustment_reason_codes.php"); require_once("remark_codes.php"); require_once("$srcdir/formatting.inc.php"); +require_once("$srcdir/billing.inc"); $debug = $_GET['debug'] ? 1 : 0; // set to 1 for debugging mode $paydate = parse_date($_GET['paydate']); @@ -241,6 +242,15 @@ require_once("$srcdir/formatting.inc.php"); if ($csc == '4') { $inverror = true; + if (!$debug) { + if ($pid && $encounter) { + foreach ($out['svc'] as $svc) { + foreach ($svc['adj'] as $adj) { + $code_value .= $svc['code'].'_'.$svc['mod'].'_'.$adj['group_code'].'_'.$adj['reason_code'].','; + }} + $code_value = substr($code_value,0,-1); + updateClaim(true, $pid, $encounter, $_REQUEST['InsId'], substr($inslabel,3),7,0,$code_value); + }} writeMessageLine($bgcolor, 'errdetail', "Not posting adjustments for denied claims, please follow up manually!"); } @@ -472,14 +482,29 @@ require_once("$srcdir/formatting.inc.php"); if (!$error && !$debug && $insurance_done) { if ($INTEGRATED_AR) { $level_done = 0 + substr($inslabel, 3); + + if($out['crossover']==1) + { sqlStatement("UPDATE form_encounter " . - "SET last_level_closed = $level_done WHERE " . + "SET last_level_closed = $level_done,last_level_billed=".$level_done." WHERE " . "pid = '$pid' AND encounter = '$encounter'"); + writeMessageLine($bgcolor, 'infdetail', + 'This claim processed by Primary and automatically forwarded to Secondary. '); + } + else + { + "UPDATE form_encounter " . + "SET last_level_closed = $level_done WHERE " . + "pid = '$pid' AND encounter = '$encounter'"; + } // Check for secondary insurance. if ($primary && arGetPayerID($pid, $service_date, 2)) { - arSetupSecondary($pid, $encounter, $debug); + arSetupSecondary($pid, $encounter, $debug,$out['crossover']); + + if($crossover==1) + { writeMessageLine($bgcolor, 'infdetail', - 'This claim is now re-queued for secondary paper billing'); + 'This claim is now re-queued for secondary paper billing');} } } else { $shipvia = 'Done: Ins1'; @@ -492,8 +517,11 @@ require_once("$srcdir/formatting.inc.php"); $insgot = strtolower($arrow['notes']); if ($primary && strpos($insgot, 'ins2') !== false) { slSetupSecondary($arrow['id'], $debug); + if($crossover<>1) + { writeMessageLine($bgcolor, 'infdetail', 'This claim is now re-queued for secondary paper billing'); + } } } } diff --git a/library/billing.inc b/library/billing.inc index d0484bcc6..c086cd8ab 100644 --- a/library/billing.inc +++ b/library/billing.inc @@ -86,7 +86,7 @@ function clearBilling($id) // payers. That logic will tailor the payer choices to the encounter date. // function updateClaim($newversion, $patient_id, $encounter_id, $payer_id=-1, $payer_type=-1, - $status=-1, $bill_process=-1, $process_file='', $target='', $partner_id=-1) + $status=-1, $bill_process=-1, $process_file='', $target='', $partner_id=-1,$crossover=0) { if (!$newversion) { $sql = "SELECT * FROM claims WHERE patient_id = '$patient_id' AND " . @@ -107,7 +107,10 @@ function updateClaim($newversion, $patient_id, $encounter_id, $payer_id=-1, $pay $billset = ""; if (empty($payer_id) || $payer_id < 0) $payer_id = 0; - if ($status >= 0) { + if ($status==7) {//$status==7 is the claim denail case. + $claimset .= ", status = '$status'"; + } + elseif ($status >= 0) { $claimset .= ", status = '$status'"; if ($status > 1) { $billset .= ", billed = 1"; @@ -116,11 +119,17 @@ function updateClaim($newversion, $patient_id, $encounter_id, $payer_id=-1, $pay $billset .= ", billed = 0"; } } - if ($bill_process >= 0) { + if ($status==7) {//$status==7 is the claim denail case. + $billset .= ", bill_process = '$status'"; + } + elseif ($bill_process >= 0) { $claimset .= ", bill_process = '$bill_process'"; $billset .= ", bill_process = '$bill_process'"; } - if ($process_file) { + if ($status==7) {//$status==7 is the claim denail case. + $claimset .= ", process_file = '$process_file'";//Denial reason code is stored here + } + elseif ($process_file) { $claimset .= ", process_file = '$process_file', process_time = NOW()"; $billset .= ", process_file = '$process_file', process_date = NOW()"; } @@ -165,10 +174,23 @@ function updateClaim($newversion, $patient_id, $encounter_id, $payer_id=-1, $pay "target = '$target', " . "x12_partner_id = '$partner_id'"; ****/ + if($crossover<>1) + { $sql = "INSERT INTO claims SET " . "patient_id = '$patient_id', " . "encounter_id = '$encounter_id', " . "bill_time = NOW() $claimset"; + } + else + { + + $sql = "INSERT INTO claims SET " . + "patient_id = '$patient_id', " . + "encounter_id = '$encounter_id', " . + "bill_time = NOW(), status=$status"; + + } + sqlStatement($sql); } diff --git a/library/parse_era.inc.php b/library/parse_era.inc.php index d40461ac7..870d7f18e 100644 --- a/library/parse_era.inc.php +++ b/library/parse_era.inc.php @@ -211,6 +211,7 @@ function parse_era($filename, $cb) { $out['subscriber_fname'] = ''; $out['subscriber_mname'] = ''; $out['subscriber_member_id'] = ''; + $out['crossover']=0; $out['svc'] = array(); // // This is the poorly-named "Patient Account Number". For 837p @@ -275,6 +276,10 @@ function parse_era($filename, $cb) { $out['provider_mname'] = trim($seg[5]); $out['provider_member_id'] = trim($seg[9]); } + else if ($segid == 'NM1' && $seg[1] == 'TT' && $out['loopid'] == '2100') { + $out['crossover'] = 1; + + } // 74 = Corrected Insured // TT = Crossover Carrier (Transfer To another payer) // PR = Corrected Payer diff --git a/library/sl_eob.inc.php b/library/sl_eob.inc.php index b754433a4..98cd3ef0a 100644 --- a/library/sl_eob.inc.php +++ b/library/sl_eob.inc.php @@ -394,7 +394,12 @@ function arPostSession($payer_id,$check_number,$check_date,$pay_total,$post_to_d // Make this invoice re-billable, new style. // - function arSetupSecondary($patient_id, $encounter_id, $debug) { + function arSetupSecondary($patient_id, $encounter_id, $debug,$crossover=0) { + +if($crossover==1) +{$status=6;}//if claim forwarded setting a new status +else +{$status=1;} // Determine the next insurance level to be billed. $ferow = sqlQuery("SELECT date, last_level_billed " . @@ -410,12 +415,12 @@ function arPostSession($payer_id,$check_number,$check_date,$pay_total,$post_to_d if ($new_payer_id) { // Queue up the claim. if (!$debug) - updateClaim(true, $patient_id, $encounter_id, $new_payer_id, $new_payer_type, 1, 5, '', 'hcfa'); + updateClaim(true, $patient_id, $encounter_id, $new_payer_id, $new_payer_type,$status, 5, '', 'hcfa','',$crossover); } else { // Just reopen the claim. if (!$debug) - updateClaim(true, $patient_id, $encounter_id, -1, -1, 1, 0, ''); + updateClaim(true, $patient_id, $encounter_id, -1, -1, $status, 0, '','','',$crossover); } return xl("Encounter ") . $encounter . xl(" is ready for re-billing."); -- 2.11.4.GIT