From fd6500fb6ab5d8aaa4e4ab1c7c236ed488724569 Mon Sep 17 00:00:00 2001 From: stephen waite Date: Tue, 26 Mar 2024 10:09:57 -0400 Subject: [PATCH] fix: ERA posting based on code mod combo billed that prevents insert into billing table (#7294) * fix: assign codekey for ERA posting based on code mod combo billed * silence minor warning * add global for disabling adding to billing table * separate out pt and enc billing note * add canceled appts counter * revert change, open new pr * revert change, open new pr --- interface/billing/sl_eob_process.php | 41 +++++++++++++++++++++++++--- library/globals.inc.php | 7 +++++ src/Billing/ParseERA.php | 2 +- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/interface/billing/sl_eob_process.php b/interface/billing/sl_eob_process.php index a730a97c480..0751b2d6a3f 100644 --- a/interface/billing/sl_eob_process.php +++ b/interface/billing/sl_eob_process.php @@ -345,7 +345,7 @@ function era_callback(&$out) writeMessageLine($bgcolor, 'infdetail', rtrim($out['warnings']), true); } - // Simplify some claim attributes for cleaner code. + // Simplify some claim attributes for cleaner code. $service_date = parse_date(isset($out['dos']) ? $out['dos'] : $out['claim_date']); $check_date = $paydate ? $paydate : parse_date($out['check_date']); $production_date = $paydate ? $paydate : parse_date($out['production_date']); @@ -359,7 +359,19 @@ function era_callback(&$out) $error = $inverror; - // This loops once for each service item in this claim. + // create array of cpts and mods for complex matching + $codes_arr_keys = array_keys($codes); + foreach ($codes_arr_keys as $key => $value) { + $tmp = explode(":", $value); + $count = count($tmp) - 1; + $cpt = $tmp[0]; + $cpts[] = $cpt; + for ($i = 1; $i <= $count; $i++) { + $mods[$cpt][] = $tmp[$i] ?? null; + } + } + + // This loops once for each service item in this claim. foreach ($out['svc'] as $svc) { // Treat a modifier in the remit data as part of the procedure key. // This key will then make its way into SQL-Ledger. @@ -369,6 +381,21 @@ function era_callback(&$out) } $prev = $codes[$codekey] ?? ''; + // However sometimes a secondary insurance (take USAA LIFE for instance) + // sometimes doesn't return the modifier that was on the service item + // processed by the primary payer so try to deal with that + if (!$prev) { + if (!$svc['mod']) { + if (in_array($svc['code'], $cpts)) { + foreach ($cpts as $k => $v) { + if ($v == $codekey) { + $codekey = $cpt . ':' . implode(':', $mods[$v]); + } + } + } + } + $prev = $codes[$codekey] ?? ''; + } $codetype = ''; //will hold code type, if exists // This reports detail lines already on file for this service item. @@ -389,9 +416,15 @@ function era_callback(&$out) unset($codes[$codekey]); } else { // If the service item is not in our database... // This is not an error. If we are not in error mode and not debugging, - // insert the service item into SL. Then display it (in green if it + // insert the service item into billing. Then display it (in green if it // was inserted, or in red if we are in error mode). - $description = "CPT4:$codekey Added by $inslabel $production_date"; + // Check the global to see if this is preferred to be an error. + if ($GLOBALS['add_unmatched_code_from_ins_co_era_to_billing'] ?? '') { + $description = "CPT4:$codekey Added by $inslabel $production_date"; + } else { + $error = true; + $description = "CPT4:$codekey returned by $inslabel $production_date"; + } if (!$error && !$debug) { SLEOB::arPostCharge( $pid, diff --git a/library/globals.inc.php b/library/globals.inc.php index 266399cca2d..a757abaa257 100644 --- a/library/globals.inc.php +++ b/library/globals.inc.php @@ -1529,6 +1529,13 @@ function gblTimeZones() xl('Enable swap secondary insurance') ), + 'add_unmatched_code_from_ins_co_era_to_billing' => array( + xl('Enable adding unmatched code from insurance company to billing table'), + 'bool', // data type + '0', // default + xl('Enable adding unmatched code from insurance company to billing table') + ), + ), // E-Sign Tab diff --git a/src/Billing/ParseERA.php b/src/Billing/ParseERA.php index 0aa08e6e051..433e4c2395f 100644 --- a/src/Billing/ParseERA.php +++ b/src/Billing/ParseERA.php @@ -183,7 +183,7 @@ public static function parseERA($filename, $cb) } $out['loopid'] = '1000A'; $out['payer_name'] = trim($seg[2]); - $out['payer_id'] = trim($seg[4] ?? null); // will be overwritten if in REF*2U below + $out['payer_id'] = trim($seg[4] ?? ''); // will be overwritten if in REF*2U below } elseif ($segid == 'N3' && $out['loopid'] == '1000A') { $out['payer_street'] = trim($seg[1]); // TBD: N302 may exist as an additional address line.