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'];
40 $financial_reporting = 0;
43 $code_id = empty($_POST['code_id']) ?
'' : $_POST['code_id'] +
0;
44 $code = $_POST['code'];
45 $code_type = $_POST['code_type'];
46 $code_text = $_POST['code_text'];
47 $modifier = $_POST['modifier'];
48 $superbill = $_POST['form_superbill'];
49 $related_code = $_POST['related_code'];
50 $cyp_factor = $_POST['cyp_factor'] +
0;
51 $active = empty($_POST['active']) ?
0 : 1;
52 $reportable = empty($_POST['reportable']) ?
0 : 1; // dx reporting
53 $financial_reporting = empty($_POST['financial_reporting']) ?
0 : 1; // financial service reporting
56 if (!empty($_POST['taxrate'])) {
57 foreach ($_POST['taxrate'] as $key => $value) {
62 if ($mode == "delete") {
63 sqlStatement("DELETE FROM codes WHERE id = ?", array($code_id) );
66 else if ($mode == "add" ||
$mode == "modify_complete") { // this covers both adding and modifying
67 $crow = sqlQuery("SELECT COUNT(*) AS count FROM codes WHERE " .
68 "code_type = '" . ffescape($code_type) . "' AND " .
69 "code = '" . ffescape($code) . "' AND " .
70 "modifier = '" . ffescape($modifier) . "' AND " .
71 "id != '" . add_escape_custom($code_id) . "'");
73 $alertmsg = xl('Cannot add/update this entry because a duplicate already exists!');
77 "code = '" . ffescape($code) . "', " .
78 "code_type = '" . ffescape($code_type) . "', " .
79 "code_text = '" . ffescape($code_text) . "', " .
80 "modifier = '" . ffescape($modifier) . "', " .
81 "superbill = '" . ffescape($superbill) . "', " .
82 "related_code = '" . ffescape($related_code) . "', " .
83 "cyp_factor = '" . ffescape($cyp_factor) . "', " .
84 "taxrates = '" . ffescape($taxrates) . "', " .
85 "active = " . add_escape_custom($active) . ", " .
86 "financial_reporting = " . add_escape_custom($financial_reporting) . ", " .
87 "reportable = " . add_escape_custom($reportable);
89 $query = "UPDATE codes SET $sql WHERE id = ?";
90 sqlStatement($query, array($code_id) );
91 sqlStatement("DELETE FROM prices WHERE pr_id = ? AND " .
92 "pr_selector = ''", array($code_id) );
95 $code_id = sqlInsert("INSERT INTO codes SET $sql");
98 foreach ($_POST['fee'] as $key => $value) {
101 sqlStatement("INSERT INTO prices ( " .
102 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
103 "?, '', ?, ?)", array($code_id,$key,$value) );
106 $code = $code_type = $code_text = $modifier = $superbill = "";
116 else if ($mode == "edit") { // someone clicked [Edit]
117 $sql = "SELECT * FROM codes WHERE id = ?";
118 $results = sqlStatement($sql, array($code_id) );
119 while ($row = sqlFetchArray($results)) {
120 $code = $row['code'];
121 $code_text = $row['code_text'];
122 $code_type = $row['code_type'];
123 $modifier = $row['modifier'];
124 // $units = $row['units'];
125 $superbill = $row['superbill'];
126 $related_code = $row['related_code'];
127 $cyp_factor = $row['cyp_factor'];
128 $taxrates = $row['taxrates'];
129 $active = 0 +
$row['active'];
130 $reportable = 0 +
$row['reportable'];
131 $financial_reporting = 0 +
$row['financial_reporting'];
134 else if ($mode == "modify") { // someone clicked [Modify]
135 // this is to modify external code types, of which the modifications
136 // are stored in the codes table
137 $code_type_name_external = $_POST['code_type_name_external'];
138 $code_external = $_POST['code_external'];
139 $code_id = $_POST['code_id'];
140 $results = code_set_search($code_type_name_external,$code_external,false,false,true); // only will return one item
141 while ($row = sqlFetchArray($results)) {
142 $code = $row['code'];
143 $code_text = $row['code_text'];
144 $code_type = $code_types[$code_type_name_external]['id'];
145 $modifier = $row['modifier'];
146 // $units = $row['units'];
147 $superbill = $row['superbill'];
148 $related_code = $row['related_code'];
149 $cyp_factor = $row['cyp_factor'];
150 $taxrates = $row['taxrates'];
151 $active = $row['active'];
152 $reportable = $row['reportable'];
153 $financial_reporting = $row['financial_reporting'];
159 if (!empty($related_code)) {
160 $related_desc = $related_code;
163 $fstart = $_REQUEST['fstart'] +
0;
164 $filter = $_REQUEST['filter'] +
0;
166 $filter_key = convert_type_id_to_key($filter);
168 $search = $_REQUEST['search'];
169 $search_reportable = $_REQUEST['search_reportable'];
170 $search_financial_reporting = $_REQUEST['search_financial_reporting'];
172 //Build the filter_elements array
173 $filter_elements = array();
174 if (!empty($search_reportable)) {
175 $filter_elements['reportable'] = $search_reportable;
177 if (!empty($search_financial_reporting)) {
178 $filter_elements['financial_reporting'] = $search_financial_reporting;
182 $count = sequential_code_set_search($filter_key,$search,NULL,NULL,true,false,NULL,NULL,$filter_elements);
185 $count = sequential_code_set_search("--ALL--",$search,NULL,NULL,true,false,NULL,NULL,$filter_elements);
187 if ($fstart >= $count) $fstart -= $pagesize;
188 if ($fstart < 0) $fstart = 0;
189 $fend = $fstart +
$pagesize;
190 if ($fend > $count) $fend = $count;
195 <?php
html_header_show(); ?
>
196 <link rel
="stylesheet" href
="<?php echo attr($css_header);?>" type
="text/css">
197 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
198 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
200 <script language
="JavaScript">
202 // This is for callback by the find-code popup.
203 // Appends to or erases the current list of related codes.
204 function set_related(codetype
, code
, selector
, codedesc
) {
205 var f
= document
.forms
[0];
206 var s
= f
.related_code
.value
;
208 if (s
.length
> 0) s +
= ';';
209 s +
= codetype +
':' + code
;
213 f
.related_code
.value
= s
;
214 f
.related_desc
.value
= s
;
217 // This invokes the find-code popup.
218 function sel_related() {
219 var f
= document
.forms
[0];
220 var i
= f
.code_type
.selectedIndex
;
223 var myid
= f
.code_type
.options
[i
].value
;
225 foreach ($code_types as $key => $value) {
226 $codeid = $value['id'];
227 $coderel = $value['rel'];
228 if (!$coderel) continue;
229 echo " if (myid == $codeid) codetype = '$coderel';";
234 alert('<?php echo addslashes( xl('This code type does not accept relations
.') ); ?>');
237 dlgopen('find_code_popup.php', '_blank', 500, 400);
240 // Some validation for saving a new code entry.
241 function validEntry(f
) {
243 alert('<?php echo addslashes( xl('No code was specified
!') ); ?>');
246 <?php
if ($GLOBALS['ippf_specific']) { ?
>
247 if (f
.code_type
.value
== 12 && !f
.related_code
.value
) {
248 alert('<?php echo addslashes( xl('A related IPPF code is required
!') ); ?>');
255 function submitAdd() {
256 var f
= document
.forms
[0];
257 if (!validEntry(f
)) return;
258 f
.mode
.value
= 'add';
259 f
.code_id
.value
= '';
263 function submitUpdate() {
264 var f
= document
.forms
[0];
265 if (! parseInt(f
.code_id
.value
)) {
266 alert('<?php echo addslashes( xl('Cannot update because you are not editing an existing entry
!') ); ?>');
269 if (!validEntry(f
)) return;
270 f
.mode
.value
= 'add';
274 function submitModifyComplete() {
275 var f
= document
.forms
[0];
276 f
.mode
.value
= 'modify_complete';
280 function submitList(offset
) {
281 var f
= document
.forms
[0];
282 var i
= parseInt(f
.fstart
.value
) + offset
;
288 function submitEdit(id
) {
289 var f
= document
.forms
[0];
290 f
.mode
.value
= 'edit';
291 f
.code_id
.value
= id
;
295 function submitModify(code_type_name
,code
,id
) {
296 var f
= document
.forms
[0];
297 f
.mode
.value
= 'modify';
298 f
.code_external
.value
= code
;
299 f
.code_id
.value
= id
;
300 f
.code_type_name_external
.value
= code_type_name
;
306 function submitDelete(id
) {
307 var f
= document
.forms
[0];
308 f
.mode
.value
= 'delete';
309 f
.code_id
.value
= id
;
313 function getCTMask() {
314 var ctid
= document
.forms
[0].code_type
.value
;
316 foreach ($code_types as $key => $value) {
317 $ctid = attr($value['id']);
318 $ctmask = attr($value['mask']);
319 echo " if (ctid == '$ctid') return '$ctmask';\n";
328 <body
class="body_top" >
330 <?php
if ($GLOBALS['concurrent_layout']) {
332 <a href
='patient_encounter.php?codefrom=superbill' target
='Main'>
333 <span
class='title'><?php
echo xlt('Superbill Codes'); ?
></span
>
334 <font
class='more'><?php
echo text($tback);?
></font
></a
>
337 <form method
='post' action
='superbill_custom_full.php' name
='theform'>
339 <input type
='hidden' name
='mode' value
=''>
344 <table border
='0' cellpadding
='0' cellspacing
='0'>
347 <td colspan
="3"> <?php
echo xlt('Not all fields are required for all codes or code types.'); ?
><br
><br
></td
>
351 <td
><?php
echo xlt('Type'); ?
>:</td
>
356 <?php
if ($mode != "modify") { ?
>
357 <select name
="code_type">
360 <?php
$external_sets = array(); ?
>
361 <?php
foreach ($code_types as $key => $value) { ?
>
362 <?php
if ( !($value['external']) ) { ?
>
363 <?php
if ($mode != "modify") { ?
>
364 <option value
="<?php echo attr($value['id']) ?>"<?php
if ($code_type == $value['id']) echo " selected" ?
>><?php
echo xlt($value['label']) ?
></option
>
367 <?php
if ($value['external']) {
368 array_push($external_sets,$key);
370 <?php
} // end foreach ?>
372 <?php
if ($mode != "modify") { ?
>
376 <?php
if ($mode == "modify") { ?
>
377 <input type
='text' size
='4' name
='code_type' readonly
='readonly' style
='display:none' value
='<?php echo attr($code_type) ?>' />
378 <?php
echo attr($code_type_name_external) ?
>
382 <?php
echo xlt('Code'); ?
>:
384 <?php
if ($mode == "modify") { ?
>
385 <input type
='text' size
='6' name
='code' readonly
='readonly' value
='<?php echo attr($code) ?>' />
387 <input type
='text' size
='6' name
='code' value
='<?php echo attr($code) ?>'
388 onkeyup
='maskkeyup(this,getCTMask())'
389 onblur
='maskblur(this,getCTMask())'
393 <?php
if (modifiers_are_used()) { ?
>
394  
; 
;<?php
echo xlt('Modifier'); ?
>:
395 <?php
if ($mode == "modify") { ?
>
396 <input type
='text' size
='3' name
='modifier' readonly
='readonly' value
='<?php echo attr($modifier) ?>'>
398 <input type
='text' size
='3' name
='modifier' value
='<?php echo attr($modifier) ?>'>
401 <input type
='hidden' name
='modifier' value
=''>
405 <input type
='checkbox' name
='active' value
='1'<?php
if (!empty($active) ||
($mode == 'modify' && $active == NULL) ) echo ' checked'; ?
> />
406 <?php
echo xlt('Active'); ?
>
411 <td
><?php
echo xlt('Description'); ?
>:</td
>
415 <?php
if ($mode == "modify") { ?
>
416 <input type
='text' size
='50' name
="code_text" readonly
="readonly" value
='<?php echo attr($code_text) ?>'>
418 <input type
='text' size
='50' name
="code_text" value
='<?php echo attr($code_text) ?>'>
425 <td
><?php
echo xlt('Category'); ?
>:</td
>
429 generate_form_field(array('data_type'=>1,'field_id'=>'superbill','list_id'=>'superbill'), $superbill);
432 <input type
='checkbox' title
='<?php echo xlt("Syndromic Surveillance Report") ?>' name
='reportable' value
='1'<?php
if (!empty($reportable)) echo ' checked'; ?
> />
433 <?php
echo xlt('Diagnosis Reporting'); ?
>
434  
; 
; 
; 
;
435 <input type
='checkbox' title
='<?php echo xlt("Service Code Finance Reporting") ?>' name
='financial_reporting' value
='1'<?php
if (!empty($financial_reporting)) echo ' checked'; ?
> />
436 <?php
echo xlt('Service Reporting'); ?
>
440 <tr
<?php
if (empty($GLOBALS['ippf_specific'])) echo " style='display:none'"; ?
>>
441 <td
><?php
echo xlt('CYP Factor'); ?
>:</td
>
444 <input type
='text' size
='10' maxlength
='20' name
="cyp_factor" value
='<?php echo attr($cyp_factor) ?>'>
448 <tr
<?php
if (!related_codes_are_used()) echo " style='display:none'"; ?
>>
449 <td
><?php
echo xlt('Relate To'); ?
>:</td
>
452 <input type
='text' size
='50' name
='related_desc'
453 value
='<?php echo attr($related_desc) ?>' onclick
="sel_related()"
454 title
='<?php echo xla('Click to select related code
'); ?>' readonly
/>
455 <input type
='hidden' name
='related_code' value
='<?php echo attr($related_code) ?>' />
460 <td
><?php
echo xlt('Fees'); ?
>:</td
>
464 $pres = sqlStatement("SELECT lo.option_id, lo.title, p.pr_price " .
465 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
466 "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
467 "WHERE list_id = 'pricelevel' ORDER BY lo.seq", array($code_id) );
468 for ($i = 0; $prow = sqlFetchArray($pres); ++
$i) {
469 if ($i) echo " ";
470 echo text(xl_list_label($prow['title'])) . " ";
471 echo "<input type='text' size='6' name='fee[" . attr($prow['option_id']) . "]' " .
472 "value='" . attr($prow['pr_price']) . "' >\n";
480 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
481 "WHERE list_id = 'taxrate' ORDER BY seq");
482 while ($prow = sqlFetchArray($pres)) {
483 if ($taxline) $taxline .= " ";
484 $taxline .= "<input type='checkbox' name='taxrate[" . attr($prow['option_id']) . "]' value='1'";
485 if (strpos(":$taxrates", $prow['option_id']) !== false) $taxline .= " checked";
487 $taxline .= text(xl_list_label($prow['title'])) . "\n";
492 <td
><?php
echo xlt('Taxes'); ?
>:</td
>
495 <?php
echo $taxline ?
>
501 <td colspan
="3" align
="center">
502 <input type
="hidden" name
="code_id" value
="<?php echo attr($code_id) ?>"><br
>
503 <input type
="hidden" name
="code_type_name_external" value
="<?php echo attr($code_type_name_external) ?>">
504 <input type
="hidden" name
="code_external" value
="<?php echo attr($code_external) ?>">
505 <?php
if ($mode == "modify") { ?
>
506 <a href
='javascript:submitModifyComplete();' class='link'>[<?php
echo xlt('Update'); ?
>]</a
>
508 <a href
='javascript:submitUpdate();' class='link'>[<?php
echo xlt('Update'); ?
>]</a
>
510 <a href
='javascript:submitAdd();' class='link'>[<?php
echo xlt('Add as New'); ?
>]</a
>
517 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
521 <select name
='filter' onchange
='submitList(0)'>
523 <?php
$all_string = xlt("All");
524 if ( !(empty($external_sets) )) {
525 // Show the external code sets that will not work with All selection
526 $all_string .= " (" . xlt("Except") . " ";
528 foreach ($external_sets as $set) {
529 if ($first_flag) { //deal with the comma
535 $all_string .= xlt($code_types[$set]['label']);
543 foreach ($code_types as $key => $value) {
544 echo "<option value='" . attr($value['id']) . "'";
545 if ($value['id'] == $filter) echo " selected";
546 echo ">" . xlt($value['label']) . "</option>\n";
550  
; 
; 
; 
;
552 <input type
="text" name
="search" size
="5" value
="<?php echo attr($search) ?>"> 
;
553 <input type
="submit" name
="go" value
='<?php echo xla('Search
'); ?>'> 
; 
;
554 <input type
='checkbox' title
='<?php echo xlt("Only Show Diagnosis Reporting Codes") ?>' name
='search_reportable' value
='1'<?php
if (!empty($search_reportable)) echo ' checked'; ?
> />
555 <?php
echo xlt('Diagnosis Reporting Only'); ?
>
556  
; 
; 
; 
;
557 <input type
='checkbox' title
='<?php echo xlt("Only Show Service Code Finance Reporting Codes") ?>' name
='search_financial_reporting' value
='1'<?php
if (!empty($search_financial_reporting)) echo ' checked'; ?
> />
558 <?php
echo xlt('Service Reporting Only'); ?
>
559 <input type
='hidden' name
='fstart' value
='<?php echo attr($fstart) ?>'>
562 <td
class='text' align
='right'>
563 <?php
if ($fstart) { ?
>
564 <a href
="javascript:submitList(-<?php echo attr($pagesize) ?>)">
569 <?php
echo ($fstart +
1) . " - $fend of $count" ?
>
571 <a href
="javascript:submitList(<?php echo attr($pagesize) ?>)">
581 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
583 <td
><span
class='bold'><?php
echo xlt('Code'); ?
></span
></td
>
584 <td
><span
class='bold'><?php
echo xlt('Mod'); ?
></span
></td
>
585 <td
><span
class='bold'><?php
echo xlt('Act'); ?
></span
></td
>
586 <td
><span
class='bold'><?php
echo xlt('Dx Rep'); ?
></span
></td
>
587 <td
><span
class='bold'><?php
echo xlt('Serv Rep'); ?
></span
></td
>
588 <td
><span
class='bold'><?php
echo xlt('Type'); ?
></span
></td
>
589 <td
><span
class='bold'><?php
echo xlt('Description'); ?
></span
></td
>
590 <?php
if (related_codes_are_used()) { ?
>
591 <td
><span
class='bold'><?php
echo xlt('Related'); ?
></span
></td
>
594 $pres = sqlStatement("SELECT title FROM list_options " .
595 "WHERE list_id = 'pricelevel' ORDER BY seq");
596 while ($prow = sqlFetchArray($pres)) {
597 echo " <td class='bold' align='right' nowrap>" . text(xl_list_label($prow['title'])) . "</td>\n";
604 // Flag is this is from an external set
605 $is_external_set=false;
606 if (in_array($filter_key,$external_sets)) {
607 $is_external_set=true;
611 $res = sequential_code_set_search($filter_key,$search,NULL,NULL,false,false,$fstart,($fend - $fstart),$filter_elements);
614 $res = sequential_code_set_search("--ALL--",$search,NULL,NULL,false,false,$fstart,($fend - $fstart),$filter_elements);
617 for ($i = 0; $row = sqlFetchArray($res); $i++
) $all[$i] = $row;
621 foreach($all as $iter) {
625 foreach ($code_types as $key => $value) {
626 if ($value['id'] == $iter['code_type']) {
627 $has_fees = $value['fee'];
633 echo " <td class='text'>" . text($iter["code"]) . "</td>\n";
634 echo " <td class='text'>" . text($iter["modifier"]) . "</td>\n";
635 if ($is_external_set) {
636 // If there is no entry in codes sql table, then default to active
637 // (this is reason for including NULL below)
638 echo " <td class='text'>" . ( ($iter["active"] ||
$iter["active"]==NULL) ?
xlt('Yes') : xlt('No')) . "</td>\n";
641 echo " <td class='text'>" . ( ($iter["active"]) ?
xlt('Yes') : xlt('No')) . "</td>\n";
643 echo " <td class='text'>" . ($iter["reportable"] ?
xlt('Yes') : xlt('No')) . "</td>\n";
644 echo " <td class='text'>" . ($iter["financial_reporting"] ?
xlt('Yes') : xlt('No')) . "</td>\n";
645 echo " <td class='text'>" . text($iter['code_type_name']) . "</td>\n";
646 echo " <td class='text'>" . text($iter['code_text']) . "</td>\n";
648 if (related_codes_are_used()) {
649 // Show related codes.
650 echo " <td class='text'>";
651 $arel = explode(';', $iter['related_code']);
652 foreach ($arel as $tmp) {
653 list($reltype, $relcode) = explode(':', $tmp);
654 $code_description = lookup_code_descriptions($reltype.":".$relcode);
655 echo text($relcode) . ' ' . text(trim($code_description)) . '<br />';
660 $pres = sqlStatement("SELECT p.pr_price " .
661 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
662 "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
663 "WHERE list_id = 'pricelevel' ORDER BY lo.seq", array($iter['id']) );
664 while ($prow = sqlFetchArray($pres)) {
665 echo "<td class='text' align='right'>" . text(bucks($prow['pr_price'])) . "</td>\n";
668 if ($is_external_set) {
669 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";
672 echo " <td align='right'><a class='link' href='javascript:submitDelete(" . attr($iter['id']) . ")'>[" . xlt('Delete') . "]</a></td>\n";
673 echo " <td align='right'><a class='link' href='javascript:submitEdit(" . attr($iter['id']) . ")'>[" . xlt('Edit') . "]</a></td>\n";
687 <script language
="JavaScript">
690 echo "alert('" . addslashes($alertmsg) . "');\n";