From bf520fc492fae61358b0857da06afb6dfb6e8d0c Mon Sep 17 00:00:00 2001 From: sunsetsystems Date: Tue, 14 Aug 2007 18:17:26 +0000 Subject: [PATCH] assorted bug fixes --- library/Claim.class.php | 25 ++++++++++++++++++++----- library/gen_x12_837.inc.php | 17 ++++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/library/Claim.class.php b/library/Claim.class.php index 5f3fc3cf7..66d4e5664 100644 --- a/library/Claim.class.php +++ b/library/Claim.class.php @@ -48,14 +48,13 @@ class Claim { "pid = '{$this->pid}' AND provider != '' AND " . "date <= '$encounter_date' " . "ORDER BY type ASC, date DESC"; - // echo "
$query
"; // debugging $dres = sqlStatement($query); $prevtype = ''; while ($drow = sqlFetchArray($dres)) { if (strcmp($prevtype, $drow['type']) == 0) continue; $prevtype = $drow['type']; - $ins = ($drow['provider'] == $billrow['payer_id']) ? - 0 : count($this->payers); + $ins = count($this->payers); + if ($drow['provider'] == $billrow['payer_id'] && empty($this->payers[0]['data'])) $ins = 0; $crow = sqlQuery("SELECT * FROM insurance_companies WHERE " . "id = '" . $drow['provider'] . "'"); $orow = new InsuranceCompany($drow['provider']); @@ -65,6 +64,20 @@ class Claim { $this->payers[$ins]['object'] = $orow; } + // This kludge hands most cases of a rare ambiguous situation, where + // the primary insurance company is the same as the secondary. It seems + // nobody planned for that! + // + for ($i = 1; $i < count($this->payers); ++$i) { + if ($billrow['process_date'] && + $this->payers[0]['data']['payer_id'] == $this->payers[$i]['data']['payer_id']) + { + $tmp = $this->payers[0]; + $this->payers[0] = $this->payers[$i]; + $this->payers[$i] = $tmp; + } + } + $this->using_modifiers = true; // Get payment and adjustment details if there are any previous payers. @@ -294,6 +307,7 @@ class Claim { continue; // it's for primary and that's not us } + if ($rcode == '42') $rcode= '45'; // reason 42 is obsolete $aadj[] = array($date, $gcode, $rcode, sprintf('%.2f', $chg)); } // end if @@ -713,8 +727,9 @@ class Claim { // NDC drug number of units. function cptNDCQuantity($prockey) { $ndcinfo = $this->procs[$prockey]['ndc_info']; - if (preg_match('/^N4(\S+)\s+(\S\S)(.*)/', $ndcinfo, $tmp)) - return x12clean($tmp[3]); + if (preg_match('/^N4(\S+)\s+(\S\S)(.*)/', $ndcinfo, $tmp)) { + return x12clean(ltrim($tmp[3], '0')); + } return ''; } diff --git a/library/gen_x12_837.inc.php b/library/gen_x12_837.inc.php index 86e46f202..b898cbb4f 100644 --- a/library/gen_x12_837.inc.php +++ b/library/gen_x12_837.inc.php @@ -149,7 +149,6 @@ function gen_x12_837($pid, $encounter, &$log) { "~\n"; // Add a REF*EI* segment if NPI was specified in the NM1 above. - if ($claim->billingFacilityNPI() && $claim->billingFacilityETIN()) { ++$edicount; $out .= "REF" . @@ -460,8 +459,18 @@ function gen_x12_837($pid, $encounter, &$log) { "*207Q00000X" . "~\n"; + // REF*1C is required here for the Medicare provider number if NPI was + // specified in NM109. Not sure if other payers require anything here. + if ($claim->providerNumber()) { + ++$edicount; + $out .= "REF" . + "*" . $claim->providerNumberType() . + "*" . $claim->providerNumber() . + "~\n"; + } + ++$edicount; - $out .= "NM1" . // Loop 2310B Service Location + $out .= "NM1" . // Loop 2310D Service Location "*77" . "*2" . "*" . $claim->facilityName() . @@ -646,10 +655,12 @@ function gen_x12_837($pid, $encounter, &$log) { } ++$edicount; + $tmpunits = $claim->cptNDCQuantity($prockey) * $claim->cptUnits($prockey); + if (!$tmpunits) $tmpunits = 1; $out .= "CTP" . // Drug Pricing. Page 500+ (Addendum pg 74). "*" . "*" . - "*0" . // dummy price, required by HIPAA + "*" . sprintf('%.2f', $claim->cptCharges($prockey) / $tmpunits) . "*" . $claim->cptNDCQuantity($prockey) . "*" . $claim->cptNDCUOM($prockey) . "~\n"; -- 2.11.4.GIT