forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatement.inc.php
More file actions
316 lines (273 loc) · 11.2 KB
/
Copy pathstatement.inc.php
File metadata and controls
316 lines (273 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php
// Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
//
// Windows compatibility mods 2009 Bill Cernansky [mi-squared.com]
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// Updated by Medical Information Integration, LLC to support download
// and multi OS use - tony@mi-squared..com 12-2009
//////////////////////////////////////////////////////////////////////
// This is a template for printing patient statements and collection
// 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.
//
$STMT_TEMP_FILE = $GLOBALS['temporary_files_dir'] . "/openemr_statements.txt";
$STMT_TEMP_FILE_PDF = $GLOBALS['temporary_files_dir'] . "/openemr_statements.pdf";
$STMT_PRINT_CMD = $GLOBALS['print_command'];
// This function builds a printable statement or collection letter from
// an associative array having the following keys:
//
// today = statement date yyyy-mm-dd
// pid = patient ID
// patient = patient name
// amount = total amount due
// to = array of addressee name/address lines
// lines = array of lines, each with the following keys:
// dos = date of service yyyy-mm-dd
// desc = description
// 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
// then you could make a PDF or PostScript or whatever peels your
// banana. These strings are sent in succession, so append a form
// feed if that is appropriate.
//
// A sample of the text based format follows:
//[Your Clinic Name] Patient Name 2009-12-29
//[Your Clinic Address] Chart Number: 1848
//[City, State Zip] Insurance information on file
//
//
//ADDRESSEE REMIT TO
//Patient Name [Your Clinic Name]
//patient address [Your Clinic Address]
//city, state zipcode [City, State Zip]
// If paying by VISA/MC/AMEX/Dis
//
//Card_____________________ Exp______ Signature___________________
// Return above part with your payment
//-----------------------------------------------------------------
//
//_______________________ STATEMENT SUMMARY _______________________
//
//Visit Date Description Amount
//
//2009-08-20 Procedure 99345 198.90
// Paid 2009-12-15: -51.50
//... more details ...
//...
//...
// skipping blanks in example
//
//
//Name: Patient Name Date: 2009-12-29 Due: 147.40
//_________________________________________________________________
//
//Please call if any of the above information is incorrect
//We appreciate prompt payment of balances due
//
//[Your billing contact name]
// Billing Department
// [Your billing dept phone]
function create_statement($stmt) {
if (! $stmt['pid']) return ""; // get out if no data
// These are your clinics return address, contact etc. Edit them.
// TBD: read this from the facility table
// Facility (service location)
$atres = sqlStatement("select f.name,f.street,f.city,f.state,f.postal_code from facility f " .
" left join users u on f.id=u.facility_id " .
" left join billing b on b.provider_id=u.id and b.pid = '".$stmt['pid']."' " .
" where service_location=1");
$row = sqlFetchArray($atres);
// Facility (service location)
$clinic_name = "{$row['name']}";
$clinic_addr = "{$row['street']}";
$clinic_csz = "{$row['city']}, {$row['state']}, {$row['postal_code']}";
// Billing location
$remit_name = $clinic_name;
$remit_addr = $clinic_addr;
$remit_csz = $clinic_csz;
// Contacts
$atres = sqlStatement("select f.attn,f.phone from facility f " .
" left join users u on f.id=u.facility_id " .
" left join billing b on b.provider_id=u.id and b.pid = '".$stmt['pid']."' " .
" where billing_location=1");
$row = sqlFetchArray($atres);
$billing_contact = "{$row['attn']}";
$billing_phone = "{$row['phone']}";
// dunning message setup
// insurance has paid something
// $stmt['age'] how old is the invoice
// $stmt['dun_count'] number of statements run
// $stmt['level_closed'] <= 3 insurance 4 = patient
if ($GLOBALS['use_dunning_message']) {
if ($stmt['ins_paid'] != 0 || $stmt['level_closed'] == 4) {
// do collection messages
switch ($stmt{'age'}) {
case $stmt{'age'} <= $GLOBALS['first_dun_msg_set']:
$dun_message = $GLOBALS['first_dun_msg_text'];
break;
case $stmt{'age'} <= $GLOBALS['second_dun_msg_set']:
$dun_message = $GLOBALS['second_dun_msg_text'];
break;
case $stmt{'age'} <= $GLOBALS['third_dun_msg_set']:
$dun_message = $GLOBALS['third_dun_msg_text'];
break;
case $stmt{'age'} <= $GLOBALS['fourth_dun_msg_set']:
$dun_message = $GLOBALS['fourth_dun_msg_text'];
break;
case $stmt{'age'} >= $GLOBALS['fifth_dun_msg_set']:
$dun_message = $GLOBALS['fifth_dun_msg_text'];
break;
}
}
}
// Text only labels
$label_addressee = xl('ADDRESSEE');
$label_remitto = xl('REMIT TO');
$label_chartnum = xl('Chart Number');
$label_insinfo = xl('Insurance information on file');
$label_totaldue = xl('Total amount due');
$label_payby = xl('If paying by');
$label_cards = xl('VISA/MC/AMEX/Dis');
$label_cardnum = xl('Card');
$label_expiry = xl('Exp');
$label_sign = xl('Signature');
$label_retpay = xl('Return above part with your payment');
$label_pgbrk = xl('STATEMENT SUMMARY');
$label_visit = xl('Visit Date');
$label_desc = xl('Description');
$label_amt = xl('Amount');
// This is the text for the top part of the page, up to but not
// including the detail lines. Some examples of variable fields are:
// %s = string with no minimum width
// %9s = right-justified string of 9 characters padded with spaces
// %-25s = left-justified string of 25 characters padded with spaces
// Note that "\n" is a line feed (new line) character.
// reformatted to handle i8n by tony
$out = sprintf("%-30s %-23s %-s\n",$clinic_name,$stmt['patient'],$stmt['today']);
$out .= sprintf("%-30s %s: %-s\n",$clinic_addr,$label_chartnum,$stmt['pid']);
$out .= sprintf("%-30s %-s\n",$clinic_csz,$label_insinfo);
$out .= sprintf("%-30s %s: %-s\n",null,$label_totaldue,$stmt['amount']);
$out .= "\n\n";
$out .= sprintf(" %-30s %-s\n",$label_addressee,$label_remitto);
$out .= sprintf(" %-30s %s\n",$stmt['to'][0],$remit_name);
$out .= sprintf(" %-30s %s\n",$stmt['to'][1],$remit_addr);
$out .= sprintf(" %-30s %s\n",$stmt['to'][2],$remit_csz);
if($stmt['to'][3]!='')//to avoid double blank lines the if condition is put.
$out .= sprintf(" %-32s\n",$stmt['to'][3]);
$out .= sprintf("_________________________________________________________________\n");
$out .= "\n";
$out .= sprintf("%-32s\n",$label_payby.' '.$label_cards);
$out .= "\n";
$out .= sprintf("%s_____________________ %s______ %s___________________\n",
$label_cardnum,$label_expiry,$label_sign);
$out .= sprintf("%-20s %s\n",null,$label_retpay);
$out .= sprintf("-----------------------------------------------------------------\n");
$out .= "\n";
$out .= sprintf("_______________________ %s _______________________\n",$label_pgbrk);
$out .= "\n";
$out .= sprintf("%-11s %-46s %s\n",$label_visit,$label_desc,$label_amt);
$out .= "\n";
// This must be set to the number of lines generated above.
//
$count = 21;
// This generates the detail lines. Again, note that the values must
// be specified in the order used.
//
foreach ($stmt['lines'] as $line) {
if ($GLOBALS['use_custom_statement']) {
$description = substr($line['desc'],0,30);
}
else {
$description = $line['desc'];
}
$tmp = substr($description, 0, 14);
if ($tmp == 'Procedure 9920' || $tmp == 'Procedure 9921')
$description = xl('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 = xl('Paid') .' '. $ddate .': '. $ddata['src'].' '. $ddata['insurance_company'];
} else if ($ddata['rsn']) {
if ($ddata['chg']) {
$amount = sprintf("%.2f", $ddata['chg']);
$desc = xl('Adj') .' '. $ddate .': ' . $ddata['rsn'].' '. $ddata['insurance_company'];
} else {
$desc = xl('Note') .' '. $ddate .': '. $ddata['rsn'].' '. $ddata['insurance_company'];
}
} else if ($ddata['chg'] < 0) {
$amount = sprintf("%.2f", $ddata['chg']);
$desc = xl('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.
//
while ($count++ < 42) $out .= "\n";
// Fixed text labels
$label_ptname = xl('Name');
$label_today = xl('Date');
$label_due = xl('Due');
$label_thanks = xl('Thank you for choosing');
$label_call = xl('Please call if any of the above information is incorrect');
$label_prompt = xl('We appreciate prompt payment of balances due');
$label_dept = xl('Billing Department');
// This is the bottom portion of the page.
$out .= "\n";
if(strlen($stmt['bill_note']) !=0 && $GLOBALS['statement_bill_note_print']) {
$out .= sprintf("%-46s\n",$stmt['bill_note']);
}
if ($GLOBALS['use_dunning_message']) {
$out .= sprintf("%-46s\n",$dun_message);
}
$out .= "\n";
$out .= sprintf("%-s: %-25s %-s: %-14s %-s: %8s\n",$label_ptname,$stmt['patient'],
$label_today,$stmt['today'],$label_due,$stmt['amount']);
$out .= sprintf("__________________________________________________________________\n");
$out .= "\n";
$out .= sprintf("%-s\n",$label_call);
$out .= sprintf("%-s\n",$label_prompt);
$out .= "\n";
$out .= sprintf("%-s\n",$billing_contact);
$out .= sprintf(" %-s\n",$label_dept);
$out .= sprintf(" %-s\n",$billing_phone);
$out .= "\014"; // this is a form feed
return $out;
}
?>