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 = return_code_information($code_type_name_external,$code_external,false); // 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 if (isset($_REQUEST['filter'])) {
166 $filter_key = array();
167 foreach ($_REQUEST['filter'] as $var) {
169 array_push($filter,$var);
170 $var_key = convert_type_id_to_key($var);
171 array_push($filter_key,$var_key);
174 $search = $_REQUEST['search'];
175 $search_reportable = $_REQUEST['search_reportable'];
176 $search_financial_reporting = $_REQUEST['search_financial_reporting'];
178 //Build the filter_elements array
179 $filter_elements = array();
180 if (!empty($search_reportable)) {
181 $filter_elements['reportable'] = $search_reportable;
183 if (!empty($search_financial_reporting)) {
184 $filter_elements['financial_reporting'] = $search_financial_reporting;
187 if (isset($_REQUEST['filter'])) {
188 $count = main_code_set_search($filter_key,$search,NULL,NULL,false,NULL,true,NULL,NULL,$filter_elements);
191 if ($fstart >= $count) $fstart -= $pagesize;
192 if ($fstart < 0) $fstart = 0;
193 $fend = $fstart +
$pagesize;
194 if ($fend > $count) $fend = $count;
199 <?php
html_header_show(); ?
>
200 <link rel
="stylesheet" href
="<?php echo attr($css_header);?>" type
="text/css">
201 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
202 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
204 <script language
="JavaScript">
206 // This is for callback by the find-code popup.
207 // Appends to or erases the current list of related codes.
208 function set_related(codetype
, code
, selector
, codedesc
) {
209 var f
= document
.forms
[0];
210 var s
= f
.related_code
.value
;
212 if (s
.length
> 0) s +
= ';';
213 s +
= codetype +
':' + code
;
217 f
.related_code
.value
= s
;
218 f
.related_desc
.value
= s
;
221 // This invokes the find-code popup.
222 function sel_related() {
223 var f
= document
.forms
[0];
224 var i
= f
.code_type
.selectedIndex
;
227 var myid
= f
.code_type
.options
[i
].value
;
229 foreach ($code_types as $key => $value) {
230 $codeid = $value['id'];
231 $coderel = $value['rel'];
232 if (!$coderel) continue;
233 echo " if (myid == $codeid) codetype = '$coderel';";
238 alert('<?php echo addslashes( xl('This code type does not accept relations
.') ); ?>');
241 dlgopen('find_code_popup.php', '_blank', 500, 400);
244 // Some validation for saving a new code entry.
245 function validEntry(f
) {
247 alert('<?php echo addslashes( xl('No code was specified
!') ); ?>');
250 <?php
if ($GLOBALS['ippf_specific']) { ?
>
251 if (f
.code_type
.value
== 12 && !f
.related_code
.value
) {
252 alert('<?php echo addslashes( xl('A related IPPF code is required
!') ); ?>');
259 function submitAdd() {
260 var f
= document
.forms
[0];
261 if (!validEntry(f
)) return;
262 f
.mode
.value
= 'add';
263 f
.code_id
.value
= '';
267 function submitUpdate() {
268 var f
= document
.forms
[0];
269 if (! parseInt(f
.code_id
.value
)) {
270 alert('<?php echo addslashes( xl('Cannot update because you are not editing an existing entry
!') ); ?>');
273 if (!validEntry(f
)) return;
274 f
.mode
.value
= 'add';
278 function submitModifyComplete() {
279 var f
= document
.forms
[0];
280 f
.mode
.value
= 'modify_complete';
284 function submitList(offset
) {
285 var f
= document
.forms
[0];
286 var i
= parseInt(f
.fstart
.value
) + offset
;
292 function submitEdit(id
) {
293 var f
= document
.forms
[0];
294 f
.mode
.value
= 'edit';
295 f
.code_id
.value
= id
;
299 function submitModify(code_type_name
,code
,id
) {
300 var f
= document
.forms
[0];
301 f
.mode
.value
= 'modify';
302 f
.code_external
.value
= code
;
303 f
.code_id
.value
= id
;
304 f
.code_type_name_external
.value
= code_type_name
;
310 function submitDelete(id
) {
311 var f
= document
.forms
[0];
312 f
.mode
.value
= 'delete';
313 f
.code_id
.value
= id
;
317 function getCTMask() {
318 var ctid
= document
.forms
[0].code_type
.value
;
320 foreach ($code_types as $key => $value) {
321 $ctid = attr($value['id']);
322 $ctmask = attr($value['mask']);
323 echo " if (ctid == '$ctid') return '$ctmask';\n";
332 <body
class="body_top" >
334 <?php
if ($GLOBALS['concurrent_layout']) {
336 <a href
='patient_encounter.php?codefrom=superbill' target
='Main'>
337 <span
class='title'><?php
echo xlt('Superbill Codes'); ?
></span
>
338 <font
class='more'><?php
echo text($tback);?
></font
></a
>
341 <form method
='post' action
='superbill_custom_full.php' name
='theform'>
343 <input type
='hidden' name
='mode' value
=''>
348 <table border
='0' cellpadding
='0' cellspacing
='0'>
351 <td colspan
="3"> <?php
echo xlt('Not all fields are required for all codes or code types.'); ?
><br
><br
></td
>
355 <td
><?php
echo xlt('Type'); ?
>:</td
>
360 <?php
if ($mode != "modify") { ?
>
361 <select name
="code_type">
364 <?php
$external_sets = array(); ?
>
365 <?php
foreach ($code_types as $key => $value) { ?
>
366 <?php
if ( !($value['external']) ) { ?
>
367 <?php
if ($mode != "modify") { ?
>
368 <option value
="<?php echo attr($value['id']) ?>"<?php
if ($code_type == $value['id']) echo " selected" ?
>><?php
echo xlt($value['label']) ?
></option
>
371 <?php
if ($value['external']) {
372 array_push($external_sets,$key);
374 <?php
} // end foreach ?>
376 <?php
if ($mode != "modify") { ?
>
380 <?php
if ($mode == "modify") { ?
>
381 <input type
='text' size
='4' name
='code_type' readonly
='readonly' style
='display:none' value
='<?php echo attr($code_type) ?>' />
382 <?php
echo attr($code_type_name_external) ?
>
386 <?php
echo xlt('Code'); ?
>:
388 <?php
if ($mode == "modify") { ?
>
389 <input type
='text' size
='6' name
='code' readonly
='readonly' value
='<?php echo attr($code) ?>' />
391 <input type
='text' size
='6' name
='code' value
='<?php echo attr($code) ?>'
392 onkeyup
='maskkeyup(this,getCTMask())'
393 onblur
='maskblur(this,getCTMask())'
397 <?php
if (modifiers_are_used()) { ?
>
398  
; 
;<?php
echo xlt('Modifier'); ?
>:
399 <?php
if ($mode == "modify") { ?
>
400 <input type
='text' size
='3' name
='modifier' readonly
='readonly' value
='<?php echo attr($modifier) ?>'>
402 <input type
='text' size
='3' name
='modifier' value
='<?php echo attr($modifier) ?>'>
405 <input type
='hidden' name
='modifier' value
=''>
409 <input type
='checkbox' name
='active' value
='1'<?php
if (!empty($active) ||
($mode == 'modify' && $active == NULL) ) echo ' checked'; ?
> />
410 <?php
echo xlt('Active'); ?
>
415 <td
><?php
echo xlt('Description'); ?
>:</td
>
419 <?php
if ($mode == "modify") { ?
>
420 <input type
='text' size
='50' name
="code_text" readonly
="readonly" value
='<?php echo attr($code_text) ?>'>
422 <input type
='text' size
='50' name
="code_text" value
='<?php echo attr($code_text) ?>'>
429 <td
><?php
echo xlt('Category'); ?
>:</td
>
433 generate_form_field(array('data_type'=>1,'field_id'=>'superbill','list_id'=>'superbill'), $superbill);
436 <input type
='checkbox' title
='<?php echo xlt("Syndromic Surveillance Report") ?>' name
='reportable' value
='1'<?php
if (!empty($reportable)) echo ' checked'; ?
> />
437 <?php
echo xlt('Diagnosis Reporting'); ?
>
438  
; 
; 
; 
;
439 <input type
='checkbox' title
='<?php echo xlt("Service Code Finance Reporting") ?>' name
='financial_reporting' value
='1'<?php
if (!empty($financial_reporting)) echo ' checked'; ?
> />
440 <?php
echo xlt('Service Reporting'); ?
>
444 <tr
<?php
if (empty($GLOBALS['ippf_specific'])) echo " style='display:none'"; ?
>>
445 <td
><?php
echo xlt('CYP Factor'); ?
>:</td
>
448 <input type
='text' size
='10' maxlength
='20' name
="cyp_factor" value
='<?php echo attr($cyp_factor) ?>'>
452 <tr
<?php
if (!related_codes_are_used()) echo " style='display:none'"; ?
>>
453 <td
><?php
echo xlt('Relate To'); ?
>:</td
>
456 <input type
='text' size
='50' name
='related_desc'
457 value
='<?php echo attr($related_desc) ?>' onclick
="sel_related()"
458 title
='<?php echo xla('Click to select related code
'); ?>' readonly
/>
459 <input type
='hidden' name
='related_code' value
='<?php echo attr($related_code) ?>' />
464 <td
><?php
echo xlt('Fees'); ?
>:</td
>
468 $pres = sqlStatement("SELECT lo.option_id, lo.title, p.pr_price " .
469 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
470 "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
471 "WHERE list_id = 'pricelevel' ORDER BY lo.seq", array($code_id) );
472 for ($i = 0; $prow = sqlFetchArray($pres); ++
$i) {
473 if ($i) echo " ";
474 echo text(xl_list_label($prow['title'])) . " ";
475 echo "<input type='text' size='6' name='fee[" . attr($prow['option_id']) . "]' " .
476 "value='" . attr($prow['pr_price']) . "' >\n";
484 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
485 "WHERE list_id = 'taxrate' ORDER BY seq");
486 while ($prow = sqlFetchArray($pres)) {
487 if ($taxline) $taxline .= " ";
488 $taxline .= "<input type='checkbox' name='taxrate[" . attr($prow['option_id']) . "]' value='1'";
489 if (strpos(":$taxrates", $prow['option_id']) !== false) $taxline .= " checked";
491 $taxline .= text(xl_list_label($prow['title'])) . "\n";
496 <td
><?php
echo xlt('Taxes'); ?
>:</td
>
499 <?php
echo $taxline ?
>
505 <td colspan
="3" align
="center">
506 <input type
="hidden" name
="code_id" value
="<?php echo attr($code_id) ?>"><br
>
507 <input type
="hidden" name
="code_type_name_external" value
="<?php echo attr($code_type_name_external) ?>">
508 <input type
="hidden" name
="code_external" value
="<?php echo attr($code_external) ?>">
509 <?php
if ($mode == "modify") { ?
>
510 <a href
='javascript:submitModifyComplete();' class='link'>[<?php
echo xlt('Update'); ?
>]</a
>
512 <a href
='javascript:submitUpdate();' class='link'>[<?php
echo xlt('Update'); ?
>]</a
>
514 <a href
='javascript:submitAdd();' class='link'>[<?php
echo xlt('Add as New'); ?
>]</a
>
521 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
525 <select name
='filter[]' multiple
='multiple'>
527 foreach ($code_types as $key => $value) {
528 echo "<option value='" . attr($value['id']) . "'";
529 if (in_array($value['id'],$filter)) echo " selected";
530 echo ">" . xlt($value['label']) . "</option>\n";
534  
; 
; 
; 
;
536 <input type
="text" name
="search" size
="5" value
="<?php echo attr($search) ?>"> 
;
537 <input type
="submit" name
="go" value
='<?php echo xla('Search
'); ?>'> 
; 
;
538 <input type
='checkbox' title
='<?php echo xlt("Only Show Diagnosis Reporting Codes") ?>' name
='search_reportable' value
='1'<?php
if (!empty($search_reportable)) echo ' checked'; ?
> />
539 <?php
echo xlt('Diagnosis Reporting Only'); ?
>
540  
; 
; 
; 
;
541 <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'; ?
> />
542 <?php
echo xlt('Service Reporting Only'); ?
>
543 <input type
='hidden' name
='fstart' value
='<?php echo attr($fstart) ?>'>
546 <td
class='text' align
='right'>
547 <?php
if ($fstart) { ?
>
548 <a href
="javascript:submitList(-<?php echo attr($pagesize) ?>)">
553 <?php
echo ($fstart +
1) . " - $fend of $count" ?
>
555 <a href
="javascript:submitList(<?php echo attr($pagesize) ?>)">
565 <table border
='0' cellpadding
='5' cellspacing
='0' width
='96%'>
567 <td
><span
class='bold'><?php
echo xlt('Code'); ?
></span
></td
>
568 <td
><span
class='bold'><?php
echo xlt('Mod'); ?
></span
></td
>
569 <td
><span
class='bold'><?php
echo xlt('Act'); ?
></span
></td
>
570 <td
><span
class='bold'><?php
echo xlt('Dx Rep'); ?
></span
></td
>
571 <td
><span
class='bold'><?php
echo xlt('Serv Rep'); ?
></span
></td
>
572 <td
><span
class='bold'><?php
echo xlt('Type'); ?
></span
></td
>
573 <td
><span
class='bold'><?php
echo xlt('Description'); ?
></span
></td
>
574 <td
><span
class='bold'><?php
echo xlt('Short Description'); ?
></span
></td
>
575 <?php
if (related_codes_are_used()) { ?
>
576 <td
><span
class='bold'><?php
echo xlt('Related'); ?
></span
></td
>
579 $pres = sqlStatement("SELECT title FROM list_options " .
580 "WHERE list_id = 'pricelevel' ORDER BY seq");
581 while ($prow = sqlFetchArray($pres)) {
582 echo " <td class='bold' align='right' nowrap>" . text(xl_list_label($prow['title'])) . "</td>\n";
590 if (isset($_REQUEST['filter'])) {
591 $res = main_code_set_search($filter_key,$search,NULL,NULL,false,NULL,false,$fstart,($fend - $fstart),$filter_elements);
594 for ($i = 0; $row = sqlFetchArray($res); $i++
) $all[$i] = $row;
598 foreach($all as $iter) {
602 foreach ($code_types as $key => $value) {
603 if ($value['id'] == $iter['code_type']) {
604 $has_fees = $value['fee'];
610 echo " <td class='text'>" . text($iter["code"]) . "</td>\n";
611 echo " <td class='text'>" . text($iter["modifier"]) . "</td>\n";
612 if ($iter["code_external"] > 0) {
613 // If there is no entry in codes sql table, then default to active
614 // (this is reason for including NULL below)
615 echo " <td class='text'>" . ( ($iter["active"] ||
$iter["active"]==NULL) ?
xlt('Yes') : xlt('No')) . "</td>\n";
618 echo " <td class='text'>" . ( ($iter["active"]) ?
xlt('Yes') : xlt('No')) . "</td>\n";
620 echo " <td class='text'>" . ($iter["reportable"] ?
xlt('Yes') : xlt('No')) . "</td>\n";
621 echo " <td class='text'>" . ($iter["financial_reporting"] ?
xlt('Yes') : xlt('No')) . "</td>\n";
622 echo " <td class='text'>" . text($iter['code_type_name']) . "</td>\n";
623 echo " <td class='text'>" . text($iter['code_text']) . "</td>\n";
624 echo " <td class='text'>" . text($iter['code_text_short']) . "</td>\n";
626 if (related_codes_are_used()) {
627 // Show related codes.
628 echo " <td class='text'>";
629 $arel = explode(';', $iter['related_code']);
630 foreach ($arel as $tmp) {
631 list($reltype, $relcode) = explode(':', $tmp);
632 $code_description = lookup_code_descriptions($reltype.":".$relcode);
633 echo text($relcode) . ' ' . text(trim($code_description)) . '<br />';
638 $pres = sqlStatement("SELECT p.pr_price " .
639 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
640 "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
641 "WHERE list_id = 'pricelevel' ORDER BY lo.seq", array($iter['id']) );
642 while ($prow = sqlFetchArray($pres)) {
643 echo "<td class='text' align='right'>" . text(bucks($prow['pr_price'])) . "</td>\n";
646 if ($iter["code_external"] > 0) {
647 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";
650 echo " <td align='right'><a class='link' href='javascript:submitDelete(" . attr($iter['id']) . ")'>[" . xlt('Delete') . "]</a></td>\n";
651 echo " <td align='right'><a class='link' href='javascript:submitEdit(" . attr($iter['id']) . ")'>[" . xlt('Edit') . "]</a></td>\n";
665 <script language
="JavaScript">
668 echo "alert('" . addslashes($alertmsg) . "');\n";