2 // Copyright (C) 2005-2006 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 include_once(dirname(__FILE__
) . '/api.inc');
10 include_once(dirname(__FILE__
) . '/../interface/forms/fee_sheet/codes.php');
11 include_once(dirname(__FILE__
) . '/../custom/code_types.inc.php');
13 // $FEE_SHEET_COLUMNS should be defined in codes.php.
14 if (empty($FEE_SHEET_COLUMNS)) $FEE_SHEET_COLUMNS = 2;
16 // If Save was clicked, save the new and modified billing lines;
17 // then if no error, redirect to patient_encounter.php.
19 if ($_POST['bn_save']) {
20 $provid = $_POST['ProviderID'];
21 if (! $provid) $provid = $_SESSION["authUserID"];
22 $bill = $_POST['bill'];
23 for ($lino = 1; $bill["$lino"]['code_type']; ++
$lino) {
24 $iter = $bill["$lino"];
26 // Skip disabled (billed) line items.
27 if ($iter['billed']) continue;
30 $code_type = $iter['code_type'];
31 $code = $iter['code'];
32 $modifier = trim($iter['mod']);
33 $fee = trim($iter['fee']);
34 $auth = $iter['auth'] ?
"1" : "0";
37 // If the item is already in the database...
43 // authorizeBilling($id, $auth);
44 sqlQuery("update billing set fee = '$fee', modifier = '$modifier', " .
45 "authorized = $auth, provider_id = '$provid' where " .
46 "id = '$id' and billed = 0 and activity = 1");
50 // Otherwise it's a new item...
52 $query = "select code_text from codes where code_type = '" .
53 $code_types[$code_type]['id'] . "' and " .
54 "code = '$code' and ";
56 $query .= "modifier = '$modifier'";
58 $query .= "(modifier is null or modifier = '')";
60 $result = sqlQuery($query);
61 $code_text = addslashes($result['code_text']);
62 addBilling($encounter, $code_type, $code, $code_text, $pid, $auth,
63 $provid, $modifier, "", $fee);
73 .billcell
{ font
-family
: sans
-serif
; font
-size
: 10pt
}
75 <script language
="JavaScript">
77 function codeselect(selobj
, newtype
) {
78 var i
= selobj
.selectedIndex
;
80 var f
= document
.forms
[0];
81 f
.newcode
.value
= selobj
.options
[i
].value
;
82 f
.newtype
.value
= newtype
;
89 <form method
="post" action
="<?php echo coding_form_action(); ?>">
90 <span
class="title"><?
echo ($GLOBALS['phone_country_code'] == '1') ?
'Fee' : 'Coding' ?
> Sheet
</span
><br
>
91 <input type
='hidden' name
='newtype' value
=''>
92 <input type
='hidden' name
='newcode' value
=''>
99 // Create all the drop-lists of preselected codes.
101 foreach ($bcodes as $key0 => $value0) {
102 foreach ($value0 as $key1 => $value1) {
104 echo ($i <= 1) ?
" <tr>\n" : "";
105 echo " <td width='50%' align='center' nowrap>\n";
106 echo " <select name='$key1' style='width:96%' onchange='codeselect(this, \"$key0\")'>\n";
107 echo " <option value=''> $key1\n";
108 foreach ($value0[$key1] as $key2 => $value2) {
109 echo " <option value='$key2'>$key2 $value2\n";
113 if ($i >= $FEE_SHEET_COLUMNS) {
120 $search_type = $default_search_type;
121 if ($_POST['search_type']) $search_type = $_POST['search_type'];
123 echo $i ?
" <td></td>\n </tr>\n" : "";
125 echo " <td colspan='$FEE_SHEET_COLUMNS' align='center' nowrap>\n";
127 // If Search was clicked, do it and write the list of results here.
128 // There's no limit on the number of results!
131 if ($_POST['bn_search'] && $_POST['search_term']) {
132 $query = "select code, modifier, code_text from codes where " .
133 "(code_text like '%" . $_POST['search_term'] . "%' or " .
134 "code like '%" . $_POST['search_term'] . "%') and " .
135 "code_type = '" . $code_types[$search_type]['id'] . "' " .
137 $res = sqlStatement($query);
138 $numrows = mysql_num_rows($res); // FIXME - not portable!
141 echo " <select name='Search Results' style='width:98%' " .
142 "onchange='codeselect(this, \"$search_type\")'";
143 if (! $numrows) echo ' disabled';
145 echo " <option value=''> Search Results ($numrows items)\n";
148 while ($row = sqlFetchArray($res)) {
149 $code = $row['code'];
150 if ($row['modifier']) $code .= "-" . $row['modifier'];
151 echo " <option value='$code'>$code " . ucfirst(strtolower($row['code_text'])) . "\n";
162 <p style
='margin-top:8px;margin-bottom:8px'>
168 foreach ($code_types as $key => $value) {
169 echo " <input type='radio' name='search_type' value='$key'";
170 if ($key == $default_search_type) echo " checked";
171 echo " />$key \n";
177 <input type
='text' name
='search_term' value
=''>  
;
180 <input type
='submit' name
='bn_search' value
='Search'>
186 <p style
='margin-top:16px;margin-bottom:8px'>
187 <table cellspacing
='5'>
189 <td
class='billcell'><b
>Type
</b
></td
>
190 <td
class='billcell'><b
>Code
</b
></td
>
191 <?
if (modifiers_are_used()) { ?
>
192 <td
class='billcell'><b
>Mod
</b
></td
>
194 <?
if (fees_are_used()) { ?
>
195 <td
class='billcell' align
='right'><b
>Fee
</b
> 
;</td
>
197 <td
class='billcell' align
='center'><b
>Auth
</b
></td
>
198 <td
class='billcell' align
='center'><b
>Delete
</b
></td
>
199 <td
class='billcell'><b
>Description
</b
></td
>
203 // This writes a billing line item to the output page.
205 function echoLine($lino, $codetype, $code, $modifier, $auth = TRUE, $del = FALSE,
206 $fee = NULL, $id = NULL, $billed = FALSE, $code_text = NULL)
210 $query = "select fee, code_text from codes where code_type = '" .
211 $code_types[$codetype]['id'] . "' and " .
212 "code = '$code' and ";
214 $query .= "modifier = '$modifier'";
216 $query .= "(modifier is null or modifier = '')";
218 $result = sqlQuery($query);
219 $code_text = $result['code_text'];
220 if (!isset($fee)) $fee = $result['fee'];
222 $strike1 = ($id && $del) ?
"<strike>" : "";
223 $strike2 = ($id && $del) ?
"</strike>" : "";
225 echo " <td class='billcell'>$strike1$codetype$strike2";
227 echo "<input type='hidden' name='bill[$lino][id]' value='$id'>";
229 echo "<input type='hidden' name='bill[$lino][code_type]' value='$codetype'>";
230 echo "<input type='hidden' name='bill[$lino][code]' value='$code'>";
231 echo "<input type='hidden' name='bill[$lino][billed]' value='$billed'>";
233 echo " <td class='billcell'>$strike1$code$strike2</td>\n";
235 if (modifiers_are_used()) {
236 echo " <td class='billcell'>$strike1$modifier$strike2" .
237 "<input type='hidden' name='bill[$lino][mod]' value='$modifier'></td>\n";
239 if (fees_are_used()) {
240 echo " <td class='billcell' align='right'>$fee</td>\n";
242 echo " <td class='billcell' align='center'><input type='checkbox'" .
243 ($auth ?
" checked" : "") . " disabled /></td>\n";
244 echo " <td class='billcell' align='center'><input type='checkbox'" .
245 " disabled /></td>\n";
247 if (modifiers_are_used()) {
248 if ($code_types[$codetype]['mod'] ||
$modifier) {
249 echo " <td class='billcell'><input type='text' name='bill[$lino][mod]' " .
250 "value='$modifier' size='" . $code_types[$codetype]['mod'] . "'></td>\n";
252 echo " <td class='billcell'> </td>\n";
255 if (fees_are_used()) {
256 if ($code_types[$codetype]['fee'] ||
$fee != 0) {
257 echo " <td class='billcell' align='right'><input type='text' name='bill[$lino][fee]' " .
258 "value='$fee' size='6' style='text-align:right'></td>\n";
260 echo " <td class='billcell'> </td>\n";
263 echo " <td class='billcell' align='center'><input type='checkbox' name='bill[$lino][auth]' " .
264 "value='1'" . ($auth ?
" checked" : "") . " /></td>\n";
265 echo " <td class='billcell' align='center'><input type='checkbox' name='bill[$lino][del]' " .
266 "value='1'" . ($del ?
" checked" : "") . " /></td>\n";
268 echo " <td class='billcell'>$strike1" . ucfirst(strtolower($code_text)) . "$strike2</td>\n";
272 // Generate lines for items already in the database.
275 $encounter_provid = -1;
276 if ($result = getBillingByEncounter($pid, $encounter, "*") ) {
277 foreach ($result as $iter) {
279 $del = $_POST['bill']["$lino"]['del']; // preserve Delete if checked
280 // list($code, $modifier) = explode("-", $iter["code"]);
281 echoLine($lino, $iter["code_type"], trim($iter["code"]), trim($iter["modifier"]),
282 $iter["authorized"], $del, $iter["fee"], $iter["id"], $iter["billed"], $iter["code_text"]);
283 if ($encounter_provid < 0 && ! $del) $encounter_provid = $iter["provider_id"];
287 // If there were no billing items then the default provider is the logged-in user.
289 if ($encounter_provid < 0) $encounter_provid = $_SESSION["authUserID"];
291 // Echo new billing items from this form here, but omit any line
292 // whose Delete checkbox is checked.
294 if ($_POST['bill']) {
295 foreach ($_POST['bill'] as $key => $iter) {
296 if ($iter["id"]) continue; // skip if it came from the database
297 if ($iter["del"]) continue; // skip if Delete was checked
298 echoLine(++
$lino, $iter["code_type"], $iter["code"], trim($iter["mod"]),
299 $iter["auth"], $iter["del"], $iter["fee"]);
303 // If a new billing code was <select>ed, add its line here. As a special
304 // case allow HCPCS codes to be included in the CPT drop-lists, and
305 // CPT4 codes included in OPCS drop-lists.
307 if ($_POST['newcode']) {
308 list($code, $modifier) = explode("-", $_POST['newcode']);
309 $newtype = $_POST['newtype'];
310 if ($newtype == "CPT4" && preg_match("/^[A-Z]/", $code))
312 else if ($newtype == "OPCS" && preg_match("/^[0-9]/", $code))
314 echoLine(++
$lino, $newtype, $code, trim($modifier));
324 <span
class="billcell">PROVIDER
:</span
>
327 // Build a drop-down list of providers. This includes users who
328 // have the word "provider" anywhere in their "additional info"
329 // field, so that we can define providers (for billing purposes)
330 // who do not appear in the calendar.
332 $query = "SELECT id, lname, fname FROM users WHERE " .
333 "authorized = 1 OR info LIKE '%provider%' ORDER BY lname, fname";
334 $res = sqlStatement($query);
336 echo " <select name='ProviderID'>\n";
337 echo " <option value=''>-- Please Select --\n";
339 while ($row = sqlFetchArray($res)) {
340 $provid = $row['id'];
341 echo " <option value='$provid'";
342 if ($provid == $encounter_provid) echo " selected";
343 echo ">" . $row['lname'] . ", " . $row['fname'] . "\n";
349  
;  
;  
;  
;  
;  
;  
;  
;  
;  
;
351 <input type
='submit' name
='bn_save' value
='Save' />
353 <input type
='submit' name
='bn_refresh' value
='Refresh'>
355 <input type
='button' value
='Cancel' onclick
='docancel()' />
357 <?php
if ($code_types['UCSMC']) { ?
>
358 <p style
='font-family:sans-serif;font-size:8pt;color:#666666;'>
360 UCSMC codes provided by the University of Calgary Sports Medicine Centre
368 // TBD: If $alertmsg, display it with a JavaScript alert().