From 5f38b177ef2b34ae97c5d2bbe31f16cc68386607 Mon Sep 17 00:00:00 2001 From: sunsetsystems Date: Thu, 15 Jun 2006 17:57:28 +0000 Subject: [PATCH] reworked patient statements to show more detail --- custom/statement.inc.php | 89 ++++++++++++++++++++++++++---------- interface/billing/sl_eob_invoice.php | 26 +++++++++-- interface/billing/sl_eob_search.php | 6 ++- library/invoice_summary.inc.php | 18 +++++++- 4 files changed, 106 insertions(+), 33 deletions(-) diff --git a/custom/statement.inc.php b/custom/statement.inc.php index 1ba502232..d82a2284d 100644 --- a/custom/statement.inc.php +++ b/custom/statement.inc.php @@ -1,6 +1,6 @@ +// Copyright (C) 2005-2006 Rod Roark // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,6 +12,7 @@ // letters. You must customize it to suit your practice. If your // needs are simple then you do not need programming experience to do // this - just read the comments and make appropriate substitutions. +// All you really need to do is replace the [strings in brackets]. ////////////////////////////////////////////////////////////////////// // The location/name of a temporary file to hold printable statements. @@ -23,7 +24,7 @@ $STMT_TEMP_FILE = "/tmp/openemr_statements.txt"; // example is designed for 8.5x11-inch paper with 1-inch margins, // 10 CPI, 6 LPI, 65 columns, 54 lines per page. // -$STMT_PRINT_CMD = "lpr -P SuperScript-870 -o cpi=10 -o lpi=6 -o page-left=72 -o page-top=72"; +$STMT_PRINT_CMD = "lpr -P HPLaserjet6P -o cpi=10 -o lpi=6 -o page-left=72 -o page-top=72"; // This function builds a printable statement or collection letter from // an associative array having the following keys: @@ -39,6 +40,17 @@ $STMT_PRINT_CMD = "lpr -P SuperScript-870 -o cpi=10 -o lpi=6 -o page-left=72 -o // amount = charge less adjustments // paid = amount paid // notice = 1 for first notice, 2 for second, etc. +// detail = associative array of details +// +// Each detail array is keyed on a string beginning with a date in +// yyyy-mm-dd format, or blanks in the case of the original charge +// items. Its values are associative arrays like this: +// +// pmt - payment amount as a positive number, only for payments +// src - check number or other source, only for payments +// chg - invoice line item amount amount, only for charges or +// adjustments (adjustments may be zero) +// rsn - adjustment reason, only for adjustments // // The returned value is a string that can be sent to a printer. // This example is plain text, but if you are a hotshot programmer @@ -57,26 +69,26 @@ function create_statement($stmt) { // Note that "\n" is a line feed (new line) character. // $out = sprintf( - "Your Business Name %-25s %s\n" . - "Address Line 1 Insurance information on file\n" . - "Address Line 2 \n" . - "City, State Zip Total amount due: %s\n" . + "[Your Clinic Name] %-23s %s\n" . + "[Your Clinic Address] Chart Number %s\n" . + "[City, State Zip] Insurance information on file\n" . + " Total amount due: %s\n" . "\n" . "\n" . "ADDRESSEE: REMIT TO:\n" . "\n" . - "%-32s Your Remit-To Name\n" . - "%-32s Your Remit-To Address\n" . - "%-32s City, State Zip\n" . - "%s\n" . + "%-32s [Remit-To Name]\n" . + "%-32s [Remit-To Address]\n" . + "%-32s [City, State Zip]\n" . + "%-32s If paying by VISA/MC/AMEX/Disc:\n" . "\n" . - "\n" . - " (Return above part with your payment by check or money order)\n" . + "Card#_____________________ Exp______ Signature__________________\n" . + " (Return above part with your payment)\n" . "-----------------------------------------------------------------\n" . "\n" . "_______________________ STATEMENT SUMMARY _______________________\n" . "\n" . - "Visit Date Description Charge Adjust Paid\n" . + "Visit Date Description Amount\n" . "\n", // These are the values for the variable fields. They must appear @@ -84,6 +96,7 @@ function create_statement($stmt) { // $stmt['patient'], $stmt['today'], + $stmt['pid'], $stmt['amount'], $stmt['to'][0], $stmt['to'][1], @@ -98,17 +111,43 @@ function create_statement($stmt) { // be specified in the order used. // foreach ($stmt['lines'] as $line) { - ++$count; $description = $line['desc']; $tmp = substr($description, 0, 14); if ($tmp == 'Procedure 9920' || $tmp == 'Procedure 9921') - $description = 'Office Visit'; - $out .= sprintf("%-10s %-29s%8s%8s%8s\n", - $line['dos'], // values start here - $description, - sprintf("%.2f", $line['amount'] + $line['adjust']), - $line['adjust'], - $line['paid']); + $description = 'Office Visit'; + + $dos = $line['dos']; + ksort($line['detail']); + + foreach ($line['detail'] as $dkey => $ddata) { + $ddate = substr($dkey, 0, 10); + if (preg_match('/^(\d\d\d\d)(\d\d)(\d\d)\s*$/', $ddate, $matches)) { + $ddate = $matches[1] . '-' . $matches[2] . '-' . $matches[3]; + } + $amount = ''; + + if ($ddata['pmt']) { + $amount = sprintf("%.2f", 0 - $ddata['pmt']); + $desc = "Paid $ddate: " . $ddata['src']; + } else if ($ddata['rsn']) { + if ($ddata['chg']) { + $amount = sprintf("%.2f", $ddata['chg']); + $desc = "Adj $ddate: " . $ddata['rsn']; + } else { + $desc = "Note $ddate: " . $ddata['rsn']; + } + } else if ($ddata['chg'] < 0) { + $amount = sprintf("%.2f", $ddata['chg']); + $desc = "Patient Payment"; + } else { + $amount = sprintf("%.2f", $ddata['chg']); + $desc = $description; + } + + $out .= sprintf("%-10s %-45s%8s\n", $dos, $desc, $amount); + $dos = ''; + ++$count; + } } // This generates blank lines until we are at line 42. @@ -121,14 +160,14 @@ function create_statement($stmt) { "Name: %-25s Date: %-10s Due:%8s\n" . "_________________________________________________________________\n" . "\n" . - "Thank you for choosing [Clinic name here].\n" . + "Thank you for choosing [Your Clinic Name].\n" . "\n" . "Please call if any of the above information is incorrect.\n" . "We appreciate prompt payment of balances due.\n" . "\n" . - "[Insert some name here]\n" . - "Practice Manager\n" . - "[Insert phone number here]" . + "[Your billing contact name]\n" . + "Billing Department\n" . + "[Your billing contact phone number]" . "\014", // this is a form feed $stmt['patient'], // values start here diff --git a/interface/billing/sl_eob_invoice.php b/interface/billing/sl_eob_invoice.php index 3966b0f39..b29a1b9aa 100644 --- a/interface/billing/sl_eob_invoice.php +++ b/interface/billing/sl_eob_invoice.php @@ -19,6 +19,7 @@ $debug = 0; // set to 1 for debugging mode $reasons = array( + "", // not choosing this allows a reason with no adjustment amount xl("Ins adjust"), xl("Coll w/o"), xl("Pt released"), @@ -443,6 +444,10 @@ function validate(f) { alert('' + code + ''); return false; } + if (f[pfx+'[adj]'].value && ! f[pfx+'[reason]'].value) { + alert('' + code); + return false; + } // TBD: validate the date format } return true; @@ -496,13 +501,26 @@ function validate(f) { updateAR($trans_id, 0, $thispay, $thisdate); $paytotal += $thispay; } - if ($thisadj) { + +// if ($thisadj) { +// // Post an adjustment: add negative invoice item, add to ar, subtract from income +// addLineItem($trans_id, $code, 0 - $thisadj, $thisdate, $thisins, $reason); +// addTransaction($trans_id, $chart_id_ar, $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins); +// addTransaction($trans_id, $chart_id_income, 0 - $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins); +// updateAR($trans_id, 0 - $thisadj); +// } + + // Be sure to record adjustment reasons even for zero adjustments. + if ($thisadj || $reason) { // Post an adjustment: add negative invoice item, add to ar, subtract from income addLineItem($trans_id, $code, 0 - $thisadj, $thisdate, $thisins, $reason); - addTransaction($trans_id, $chart_id_ar, $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins); - addTransaction($trans_id, $chart_id_income, 0 - $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins); - updateAR($trans_id, 0 - $thisadj); + if ($thisadj) { + addTransaction($trans_id, $chart_id_ar, $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins); + addTransaction($trans_id, $chart_id_income, 0 - $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins); + updateAR($trans_id, 0 - $thisadj); + } } + } $form_duedate = fixDate($_POST['form_duedate']); $form_notes = trim($_POST['form_notes']); diff --git a/interface/billing/sl_eob_search.php b/interface/billing/sl_eob_search.php index c44fbd846..3a5ec5c6f 100644 --- a/interface/billing/sl_eob_search.php +++ b/interface/billing/sl_eob_search.php @@ -89,6 +89,7 @@ // amount = charge less adjustments // paid = amount paid // notice = 1 for first notice, 2 for second, etc. + // detail = array of details, see invoice_summary.inc.php // if ($stmt['cid'] != $row['customer_id']) { fwrite($fhprint, create_statement($stmt)); @@ -113,15 +114,16 @@ $stmt['age'] = round((strtotime($today) - strtotime($stmt['duedate'])) / (24 * 60 * 60)); - $invlines = get_invoice_summary($row['id']); + $invlines = get_invoice_summary($row['id'], true); // true added by Rod 2006-06-09 foreach ($invlines as $key => $value) { $line = array(); $line['dos'] = $svcdate; - $line['desc'] = "Procedure $key"; + $line['desc'] = ($key == 'CO-PAY') ? "Patient Payment" : "Procedure $key"; $line['amount'] = sprintf("%.2f", $value['chg']); $line['adjust'] = sprintf("%.2f", $value['adj']); $line['paid'] = sprintf("%.2f", $value['chg'] - $value['bal']); $line['notice'] = $duncount + 1; + $line['detail'] = $value['dtl']; // Added by Rod 2006-06-09 $stmt['lines'][] = $line; $stmt['amount'] = sprintf("%.2f", $stmt['amount'] + $value['bal']); } diff --git a/library/invoice_summary.inc.php b/library/invoice_summary.inc.php index 3fadb1ea4..4beaf111e 100644 --- a/library/invoice_summary.inc.php +++ b/library/invoice_summary.inc.php @@ -9,11 +9,23 @@ // This returns an associative array keyed on procedure code, representing // all charge items for one invoice. This array's values are themselves // associative arrays having the following keys: +// // chg - the sum of line items, including adjustments, for the code // bal - the unpaid balance +// adj - the (positive) sum of inverted adjustments // ins - the id of the insurance company that was billed // dtl - associative array of details, if requested // +// Where details are requested, each dtl array is keyed on a string +// beginning with a date in yyyy-mm-dd format, or blanks in the case +// of the original charge items. The value array is: +// +// pmt - payment amount as a positive number, only for payments +// src - check number or other source, only for payments +// chg - invoice line item amount amount, only for charges or +// adjustments (adjustments may be zero) +// rsn - adjustment reason, only for adjustments + function get_invoice_summary($trans_id, $with_detail = false) { global $sl_err, $sl_cash_acc; @@ -50,8 +62,10 @@ function get_invoice_summary($trans_id, $with_detail = false) { } } - // Request all line items with money belonging to the invoice. - $inres = SLQuery("select * from invoice where trans_id = $trans_id and sellprice != 0"); + // Request all line items with money or adjustment reasons belonging + // to the invoice. + $inres = SLQuery("SELECT * FROM invoice WHERE trans_id = $trans_id AND " . + "( sellprice != 0 OR description LIKE 'Adjustment%' )"); if ($sl_err) die($sl_err); // Add charges and adjustments for each procedure code into its total and balance. -- 2.11.4.GIT