2 // Copyright (C) 2007-2008 Rod Roark <rod@sunsetsystems.com>
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");
18 // This file is optional. You can create it to customize how the printed
19 // fee sheet looks, otherwise you'll get a mirror of your actual fee sheet.
21 if (file_exists("../../custom/fee_sheet_codes.php"))
22 include_once ("../../custom/fee_sheet_codes.php");
24 $fontsize = trim($_REQUEST['fontsize']) +
0;
25 if (!$fontsize) $fontsize = 7;
26 $page_height = trim($_REQUEST['page_height']) +
0;
27 if (!$page_height) $page_height = 700;
30 // The $SBCODES table is a simple indexed array whose values are
31 // strings of the form "code|text" where code may be either a billing
32 // code or one of the following:
34 // *H - A main heading, where "text" is its title (to be centered).
35 // *G - Specifies a new category, where "text" is its name.
36 // *B - A borderless blank row.
37 // *C - Ends the current column and starts a new one.
39 // If $SBCODES is not provided, then manufacture it from the Fee Sheet.
41 if (empty($SBCODES)) {
45 // Create entries based on the fee_sheet_options table.
46 $res = sqlStatement("SELECT * FROM fee_sheet_options " .
47 "ORDER BY fs_category, fs_option");
48 while ($row = sqlFetchArray($res)) {
49 $fs_category = $row['fs_category'];
50 $fs_option = $row['fs_option'];
51 $fs_codes = $row['fs_codes'];
52 if($fs_category !== $last_category) {
53 $last_category = $fs_category;
54 $SBCODES[] = '*G|' . substr($fs_category, 1);
56 $SBCODES[] = " |" . substr($fs_option, 1);
59 // Create entries based on categories defined within the codes.
60 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
61 "WHERE list_id = 'superbill' ORDER BY seq");
62 while ($prow = sqlFetchArray($pres)) {
63 $SBCODES[] = '*G|' . $prow['title'];
64 $res = sqlStatement("SELECT code_type, code, code_text FROM codes " .
65 "WHERE superbill = '" . $prow['option_id'] . "' " .
66 "ORDER BY code_text");
67 while ($row = sqlFetchArray($res)) {
68 $SBCODES[] = $row['code'] . '|' . $row['code_text'];
72 // Create one more group, for Products.
73 if ($GLOBALS['sell_non_drug_products']) {
74 $SBCODES[] = '*G|' . xl('Products');
75 $tres = sqlStatement("SELECT dt.drug_id, dt.selector, d.name " .
76 "FROM drug_templates AS dt, drugs AS d WHERE " .
77 "d.drug_id = dt.drug_id " .
78 "ORDER BY d.name, dt.selector, dt.drug_id");
79 while ($trow = sqlFetchArray($tres)) {
80 $tmp = $trow['selector'];
81 if ($trow['name'] !== $trow['selector']) $tmp .= ' ' . $trow['name'];
82 $SBCODES[] = $trow['drug_id'] . '|' . $tmp;
86 // Extra stuff for the labs section.
87 $SBCODES[] = '*G|' . xl('Additional Labs');
88 $percol = intval((count($SBCODES) +
2) / 3);
89 while (count($SBCODES) < $percol * 3) $SBCODES[] = '*B|';
91 // Adjust lines per page to distribute lines evenly among the pages.
92 $pages = intval(($percol +
$lines_in_stats +
$lines_per_page - 1) / $lines_per_page);
93 $lines_per_page = intval($percol +
$lines_in_stats +
$pages - 1) / $pages;
95 // Figure out page and column breaks.
98 $page_start_index = 0;
99 while ($lines +
$lines_in_stats > $lines_per_page) {
101 $lines_this_page = $lines > $lines_per_page ?
$lines_per_page : $lines;
102 $lines -= $lines_this_page;
103 array_splice($SBCODES, $lines_this_page*3 +
$page_start_index, 0, '*C|');
104 array_splice($SBCODES, $lines_this_page*2 +
$page_start_index, 0, '*C|');
105 array_splice($SBCODES, $lines_this_page*1 +
$page_start_index, 0, '*C|');
106 $page_start_index +
= $lines_this_page * 3 +
3;
108 array_splice($SBCODES, $lines*2 +
$page_start_index, 0, '*C|');
109 array_splice($SBCODES, $lines*1 +
$page_start_index, 0, '*C|');
114 <?php
html_header_show(); ?
>
118 font
-family
: sans
-serif
;
124 border
-width
: 0 0 1px
1px
;
126 border
-collapse
: collapse
;
127 border
-color
: #999999;
133 border
-width
: 0 0 0 0;
134 border
-color
: #999999;
137 font
-family
: sans
-serif
;
139 font
-size
: <?php
echo $fontsize ?
>pt
;
140 background
-color
: #cccccc;
141 padding
: <?php
echo $padding ?
>pt
2pt
0pt
2pt
;
143 border
-width
: 1px
1px
0 0;
144 border
-color
: #999999;
147 font
-family
: sans
-serif
;
149 font
-size
: <?php
echo $fontsize ?
>pt
;
150 padding
: <?php
echo $padding ?
>pt
2pt
0pt
2pt
;
152 border
-width
: 1px
1px
0 0;
153 border
-color
: #999999;
156 font
-family
: sans
-serif
;
158 font
-size
: <?php
echo $fontsize ?
>pt
;
159 padding
: <?php
echo $padding ?
>pt
2pt
0pt
2pt
;
161 border
-width
: 1px
1px
0 0;
162 border
-color
: #999999;
168 // Get the co-pay amount that is effective on the given date.
169 // Or if no insurance on that date, return -1.
171 function getCopay($patient_id, $encdate) {
172 $tmp = sqlQuery("SELECT provider, copay FROM insurance_data " .
173 "WHERE pid = '$patient_id' AND type = 'primary' " .
174 "AND date <= '$encdate' ORDER BY date DESC LIMIT 1");
175 if ($tmp['provider']) return sprintf('%01.2f', 0 +
$tmp['copay']);
179 function genColumn($ix) {
181 for ($imax = count($SBCODES); $ix < $imax; ++
$ix) {
182 $a = explode('|', $SBCODES[$ix], 2);
184 if ($cmd == '*C') { // column break
187 if ($cmd == '*B') { // Borderless and empty
188 echo "<tr><td colspan='5' class='fscode' style='border-width:0 1px 0 0;padding-top:1px;' nowrap> </td></tr>\n";
190 else if ($cmd == '*G') {
191 // $title = htmlentities(strtoupper($a[1]));
192 $title = htmlentities($a[1]);
193 if (!$title) $title=' ';
194 echo "<tr><td colspan='5' align='center' class='fsgroup' style='vertical-align:middle' nowrap>$title</td></tr>\n";
196 else if ($cmd == '*H') {
197 // $title = htmlentities(strtoupper($a[1]));
198 $title = htmlentities($a[1]);
199 if (!$title) $title=' ';
200 echo "<tr><td colspan='5' class='fshead' style='vertical-align:middle' nowrap>$title</td></tr>\n";
203 $title = htmlentities($a[1]);
204 if (!$title) $title=' ';
205 $b = explode(':', $cmd);
207 echo "<td class='fscode' style='vertical-align:middle;width:14pt' nowrap> </td>\n";
208 if (count($b) <= 1) {
210 if (!$code) $code=' ';
211 echo "<td class='fscode' style='vertical-align:middle' nowrap>$code</td>\n";
212 echo "<td colspan='3' class='fscode' style='vertical-align:middle' nowrap>$title</td>\n";
215 echo "<td colspan='2' class='fscode' style='vertical-align:middle' nowrap>" . $b[0] . '/' . $b[1] . "</td>\n";
216 echo "<td colspan='2' class='fscode' style='vertical-align:middle' nowrap>$title</td>\n";
224 $today = date('Y-m-d');
226 $alertmsg = ''; // anything here pops up in an alert box
228 // Get details for what we guess is the primary facility.
229 $frow = sqlQuery("SELECT * FROM facility " .
230 "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1");
232 // Get the patient's name and chart number.
233 $patdata = getPatientData($pid);
235 // This tracks our position in the $SBCODES array.
239 <title
><?php
echo htmlentities($frow['name']); ?
></title
>
240 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
241 <script language
="JavaScript">
243 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
245 // Process click on Print button.
247 var divstyle
= document
.getElementById('hideonprint').style
;
248 divstyle
.display
= 'none';
254 <body bgcolor
='#ffffff'>
255 <form name
='theform' method
='post' action
='printed_fee_sheet.php'
256 onsubmit
='return top.restoreSession()'>
259 <?php
while (--$pages >= 0) { ?
>
261 <table
class='bordertbl' cellspacing
='0' cellpadding
='0' width
='100%'>
264 <table border
='0' cellspacing
='0' cellpadding
='0' width
='100%' style
='height:<?php echo $page_height ?>pt'>
266 <td
class='toprow' style
='width:10%'></td
>
267 <td
class='toprow' style
='width:10%'></td
>
268 <td
class='toprow' style
='width:25%'></td
>
269 <td
class='toprow' style
='width:55%'></td
>
272 $cindex = genColumn($cindex); // Column 1
275 <?php
if ($pages == 0) { // if this is the last page ?>
278 <td colspan
='3' valign
='top' class='fshead' style
='height:50pt'>
281 echo $patdata['fname'] . ' ' . $patdata['mname'] . ' ' . $patdata['lname'] . "<br>\n";
282 echo $patdata['street'] . "<br>\n";
283 echo $patdata['city'] . ', ' . $patdata['state'] . ' ' . $patdata['postal_code'] . "\n";
286 <td valign
='top' class='fshead'>
287 DOB
:<br
><?php
echo $patdata['DOB']; ?
><br
>
288 ID
:<br
><?php
echo $patdata['pubpid']; ?
>
292 <td colspan
='3' valign
='top' class='fshead' style
='height:25pt'>
294 <?php
// Doctor name here ?>
296 <td valign
='top' class='fshead'>
298 <?php
// Encounter reason here ?>
302 <td colspan
='4' valign
='top' class='fshead' style
='height:25pt'>
304 if (empty($GLOBALS['ippf_specific'])) {
306 foreach (array('primary','secondary','tertiary') as $instype) {
307 $query = "SELECT * FROM insurance_data WHERE " .
308 "pid = '$pid' AND type = '$instype' " .
309 "ORDER BY date DESC LIMIT 1";
310 $row = sqlQuery($query);
311 if ($row['provider']) {
312 $icobj = new InsuranceCompany($row['provider']);
313 $adobj = $icobj->get_address();
314 $insco_name = trim($icobj->get_name());
315 if ($instype != 'primary') echo ",";
317 echo " $insco_name";
319 echo " <font color='red'><b>Missing Name</b></font>";
325 // IPPF wants a visit date box with the current date in it.
326 echo "Visit date:<br>\n";
327 echo date('Y-m-d') . "\n";
333 <td colspan
='4' valign
='top' class='fshead' style
='height:25pt'>
338 <td colspan
='4' valign
='top' class='fshead' style
='height:25pt'>
343 <td colspan='4' valign='top
' class='fshead
' style='height
:25pt
'>
348 <td colspan
='4' valign
='top' class='fshead' style
='height:25pt'>
353 <?php
} // end if last page ?>
358 <table border
='0' cellspacing
='0' cellpadding
='0' width
='100%' style
='height:<?php echo $page_height ?>pt'>
360 <td
class='toprow' style
='width:10%'></td
>
361 <td
class='toprow' style
='width:10%'></td
>
362 <td
class='toprow' style
='width:25%'></td
>
363 <td
class='toprow' style
='width:55%'></td
>
366 $cindex = genColumn($cindex); // Column 2
369 <?php
if ($pages == 0) { // if this is the last page ?>
372 <td colspan
='4' valign
='top' class='fshead' style
='height:100pt'>
373 Additional procedures
:<br
>
377 <td colspan
='4' valign
='top' class='fshead' style
='height:100pt'>
382 <?php
} // end if last page ?>
387 <table border
='0' cellspacing
='0' cellpadding
='0' width
='100%' style
='height:<?php echo $page_height ?>pt'>
389 <td
class='toprow' style
='width:10%'></td
>
390 <td
class='toprow' style
='width:10%'></td
>
391 <td
class='toprow' style
='width:25%'></td
>
392 <td
class='toprow' style
='width:55%'></td
>
395 $cindex = genColumn($cindex); // Column 3
398 <?php
if ($pages == 0) { // if this is the last page ?>
401 <td valign
='top' colspan
='4' class='fshead' style
='height:150pt;border-width:0 1px 0 0'>
406 <td valign
='top' colspan
='4' class='fshead' style
='height:50pt'>
411 <?php
} // end if last page ?>
419 <?php
} // end while ?>
421 <div id
='hideonprint'>
423 <input type
='button' value
='<?php xl('Print','e
'); ?>' onclick
='printme()' />
424  
; 
;Font Size in Points
:
425 <input type
='text' name
='fontsize' size
='2' maxlength
='5' value
='<?php echo $fontsize ?>' />
426  
; 
;Page Height in Points
:
427 <input type
='text' name
='page_height' size
='3' maxlength
='4' value
='<?php echo $page_height ?>' />
429 <input type
='submit' name
='form_submit' value
='Refresh' />