2 //////////////////////////////////////////////////////////////////////
3 // ------------------ DO NOT MODIFY VIEW.PHP !!! ---------------------
4 // View.php is an exact duplicate of new.php. If you wish to make
5 // any changes, then change new.php and either (recommended) make
6 // view.php a symbolic link to new.php, or copy new.php to view.php.
8 // And if you check in a change to either module, be sure to check
9 // in the other (identical) module also.
11 // This nonsense will go away if we ever move to subversion.
12 //////////////////////////////////////////////////////////////////////
14 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
16 // This program is free software; you can redistribute it and/or
17 // modify it under the terms of the GNU General Public License
18 // as published by the Free Software Foundation; either version 2
19 // of the License, or (at your option) any later version.
21 include_once("../../globals.php");
22 include_once("$srcdir/api.inc");
23 include_once("codes.php");
24 include_once("../../../custom/code_types.inc.php");
26 // If Save was clicked, save the new and modified billing lines;
27 // then if no error, redirect to patient_encounter.php.
29 if ($_POST['bn_save']) {
30 $provid = $_POST['ProviderID'];
31 if (! $provid) $provid = $_SESSION["authUserID"];
32 $bill = $_POST['bill'];
33 for ($lino = 1; $bill["$lino"]['code_type']; ++
$lino) {
34 $iter = $bill["$lino"];
36 // Skip disabled (billed) line items.
37 if ($iter['billed']) continue;
40 $code_type = $iter['code_type'];
41 $code = $iter['code'];
42 $modifier = trim($iter['mod']);
43 $fee = trim($iter['fee']);
44 $auth = $iter['auth'] ?
"1" : "0";
47 // If the item is already in the database...
53 // authorizeBilling($id, $auth);
54 sqlQuery("update billing set fee = '$fee', modifier = '$modifier', " .
55 "authorized = $auth, provider_id = '$provid' where " .
56 "id = '$id' and billed = 0 and activity = 1");
60 // Otherwise it's a new item...
62 $query = "select code_text from codes where code_type = '" .
63 $code_types[$code_type]['id'] . "' and " .
64 "code = '$code' and ";
66 $query .= "modifier = '$modifier'";
68 $query .= "(modifier is null or modifier = '')";
70 $result = sqlQuery($query);
71 $code_text = addslashes($result['code_text']);
72 addBilling($encounter, $code_type, $code, $code_text, $pid, $auth,
73 $provid, $modifier, "", $fee);
77 formHeader("Redirecting....");
85 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
87 .billcell
{ font
-family
: sans
-serif
; font
-size
: 10pt
}
89 <script language
="JavaScript">
91 function codeselect(selobj
, newtype
) {
92 var i
= selobj
.selectedIndex
;
94 var f
= document
.forms
[0];
95 f
.newcode
.value
= selobj
.options
[i
].value
;
96 f
.newtype
.value
= newtype
;
104 <body
<?
echo $top_bg_line;?
> topmargin
="0" rightmargin
="0" leftmargin
="2" bottommargin
="0" marginwidth
="2" marginheight
="0">
105 <form method
="post" action
="<?echo $rootdir;?>/forms/fee_sheet/new.php">
106 <span
class="title">Fee Sheet
</span
><br
>
107 <input type
='hidden' name
='newtype' value
=''>
108 <input type
='hidden' name
='newcode' value
=''>
115 // Create all the drop-lists of preselected codes.
117 foreach ($bcodes as $key0 => $value0) {
118 foreach ($value0 as $key1 => $value1) {
120 echo ($i & 1) ?
" <tr>\n" : "";
121 echo " <td width='50%' align='center' nowrap>\n";
122 echo " <select name='$key1' style='width:96%' onchange='codeselect(this, \"$key0\")'>\n";
123 echo " <option value=''> $key1\n";
124 foreach ($value0[$key1] as $key2 => $value2) {
125 echo " <option value='$key2'>$key2 $value2\n";
129 echo ($i & 1) ?
"" : " </tr>\n";
133 $search_type = $default_search_type;
134 if ($_POST['search_type']) $search_type = $_POST['search_type'];
136 echo ($i & 1) ?
" <td></td>\n </tr>\n" : "";
138 echo " <td colspan='2' align='center' nowrap>\n";
140 // If Search was clicked, do it and write the list of results here.
141 // There's no limit on the number of results!
144 if ($_POST['bn_search'] && $_POST['search_term']) {
145 $query = "select code, modifier, code_text from codes where " .
146 "(code_text like '%" . $_POST['search_term'] . "%' or " .
147 "code like '%" . $_POST['search_term'] . "%') and " .
148 "code_type = '" . $code_types[$search_type]['id'] . "' " .
150 $res = sqlStatement($query);
151 $numrows = mysql_num_rows($res); // FIXME - not portable!
154 echo " <select name='Search Results' style='width:98%' " .
155 "onchange='codeselect(this, \"$search_type\")'";
156 if (! $numrows) echo ' disabled';
158 echo " <option value=''> Search Results ($numrows items)\n";
161 while ($row = sqlFetchArray($res)) {
162 $code = $row['code'];
163 if ($row['modifier']) $code .= "-" . $row['modifier'];
164 echo " <option value='$code'>$code " . ucfirst(strtolower($row['code_text'])) . "\n";
175 <p style
='margin-top:8px;margin-bottom:8px'>
181 foreach ($code_types as $key => $value) {
182 echo " <input type='radio' name='search_type' value='$key'";
183 if ($key == $default_search_type) echo " checked";
184 echo " />$key \n";
190 <input type
='text' name
='search_term' value
=''>  
;
193 <input type
='submit' name
='bn_search' value
='Search'>
199 <p style
='margin-top:16px;margin-bottom:8px'>
200 <table cellspacing
='5'>
202 <td
class='billcell'><b
>Type
</b
></td
>
203 <td
class='billcell'><b
>Code
</b
></td
>
204 <?
if (modifiers_are_used()) { ?
>
205 <td
class='billcell'><b
>Mod
</b
></td
>
207 <?
if (fees_are_used()) { ?
>
208 <td
class='billcell' align
='right'><b
>Fee
</b
> 
;</td
>
210 <td
class='billcell' align
='center'><b
>Auth
</b
></td
>
211 <td
class='billcell' align
='center'><b
>Delete
</b
></td
>
212 <td
class='billcell'><b
>Description
</b
></td
>
216 // This writes a billing line item to the output page.
218 function echoLine($lino, $codetype, $code, $modifier, $auth = TRUE, $del = FALSE,
219 $fee = NULL, $id = NULL, $billed = FALSE, $code_text = NULL)
223 $query = "select fee, code_text from codes where code_type = '" .
224 $code_types[$codetype]['id'] . "' and " .
225 "code = '$code' and ";
227 $query .= "modifier = '$modifier'";
229 $query .= "(modifier is null or modifier = '')";
231 $result = sqlQuery($query);
232 $code_text = $result['code_text'];
233 if (!isset($fee)) $fee = $result['fee'];
235 $strike1 = ($id && $del) ?
"<strike>" : "";
236 $strike2 = ($id && $del) ?
"</strike>" : "";
238 echo " <td class='billcell'>$strike1$codetype$strike2";
240 echo "<input type='hidden' name='bill[$lino][id]' value='$id'>";
242 echo "<input type='hidden' name='bill[$lino][code_type]' value='$codetype'>";
243 echo "<input type='hidden' name='bill[$lino][code]' value='$code'>";
244 echo "<input type='hidden' name='bill[$lino][billed]' value='$billed'>";
246 echo " <td class='billcell'>$strike1$code$strike2</td>\n";
248 if (modifiers_are_used()) {
249 echo " <td class='billcell'>$strike1$modifier$strike2" .
250 "<input type='hidden' name='bill[$lino][mod]' value='$modifier'></td>\n";
252 if (fees_are_used()) {
253 echo " <td class='billcell' align='right'>$fee</td>\n";
255 echo " <td class='billcell' align='center'><input type='checkbox'" .
256 ($auth ?
" checked" : "") . " disabled /></td>\n";
257 echo " <td class='billcell' align='center'><input type='checkbox'" .
258 " disabled /></td>\n";
260 if (modifiers_are_used()) {
261 if ($code_types[$codetype]['mod'] ||
$modifier) {
262 echo " <td class='billcell'><input type='text' name='bill[$lino][mod]' " .
263 "value='$modifier' size='" . $code_types[$codetype]['mod'] . "'></td>\n";
265 echo " <td class='billcell'> </td>\n";
268 if (fees_are_used()) {
269 if ($code_types[$codetype]['fee'] ||
$fee != 0) {
270 echo " <td class='billcell' align='right'><input type='text' name='bill[$lino][fee]' " .
271 "value='$fee' size='6' style='text-align:right'></td>\n";
273 echo " <td class='billcell'> </td>\n";
276 echo " <td class='billcell' align='center'><input type='checkbox' name='bill[$lino][auth]' " .
277 "value='1'" . ($auth ?
" checked" : "") . " /></td>\n";
278 echo " <td class='billcell' align='center'><input type='checkbox' name='bill[$lino][del]' " .
279 "value='1'" . ($del ?
" checked" : "") . " /></td>\n";
281 echo " <td class='billcell'>$strike1" . ucfirst(strtolower($code_text)) . "$strike2</td>\n";
285 // Generate lines for items already in the database.
288 $encounter_provid = -1;
289 if ($result = getBillingByEncounter($pid, $encounter, "*") ) {
290 foreach ($result as $iter) {
292 $del = $_POST['bill']["$lino"]['del']; // preserve Delete if checked
293 // list($code, $modifier) = explode("-", $iter["code"]);
294 echoLine($lino, $iter["code_type"], trim($iter["code"]), trim($iter["modifier"]),
295 $iter["authorized"], $del, $iter["fee"], $iter["id"], $iter["billed"], $iter["code_text"]);
296 if ($encounter_provid < 0 && ! $del) $encounter_provid = $iter["provider_id"];
300 // If there were no billing items then the default provider is the logged-in user.
302 if ($encounter_provid < 0) $encounter_provid = $_SESSION["authUserID"];
304 // Echo new billing items from this form here, but omit any line
305 // whose Delete checkbox is checked.
307 if ($_POST['bill']) {
308 foreach ($_POST['bill'] as $key => $iter) {
309 if ($iter["id"]) continue; // skip if it came from the database
310 if ($iter["del"]) continue; // skip if Delete was checked
311 echoLine(++
$lino, $iter["code_type"], $iter["code"], trim($iter["mod"]),
312 $iter["auth"], $iter["del"], $iter["fee"]);
316 // If a new billing code was <select>ed, add its line here. As a special
317 // case allow HCPCS codes to be included in the CPT drop-lists.
319 if ($_POST['newcode']) {
320 list($code, $modifier) = explode("-", $_POST['newcode']);
321 $newtype = $_POST['newtype'];
322 if ($newtype == "CPT4" && preg_match("/^[A-Z]/", $code))
324 echoLine(++
$lino, $newtype, $code, trim($modifier));
334 <span
class="billcell">PROVIDER
:</span
>
337 // Build a drop-down list of providers.
339 $query = "select id, lname, fname from users where " .
340 "authorized = 1 order by lname, fname";
341 $res = sqlStatement($query);
343 echo " <select name='ProviderID'>\n";
344 echo " <option value=''>-- Please Select --\n";
346 while ($row = sqlFetchArray($res)) {
347 $provid = $row['id'];
348 echo " <option value='$provid'";
349 if ($provid == $encounter_provid) echo " selected";
350 echo ">" . $row['lname'] . ", " . $row['fname'] . "\n";
356  
;  
;  
;  
;  
;  
;  
;  
;  
;  
;
358 <input type
='submit' name
='bn_save' value
='Save' />
360 <input type
='submit' name
='bn_refresh' value
='Refresh'>
362 <input type
='button' value
='Cancel' onclick
="location='<? echo "$rootdir/patient_file
/encounter
/patient_encounter
.php
" ?>'" />
369 // TBD: If $alertmsg, display it with a JavaScript alert().