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");
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;
27 // If $SBCODES is not provided, then manufacture it from the Fee Sheet.
29 if (empty($SBCODES)) {
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
84 <?php
html_header_show(); ?
>
88 font
-family
: sans
-serif
;
94 border
-width
: 0 0 1px
1px
;
96 border
-collapse
: collapse
;
97 border
-color
: #999999;
103 border
-width
: 0 0 0 0;
104 border
-color
: #999999;
107 font
-family
: sans
-serif
;
109 font
-size
: <?php
echo $fontsize ?
>pt
;
110 background
-color
: #cccccc;
111 padding
: <?php
echo $padding ?
>pt
2pt
0pt
2pt
;
113 border
-width
: 1px
1px
0 0;
114 border
-color
: #999999;
117 font
-family
: sans
-serif
;
119 font
-size
: <?php
echo $fontsize ?
>pt
;
120 padding
: <?php
echo $padding ?
>pt
2pt
0pt
2pt
;
122 border
-width
: 1px
1px
0 0;
123 border
-color
: #999999;
126 font
-family
: sans
-serif
;
128 font
-size
: <?php
echo $fontsize ?
>pt
;
129 padding
: <?php
echo $padding ?
>pt
2pt
0pt
2pt
;
131 border
-width
: 1px
1px
0 0;
132 border
-color
: #999999;
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']);
149 function genColumn($ix) {
151 for ($imax = count($SBCODES); $ix < $imax; ++
$ix) {
152 $a = explode('|', $SBCODES[$ix], 2);
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> </td></tr>\n";
160 else if ($cmd == '*G') {
161 // $title = htmlentities(strtoupper($a[1]));
162 $title = htmlentities($a[1]);
163 if (!$title) $title=' ';
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=' ';
170 echo "<tr><td colspan='5' class='fshead' style='vertical-align:middle' nowrap>$title</td></tr>\n";
173 $title = htmlentities($a[1]);
174 if (!$title) $title=' ';
175 $b = explode(':', $cmd);
177 echo "<td class='fscode' style='vertical-align:middle;width:14pt' nowrap> </td>\n";
178 if (count($b) <= 1) {
180 if (!$code) $code=' ';
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";
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";
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.
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.
217 var divstyle
= document
.getElementById('hideonprint').style
;
218 divstyle
.display
= 'none';
224 <body bgcolor
='#ffffff'>
225 <form name
='theform' method
='post' action
='printed_fee_sheet.php'
226 onsubmit
='return top.restoreSession()'>
229 <table
class='bordertbl' cellspacing
='0' cellpadding
='0' width
='100%'>
232 <table border
='0' cellspacing
='0' cellpadding
='0' width
='100%' style
='height:<?php echo $page_height ?>pt'>
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
>
240 $cindex = genColumn($cindex); // Column 1
243 <td colspan
='3' valign
='top' class='fshead' style
='height:50pt'>
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";
251 <td valign
='top' class='fshead'>
252 DOB
:<br
><?php
echo $patdata['DOB']; ?
><br
>
253 ID
:<br
><?php
echo $patdata['pubpid']; ?
>
257 <td colspan
='3' valign
='top' class='fshead' style
='height:25pt'>
259 <?php
// Doctor name here ?>
261 <td valign
='top' class='fshead'>
263 <?php
// Encounter reason here ?>
267 <td colspan
='4' valign
='top' class='fshead' style
='height:25pt'>
269 if (empty($GLOBALS['ippf_specific'])) {
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 ",";
282 echo " $insco_name";
284 echo " <font color='red'><b>Missing Name</b></font>";
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";
298 <td colspan
='4' valign
='top' class='fshead' style
='height:25pt'>
303 <td colspan
='4' valign
='top' class='fshead' style
='height:25pt'>
308 <td colspan='4' valign='top
' class='fshead
' style='height
:25pt
'>
313 <td colspan
='4' valign
='top' class='fshead' style
='height:25pt'>
320 <table border
='0' cellspacing
='0' cellpadding
='0' width
='100%' style
='height:<?php echo $page_height ?>pt'>
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
>
328 $cindex = genColumn($cindex); // Column 2
331 <td colspan
='4' valign
='top' class='fshead' style
='height:100pt'>
332 Additional procedures
:<br
>
336 <td colspan
='4' valign
='top' class='fshead' style
='height:100pt'>
343 <table border
='0' cellspacing
='0' cellpadding
='0' width
='100%' style
='height:<?php echo $page_height ?>pt'>
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
>
351 $cindex = genColumn($cindex); // Column 3
354 <td valign
='top' colspan
='4' class='fshead' style
='height:150pt;border-width:0 1px 0 0'>
359 <td valign
='top' colspan
='4' class='fshead' style
='height:50pt'>
369 <div id
='hideonprint'>
371 <input type
='button' value
='<?php xl('Print','e
'); ?>' onclick
='printme()' />
372  
; 
;Font Size in Points
:
373 <input type
='text' name
='fontsize' size
='2' maxlength
='5' value
='<?php echo $fontsize ?>' />
374  
; 
;Page Height in Points
:
375 <input type
='text' name
='page_height' size
='3' maxlength
='4' value
='<?php echo $page_height ?>' />
377 <input type
='submit' name
='form_submit' value
='Refresh' />