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 function submitAdd() {
193 var f
= document
.forms
[0];
195 alert('No code was specified!');
198 f
.mode
.value
= 'add';
199 f
.code_id
.value
= '';
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
') ?>');
210 alert('<?php xl('No code was specified
!','e
') ?>');
213 f
.mode
.value
= 'add';
217 function submitList(offset
) {
218 var f
= document
.forms
[0];
219 var i
= parseInt(f
.fstart
.value
) + offset
;
225 function submitEdit(id
) {
226 var f
= document
.forms
[0];
227 f
.mode
.value
= 'edit';
228 f
.code_id
.value
= id
;
232 function submitDelete(id
) {
233 var f
= document
.forms
[0];
234 f
.mode
.value
= 'delete';
235 f
.code_id
.value
= id
;
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>
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
>
254 <form method
='post' action
='superbill_custom_full.php' name
='theform'>
256 <input type
='hidden' name
='mode' value
=''>
261 <table border
='0' cellpadding
='0' cellspacing
='0'>
264 <td colspan
="3"> <?php
xl('Not all fields are required for all codes or code types.','e'); ?
><br
><br
></td
>
268 <td
><?php
xl('Type','e'); ?
>:</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
>
277 <?php
xl('Code','e'); ?
>:
278 <input type
='text' size
='6' name
='code' value
='<?php echo $code ?>'>
279 <?php
if (modifiers_are_used()) { ?
>
280  
; 
;<?php
xl('Modifier','e'); ?
>:
281 <input type
='text' size
='3' name
='modifier' value
='<?php echo $modifier ?>'>
283 <input type
='hidden' name
='modifier' value
='<?php echo $modifier ?>'>
289 <td
><?php
xl('Description','e'); ?
>:</td
>
292 <input type
='text' size
='50' name
="code_text" value
='<?php echo $code_text ?>'>
297 <td
><?php
xl('Category','e'); ?
>:</td
>
300 <select name
="superbill">
301 <option value
=''>Unassigned
</option
>
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";
315 <tr
<?php
if (empty($GLOBALS['ippf_specific'])) echo " style='display:none'"; ?
>>
316 <td
><?php
xl('CYP Factor','e'); ?
>:</td
>
319 <input type
='text' size
='10' maxlength
='20' name
="cyp_factor" value
='<?php echo $cyp_factor ?>'>
323 <tr
<?php
if (!related_codes_are_used()) echo " style='display:none'"; ?
>>
324 <td
><?php
xl('Relate To','e'); ?
>:</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 ?>' />
335 <td
><?php
xl('Fees','e'); ?
>:</td
>
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 " ";
345 echo $prow['title'] . " ";
346 echo "<input type='text' size='6' name='fee[" . $prow['option_id'] . "]' " .
347 "value='" . $prow['pr_price'] . "' >\n";
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 .= " ";
359 $taxline .= "<input type='checkbox' name='taxrate[" . $prow['option_id'] . "]' value='1'";
360 if (strpos(":$taxrates", $prow['option_id']) !== false) $taxline .= " checked";
362 $taxline .= $prow['title'] . "\n";
367 <td
><?php
xl('Taxes','e'); ?
>:</td
>
370 <?php
echo $taxline ?
>
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
>
380 <a href
='javascript:submitAdd();' class='link'>[<?php
xl('Add as New','e'); ?
>]</a
>
386 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
390 <select name
='filter' onchange
='submitList(0)'>
391 <option value
='0'>All
</option
>
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";
400  
; 
; 
; 
;
402 <input type
="text" name
="search" size
="5" value
="<?php echo $search ?>"> 
;
403 <input type
="submit" name
="go" value
="Search">
404 <input type
='hidden' name
='fstart' value
='<?php echo $fstart ?>'>
407 <td
class='text' align
='right'>
408 <?php
if ($fstart) { ?
>
409 <a href
="javascript:submitList(-<?php echo $pagesize ?>)">
414 <?php
echo ($fstart +
1) . " - $fend of $count" ?
>
416 <a href
="javascript:submitList(<?php echo $pagesize ?>)">
426 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
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
>
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>
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";
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;
456 foreach($all as $iter) {
460 foreach ($code_types as $key => $value) {
461 if ($value['id'] == $iter['code_type']) {
462 $has_fees = $value['fee'];
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";
475 // echo "<span class='text'>" . $iter['modifier'] . "</span>";
480 // echo "<span class='text'>" . $iter['units'] . "</span>";
485 // echo "<span class='text'>$" . sprintf("%01.2f", $iter['fee']) . "</span>";
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";
510 <script language
="JavaScript">
513 echo "alert('" . htmlentities($alertmsg) . "');\n";