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);
17 // Format dollars for display.
19 function bucks($amount) {
21 $amount = sprintf("%.2f", $amount);
22 if ($amount != 0.00) return $amount;
29 $mode = $_POST['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;
45 if (!empty($_POST['taxrate'])) {
46 foreach ($_POST['taxrate'] as $key => $value) {
51 if ($mode == "delete") {
52 sqlStatement("DELETE FROM codes WHERE id = '$code_id'");
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 " .
62 $alertmsg = "Cannot add/update this entry because a duplicate already exists!";
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) . "'";
76 $query = "UPDATE codes SET $sql WHERE id = '$code_id'";
78 sqlStatement("DELETE FROM prices WHERE pr_id = '$code_id' AND " .
82 $code_id = sqlInsert("INSERT INTO codes SET $sql");
85 foreach ($_POST['fee'] as $key => $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 = "";
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'];
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'];
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;
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
;
159 if (s
.length
> 0) s +
= ';';
160 s +
= codetype +
':' + code
;
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
;
174 var myid
= f
.code_type
.options
[i
].value
;
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';";
185 alert('<?php xl('This code type does not accept relations
.','e
') ?>');
188 // dlgopen('find_code_popup.php?codetype=' + codetype, '_blank', 500, 400);
189 dlgopen('find_code_popup.php', '_blank', 500, 400);
192 // Some validation for saving a new code entry.
193 function validEntry(f
) {
195 alert('<?php xl('No code was specified
!','e
') ?>');
198 <?php
if ($GLOBALS['ippf_specific']) { ?
>
199 if (f
.code_type
.value
== 12 && !f
.related_code
.value
) {
200 alert('<?php echo xl('A related IPPF code is required
!'); ?>');
207 function submitAdd() {
208 var f
= document
.forms
[0];
209 if (!validEntry(f
)) return;
210 f
.mode
.value
= 'add';
211 f
.code_id
.value
= '';
215 function submitUpdate() {
216 var f
= document
.forms
[0];
217 if (! parseInt(f
.code_id
.value
)) {
218 alert('<?php xl('Cannot update because you are not editing an existing entry
!','e
') ?>');
221 if (!validEntry(f
)) return;
222 f
.mode
.value
= 'add';
226 function submitList(offset
) {
227 var f
= document
.forms
[0];
228 var i
= parseInt(f
.fstart
.value
) + offset
;
234 function submitEdit(id
) {
235 var f
= document
.forms
[0];
236 f
.mode
.value
= 'edit';
237 f
.code_id
.value
= id
;
241 function submitDelete(id
) {
242 var f
= document
.forms
[0];
243 f
.mode
.value
= 'delete';
244 f
.code_id
.value
= id
;
251 <body
class="body_top">
253 <?php
if ($GLOBALS['concurrent_layout']) {
254 // <a href="superbill_codes.php">
255 // <span class=title>??php xl('Superbill Codes','e'); ??</span>
256 // <font class=more>??php echo $tback;??</font></a>
258 <a href
='patient_encounter.php?codefrom=superbill' target
='Main'>
259 <span
class='title'><?php
xl('Superbill Codes','e'); ?
></span
>
260 <font
class='more'><?php
echo $tback;?
></font
></a
>
263 <form method
='post' action
='superbill_custom_full.php' name
='theform'>
265 <input type
='hidden' name
='mode' value
=''>
270 <table border
='0' cellpadding
='0' cellspacing
='0'>
273 <td colspan
="3"> <?php
xl('Not all fields are required for all codes or code types.','e'); ?
><br
><br
></td
>
277 <td
><?php
xl('Type','e'); ?
>:</td
>
280 <select name
="code_type">
281 <?php
foreach ($code_types as $key => $value) { ?
>
282 <option value
="<?php echo $value['id'] ?>"<?php
if ($GLOBALS['code_type'] == $value['id']) echo " selected" ?
>><?php
echo $key ?
></option
>
286 <?php
xl('Code','e'); ?
>:
287 <input type
='text' size
='6' name
='code' value
='<?php echo $code ?>'>
288 <?php
if (modifiers_are_used()) { ?
>
289  
; 
;<?php
xl('Modifier','e'); ?
>:
290 <input type
='text' size
='3' name
='modifier' value
='<?php echo $modifier ?>'>
292 <input type
='hidden' name
='modifier' value
='<?php echo $modifier ?>'>
298 <td
><?php
xl('Description','e'); ?
>:</td
>
301 <input type
='text' size
='50' name
="code_text" value
='<?php echo $code_text ?>'>
306 <td
><?php
xl('Category','e'); ?
>:</td
>
309 <select name
="superbill">
310 <option value
=''>Unassigned
</option
>
312 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
313 "WHERE list_id = 'superbill' ORDER BY seq");
314 while ($prow = sqlFetchArray($pres)) {
315 echo ' <option value="' . $prow['option_id'] . '"';
316 if ($superbill == $prow['option_id']) echo " selected";
317 echo ">" . $prow['title'] . "</option>\n";
324 <tr
<?php
if (empty($GLOBALS['ippf_specific'])) echo " style='display:none'"; ?
>>
325 <td
><?php
xl('CYP Factor','e'); ?
>:</td
>
328 <input type
='text' size
='10' maxlength
='20' name
="cyp_factor" value
='<?php echo $cyp_factor ?>'>
332 <tr
<?php
if (!related_codes_are_used()) echo " style='display:none'"; ?
>>
333 <td
><?php
xl('Relate To','e'); ?
>:</td
>
336 <input type
='text' size
='50' name
='related_desc'
337 value
='<?php echo $related_desc ?>' onclick
="sel_related()"
338 title
='<?php xl('Click to select related code
','e
'); ?>' readonly
/>
339 <input type
='hidden' name
='related_code' value
='<?php echo $related_code ?>' />
344 <td
><?php
xl('Fees','e'); ?
>:</td
>
348 $pres = sqlStatement("SELECT lo.option_id, lo.title, p.pr_price " .
349 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
350 "p.pr_id = '$code_id' AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
351 "WHERE list_id = 'pricelevel' ORDER BY lo.seq");
352 for ($i = 0; $prow = sqlFetchArray($pres); ++
$i) {
353 if ($i) echo " ";
354 echo $prow['title'] . " ";
355 echo "<input type='text' size='6' name='fee[" . $prow['option_id'] . "]' " .
356 "value='" . $prow['pr_price'] . "' >\n";
364 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
365 "WHERE list_id = 'taxrate' ORDER BY seq");
366 while ($prow = sqlFetchArray($pres)) {
367 if ($taxline) $taxline .= " ";
368 $taxline .= "<input type='checkbox' name='taxrate[" . $prow['option_id'] . "]' value='1'";
369 if (strpos(":$taxrates", $prow['option_id']) !== false) $taxline .= " checked";
371 $taxline .= $prow['title'] . "\n";
376 <td
><?php
xl('Taxes','e'); ?
>:</td
>
379 <?php
echo $taxline ?
>
385 <td colspan
="3" align
="center">
386 <input type
="hidden" name
="code_id" value
="<?php echo $code_id ?>"><br
>
387 <a href
='javascript:submitUpdate();' class='link'>[<?php
xl('Update','e'); ?
>]</a
>
389 <a href
='javascript:submitAdd();' class='link'>[<?php
xl('Add as New','e'); ?
>]</a
>
395 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
399 <select name
='filter' onchange
='submitList(0)'>
400 <option value
='0'>All
</option
>
402 foreach ($code_types as $key => $value) {
403 echo "<option value='" . $value['id'] . "'";
404 if ($value['id'] == $filter) echo " selected";
405 echo ">$key</option>\n";
409  
; 
; 
; 
;
411 <input type
="text" name
="search" size
="5" value
="<?php echo $search ?>"> 
;
412 <input type
="submit" name
="go" value
="Search">
413 <input type
='hidden' name
='fstart' value
='<?php echo $fstart ?>'>
416 <td
class='text' align
='right'>
417 <?php
if ($fstart) { ?
>
418 <a href
="javascript:submitList(-<?php echo $pagesize ?>)">
423 <?php
echo ($fstart +
1) . " - $fend of $count" ?
>
425 <a href
="javascript:submitList(<?php echo $pagesize ?>)">
435 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
437 <td
><span
class='bold'><?php
xl('Code','e'); ?
></span
></td
>
438 <td
><span
class='bold'><?php
xl('Mod','e'); ?
></span
></td
>
439 <td
><span
class='bold'><?php
xl('Type','e'); ?
></span
></td
>
440 <td
><span
class='bold'><?php
xl('Description','e'); ?
></span
></td
>
441 <?php
if (related_codes_are_used()) { ?
>
442 <td
><span
class='bold'><?php
xl('Related','e'); ?
></span
></td
>
445 <td
><span
class='bold'><?php
// xl('Modifier','e'); ?></span></td>
446 <td
><span
class='bold'><?php
// xl('Units','e'); ?></span></td>
447 <td
><span
class='bold'><?php
// xl('Fee','e'); ?></span></td>
450 $pres = sqlStatement("SELECT title FROM list_options " .
451 "WHERE list_id = 'pricelevel' ORDER BY seq");
452 while ($prow = sqlFetchArray($pres)) {
453 echo " <td class='bold' align='right' nowrap>" . $prow['title'] . "</td>\n";
461 $res = sqlStatement("SELECT * FROM codes WHERE $where " .
462 "ORDER BY code_type, code, code_text LIMIT $fstart, " . ($fend - $fstart));
464 for ($i = 0; $row = sqlFetchArray($res); $i++
) $all[$i] = $row;
468 foreach($all as $iter) {
472 foreach ($code_types as $key => $value) {
473 if ($value['id'] == $iter['code_type']) {
474 $has_fees = $value['fee'];
480 echo " <td class='text'>" . $iter["code"] . "</td>\n";
481 echo " <td class='text'" . $iter["modifier"] . "</td>\n";
482 echo " <td class='text'>$key</td>\n";
483 echo " <td class='text'>" . $iter['code_text'] . "</td>\n";
485 if (related_codes_are_used()) {
486 // Show related codes.
487 echo " <td class='text'>";
488 $arel = explode(';', $iter['related_code']);
489 foreach ($arel as $tmp) {
490 list($reltype, $relcode) = explode(':', $tmp);
491 $reltype = $code_types[$reltype]['id'];
492 $relrow = sqlQuery("SELECT code_text FROM codes WHERE " .
493 "code_type = '$reltype' AND code = '$relcode' LIMIT 1");
494 echo $relcode . ' ' . trim($relrow['code_text']) . '<br />';
501 // echo "<span class='text'>" . $iter['modifier'] . "</span>";
506 // echo "<span class='text'>" . $iter['units'] . "</span>";
511 // echo "<span class='text'>$" . sprintf("%01.2f", $iter['fee']) . "</span>";
515 $pres = sqlStatement("SELECT p.pr_price " .
516 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
517 "p.pr_id = '" . $iter['id'] . "' AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
518 "WHERE list_id = 'pricelevel' ORDER BY lo.seq");
519 while ($prow = sqlFetchArray($pres)) {
520 echo "<td class='text' align='right'>" . bucks($prow['pr_price']) . "</td>\n";
523 echo " <td align='right'><a class='link' href='javascript:submitDelete(" . $iter['id'] . ")'>[Del]</a></td>\n";
524 echo " <td align='right'><a class='link' href='javascript:submitEdit(" . $iter['id'] . ")'>[Edit]</a></td>\n";
536 <script language
="JavaScript">
539 echo "alert('" . htmlentities($alertmsg) . "');\n";