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 // $FEE_SHEET_COLUMNS should be defined in codes.php.
27 if (empty($FEE_SHEET_COLUMNS)) $FEE_SHEET_COLUMNS = 2;
29 $returnurl = $GLOBALS['concurrent_layout'] ?
'encounter_top.php' : 'patient_encounter.php';
31 // If Save was clicked, save the new and modified billing lines;
32 // then if no error, redirect to $returnurl.
34 if ($_POST['bn_save']) {
35 $provid = $_POST['ProviderID'];
36 if (! $provid) $provid = $_SESSION["authUserID"];
37 $bill = $_POST['bill'];
38 for ($lino = 1; $bill["$lino"]['code_type']; ++
$lino) {
39 $iter = $bill["$lino"];
41 // Skip disabled (billed) line items.
42 if ($iter['billed']) continue;
45 $code_type = $iter['code_type'];
46 $code = $iter['code'];
47 $modifier = trim($iter['mod']);
48 $fee = trim($iter['fee']);
49 $auth = $iter['auth'] ?
"1" : "0";
52 // If the item is already in the database...
58 // authorizeBilling($id, $auth);
59 sqlQuery("update billing set fee = '$fee', modifier = '$modifier', " .
60 "authorized = $auth, provider_id = '$provid' where " .
61 "id = '$id' and billed = 0 and activity = 1");
65 // Otherwise it's a new item...
67 $query = "select code_text from codes where code_type = '" .
68 $code_types[$code_type]['id'] . "' and " .
69 "code = '$code' and ";
71 $query .= "modifier = '$modifier'";
73 $query .= "(modifier is null or modifier = '')";
75 $result = sqlQuery($query);
76 $code_text = addslashes($result['code_text']);
77 addBilling($encounter, $code_type, $code, $code_text, $pid, $auth,
78 $provid, $modifier, "", $fee);
82 formHeader("Redirecting....");
90 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
92 .billcell
{ font
-family
: sans
-serif
; font
-size
: 10pt
}
94 <script language
="JavaScript">
96 function codeselect(selobj
, newtype
) {
97 var i
= selobj
.selectedIndex
;
99 var f
= document
.forms
[0];
100 f
.newcode
.value
= selobj
.options
[i
].value
;
101 f
.newtype
.value
= newtype
;
109 <body
<?
echo $top_bg_line;?
> topmargin
="0" rightmargin
="0" leftmargin
="2" bottommargin
="0" marginwidth
="2" marginheight
="0">
110 <form method
="post" action
="<?echo $rootdir;?>/forms/fee_sheet/new.php">
111 <span
class="title"><?
echo ($GLOBALS['phone_country_code'] == '1') ?
'Fee' : 'Coding' ?
> <?php
xl('Sheet','e');?
></span
><br
>
112 <input type
='hidden' name
='newtype' value
=''>
113 <input type
='hidden' name
='newcode' value
=''>
120 // Create all the drop-lists of preselected codes.
122 foreach ($bcodes as $key0 => $value0) {
123 foreach ($value0 as $key1 => $value1) {
125 echo ($i <= 1) ?
" <tr>\n" : "";
126 echo " <td width='50%' align='center' nowrap>\n";
127 echo " <select name='$key1' style='width:96%' onchange='codeselect(this, \"$key0\")'>\n";
128 echo " <option value=''> $key1\n";
129 foreach ($value0[$key1] as $key2 => $value2) {
130 echo " <option value='$key2'>$key2 $value2\n";
134 if ($i >= $FEE_SHEET_COLUMNS) {
141 $search_type = $default_search_type;
142 if ($_POST['search_type']) $search_type = $_POST['search_type'];
144 echo $i ?
" <td></td>\n </tr>\n" : "";
146 echo " <td colspan='$FEE_SHEET_COLUMNS' align='center' nowrap>\n";
148 // If Search was clicked, do it and write the list of results here.
149 // There's no limit on the number of results!
152 if ($_POST['bn_search'] && $_POST['search_term']) {
153 $query = "select code, modifier, code_text from codes where " .
154 "(code_text like '%" . $_POST['search_term'] . "%' or " .
155 "code like '%" . $_POST['search_term'] . "%') and " .
156 "code_type = '" . $code_types[$search_type]['id'] . "' " .
158 $res = sqlStatement($query);
159 $numrows = mysql_num_rows($res); // FIXME - not portable!
162 echo " <select name='Search Results' style='width:98%' " .
163 "onchange='codeselect(this, \"$search_type\")'";
164 if (! $numrows) echo ' disabled';
166 echo " <option value=''> Search Results ($numrows items)\n";
169 while ($row = sqlFetchArray($res)) {
170 $code = $row['code'];
171 if ($row['modifier']) $code .= "-" . $row['modifier'];
172 echo " <option value='$code'>$code " . ucfirst(strtolower($row['code_text'])) . "\n";
183 <p style
='margin-top:8px;margin-bottom:8px'>
187 <?php
xl('Search','e'); ?
> 
;
189 foreach ($code_types as $key => $value) {
190 echo " <input type='radio' name='search_type' value='$key'";
191 if ($key == $default_search_type) echo " checked";
192 echo " />$key \n";
195 <?php
xl('for','e'); ?
> 
;
198 <input type
='text' name
='search_term' value
=''>  
;
201 <input type
='submit' name
='bn_search' value
='<?php xl('Search
','e
');?>'>
207 <p style
='margin-top:16px;margin-bottom:8px'>
208 <table cellspacing
='5'>
210 <td
class='billcell'><b
><?php
xl('Type','e');?
></b
></td
>
211 <td
class='billcell'><b
><?php
xl('Code','e');?
></b
></td
>
212 <?
if (modifiers_are_used()) { ?
>
213 <td
class='billcell'><b
><?php
xl('Mod','e');?
></b
></td
>
215 <?
if (fees_are_used()) { ?
>
216 <td
class='billcell' align
='right'><b
><?php
xl('Fee','e');?
></b
> 
;</td
>
218 <td
class='billcell' align
='center'><b
><?php
xl('Auth','e');?
></b
></td
>
219 <td
class='billcell' align
='center'><b
><?php
xl('Delete','e');?
></b
></td
>
220 <td
class='billcell'><b
><?php
xl('Description','e');?
></b
></td
>
224 // This writes a billing line item to the output page.
226 function echoLine($lino, $codetype, $code, $modifier, $auth = TRUE, $del = FALSE,
227 $fee = NULL, $id = NULL, $billed = FALSE, $code_text = NULL)
231 $query = "select fee, code_text from codes where code_type = '" .
232 $code_types[$codetype]['id'] . "' and " .
233 "code = '$code' and ";
235 $query .= "modifier = '$modifier'";
237 $query .= "(modifier is null or modifier = '')";
239 $result = sqlQuery($query);
240 $code_text = $result['code_text'];
241 if (!isset($fee)) $fee = $result['fee'];
243 $strike1 = ($id && $del) ?
"<strike>" : "";
244 $strike2 = ($id && $del) ?
"</strike>" : "";
246 echo " <td class='billcell'>$strike1$codetype$strike2";
248 echo "<input type='hidden' name='bill[$lino][id]' value='$id'>";
250 echo "<input type='hidden' name='bill[$lino][code_type]' value='$codetype'>";
251 echo "<input type='hidden' name='bill[$lino][code]' value='$code'>";
252 echo "<input type='hidden' name='bill[$lino][billed]' value='$billed'>";
254 echo " <td class='billcell'>$strike1$code$strike2</td>\n";
256 if (modifiers_are_used()) {
257 echo " <td class='billcell'>$strike1$modifier$strike2" .
258 "<input type='hidden' name='bill[$lino][mod]' value='$modifier'></td>\n";
260 if (fees_are_used()) {
261 echo " <td class='billcell' align='right'>$fee</td>\n";
263 echo " <td class='billcell' align='center'><input type='checkbox'" .
264 ($auth ?
" checked" : "") . " disabled /></td>\n";
265 echo " <td class='billcell' align='center'><input type='checkbox'" .
266 " disabled /></td>\n";
268 if (modifiers_are_used()) {
269 if ($code_types[$codetype]['mod'] ||
$modifier) {
270 echo " <td class='billcell'><input type='text' name='bill[$lino][mod]' " .
271 "value='$modifier' size='" . $code_types[$codetype]['mod'] . "'></td>\n";
273 echo " <td class='billcell'> </td>\n";
276 if (fees_are_used()) {
277 if ($code_types[$codetype]['fee'] ||
$fee != 0) {
278 echo " <td class='billcell' align='right'><input type='text' name='bill[$lino][fee]' " .
279 "value='$fee' size='6' style='text-align:right'></td>\n";
281 echo " <td class='billcell'> </td>\n";
284 echo " <td class='billcell' align='center'><input type='checkbox' name='bill[$lino][auth]' " .
285 "value='1'" . ($auth ?
" checked" : "") . " /></td>\n";
286 echo " <td class='billcell' align='center'><input type='checkbox' name='bill[$lino][del]' " .
287 "value='1'" . ($del ?
" checked" : "") . " /></td>\n";
289 echo " <td class='billcell'>$strike1" . ucfirst(strtolower($code_text)) . "$strike2</td>\n";
293 // Generate lines for items already in the database.
296 $encounter_provid = -1;
297 if ($result = getBillingByEncounter($pid, $encounter, "*") ) {
298 foreach ($result as $iter) {
300 $del = $_POST['bill']["$lino"]['del']; // preserve Delete if checked
301 // list($code, $modifier) = explode("-", $iter["code"]);
302 echoLine($lino, $iter["code_type"], trim($iter["code"]), trim($iter["modifier"]),
303 $iter["authorized"], $del, $iter["fee"], $iter["id"], $iter["billed"], $iter["code_text"]);
304 if ($encounter_provid < 0 && ! $del) $encounter_provid = $iter["provider_id"];
308 // If there were no billing items then try setting the default provider
309 // to that of the new encounter form.
311 if ($encounter_provid < 0) {
312 $tmp = sqlQuery("SELECT users.id FROM forms, users WHERE " .
313 "forms.pid = '$pid' AND forms.encounter = '$encounter' AND " .
314 "forms.formdir='newpatient' AND users.username = forms.user AND " .
315 "users.authorized = 1");
316 if ($tmp['id']) $encounter_provid = $tmp['id'];
319 // If still no default provider then make it the logged-in user.
321 if ($encounter_provid < 0) $encounter_provid = $_SESSION["authUserID"];
323 // Echo new billing items from this form here, but omit any line
324 // whose Delete checkbox is checked.
326 if ($_POST['bill']) {
327 foreach ($_POST['bill'] as $key => $iter) {
328 if ($iter["id"]) continue; // skip if it came from the database
329 if ($iter["del"]) continue; // skip if Delete was checked
330 echoLine(++
$lino, $iter["code_type"], $iter["code"], trim($iter["mod"]),
331 $iter["auth"], $iter["del"], $iter["fee"]);
335 // If a new billing code was <select>ed, add its line here. As a special
336 // case allow HCPCS codes to be included in the CPT drop-lists, and
337 // CPT4 codes included in OPCS drop-lists.
339 if ($_POST['newcode']) {
340 list($code, $modifier) = explode("-", $_POST['newcode']);
341 $newtype = $_POST['newtype'];
342 if ($newtype == "CPT4" && preg_match("/^[A-Z]/", $code))
344 else if ($newtype == "OPCS" && preg_match("/^[0-9]/", $code))
346 echoLine(++
$lino, $newtype, $code, trim($modifier));
356 <span
class="billcell"><?php
xl('PROVIDER:','e');?
></span
>
359 // Build a drop-down list of providers. This includes users who
360 // have the word "provider" anywhere in their "additional info"
361 // field, so that we can define providers (for billing purposes)
362 // who do not appear in the calendar.
364 $query = "SELECT id, lname, fname FROM users WHERE " .
365 "( authorized = 1 OR info LIKE '%provider%' ) AND username != '' " .
366 "ORDER BY lname, fname";
367 $res = sqlStatement($query);
369 echo " <select name='ProviderID'>\n";
370 echo " <option value=''>-- Please Select --\n";
372 while ($row = sqlFetchArray($res)) {
373 $provid = $row['id'];
374 echo " <option value='$provid'";
375 if ($provid == $encounter_provid) echo " selected";
376 echo ">" . $row['lname'] . ", " . $row['fname'] . "\n";
382  
;  
;  
;  
;  
;  
;  
;  
;  
;  
;
384 <input type
='submit' name
='bn_save' value
='<?php xl('Save
','e
');?>' />
386 <input type
='submit' name
='bn_refresh' value
='<?php xl('Refresh
','e
');?>'>
388 <input type
='button' value
='<?php xl('Cancel
','e
');?>' onclick
="location='<? echo "$rootdir/patient_file
/encounter
/$returnurl" ?>'" />
390 <?php
if ($code_types['UCSMC']) { ?
>
391 <p style
='font-family:sans-serif;font-size:8pt;color:#666666;'>
393 <?php
xl('UCSMC codes provided by the University of Calgary Sports Medicine Centre','e');?
>
401 // TBD: If $alertmsg, display it with a JavaScript alert().