Skip to content

Commit

Permalink
fix: ERA posting based on code mod combo billed that prevents insert …
Browse files Browse the repository at this point in the history
…into billing table (openemr#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
  • Loading branch information
stephenwaite authored Mar 26, 2024
1 parent 4795cc0 commit fd6500f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
41 changes: 37 additions & 4 deletions interface/billing/sl_eob_process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions library/globals.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Billing/ParseERA.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fd6500f

Please sign in to comment.