Initial import.
[openemr.git] / interface / forms / fee_sheet / new.php
blob70835b7e4b3ed76c0363d76a10cd3ab43c33132f
1 <?php
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.
7 //
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;
39 $id = $iter['id'];
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";
45 $del = $iter['del'];
47 // If the item is already in the database...
48 if ($id) {
49 if ($del) {
50 deleteBilling($id);
52 else {
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...
61 else if (! $del) {
62 $query = "select code_text from codes where code_type = '" .
63 $code_types[$code_type]['id'] . "' and " .
64 "code = '$code' and ";
65 if ($modifier) {
66 $query .= "modifier = '$modifier'";
67 } else {
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....");
78 formJump();
79 formFooter();
80 exit;
83 <html>
84 <head>
85 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
86 <style>
87 .billcell { font-family: sans-serif; font-size: 10pt }
88 </style>
89 <script language="JavaScript">
91 function codeselect(selobj, newtype) {
92 var i = selobj.selectedIndex;
93 if (i > 0) {
94 var f = document.forms[0];
95 f.newcode.value = selobj.options[i].value;
96 f.newtype.value = newtype;
97 f.submit();
101 </script>
102 </head>
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=''>
110 <center>
111 <table width='95%'>
113 $i = 0;
115 // Create all the drop-lists of preselected codes.
117 foreach ($bcodes as $key0 => $value0) {
118 foreach ($value0 as $key1 => $value1) {
119 ++$i;
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";
127 echo " </select>\n";
128 echo " </td>\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" : "";
137 echo " <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!
143 $numrows = 0;
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'] . "' " .
149 "order by code";
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';
157 echo ">\n";
158 echo " <option value=''> Search Results ($numrows items)\n";
160 if ($numrows) {
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";
168 echo " </select>\n";
169 echo " </td>\n";
170 echo " </tr>\n";
173 </table>
175 <p style='margin-top:8px;margin-bottom:8px'>
176 <table>
177 <tr>
178 <td>
179 Search&nbsp;
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&nbsp;\n";
187 for&nbsp;
188 </td>
189 <td>
190 <input type='text' name='search_term' value=''> &nbsp;
191 </td>
192 <td>
193 <input type='submit' name='bn_search' value='Search'>
194 </td>
195 </tr>
196 </table>
197 </p>
199 <p style='margin-top:16px;margin-bottom:8px'>
200 <table cellspacing='5'>
201 <tr>
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>
206 <? } ?>
207 <? if (fees_are_used()) { ?>
208 <td class='billcell' align='right'><b>Fee</b>&nbsp;</td>
209 <? } ?>
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>
213 </tr>
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)
221 global $code_types;
222 if (! $code_text) {
223 $query = "select fee, code_text from codes where code_type = '" .
224 $code_types[$codetype]['id'] . "' and " .
225 "code = '$code' and ";
226 if ($modifier) {
227 $query .= "modifier = '$modifier'";
228 } else {
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>" : "";
237 echo " <tr>\n";
238 echo " <td class='billcell'>$strike1$codetype$strike2";
239 if ($id) {
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'>";
245 echo "</td>\n";
246 echo " <td class='billcell'>$strike1$code$strike2</td>\n";
247 if ($billed) {
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";
259 } else {
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";
264 } else {
265 echo " <td class='billcell'>&nbsp;</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";
272 } else {
273 echo " <td class='billcell'>&nbsp;</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";
282 echo " </tr>\n";
285 // Generate lines for items already in the database.
287 $lino = 0;
288 $encounter_provid = -1;
289 if ($result = getBillingByEncounter($pid, $encounter, "*") ) {
290 foreach ($result as $iter) {
291 ++$lino;
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))
323 $newtype = "HCPCS";
324 echoLine(++$lino, $newtype, $code, trim($modifier));
328 </table>
329 </p>
331 <br>
332 &nbsp;
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";
353 echo " </select>\n";
356 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
358 <input type='submit' name='bn_save' value='Save' />
359 &nbsp;
360 <input type='submit' name='bn_refresh' value='Refresh'>
361 &nbsp;
362 <input type='button' value='Cancel' onclick="location='<? echo "$rootdir/patient_file/encounter/patient_encounter.php" ?>'" />
364 </center>
366 </form>
367 <?php
369 // TBD: If $alertmsg, display it with a JavaScript alert().
372 </body>
373 </html>