3 // Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 //////////////////////////////////////////////////////////////////////
11 // This is a template for printing patient statements and collection
12 // letters. You must customize it to suit your practice. If your
13 // needs are simple then you do not need programming experience to do
14 // this - just read the comments and make appropriate substitutions.
15 // All you really need to do is replace the [strings in brackets].
16 //////////////////////////////////////////////////////////////////////
18 // The location/name of a temporary file to hold printable statements.
20 $STMT_TEMP_FILE = "/tmp/openemr_statements.txt";
22 // This is the command to be used for printing (without the filename).
23 // The word following "-P" should be the name of your printer. This
24 // example is designed for 8.5x11-inch paper with 1-inch margins,
25 // 10 CPI, 6 LPI, 65 columns, 54 lines per page.
27 $STMT_PRINT_CMD = "lpr -P HPLaserjet6P -o cpi=10 -o lpi=6 -o page-left=72 -o page-top=72";
29 // This function builds a printable statement or collection letter from
30 // an associative array having the following keys:
32 // today = statement date yyyy-mm-dd
34 // patient = patient name
35 // amount = total amount due
36 // to = array of addressee name/address lines
37 // lines = array of lines, each with the following keys:
38 // dos = date of service yyyy-mm-dd
40 // amount = charge less adjustments
42 // notice = 1 for first notice, 2 for second, etc.
43 // detail = associative array of details
45 // Each detail array is keyed on a string beginning with a date in
46 // yyyy-mm-dd format, or blanks in the case of the original charge
47 // items. Its values are associative arrays like this:
49 // pmt - payment amount as a positive number, only for payments
50 // src - check number or other source, only for payments
51 // chg - invoice line item amount amount, only for charges or
52 // adjustments (adjustments may be zero)
53 // rsn - adjustment reason, only for adjustments
55 // The returned value is a string that can be sent to a printer.
56 // This example is plain text, but if you are a hotshot programmer
57 // then you could make a PDF or PostScript or whatever peels your
58 // banana. These strings are sent in succession, so append a form
59 // feed if that is appropriate.
61 function create_statement($stmt) {
62 if (! $stmt['pid']) return ""; // get out if no data
64 // This is the text for the top part of the page, up to but not
65 // including the detail lines. Some examples of variable fields are:
66 // %s = string with no minimum width
67 // %9s = right-justified string of 9 characters padded with spaces
68 // %-25s = left-justified string of 25 characters padded with spaces
69 // Note that "\n" is a line feed (new line) character.
72 "[Your Clinic Name] %-23s %s\n" .
73 "[Your Clinic Address] Chart Number %s\n" .
74 "[City, State Zip] Insurance information on file\n" .
75 " Total amount due: %s\n" .
78 "ADDRESSEE: REMIT TO:\n" .
80 "%-32s [Remit-To Name]\n" .
81 "%-32s [Remit-To Address]\n" .
82 "%-32s [City, State Zip]\n" .
83 "%-32s If paying by VISA/MC/AMEX/Disc:\n" .
85 "Card#_____________________ Exp______ Signature__________________\n" .
86 " (Return above part with your payment)\n" .
87 "-----------------------------------------------------------------\n" .
89 "_______________________ STATEMENT SUMMARY _______________________\n" .
91 "Visit Date Description Amount\n" .
94 // These are the values for the variable fields. They must appear
95 // here in the same order as in the above text!
106 // This must be set to the number of lines generated above.
110 // This generates the detail lines. Again, note that the values must
111 // be specified in the order used.
113 foreach ($stmt['lines'] as $line) {
114 $description = $line['desc'];
115 $tmp = substr($description, 0, 14);
116 if ($tmp == 'Procedure 9920' ||
$tmp == 'Procedure 9921')
117 $description = 'Office Visit';
120 ksort($line['detail']);
122 foreach ($line['detail'] as $dkey => $ddata) {
123 $ddate = substr($dkey, 0, 10);
124 if (preg_match('/^(\d\d\d\d)(\d\d)(\d\d)\s*$/', $ddate, $matches)) {
125 $ddate = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
130 $amount = sprintf("%.2f", 0 - $ddata['pmt']);
131 $desc = "Paid $ddate: " . $ddata['src'];
132 } else if ($ddata['rsn']) {
134 $amount = sprintf("%.2f", $ddata['chg']);
135 $desc = "Adj $ddate: " . $ddata['rsn'];
137 $desc = "Note $ddate: " . $ddata['rsn'];
139 } else if ($ddata['chg'] < 0) {
140 $amount = sprintf("%.2f", $ddata['chg']);
141 $desc = "Patient Payment";
143 $amount = sprintf("%.2f", $ddata['chg']);
144 $desc = $description;
147 $out .= sprintf("%-10s %-45s%8s\n", $dos, $desc, $amount);
153 // This generates blank lines until we are at line 42.
155 while ($count++
< 42) $out .= "\n";
157 // This is the bottom portion of the page. You know the drill.
160 "Name: %-25s Date: %-10s Due:%8s\n" .
161 "_________________________________________________________________\n" .
163 "Thank you for choosing [Your Clinic Name].\n" .
165 "Please call if any of the above information is incorrect.\n" .
166 "We appreciate prompt payment of balances due.\n" .
168 "[Your billing contact name]\n" .
169 "Billing Department\n" .
170 "[Your billing contact phone number]" .
171 "\014", // this is a form feed
173 $stmt['patient'], // values start here