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 $fake_register_globals=false;
8 $sanitize_all_escapes=true;
10 require_once("../../globals.php");
11 require_once("../../../custom/code_types.inc.php");
12 require_once("$srcdir/sql.inc");
13 require_once("$srcdir/options.inc.php");
14 require_once("$srcdir/formatting.inc.php");
15 require_once("$srcdir/formdata.inc.php");
17 // Translation for form fields.
18 function ffescape($field) {
19 $field = add_escape_custom($field);
23 // Format dollars for display.
25 function bucks($amount) {
27 $amount = oeFormatMoney($amount);
35 $mode = $_POST['mode'];
42 $code_id = empty($_POST['code_id']) ?
'' : $_POST['code_id'] +
0;
43 $code = $_POST['code'];
44 $code_type = $_POST['code_type'];
45 $code_text = $_POST['code_text'];
46 $modifier = $_POST['modifier'];
47 $superbill = $_POST['form_superbill'];
48 $related_code = $_POST['related_code'];
49 $cyp_factor = $_POST['cyp_factor'] +
0;
50 $active = empty($_POST['active']) ?
0 : 1;
51 $reportable = empty($_POST['reportable']) ?
0 : 1;
54 if (!empty($_POST['taxrate'])) {
55 foreach ($_POST['taxrate'] as $key => $value) {
60 if ($mode == "delete") {
61 sqlStatement("DELETE FROM codes WHERE id = ?", array($code_id) );
64 else if ($mode == "add" ||
$mode == "modify_complete") { // this covers both adding and modifying
65 $crow = sqlQuery("SELECT COUNT(*) AS count FROM codes WHERE " .
66 "code_type = '" . ffescape($code_type) . "' AND " .
67 "code = '" . ffescape($code) . "' AND " .
68 "modifier = '" . ffescape($modifier) . "' AND " .
69 "id != '" . add_escape_custom($code_id) . "'");
71 $alertmsg = xl('Cannot add/update this entry because a duplicate already exists!');
75 "code = '" . ffescape($code) . "', " .
76 "code_type = '" . ffescape($code_type) . "', " .
77 "code_text = '" . ffescape($code_text) . "', " .
78 "modifier = '" . ffescape($modifier) . "', " .
79 "superbill = '" . ffescape($superbill) . "', " .
80 "related_code = '" . ffescape($related_code) . "', " .
81 "cyp_factor = '" . ffescape($cyp_factor) . "', " .
82 "taxrates = '" . ffescape($taxrates) . "', " .
83 "active = " . add_escape_custom($active) . ", " .
84 "reportable = " . add_escape_custom($reportable);
86 $query = "UPDATE codes SET $sql WHERE id = ?";
87 sqlStatement($query, array($code_id) );
88 sqlStatement("DELETE FROM prices WHERE pr_id = ? AND " .
89 "pr_selector = ''", array($code_id) );
92 $code_id = sqlInsert("INSERT INTO codes SET $sql");
95 foreach ($_POST['fee'] as $key => $value) {
98 sqlStatement("INSERT INTO prices ( " .
99 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
100 "?, '', ?, ?)", array($code_id,$key,$value) );
103 $code = $code_type = $code_text = $modifier = $superbill = "";
113 else if ($mode == "edit") { // someone clicked [Edit]
114 $sql = "SELECT * FROM codes WHERE id = ?";
115 $results = sqlStatement($sql, array($code_id) );
116 while ($row = sqlFetchArray($results)) {
117 $code = $row['code'];
118 $code_text = $row['code_text'];
119 $code_type = $row['code_type'];
120 $modifier = $row['modifier'];
121 // $units = $row['units'];
122 $superbill = $row['superbill'];
123 $related_code = $row['related_code'];
124 $cyp_factor = $row['cyp_factor'];
125 $taxrates = $row['taxrates'];
126 $active = 0 +
$row['active'];
127 $reportable = 0 +
$row['reportable'];
130 else if ($mode == "modify") { // someone clicked [Modify]
131 // this is to modify external code types, of which the modifications
132 // are stored in the codes table
133 $code_type_name_external = $_POST['code_type_name_external'];
134 $code_external = $_POST['code_external'];
135 $code_id = $_POST['code_id'];
136 $results = code_set_search($code_type_name_external,$code_external,false,false,true); // only will return one item
137 while ($row = sqlFetchArray($results)) {
138 $code = $row['code'];
139 $code_text = $row['code_text'];
140 $code_type = $code_types[$code_type_name_external]['id'];
141 $modifier = $row['modifier'];
142 // $units = $row['units'];
143 $superbill = $row['superbill'];
144 $related_code = $row['related_code'];
145 $cyp_factor = $row['cyp_factor'];
146 $taxrates = $row['taxrates'];
147 $active = $row['active'];
148 $reportable = $row['reportable'];
154 if (!empty($related_code)) {
155 $related_desc = $related_code;
158 $fstart = $_REQUEST['fstart'] +
0;
159 $filter = $_REQUEST['filter'] +
0;
161 $filter_key = convert_type_id_to_key($filter);
163 $search = $_REQUEST['search'];
166 $count = code_set_search($filter_key,$search,true,false);
169 $count = code_set_search("--ALL--",$search,true,false);
171 if ($fstart >= $count) $fstart -= $pagesize;
172 if ($fstart < 0) $fstart = 0;
173 $fend = $fstart +
$pagesize;
174 if ($fend > $count) $fend = $count;
179 <?php
html_header_show(); ?
>
180 <link rel
="stylesheet" href
="<?php echo attr($css_header);?>" type
="text/css">
181 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
182 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
184 <script language
="JavaScript">
186 // This is for callback by the find-code popup.
187 // Appends to or erases the current list of related codes.
188 function set_related(codetype
, code
, selector
, codedesc
) {
189 var f
= document
.forms
[0];
190 var s
= f
.related_code
.value
;
192 if (s
.length
> 0) s +
= ';';
193 s +
= codetype +
':' + code
;
197 f
.related_code
.value
= s
;
198 f
.related_desc
.value
= s
;
201 // This invokes the find-code popup.
202 function sel_related() {
203 var f
= document
.forms
[0];
204 var i
= f
.code_type
.selectedIndex
;
207 var myid
= f
.code_type
.options
[i
].value
;
209 foreach ($code_types as $key => $value) {
210 $codeid = $value['id'];
211 $coderel = $value['rel'];
212 if (!$coderel) continue;
213 echo " if (myid == $codeid) codetype = '$coderel';";
218 alert('<?php echo addslashes( xl('This code type does not accept relations
.') ); ?>');
221 dlgopen('find_code_popup.php', '_blank', 500, 400);
224 // Some validation for saving a new code entry.
225 function validEntry(f
) {
227 alert('<?php echo addslashes( xl('No code was specified
!') ); ?>');
230 <?php
if ($GLOBALS['ippf_specific']) { ?
>
231 if (f
.code_type
.value
== 12 && !f
.related_code
.value
) {
232 alert('<?php echo addslashes( xl('A related IPPF code is required
!') ); ?>');
239 function submitAdd() {
240 var f
= document
.forms
[0];
241 if (!validEntry(f
)) return;
242 f
.mode
.value
= 'add';
243 f
.code_id
.value
= '';
247 function submitUpdate() {
248 var f
= document
.forms
[0];
249 if (! parseInt(f
.code_id
.value
)) {
250 alert('<?php echo addslashes( xl('Cannot update because you are not editing an existing entry
!') ); ?>');
253 if (!validEntry(f
)) return;
254 f
.mode
.value
= 'add';
258 function submitModifyComplete() {
259 var f
= document
.forms
[0];
260 f
.mode
.value
= 'modify_complete';
264 function submitList(offset
) {
265 var f
= document
.forms
[0];
266 var i
= parseInt(f
.fstart
.value
) + offset
;
272 function submitEdit(id
) {
273 var f
= document
.forms
[0];
274 f
.mode
.value
= 'edit';
275 f
.code_id
.value
= id
;
279 function submitModify(code_type_name
,code
,id
) {
280 var f
= document
.forms
[0];
281 f
.mode
.value
= 'modify';
282 f
.code_external
.value
= code
;
283 f
.code_id
.value
= id
;
284 f
.code_type_name_external
.value
= code_type_name
;
290 function submitDelete(id
) {
291 var f
= document
.forms
[0];
292 f
.mode
.value
= 'delete';
293 f
.code_id
.value
= id
;
297 function getCTMask() {
298 var ctid
= document
.forms
[0].code_type
.value
;
300 foreach ($code_types as $key => $value) {
301 $ctid = attr($value['id']);
302 $ctmask = attr($value['mask']);
303 echo " if (ctid == '$ctid') return '$ctmask';\n";
312 <body
class="body_top" >
314 <?php
if ($GLOBALS['concurrent_layout']) {
316 <a href
='patient_encounter.php?codefrom=superbill' target
='Main'>
317 <span
class='title'><?php
echo xlt('Superbill Codes'); ?
></span
>
318 <font
class='more'><?php
echo text($tback);?
></font
></a
>
321 <form method
='post' action
='superbill_custom_full.php' name
='theform'>
323 <input type
='hidden' name
='mode' value
=''>
328 <table border
='0' cellpadding
='0' cellspacing
='0'>
331 <td colspan
="3"> <?php
echo xlt('Not all fields are required for all codes or code types.'); ?
><br
><br
></td
>
335 <td
><?php
echo xlt('Type'); ?
>:</td
>
340 <?php
if ($mode != "modify") { ?
>
341 <select name
="code_type">
344 <?php
$external_sets = array(); ?
>
345 <?php
foreach ($code_types as $key => $value) { ?
>
346 <?php
if ( !($value['external']) ) { ?
>
347 <?php
if ($mode != "modify") { ?
>
348 <option value
="<?php echo attr($value['id']) ?>"<?php
if ($code_type == $value['id']) echo " selected" ?
>><?php
echo xlt($value['label']) ?
></option
>
351 <?php
if ($value['external']) {
352 array_push($external_sets,$key);
354 <?php
} // end foreach ?>
356 <?php
if ($mode != "modify") { ?
>
360 <?php
if ($mode == "modify") { ?
>
361 <input type
='text' size
='4' name
='code_type' readonly
='readonly' style
='display:none' value
='<?php echo attr($code_type) ?>' />
362 <?php
echo attr($code_type_name_external) ?
>
366 <?php
echo xlt('Code'); ?
>:
368 <?php
if ($mode == "modify") { ?
>
369 <input type
='text' size
='6' name
='code' readonly
='readonly' value
='<?php echo attr($code) ?>' />
371 <input type
='text' size
='6' name
='code' value
='<?php echo attr($code) ?>'
372 onkeyup
='maskkeyup(this,getCTMask())'
373 onblur
='maskblur(this,getCTMask())'
377 <?php
if (modifiers_are_used()) { ?
>
378  
; 
;<?php
echo xlt('Modifier'); ?
>:
379 <?php
if ($mode == "modify") { ?
>
380 <input type
='text' size
='3' name
='modifier' readonly
='readonly' value
='<?php echo attr($modifier) ?>'>
382 <input type
='text' size
='3' name
='modifier' value
='<?php echo attr($modifier) ?>'>
385 <input type
='hidden' name
='modifier' value
=''>
389 <input type
='checkbox' name
='active' value
='1'<?php
if (!empty($active) ||
($mode == 'modify' && $active == NULL) ) echo ' checked'; ?
> />
390 <?php
echo xlt('Active'); ?
>
395 <td
><?php
echo xlt('Description'); ?
>:</td
>
399 <?php
if ($mode == "modify") { ?
>
400 <input type
='text' size
='50' name
="code_text" readonly
="readonly" value
='<?php echo attr($code_text) ?>'>
402 <input type
='text' size
='50' name
="code_text" value
='<?php echo attr($code_text) ?>'>
409 <td
><?php
echo xlt('Category'); ?
>:</td
>
413 generate_form_field(array('data_type'=>1,'field_id'=>'superbill','list_id'=>'superbill'), $superbill);
416 <input type
='checkbox' name
='reportable' value
='1'<?php
if (!empty($reportable)) echo ' checked'; ?
> />
417 <?php
echo xlt('Reportable'); ?
>
421 <tr
<?php
if (empty($GLOBALS['ippf_specific'])) echo " style='display:none'"; ?
>>
422 <td
><?php
echo xlt('CYP Factor'); ?
>:</td
>
425 <input type
='text' size
='10' maxlength
='20' name
="cyp_factor" value
='<?php echo attr($cyp_factor) ?>'>
429 <tr
<?php
if (!related_codes_are_used()) echo " style='display:none'"; ?
>>
430 <td
><?php
echo xlt('Relate To'); ?
>:</td
>
433 <input type
='text' size
='50' name
='related_desc'
434 value
='<?php echo attr($related_desc) ?>' onclick
="sel_related()"
435 title
='<?php echo xla('Click to select related code
'); ?>' readonly
/>
436 <input type
='hidden' name
='related_code' value
='<?php echo attr($related_code) ?>' />
441 <td
><?php
echo xlt('Fees'); ?
>:</td
>
445 $pres = sqlStatement("SELECT lo.option_id, lo.title, p.pr_price " .
446 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
447 "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
448 "WHERE list_id = 'pricelevel' ORDER BY lo.seq", array($code_id) );
449 for ($i = 0; $prow = sqlFetchArray($pres); ++
$i) {
450 if ($i) echo " ";
451 echo text(xl_list_label($prow['title'])) . " ";
452 echo "<input type='text' size='6' name='fee[" . attr($prow['option_id']) . "]' " .
453 "value='" . attr($prow['pr_price']) . "' >\n";
461 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
462 "WHERE list_id = 'taxrate' ORDER BY seq");
463 while ($prow = sqlFetchArray($pres)) {
464 if ($taxline) $taxline .= " ";
465 $taxline .= "<input type='checkbox' name='taxrate[" . attr($prow['option_id']) . "]' value='1'";
466 if (strpos(":$taxrates", $prow['option_id']) !== false) $taxline .= " checked";
468 $taxline .= text(xl_list_label($prow['title'])) . "\n";
473 <td
><?php
echo xlt('Taxes'); ?
>:</td
>
476 <?php
echo $taxline ?
>
482 <td colspan
="3" align
="center">
483 <input type
="hidden" name
="code_id" value
="<?php echo attr($code_id) ?>"><br
>
484 <input type
="hidden" name
="code_type_name_external" value
="<?php echo attr($code_type_name_external) ?>">
485 <input type
="hidden" name
="code_external" value
="<?php echo attr($code_external) ?>">
486 <?php
if ($mode == "modify") { ?
>
487 <a href
='javascript:submitModifyComplete();' class='link'>[<?php
echo xlt('Update'); ?
>]</a
>
489 <a href
='javascript:submitUpdate();' class='link'>[<?php
echo xlt('Update'); ?
>]</a
>
491 <a href
='javascript:submitAdd();' class='link'>[<?php
echo xlt('Add as New'); ?
>]</a
>
498 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
502 <select name
='filter' onchange
='submitList(0)'>
504 <?php
$all_string = xlt("All");
505 if ( !(empty($external_sets) )) {
506 // Show the external code sets that will not work with All selection
507 $all_string .= " (" . xlt("Except") . " ";
509 foreach ($external_sets as $set) {
510 if ($first_flag) { //deal with the comma
516 $all_string .= $code_types[$set]['label'];
524 foreach ($code_types as $key => $value) {
525 echo "<option value='" . attr($value['id']) . "'";
526 if ($value['id'] == $filter) echo " selected";
527 echo ">" . xlt($value['label']) . "</option>\n";
531  
; 
; 
; 
;
533 <input type
="text" name
="search" size
="5" value
="<?php echo attr($search) ?>"> 
;
534 <input type
="submit" name
="go" value
='<?php echo xla('Search
'); ?>'>
535 <input type
='hidden' name
='fstart' value
='<?php echo attr($fstart) ?>'>
538 <td
class='text' align
='right'>
539 <?php
if ($fstart) { ?
>
540 <a href
="javascript:submitList(-<?php echo attr($pagesize) ?>)">
545 <?php
echo ($fstart +
1) . " - $fend of $count" ?
>
547 <a href
="javascript:submitList(<?php echo attr($pagesize) ?>)">
557 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
559 <td
><span
class='bold'><?php
echo xlt('Code'); ?
></span
></td
>
560 <td
><span
class='bold'><?php
echo xlt('Mod'); ?
></span
></td
>
561 <td
><span
class='bold'><?php
echo xlt('Act'); ?
></span
></td
>
562 <td
><span
class='bold'><?php
echo xlt('Rep'); ?
></span
></td
>
563 <td
><span
class='bold'><?php
echo xlt('Type'); ?
></span
></td
>
564 <td
><span
class='bold'><?php
echo xlt('Description'); ?
></span
></td
>
565 <?php
if (related_codes_are_used()) { ?
>
566 <td
><span
class='bold'><?php
echo xlt('Related'); ?
></span
></td
>
569 $pres = sqlStatement("SELECT title FROM list_options " .
570 "WHERE list_id = 'pricelevel' ORDER BY seq");
571 while ($prow = sqlFetchArray($pres)) {
572 echo " <td class='bold' align='right' nowrap>" . text(xl_list_label($prow['title'])) . "</td>\n";
579 // Flag is this is from an external set
580 $is_external_set=false;
581 if (in_array($filter_key,$external_sets)) {
582 $is_external_set=true;
586 $res = code_set_search($filter_key,$search,false,false,false,$fstart,($fend - $fstart));
589 $res = code_set_search("--ALL--",$search,false,false,false,$fstart,($fend - $fstart));
592 for ($i = 0; $row = sqlFetchArray($res); $i++
) $all[$i] = $row;
596 foreach($all as $iter) {
600 foreach ($code_types as $key => $value) {
601 if ($value['id'] == $iter['code_type']) {
602 $has_fees = $value['fee'];
608 echo " <td class='text'>" . text($iter["code"]) . "</td>\n";
609 echo " <td class='text'>" . text($iter["modifier"]) . "</td>\n";
610 if ($is_external_set) {
611 echo " <td class='text'>" . ( ($iter["active"] ||
$iter["active"]==NULL) ?
xlt('Yes') : xlt('No')) . "</td>\n";
614 echo " <td class='text'>" . ( ($iter["active"]) ?
xlt('Yes') : xlt('No')) . "</td>\n";
616 echo " <td class='text'>" . ($iter["reportable"] ?
xlt('Yes') : xlt('No')) . "</td>\n";
617 echo " <td class='text'>" . text($iter['code_type_name']) . "</td>\n";
618 echo " <td class='text'>" . text($iter['code_text']) . "</td>\n";
620 if (related_codes_are_used()) {
621 // Show related codes.
622 echo " <td class='text'>";
623 $arel = explode(';', $iter['related_code']);
624 foreach ($arel as $tmp) {
625 list($reltype, $relcode) = explode(':', $tmp);
626 $code_description = lookup_code_descriptions($reltype.":".$relcode);
627 echo text($relcode) . ' ' . text(trim($code_description)) . '<br />';
632 $pres = sqlStatement("SELECT p.pr_price " .
633 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
634 "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
635 "WHERE list_id = 'pricelevel' ORDER BY lo.seq", array($iter['id']) );
636 while ($prow = sqlFetchArray($pres)) {
637 echo "<td class='text' align='right'>" . text(bucks($prow['pr_price'])) . "</td>\n";
640 if ($is_external_set) {
641 echo " <td align='right'><a class='link' href='javascript:submitModify(\"" . attr($iter['code_type_name']) . "\",\"" . attr($iter['code']) . "\",\"" . attr($iter['id']) . "\")'>[" . xlt('Modify') . "]</a></td>\n";
644 echo " <td align='right'><a class='link' href='javascript:submitDelete(" . attr($iter['id']) . ")'>[" . xlt('Delete') . "]</a></td>\n";
645 echo " <td align='right'><a class='link' href='javascript:submitEdit(" . attr($iter['id']) . ")'>[" . xlt('Edit') . "]</a></td>\n";
659 <script language
="JavaScript">
662 echo "alert('" . addslashes($alertmsg) . "');\n";