added ippf_specific flag and CYP factor
[openemr.git] / interface / patient_file / encounter / superbill_custom_full.php
blobcd12e6bb3485d85b1d42b7ba9df1ef046bddfa4e
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 include_once("../../globals.php");
8 include_once("../../../custom/code_types.inc.php");
9 include_once("$srcdir/sql.inc");
11 // Translation for form fields.
12 function ffescape($field) {
13 if (!get_magic_quotes_gpc()) $field = addslashes($field);
14 return trim($field);
17 // Format dollars for display.
19 function bucks($amount) {
20 if ($amount) {
21 $amount = sprintf("%.2f", $amount);
22 if ($amount != 0.00) return $amount;
24 return '';
27 $alertmsg = '';
28 $pagesize = 100;
29 $mode = $_POST['mode'];
30 $code_id = 0;
31 $related_code = '';
33 if (isset($mode)) {
34 $code_id = $_POST['code_id'] + 0;
35 $code = $_POST['code'];
36 $code_type = $_POST['code_type'];
37 $code_text = $_POST['code_text'];
38 $modifier = $_POST['modifier'];
39 // $units = $_POST['units'];
40 $superbill = $_POST['superbill'];
41 $related_code = $_POST['related_code'];
42 $cyp_factor = $_POST['cyp_factor'] + 0;
44 $taxrates = "";
45 if (!empty($_POST['taxrate'])) {
46 foreach ($_POST['taxrate'] as $key => $value) {
47 $taxrates .= "$key:";
51 if ($mode == "delete") {
52 sqlStatement("DELETE FROM codes WHERE id = '$code_id'");
53 $code_id = 0;
55 else if ($mode == "add") { // this covers both adding and modifying
56 $crow = sqlQuery("SELECT COUNT(*) AS count FROM codes WHERE " .
57 "code_type = '" . ffescape($code_type) . "' AND " .
58 "code = '" . ffescape($code) . "' AND " .
59 "modifier = '" . ffescape($modifier) . "' AND " .
60 "id != '$code_id'");
61 if ($crow['count']) {
62 $alertmsg = "Cannot add/update this entry because a duplicate already exists!";
64 else {
65 $sql =
66 "code = '" . ffescape($code) . "', " .
67 "code_type = '" . ffescape($code_type) . "', " .
68 "code_text = '" . ffescape($code_text) . "', " .
69 "modifier = '" . ffescape($modifier) . "', " .
70 // "units = '" . ffescape($units) . "', " .
71 "superbill = '" . ffescape($superbill) . "', " .
72 "related_code = '" . ffescape($related_code) . "', " .
73 "cyp_factor = '" . ffescape($cyp_factor) . "', " .
74 "taxrates = '" . ffescape($taxrates) . "'";
75 if ($code_id) {
76 $query = "UPDATE codes SET $sql WHERE id = '$code_id'";
77 sqlStatement($query);
78 sqlStatement("DELETE FROM prices WHERE pr_id = '$code_id' AND " .
79 "pr_selector = ''");
81 else {
82 $code_id = sqlInsert("INSERT INTO codes SET $sql");
84 if (!$alertmsg) {
85 foreach ($_POST['fee'] as $key => $value) {
86 $value = $value + 0;
87 if ($value) {
88 sqlStatement("INSERT INTO prices ( " .
89 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
90 "'$code_id', '', '$key', '$value' )");
93 $code = $code_type = $code_text = $modifier = $superbill = "";
94 $code_id = 0;
95 $related_code = '';
96 $cyp_factor = 0;
97 $taxrates = '';
101 else if ($mode == "edit") { // someone clicked [Edit]
102 $sql = "SELECT * FROM codes WHERE id = '$code_id'";
103 $results = sqlQ($sql);
104 while ($row = mysql_fetch_assoc($results)) {
105 $code = $row['code'];
106 $code_text = $row['code_text'];
107 $code_type = $row['code_type'];
108 $modifier = $row['modifier'];
109 // $units = $row['units'];
110 $superbill = $row['superbill'];
111 $related_code = $row['related_code'];
112 $cyp_factor = $row['cyp_factor'];
113 $taxrates = $row['taxrates'];
118 $related_desc = '';
119 if (!empty($related_code)) {
120 // $relrow = sqlQuery("SELECT code_text FROM codes WHERE code = '$related_code'");
121 // $related_desc = $related_code . ': ' . trim($relrow['code_text']);
122 $related_desc = $related_code;
125 $fstart = $_REQUEST['fstart'] + 0;
126 $filter = $_REQUEST['filter'] + 0;
127 $search = $_REQUEST['search'];
129 $where = "1 = 1";
130 if ($filter) {
131 $where .= " AND code_type = '$filter'";
133 if (!empty($search)) {
134 $where .= " AND code LIKE '" . ffescape($search) . "%'";
137 $crow = sqlQuery("SELECT count(*) AS count FROM codes WHERE $where");
138 $count = $crow['count'];
139 if ($fstart >= $count) $fstart -= $pagesize;
140 if ($fstart < 0) $fstart = 0;
141 $fend = $fstart + $pagesize;
142 if ($fend > $count) $fend = $count;
145 <html>
146 <head>
147 <?php html_header_show(); ?>
148 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
149 <script type="text/javascript" src="../../../library/dialog.js"></script>
151 <script language="JavaScript">
153 // This is for callback by the find-code popup.
154 // Appends to or erases the current list of related codes.
155 function set_related(codetype, code, selector, codedesc) {
156 var f = document.forms[0];
157 var s = f.related_code.value;
158 if (code) {
159 if (s.length > 0) s += ';';
160 s += codetype + ':' + code;
161 } else {
162 s = '';
164 f.related_code.value = s;
165 f.related_desc.value = s;
168 // This invokes the find-code popup.
169 function sel_related() {
170 var f = document.forms[0];
171 var i = f.code_type.selectedIndex;
172 var codetype = '';
173 if (i >= 0) {
174 var myid = f.code_type.options[i].value;
175 <?php
176 foreach ($code_types as $key => $value) {
177 $codeid = $value['id'];
178 $coderel = $value['rel'];
179 if (!$coderel) continue;
180 echo " if (myid == $codeid) codetype = '$coderel';";
184 if (!codetype) {
185 alert('<?php xl('This code type does not accept relations.','e') ?>');
186 return;
188 // dlgopen('find_code_popup.php?codetype=' + codetype, '_blank', 500, 400);
189 dlgopen('find_code_popup.php', '_blank', 500, 400);
192 function submitAdd() {
193 var f = document.forms[0];
194 if (!f.code.value) {
195 alert('No code was specified!');
196 return;
198 f.mode.value = 'add';
199 f.code_id.value = '';
200 f.submit();
203 function submitUpdate() {
204 var f = document.forms[0];
205 if (! parseInt(f.code_id.value)) {
206 alert('<?php xl('Cannot update because you are not editing an existing entry!','e') ?>');
207 return;
209 if (!f.code.value) {
210 alert('<?php xl('No code was specified!','e') ?>');
211 return;
213 f.mode.value = 'add';
214 f.submit();
217 function submitList(offset) {
218 var f = document.forms[0];
219 var i = parseInt(f.fstart.value) + offset;
220 if (i < 0) i = 0;
221 f.fstart.value = i;
222 f.submit();
225 function submitEdit(id) {
226 var f = document.forms[0];
227 f.mode.value = 'edit';
228 f.code_id.value = id;
229 f.submit();
232 function submitDelete(id) {
233 var f = document.forms[0];
234 f.mode.value = 'delete';
235 f.code_id.value = id;
236 f.submit();
239 </script>
241 </head>
242 <body class="body_top">
244 <?php if ($GLOBALS['concurrent_layout']) {
245 // <a href="superbill_codes.php">
246 // <span class=title>??php xl('Superbill Codes','e'); ??</span>
247 // <font class=more>??php echo $tback;??</font></a>
248 } else { ?>
249 <a href='patient_encounter.php?codefrom=superbill' target='Main'>
250 <span class='title'><?php xl('Superbill Codes','e'); ?></span>
251 <font class='more'><?php echo $tback;?></font></a>
252 <?php } ?>
254 <form method='post' action='superbill_custom_full.php' name='theform'>
256 <input type='hidden' name='mode' value=''>
258 <br>
260 <center>
261 <table border='0' cellpadding='0' cellspacing='0'>
263 <tr>
264 <td colspan="3"> <?php xl('Not all fields are required for all codes or code types.','e'); ?><br><br></td>
265 </tr>
267 <tr>
268 <td><?php xl('Type','e'); ?>:</td>
269 <td width="5"></td>
270 <td>
271 <select name="code_type">
272 <?php foreach ($code_types as $key => $value) { ?>
273 <option value="<?php echo $value['id'] ?>"<?php if ($GLOBALS['code_type'] == $value['id']) echo " selected" ?>><?php echo $key ?></option>
274 <?php } ?>
275 </select>
276 &nbsp;&nbsp;
277 <?php xl('Code','e'); ?>:
278 <input type='text' size='6' name='code' value='<?php echo $code ?>'>
279 <?php if (modifiers_are_used()) { ?>
280 &nbsp;&nbsp;<?php xl('Modifier','e'); ?>:
281 <input type='text' size='3' name='modifier' value='<?php echo $modifier ?>'>
282 <?php } else { ?>
283 <input type='hidden' name='modifier' value='<?php echo $modifier ?>'>
284 <?php } ?>
285 </td>
286 </tr>
288 <tr>
289 <td><?php xl('Description','e'); ?>:</td>
290 <td></td>
291 <td>
292 <input type='text' size='50' name="code_text" value='<?php echo $code_text ?>'>
293 </td>
294 </tr>
296 <tr>
297 <td><?php xl('Category','e'); ?>:</td>
298 <td></td>
299 <td>
300 <select name="superbill">
301 <option value=''>Unassigned</option>
302 <?php
303 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
304 "WHERE list_id = 'superbill' ORDER BY seq");
305 while ($prow = sqlFetchArray($pres)) {
306 echo ' <option value="' . $prow['option_id'] . '"';
307 if ($superbill == $prow['option_id']) echo " selected";
308 echo ">" . $prow['title'] . "</option>\n";
311 </select>
312 </td>
313 </tr>
315 <tr<?php if (empty($GLOBALS['ippf_specific'])) echo " style='display:none'"; ?>>
316 <td><?php xl('CYP Factor','e'); ?>:</td>
317 <td></td>
318 <td>
319 <input type='text' size='10' maxlength='20' name="cyp_factor" value='<?php echo $cyp_factor ?>'>
320 </td>
321 </tr>
323 <tr<?php if (!related_codes_are_used()) echo " style='display:none'"; ?>>
324 <td><?php xl('Relate To','e'); ?>:</td>
325 <td></td>
326 <td>
327 <input type='text' size='50' name='related_desc'
328 value='<?php echo $related_desc ?>' onclick="sel_related()"
329 title='<?php xl('Click to select related code','e'); ?>' readonly />
330 <input type='hidden' name='related_code' value='<?php echo $related_code ?>' />
331 </td>
332 </tr>
334 <tr>
335 <td><?php xl('Fees','e'); ?>:</td>
336 <td></td>
337 <td>
338 <?php
339 $pres = sqlStatement("SELECT lo.option_id, lo.title, p.pr_price " .
340 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
341 "p.pr_id = '$code_id' AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
342 "WHERE list_id = 'pricelevel' ORDER BY lo.seq");
343 for ($i = 0; $prow = sqlFetchArray($pres); ++$i) {
344 if ($i) echo "&nbsp;&nbsp;";
345 echo $prow['title'] . " ";
346 echo "<input type='text' size='6' name='fee[" . $prow['option_id'] . "]' " .
347 "value='" . $prow['pr_price'] . "' >\n";
350 </td>
351 </tr>
353 <?php
354 $taxline = '';
355 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
356 "WHERE list_id = 'taxrate' ORDER BY seq");
357 while ($prow = sqlFetchArray($pres)) {
358 if ($taxline) $taxline .= "&nbsp;&nbsp;";
359 $taxline .= "<input type='checkbox' name='taxrate[" . $prow['option_id'] . "]' value='1'";
360 if (strpos(":$taxrates", $prow['option_id']) !== false) $taxline .= " checked";
361 $taxline .= " />\n";
362 $taxline .= $prow['title'] . "\n";
364 if ($taxline) {
366 <tr>
367 <td><?php xl('Taxes','e'); ?>:</td>
368 <td></td>
369 <td>
370 <?php echo $taxline ?>
371 </td>
372 </tr>
373 <?php } ?>
375 <tr>
376 <td colspan="3" align="center">
377 <input type="hidden" name="code_id" value="<?php echo $code_id ?>"><br>
378 <a href='javascript:submitUpdate();' class='link'>[<?php xl('Update','e'); ?>]</a>
379 &nbsp;&nbsp;
380 <a href='javascript:submitAdd();' class='link'>[<?php xl('Add as New','e'); ?>]</a>
381 </td>
382 </tr>
384 </table>
386 <table border='0' cellpadding='5' cellspacing='0' width='96%'>
387 <tr>
389 <td class='text'>
390 <select name='filter' onchange='submitList(0)'>
391 <option value='0'>All</option>
392 <?php
393 foreach ($code_types as $key => $value) {
394 echo "<option value='" . $value['id'] . "'";
395 if ($value['id'] == $filter) echo " selected";
396 echo ">$key</option>\n";
399 </select>
400 &nbsp;&nbsp;&nbsp;&nbsp;
402 <input type="text" name="search" size="5" value="<?php echo $search ?>">&nbsp;
403 <input type="submit" name="go" value="Search">
404 <input type='hidden' name='fstart' value='<?php echo $fstart ?>'>
405 </td>
407 <td class='text' align='right'>
408 <?php if ($fstart) { ?>
409 <a href="javascript:submitList(-<?php echo $pagesize ?>)">
410 &lt;&lt;
411 </a>
412 &nbsp;&nbsp;
413 <?php } ?>
414 <?php echo ($fstart + 1) . " - $fend of $count" ?>
415 &nbsp;&nbsp;
416 <a href="javascript:submitList(<?php echo $pagesize ?>)">
417 &gt;&gt;
418 </a>
419 </td>
421 </tr>
422 </table>
424 </form>
426 <table border='0' cellpadding='5' cellspacing='0' width='96%'>
427 <tr>
428 <td><span class='bold'><?php xl('Code','e'); ?></span></td>
429 <td><span class='bold'><?php xl('Mod','e'); ?></span></td>
430 <td><span class='bold'><?php xl('Type','e'); ?></span></td>
431 <td><span class='bold'><?php xl('Description','e'); ?></span></td>
432 <!--
433 <td><span class='bold'><?php // xl('Modifier','e'); ?></span></td>
434 <td><span class='bold'><?php // xl('Units','e'); ?></span></td>
435 <td><span class='bold'><?php // xl('Fee','e'); ?></span></td>
437 <?php
438 $pres = sqlStatement("SELECT title FROM list_options " .
439 "WHERE list_id = 'pricelevel' ORDER BY seq");
440 while ($prow = sqlFetchArray($pres)) {
441 echo " <td class='bold' align='right' nowrap>" . $prow['title'] . "</td>\n";
444 <td></td>
445 <td></td>
446 </tr>
447 <?php
449 $res = sqlStatement("SELECT * FROM codes WHERE $where " .
450 "ORDER BY code_type, code, code_text LIMIT $fstart, " . ($fend - $fstart));
452 for ($i = 0; $row = sqlFetchArray($res); $i++) $all[$i] = $row;
454 if (!empty($all)) {
455 $count = 0;
456 foreach($all as $iter) {
457 $count++;
459 $has_fees = false;
460 foreach ($code_types as $key => $value) {
461 if ($value['id'] == $iter['code_type']) {
462 $has_fees = $value['fee'];
463 break;
467 echo " <tr>\n";
468 echo " <td class='text'>" . $iter["code"] . "</td>\n";
469 echo " <td class='text'" . $iter["modifier"] . "</td>\n";
470 echo " <td class='text'>$key</td>\n";
471 echo " <td class='text'>" . $iter['code_text'] . "</td>\n";
473 // echo "<td>";
474 // if ($has_fees) {
475 // echo "<span class='text'>" . $iter['modifier'] . "</span>";
476 // }
477 // echo "</td>";
478 // echo "<td>";
479 // if ($has_fees) {
480 // echo "<span class='text'>" . $iter['units'] . "</span>";
481 // }
482 // echo "</td>";
483 // echo "<td>";
484 // if ($has_fees) {
485 // echo "<span class='text'>$" . sprintf("%01.2f", $iter['fee']) . "</span>";
486 // }
487 // echo "</td>";
489 $pres = sqlStatement("SELECT p.pr_price " .
490 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
491 "p.pr_id = '" . $iter['id'] . "' AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
492 "WHERE list_id = 'pricelevel' ORDER BY lo.seq");
493 while ($prow = sqlFetchArray($pres)) {
494 echo "<td class='text' align='right'>" . bucks($prow['pr_price']) . "</td>\n";
497 echo " <td align='right'><a class='link' href='javascript:submitDelete(" . $iter['id'] . ")'>[Del]</a></td>\n";
498 echo " <td align='right'><a class='link' href='javascript:submitEdit(" . $iter['id'] . ")'>[Edit]</a></td>\n";
499 echo " </tr>\n";
506 </table>
508 </center>
510 <script language="JavaScript">
511 <?php
512 if ($alertmsg) {
513 echo "alert('" . htmlentities($alertmsg) . "');\n";
516 </script>
518 </body>
519 </html>