added new layouts and lists for GCAC and contraception issues
[openemr.git] / interface / patient_file / printed_fee_sheet.php
blobfd4d500193b857d70bf76aed46772a72f3ce8097
1 <?php
2 // Copyright (C) 2007-2008 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("$srcdir/patient.inc");
12 require_once("$srcdir/classes/Address.class.php");
13 require_once("$srcdir/classes/InsuranceCompany.class.php");
15 // This file is optional. You can create it to customize how the printed
16 // fee sheet looks, otherwise you'll get a mirror of your actual fee sheet.
18 if (file_exists("../../custom/fee_sheet_codes.php"))
19 include_once ("../../custom/fee_sheet_codes.php");
21 $fontsize = trim($_REQUEST['fontsize']) + 0;
22 if (!$fontsize) $fontsize = 7;
23 $page_height = trim($_REQUEST['page_height']) + 0;
24 if (!$page_height) $page_height = 700;
25 $padding = 0;
27 // If $SBCODES is not provided, then manufacture it from the Fee Sheet.
29 if (empty($SBCODES)) {
30 $SBCODES = array();
31 $last_category = '';
33 // Create entries based on the fee_sheet_options table.
34 $res = sqlStatement("SELECT * FROM fee_sheet_options " .
35 "ORDER BY fs_category, fs_option");
36 while ($row = sqlFetchArray($res)) {
37 $fs_category = $row['fs_category'];
38 $fs_option = $row['fs_option'];
39 $fs_codes = $row['fs_codes'];
40 if($fs_category !== $last_category) {
41 $last_category = $fs_category;
42 $SBCODES[] = '*G|' . substr($fs_category, 1);
44 $SBCODES[] = " |" . substr($fs_option, 1);
47 // Create entries based on categories defined within the codes.
48 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
49 "WHERE list_id = 'superbill' ORDER BY seq");
50 while ($prow = sqlFetchArray($pres)) {
51 $SBCODES[] = '*G|' . $prow['title'];
52 $res = sqlStatement("SELECT code_type, code, code_text FROM codes " .
53 "WHERE superbill = '" . $prow['option_id'] . "' " .
54 "ORDER BY code_text");
55 while ($row = sqlFetchArray($res)) {
56 $SBCODES[] = $row['code'] . '|' . $row['code_text'];
60 // Create one more group, for Products.
61 if ($GLOBALS['sell_non_drug_products']) {
62 $SBCODES[] = '*G|' . xl('Products');
63 $tres = sqlStatement("SELECT dt.drug_id, dt.selector, d.name " .
64 "FROM drug_templates AS dt, drugs AS d WHERE " .
65 "d.drug_id = dt.drug_id " .
66 "ORDER BY d.name, dt.selector, dt.drug_id");
67 while ($trow = sqlFetchArray($tres)) {
68 $tmp = $trow['selector'];
69 if ($trow['name'] !== $trow['selector']) $tmp .= ' ' . $trow['name'];
70 $SBCODES[] = $trow['drug_id'] . '|' . $tmp;
74 // Extra stuff for the labs section and splitting evenly into 3 columns.
75 $SBCODES[] = '*G|' . xl('Additional Labs');
76 $percol = intval((count($SBCODES) + 2) / 3);
77 while (count($SBCODES) < $percol * 3) $SBCODES[] = '*B|';
78 array_splice($SBCODES, $percol*2, 0, '*C|'); // ends 2nd column
79 array_splice($SBCODES, $percol*1, 0, '*C|'); // ends 1st column
82 <html>
83 <head>
84 <?php html_header_show(); ?>
86 <style>
87 body {
88 font-family: sans-serif;
89 font-weight: normal;
91 .bordertbl {
92 width: 100%;
93 border-style: solid;
94 border-width: 0 0 1px 1px;
95 border-spacing: 0;
96 border-collapse: collapse;
97 border-color: #999999;
99 td.toprow {
100 height: 1px;
101 padding: 0;
102 border-style: solid;
103 border-width: 0 0 0 0;
104 border-color: #999999;
106 td.fsgroup {
107 font-family: sans-serif;
108 font-weight: bold;
109 font-size: <?php echo $fontsize ?>pt;
110 background-color: #cccccc;
111 padding: <?php echo $padding ?>pt 2pt 0pt 2pt;
112 border-style: solid;
113 border-width: 1px 1px 0 0;
114 border-color: #999999;
116 td.fshead {
117 font-family: sans-serif;
118 font-weight: bold;
119 font-size: <?php echo $fontsize ?>pt;
120 padding: <?php echo $padding ?>pt 2pt 0pt 2pt;
121 border-style: solid;
122 border-width: 1px 1px 0 0;
123 border-color: #999999;
125 td.fscode {
126 font-family: sans-serif;
127 font-weight: normal;
128 font-size: <?php echo $fontsize ?>pt;
129 padding: <?php echo $padding ?>pt 2pt 0pt 2pt;
130 border-style: solid;
131 border-width: 1px 1px 0 0;
132 border-color: #999999;
134 </style>
136 <?php
138 // Get the co-pay amount that is effective on the given date.
139 // Or if no insurance on that date, return -1.
141 function getCopay($patient_id, $encdate) {
142 $tmp = sqlQuery("SELECT provider, copay FROM insurance_data " .
143 "WHERE pid = '$patient_id' AND type = 'primary' " .
144 "AND date <= '$encdate' ORDER BY date DESC LIMIT 1");
145 if ($tmp['provider']) return sprintf('%01.2f', 0 + $tmp['copay']);
146 return -1;
149 function genColumn($ix) {
150 global $SBCODES;
151 for ($imax = count($SBCODES); $ix < $imax; ++$ix) {
152 $a = explode('|', $SBCODES[$ix], 2);
153 $cmd = trim($a[0]);
154 if ($cmd == '*C') {
155 return ++$ix; // column break
157 if ($cmd == '*B') { // Borderless and empty
158 echo "<tr><td colspan='5' class='fscode' style='border-width:0 1px 0 0;padding-top:1px;' nowrap>&nbsp;</td></tr>\n";
160 else if ($cmd == '*G') {
161 // $title = htmlentities(strtoupper($a[1]));
162 $title = htmlentities($a[1]);
163 if (!$title) $title='&nbsp;';
164 echo "<tr><td colspan='5' align='center' class='fsgroup' style='vertical-align:middle' nowrap>$title</td></tr>\n";
166 else if ($cmd == '*H') {
167 // $title = htmlentities(strtoupper($a[1]));
168 $title = htmlentities($a[1]);
169 if (!$title) $title='&nbsp;';
170 echo "<tr><td colspan='5' class='fshead' style='vertical-align:middle' nowrap>$title</td></tr>\n";
172 else {
173 $title = htmlentities($a[1]);
174 if (!$title) $title='&nbsp;';
175 $b = explode(':', $cmd);
176 echo "<tr>";
177 echo "<td class='fscode' style='vertical-align:middle;width:14pt' nowrap>&nbsp;</td>\n";
178 if (count($b) <= 1) {
179 $code = $b[0];
180 if (!$code) $code='&nbsp;';
181 echo "<td class='fscode' style='vertical-align:middle' nowrap>$code</td>\n";
182 echo "<td colspan='3' class='fscode' style='vertical-align:middle' nowrap>$title</td>\n";
184 else {
185 echo "<td colspan='2' class='fscode' style='vertical-align:middle' nowrap>" . $b[0] . '/' . $b[1] . "</td>\n";
186 echo "<td colspan='2' class='fscode' style='vertical-align:middle' nowrap>$title</td>\n";
188 echo "</tr>\n";
191 return $ix;
194 $today = date('Y-m-d');
196 $alertmsg = ''; // anything here pops up in an alert box
198 // Get details for what we guess is the primary facility.
199 $frow = sqlQuery("SELECT * FROM facility " .
200 "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1");
202 // Get the patient's name and chart number.
203 $patdata = getPatientData($pid);
205 // This tracks our position in the $SBCODES array.
206 $cindex = 0;
209 <title><?php echo htmlentities($frow['name']); ?></title>
210 <script type="text/javascript" src="../../library/dialog.js"></script>
211 <script language="JavaScript">
213 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
215 // Process click on Print button.
216 function printme() {
217 var divstyle = document.getElementById('hideonprint').style;
218 divstyle.display = 'none';
219 window.print();
222 </script>
223 </head>
224 <body bgcolor='#ffffff'>
225 <form name='theform' method='post' action='printed_fee_sheet.php'
226 onsubmit='return top.restoreSession()'>
227 <center>
229 <table class='bordertbl' cellspacing='0' cellpadding='0' width='100%'>
230 <tr>
231 <td valign='top'>
232 <table border='0' cellspacing='0' cellpadding='0' width='100%' style='height:<?php echo $page_height ?>pt'>
233 <tr>
234 <td class='toprow' style='width:10%'></td>
235 <td class='toprow' style='width:10%'></td>
236 <td class='toprow' style='width:25%'></td>
237 <td class='toprow' style='width:55%'></td>
238 </tr>
239 <?php
240 $cindex = genColumn($cindex); // Column 1
242 <tr>
243 <td colspan='3' valign='top' class='fshead' style='height:50pt'>
244 Patient:<br>
245 <?php
246 echo $patdata['fname'] . ' ' . $patdata['mname'] . ' ' . $patdata['lname'] . "<br>\n";
247 echo $patdata['street'] . "<br>\n";
248 echo $patdata['city'] . ', ' . $patdata['state'] . ' ' . $patdata['postal_code'] . "\n";
250 </td>
251 <td valign='top' class='fshead'>
252 DOB:<br><?php echo $patdata['DOB']; ?><br>
253 ID:<br><?php echo $patdata['pubpid']; ?>
254 </td>
255 </tr>
256 <tr>
257 <td colspan='3' valign='top' class='fshead' style='height:25pt'>
258 Doctor:&nbsp;
259 <?php // Doctor name here ?>
260 </td>
261 <td valign='top' class='fshead'>
262 Reason:&nbsp;
263 <?php // Encounter reason here ?>
264 </td>
265 </tr>
266 <tr>
267 <td colspan='4' valign='top' class='fshead' style='height:25pt'>
268 <?php
269 if (empty($GLOBALS['ippf_specific'])) {
270 echo "Insurance:\n";
271 foreach (array('primary','secondary','tertiary') as $instype) {
272 $query = "SELECT * FROM insurance_data WHERE " .
273 "pid = '$pid' AND type = '$instype' " .
274 "ORDER BY date DESC LIMIT 1";
275 $row = sqlQuery($query);
276 if ($row['provider']) {
277 $icobj = new InsuranceCompany($row['provider']);
278 $adobj = $icobj->get_address();
279 $insco_name = trim($icobj->get_name());
280 if ($instype != 'primary') echo ",";
281 if ($insco_name) {
282 echo "&nbsp;$insco_name";
283 } else {
284 echo "&nbsp;<font color='red'><b>Missing Name</b></font>";
289 else {
290 // IPPF wants a visit date box with the current date in it.
291 echo "Visit date:<br>\n";
292 echo date('Y-m-d') . "\n";
295 </td>
296 </tr>
297 <tr>
298 <td colspan='4' valign='top' class='fshead' style='height:25pt'>
299 Prior balance:<br>
300 </td>
301 </tr>
302 <tr>
303 <td colspan='4' valign='top' class='fshead' style='height:25pt'>
304 Today's charges:<br>
305 </td>
306 </tr>
307 <tr>
308 <td colspan='4' valign='top' class='fshead' style='height:25pt'>
309 Today's payment:<br>
310 </td>
311 </tr>
312 <tr>
313 <td colspan='4' valign='top' class='fshead' style='height:25pt'>
314 Notes:<br>
315 </td>
316 </tr>
317 </table>
318 </td>
319 <td valign='top'>
320 <table border='0' cellspacing='0' cellpadding='0' width='100%' style='height:<?php echo $page_height ?>pt'>
321 <tr>
322 <td class='toprow' style='width:10%'></td>
323 <td class='toprow' style='width:10%'></td>
324 <td class='toprow' style='width:25%'></td>
325 <td class='toprow' style='width:55%'></td>
326 </tr>
327 <?php
328 $cindex = genColumn($cindex); // Column 2
330 <tr>
331 <td colspan='4' valign='top' class='fshead' style='height:100pt'>
332 Additional procedures:<br>
333 </td>
334 </tr>
335 <tr>
336 <td colspan='4' valign='top' class='fshead' style='height:100pt'>
337 Diagnosis:<br>
338 </td>
339 </tr>
340 </table>
341 </td>
342 <td valign='top'>
343 <table border='0' cellspacing='0' cellpadding='0' width='100%' style='height:<?php echo $page_height ?>pt'>
344 <tr>
345 <td class='toprow' style='width:10%'></td>
346 <td class='toprow' style='width:10%'></td>
347 <td class='toprow' style='width:25%'></td>
348 <td class='toprow' style='width:55%'></td>
349 </tr>
350 <?php
351 $cindex = genColumn($cindex); // Column 3
353 <tr>
354 <td valign='top' colspan='4' class='fshead' style='height:150pt;border-width:0 1px 0 0'>
355 &nbsp;
356 </td>
357 </tr>
358 <tr>
359 <td valign='top' colspan='4' class='fshead' style='height:50pt'>
360 M.D. Signature:<br>
361 </td>
362 </tr>
363 </table>
364 </td>
365 </tr>
367 </table>
369 <div id='hideonprint'>
371 <input type='button' value='<?php xl('Print','e'); ?>' onclick='printme()' />
372 &nbsp;&nbsp;Font Size in Points:
373 <input type='text' name='fontsize' size='2' maxlength='5' value='<?php echo $fontsize ?>' />
374 &nbsp;&nbsp;Page Height in Points:
375 <input type='text' name='page_height' size='3' maxlength='4' value='<?php echo $page_height ?>' />
376 &nbsp;&nbsp;
377 <input type='submit' name='form_submit' value='Refresh' />
378 </div>
380 </form>
381 </center>
382 </body>
383 </html>