From 6561e30b45a0b1dcece2ed875c346bddcb5b99e5 Mon Sep 17 00:00:00 2001 From: bradymiller Date: Wed, 25 Jul 2012 19:06:26 -0700 Subject: [PATCH] Fixing accounting/billing bugs -Fees->Checkout now show copays that are stored in the ar_activity table -Avoid internationalization problems (no reason to run code and modifier through strtoupper() function) -Billing table no longer holds COPAYs (now in ar_activity table), so modified code to support this -Some code cleanup and function modularization --- interface/billing/sl_eob_search.php | 9 +-- interface/patient_file/front_payment.php | 23 +------- interface/patient_file/pos_checkout.php | 20 ++++--- interface/patient_file/printed_fee_sheet.php | 13 +---- library/Claim.class.php | 8 +-- library/billing.inc | 22 ++++++++ library/invoice_summary.inc.php | 84 ++++++++-------------------- 7 files changed, 67 insertions(+), 112 deletions(-) diff --git a/interface/billing/sl_eob_search.php b/interface/billing/sl_eob_search.php index f089bca58..f1df2823a 100644 --- a/interface/billing/sl_eob_search.php +++ b/interface/billing/sl_eob_search.php @@ -664,17 +664,18 @@ if ($_POST['form_search'] || $_POST['form_print']) { } } + // Notes that as of release 4.1.1 the copays are stored + // in the ar_activity table marked with a PCP in the account_code column. $query = "SELECT f.id, f.pid, f.encounter, f.date, " . "f.last_level_billed, f.last_level_closed, f.last_stmt_date, f.stmt_count, " . "p.fname, p.mname, p.lname, p.pubpid, p.genericname2, p.genericval2, " . "( SELECT SUM(b.fee) FROM billing AS b WHERE " . "b.pid = f.pid AND b.encounter = f.encounter AND " . "b.activity = 1 AND b.code_type != 'COPAY' ) AS charges, " . - "( SELECT SUM(b.fee) FROM billing AS b WHERE " . - "b.pid = f.pid AND b.encounter = f.encounter AND " . - "b.activity = 1 AND b.code_type = 'COPAY' ) AS copays, " . "( SELECT SUM(a.pay_amount) FROM ar_activity AS a WHERE " . - "a.pid = f.pid AND a.encounter = f.encounter ) AS payments, " . + "a.pid = f.pid AND a.encounter = f.encounter AND a.payer_type = 0 AND a.account_code = 'PCP')*-1 AS copays, " . + "( SELECT SUM(a.pay_amount) FROM ar_activity AS a WHERE " . + "a.pid = f.pid AND a.encounter = f.encounter AND a.account_code != 'PCP') AS payments, " . "( SELECT SUM(a.adj_amount) FROM ar_activity AS a WHERE " . "a.pid = f.pid AND a.encounter = f.encounter ) AS adjustments " . "FROM form_encounter AS f " . diff --git a/interface/patient_file/front_payment.php b/interface/patient_file/front_payment.php index 609dd4834..91884bbe1 100644 --- a/interface/patient_file/front_payment.php +++ b/interface/patient_file/front_payment.php @@ -12,6 +12,7 @@ $sanitize_all_escapes=true; require_once("../globals.php"); require_once("$srcdir/acl.inc"); require_once("$srcdir/patient.inc"); +require_once("$srcdir/billing.inc"); require_once("$srcdir/forms.inc"); require_once("$srcdir/sl_eob.inc.php"); require_once("$srcdir/invoice_summary.inc.php"); @@ -46,28 +47,6 @@ function rawbucks($amount) { return ''; } -// Get the co-pay amount that is effective on the given date. -// Or if no insurance on that date, return -1. -// -function getCopay($patient_id, $encdate) { - $tmp = sqlQuery("SELECT provider, copay FROM insurance_data " . - "WHERE pid = '$patient_id' AND type = 'primary' " . - "AND date <= '$encdate' ORDER BY date DESC LIMIT 1"); - if ($tmp['provider']) return sprintf('%01.2f', 0 + $tmp['copay']); - return 0; -} - -// Get the total co-pay amount paid by the patient for an encounter -function getPatientCopay($patient_id, $encounter) { - $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where ". - "pid = ? and encounter = ? and payer_type=0 and account_code='PCP'", - array($patient_id,$encounter)); - //new fees screen copay gives account_code='PCP' - $rowMoneyGot = sqlFetchArray($resMoneyGot); - $Copay=$rowMoneyGot['PatientPay']; - return $Copay*-1; -} - // Display a row of data for an encounter. // $var_index=0; diff --git a/interface/patient_file/pos_checkout.php b/interface/patient_file/pos_checkout.php index cf94baeb4..32ee33a7b 100644 --- a/interface/patient_file/pos_checkout.php +++ b/interface/patient_file/pos_checkout.php @@ -497,8 +497,8 @@ function generate_receipt($patient_id, $encounter=0) { "a.pid = ? AND a.encounter = ? AND " . "a.pay_amount != 0 " . "ORDER BY s.check_date, a.sequence_no", array($patient_id,$encounter) ); - $payer = empty($inrow['payer_type']) ? 'Pt' : ('Ins' . $inrow['payer_type']); while ($inrow = sqlFetchArray($inres)) { + $payer = empty($inrow['payer_type']) ? 'Pt' : ('Ins' . $inrow['payer_type']); $charges -= sprintf('%01.2f', $inrow['pay_amount']); receiptPaymentLine($svcdate, $inrow['pay_amount'], $payer . ' ' . $inrow['reference']); @@ -841,9 +841,7 @@ if (!empty($_GET['enc'])) { exit(); } -// Get the unbilled billing table items and product sales for -// this patient. - +// Get the unbilled billing table items for this patient. $query = "SELECT id, date, code_type, code, modifier, code_text, " . "provider_id, payer_id, units, fee, encounter " . "FROM billing WHERE pid = ? AND activity = 1 AND " . @@ -851,6 +849,7 @@ $query = "SELECT id, date, code_type, code, modifier, code_text, " . "ORDER BY encounter DESC, id ASC"; $bres = sqlStatement($query, array($patient_id) ); +// Get the product sales for this patient. $query = "SELECT s.sale_id, s.sale_date, s.prescription_id, s.fee, " . "s.quantity, s.encounter, s.drug_id, d.name, r.provider_id " . "FROM drug_sales AS s " . @@ -1012,7 +1011,7 @@ $inv_payer = 0; $gcac_related_visit = false; $gcac_service_provided = false; -// Process billing table items. Note this includes co-pays. +// Process billing table items. // Items that are not allowed to have a fee are skipped. // while ($brow = sqlFetchArray($bres)) { @@ -1067,6 +1066,13 @@ while ($brow = sqlFetchArray($bres)) { } } +// Process copays +// +$totalCopay = getPatientCopay($patient_id,$encounter); +if ($totalCopay < 0) { + write_form_line("COPAY", "", "", "", "", $totalCopay, "", ""); +} + // Process drug sales / products. // while ($drow = sqlFetchArray($dres)) { @@ -1098,8 +1104,8 @@ foreach ($taxes as $key => $value) { } } -// Note that we don't try to get anything from the ar_activity table. Since -// this is the checkout, nothing should be there yet for this invoice. +// Besides copays, do not collect any other information from ar_activity, +// since this is for appt checkout. if ($inv_encounter) { $erow = sqlQuery("SELECT provider_id FROM form_encounter WHERE " . diff --git a/interface/patient_file/printed_fee_sheet.php b/interface/patient_file/printed_fee_sheet.php index 6dd272a64..e913b688f 100644 --- a/interface/patient_file/printed_fee_sheet.php +++ b/interface/patient_file/printed_fee_sheet.php @@ -13,22 +13,11 @@ require_once("../globals.php"); require_once("$srcdir/acl.inc"); require_once("$srcdir/patient.inc"); +require_once("$srcdir/billing.inc"); require_once("$srcdir/classes/Address.class.php"); require_once("$srcdir/classes/InsuranceCompany.class.php"); require_once("$srcdir/formatting.inc.php"); -// Get the co-pay amount that is effective on the given date. -// Or if no insurance on that date, return -1. -// -function getCopay($patient_id, $encdate) { - $tmp = sqlQuery("SELECT provider, copay FROM insurance_data " . - "WHERE pid = '$patient_id' AND type = 'primary' " . - "AND date <= '$encdate' ORDER BY date DESC LIMIT 1"); - if ($tmp['provider']) - return sprintf('%01.2f', 0 + $tmp['copay']); - return -1; -} - function genColumn($ix) { global $html; global $SBCODES; diff --git a/library/Claim.class.php b/library/Claim.class.php index 7e49e0dd1..1ddfc24cb 100644 --- a/library/Claim.class.php +++ b/library/Claim.class.php @@ -51,7 +51,7 @@ class Claim { var $billing_options; // row from form_misc_billing_options table var $invoice; // result from get_invoice_summary() var $payers; // array of arrays, for all payers - var $copay; // total of copays from the billing table + var $copay; // total of copays from the ar_activity table function loadPayerInfo(&$billrow) { global $sl_err; @@ -157,10 +157,6 @@ class Claim { "b.activity = '1' ORDER BY b.date, b.id"; $res = sqlStatement($sql); while ($row = sqlFetchArray($res)) { - if ($row['code_type'] == 'COPAY') { - $this->copay -= $row['fee']; - continue; - } // Save all diagnosis codes. if ($row['ct_diag'] == '1') { $this->diags[$row['code']] = $row['code']; @@ -514,7 +510,7 @@ class Claim { // function patientPaidAmount() { // For primary claims $this->invoice is not loaded, so get the co-pay - // from the billing table instead. + // from the ar_activity table instead. if (empty($this->invoice)) return $this->copay; // $amount = 0; diff --git a/library/billing.inc b/library/billing.inc index 0378bcd25..bec594ee1 100644 --- a/library/billing.inc +++ b/library/billing.inc @@ -233,4 +233,26 @@ function isEncounterBilled($pid, $encounter) { } return $count ? true : false; } + +// Get the co-pay amount that is effective on the given date. +// Or if no insurance on that date, return -1. +// +function getCopay($patient_id, $encdate) { + $tmp = sqlQuery("SELECT provider, copay FROM insurance_data " . + "WHERE pid = '$patient_id' AND type = 'primary' " . + "AND date <= '$encdate' ORDER BY date DESC LIMIT 1"); + if ($tmp['provider']) return sprintf('%01.2f', 0 + $tmp['copay']); + return 0; +} + +// Get the total co-pay amount paid by the patient for an encounter +function getPatientCopay($patient_id, $encounter) { + $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where ". + "pid = ? and encounter = ? and payer_type=0 and account_code='PCP'", + array($patient_id,$encounter)); + //new fees screen copay gives account_code='PCP' + $rowMoneyGot = sqlFetchArray($resMoneyGot); + $Copay=$rowMoneyGot['PatientPay']; + return $Copay*-1; +} ?> diff --git a/library/invoice_summary.inc.php b/library/invoice_summary.inc.php index 6629e356c..6d95038d7 100644 --- a/library/invoice_summary.inc.php +++ b/library/invoice_summary.inc.php @@ -30,6 +30,7 @@ // arseq - ar_activity.sequence_no when it applies. require_once("sl_eob.inc.php"); +require_once(dirname(__FILE__) . "/../custom/code_types.inc.php"); function get_invoice_summary($trans_id, $with_detail = false) { global $sl_err, $sl_cash_acc; @@ -134,42 +135,6 @@ function ar_get_invoice_summary($patient_id, $encounter_id, $with_detail = false $keysuff1 = 1000; $keysuff2 = 5000; - //Get CO-PAYs from ar_activity - $resPCP = sqlStatement(" - SELECT post_time as date, co.code_type, co.code, co.modifier, co.code_text, pay_amount AS fee , units, account_code - FROM ar_activity AS ar, codes AS co - WHERE ar.code=co.code AND ar.modifier=co.modifier - AND account_code = 'PCP' - AND pid=? AND encounter=? ORDER BY fee DESC,CODE,modifier - ",array($patient_id,$encounter_id)); - - while ($rowPCP = sqlFetchArray($resPCP)) { - $amount = sprintf('%01.2f', $rowPCP['fee']); - - $code = 'CO-PAY'; - $codes[$code]['bal'] += $amount; - if ($rowPCP['modifier']) $code .= ':' . strtoupper($rowPCP['modifier']); - $codes[$code]['chg'] += $amount; - - // Add the details if they want 'em. - if ($with_detail) { - if (! $codes[$code]['dtl']) $codes[$code]['dtl'] = array(); - $tmp = array(); - $tmp['pmt'] = 0 - $amount; - $tmp['src'] = 'Pt Paid'; - $tmp['plv'] = 0; - $tmp['tab'] = 'ar_activity'; - $tmp['id'] = $rowPCP['id']; - - $tmpkey = substr($rowPCP['date'], 0, 10) . $keysuff2++; - $tmp['code_text'] = $rowPCP['code_text'];//Z&H - $tmp['code_value'] = $rowPCP['code'];//Z&H - $tmp['modifier'] = $rowPCP['modifier']; - $tmp['justify'] = $rowPCP['justify']; - $codes[$code]['dtl'][$tmpkey] = $tmp; - } - } - // Get charges from services. $res = sqlStatement("SELECT " . "date, code_type, code, modifier, code_text, fee " . @@ -180,35 +145,26 @@ function ar_get_invoice_summary($patient_id, $encounter_id, $with_detail = false while ($row = sqlFetchArray($res)) { $amount = sprintf('%01.2f', $row['fee']); - if ($row['code_type'] == 'COPAY') { - $code = 'CO-PAY'; - $codes[$code]['bal'] += $amount; - } - else { - $code = strtoupper($row['code']); + $code = $row['code']; if (! $code) $code = "Unknown"; - if ($row['modifier']) $code .= ':' . strtoupper($row['modifier']); + if ($row['modifier']) $code .= ':' . $row['modifier']; $codes[$code]['chg'] += $amount; $codes[$code]['bal'] += $amount; - } - // Pass the code type label + // Pass the code type, code and code_text fields + // Although not all used yet, useful information + // to improve the statement reporting etc. $codes[$code]['code_type'] = $row['code_type']; + $codes[$code]['code_value'] = $row['code']; + $codes[$code]['modifier'] = $row['modifier']; + $codes[$code]['code_text'] = $row['code_text']; // Add the details if they want 'em. if ($with_detail) { if (! $codes[$code]['dtl']) $codes[$code]['dtl'] = array(); $tmp = array(); - if ($row['code_type'] == 'COPAY') { - $tmp['pmt'] = 0 - $amount; - $tmp['src'] = 'Pt Paid'; - $tmp['plv'] = 0; - $tmpkey = substr($row['date'], 0, 10) . $keysuff2++; - } - else { - $tmp['chg'] = $amount; - $tmpkey = " " . $keysuff1++; - } + $tmp['chg'] = $amount; + $tmpkey = " " . $keysuff1++; $codes[$code]['dtl'][$tmpkey] = $tmp; } } @@ -235,10 +191,10 @@ function ar_get_invoice_summary($patient_id, $encounter_id, $with_detail = false } } - // Get payments and adjustments. + // Get payments and adjustments. (includes copays) $res = sqlStatement("SELECT " . - "a.code, a.modifier, a.memo, a.payer_type, a.adj_amount, a.pay_amount, a.reason_code, " . - "a.post_time, a.session_id, a.sequence_no, " . + "a.code_type, a.code, a.modifier, a.memo, a.payer_type, a.adj_amount, a.pay_amount, a.reason_code, " . + "a.post_time, a.session_id, a.sequence_no, a.account_code, " . "s.payer_id, s.reference, s.check_date, s.deposit_date " . ",i.name " . "FROM ar_activity AS a " . @@ -247,9 +203,9 @@ function ar_get_invoice_summary($patient_id, $encounter_id, $with_detail = false "WHERE a.pid = ? AND a.encounter = ? " . "ORDER BY s.check_date, a.sequence_no", array($patient_id,$encounter_id) ); while ($row = sqlFetchArray($res)) { - $code = strtoupper($row['code']); + $code = $row['code']; if (! $code) $code = "Unknown"; - if ($row['modifier']) $code .= ':' . strtoupper($row['modifier']); + if ($row['modifier']) $code .= ':' . $row['modifier']; $ins_id = 0 + $row['payer_id']; $codes[$code]['bal'] -= $row['pay_amount']; $codes[$code]['bal'] -= $row['adj_amount']; @@ -274,7 +230,13 @@ function ar_get_invoice_summary($patient_id, $encounter_id, $with_detail = false else { $tmpkey = $paydate . $keysuff2++; } - $tmp['src'] = empty($row['session_id']) ? $row['memo'] : $row['reference']; + if ($row['account_code'] == "PCP") { + //copay + $tmp['src'] = 'Pt Paid'; + } + else { + $tmp['src'] = empty($row['session_id']) ? $row['memo'] : $row['reference']; + } $tmp['insurance_company'] = substr($row['name'], 0, 10); if ($ins_id) $tmp['ins'] = $ins_id; $tmp['plv'] = $row['payer_type']; -- 2.11.4.GIT