Fix for mysql error on saving a new service code.
[openemr.git] / interface / patient_file / encounter / superbill_custom_full.php
blob126f894cedeb66130271c0d1e334a2fe80a3e7a5
1 <?php
3 /**
4 * Provides manual administration of codes
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Stephen Waite <stephen.waite@cmsvt.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2015-2017, 2022 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2018-2021 Stephen Waite <stephen.waite@cmsvt.com>
13 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../../globals.php");
18 require_once("../../../custom/code_types.inc.php");
19 require_once("$srcdir/options.inc.php");
21 use OpenEMR\Common\Acl\AclMain;
22 use OpenEMR\Common\Csrf\CsrfUtils;
23 use OpenEMR\Core\Header;
25 // gacl control
26 $thisauthview = AclMain::aclCheckCore('admin', 'superbill', false, 'view');
27 $thisauthwrite = AclMain::aclCheckCore('admin', 'superbill', false, 'write');
29 if (!($thisauthwrite || $thisauthview)) {
30 echo "<html>\n<body>\n";
31 echo "<p>" . xlt('You are not authorized for this.') . "</p>\n";
32 echo "</body>\n</html>\n";
33 exit();
35 // For revenue codes
36 $institutional = $GLOBALS['ub04_support'] == "1" ? true : false;
38 // Translation for form fields.
39 function ffescape($field)
41 $field = add_escape_custom($field);
42 return trim($field);
45 // Format dollars for display.
47 function bucks($amount)
49 if ($amount) {
50 $amount = oeFormatMoney($amount);
51 return $amount;
54 return '';
57 $alertmsg = '';
58 $pagesize = 100;
59 $mode = $_POST['mode'] ?? null;
60 $code_id = 0;
61 $related_code = '';
62 $active = 1;
63 $reportable = 0;
64 $financial_reporting = 0;
65 $revenue_code = '';
67 if (isset($mode) && $thisauthwrite) {
68 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
69 CsrfUtils::csrfNotVerified();
72 $code_id = empty($_POST['code_id']) ? '' : $_POST['code_id'] + 0;
73 $code = $_POST['code'];
74 $code_type = $_POST['code_type'];
75 $code_text = $_POST['code_text'];
76 $modifier = $_POST['modifier'];
77 $superbill = $_POST['form_superbill'];
78 $related_code = $_POST['related_code'];
79 $cyp_factor = is_numeric($_POST['cyp_factor']) ? $_POST['cyp_factor'] + 0 : 0;
80 $active = empty($_POST['active']) ? 0 : 1;
81 $reportable = empty($_POST['reportable']) ? 0 : 1; // dx reporting
82 $financial_reporting = empty($_POST['financial_reporting']) ? 0 : 1; // financial service reporting
83 $revenue_code = $_POST['revenue_code'] ?? '';
85 $taxrates = "";
86 if (!empty($_POST['taxrate'])) {
87 foreach ($_POST['taxrate'] as $key => $value) {
88 $taxrates .= "$key:";
92 if ($mode == "delete") {
93 sqlStatement("DELETE FROM codes WHERE id = ?", array($code_id));
94 $code_id = 0;
95 } elseif ($mode == "add" || $mode == "modify_complete") { // this covers both adding and modifying
96 $crow = sqlQuery("SELECT COUNT(*) AS count FROM codes WHERE " .
97 "code_type = '" . ffescape($code_type) . "' AND " .
98 "code = '" . ffescape($code) . "' AND " .
99 "modifier = '" . ffescape($modifier) . "' AND " .
100 "id != '" . add_escape_custom($code_id) . "'");
101 if ($crow['count']) {
102 $alertmsg = xl('Cannot add/update this entry because a duplicate already exists!');
103 } else {
104 $sql =
105 "code = '" . ffescape($code) . "', " .
106 "code_type = '" . ffescape($code_type) . "', " .
107 "code_text = '" . ffescape($code_text) . "', " .
108 "modifier = '" . ffescape($modifier) . "', " .
109 "superbill = '" . ffescape($superbill) . "', " .
110 "related_code = '" . ffescape($related_code) . "', " .
111 "cyp_factor = '" . ffescape($cyp_factor) . "', " .
112 "taxrates = '" . ffescape($taxrates) . "', " .
113 "active = " . add_escape_custom($active) . ", " .
114 "financial_reporting = " . add_escape_custom($financial_reporting) . ", " .
115 "revenue_code = '" . ffescape($revenue_code) . "', " .
116 "reportable = '" . add_escape_custom($reportable) . "' ";
117 if ($code_id) {
118 $query = "UPDATE codes SET $sql WHERE id = ?";
119 sqlStatement($query, array($code_id));
120 sqlStatement("DELETE FROM prices WHERE pr_id = ? AND " .
121 "pr_selector = ''", array($code_id));
122 } else {
123 $code_id = sqlInsert("INSERT INTO codes SET $sql");
126 if (!$alertmsg) {
127 foreach ($_POST['fee'] as $key => $value) {
128 $value = $value ?? 0;
129 if ($value) {
130 sqlStatement("INSERT INTO prices ( " .
131 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
132 "?, '', ?, ?)", array($code_id,$key,$value));
136 $code = $code_type = $code_text = $modifier = $superbill = "";
137 $code_id = 0;
138 $related_code = '';
139 $cyp_factor = 0;
140 $taxrates = '';
141 $active = 1;
142 $reportable = 0;
143 $revenue_code = '';
146 } elseif ($mode == "edit") { // someone clicked [Edit]
147 $sql = "SELECT * FROM codes WHERE id = ?";
148 $results = sqlStatement($sql, array($code_id));
149 while ($row = sqlFetchArray($results)) {
150 $code = $row['code'];
151 $code_text = $row['code_text'];
152 $code_type = $row['code_type'];
153 $modifier = $row['modifier'];
154 // $units = $row['units'];
155 $superbill = $row['superbill'];
156 $related_code = $row['related_code'];
157 $revenue_code = $row['revenue_code'] ?? '';
158 $cyp_factor = $row['cyp_factor'];
159 $taxrates = $row['taxrates'];
160 $active = 0 + $row['active'];
161 $reportable = 0 + $row['reportable'];
162 $financial_reporting = 0 + $row['financial_reporting'];
164 } elseif ($mode == "modify") { // someone clicked [Modify]
165 // this is to modify external code types, of which the modifications
166 // are stored in the codes table
167 $code_type_name_external = $_POST['code_type_name_external'];
168 $code_external = $_POST['code_external'];
169 $code_id = $_POST['code_id'];
170 $results = return_code_information($code_type_name_external, $code_external, false); // only will return one item
171 while ($row = sqlFetchArray($results)) {
172 $code = $row['code'];
173 $code_text = $row['code_text'];
174 $code_type = $code_types[$code_type_name_external]['id'];
175 $modifier = $row['modifier'];
176 // $units = $row['units'];
177 $superbill = $row['superbill'];
178 $related_code = $row['related_code'];
179 $revenue_code = $row['revenue_code'] ?? '';
180 $cyp_factor = $row['cyp_factor'];
181 $taxrates = $row['taxrates'];
182 $active = $row['active'];
183 $reportable = $row['reportable'];
184 $financial_reporting = $row['financial_reporting'];
188 // If codes history is enabled in the billing globals save data to codes history table
189 if (
190 $GLOBALS['save_codes_history'] && $alertmsg == '' &&
191 ( $mode == "add" || $mode == "modify_complete" || $mode == "delete" )
193 $action_type = empty($_POST['code_id']) ? 'new' : $mode;
194 $action_type = ($action_type == 'add') ? 'update' : $action_type ;
195 $code = $_POST['code'];
196 $code_type = $_POST['code_type'];
197 $code_text = $_POST['code_text'];
198 $modifier = $_POST['modifier'];
199 $superbill = $_POST['form_superbill'];
200 $related_code = $_POST['related_code'];
201 $revenue_code = $_POST['revenue_code'] ?? '';
202 $cyp_factor = $_POST['cyp_factor'] ?? 0;
203 $active = empty($_POST['active']) ? 0 : 1;
204 $reportable = empty($_POST['reportable']) ? 0 : 1; // dx reporting
205 $financial_reporting = empty($_POST['financial_reporting']) ? 0 : 1; // financial service reporting
206 $fee = json_encode($_POST['fee']);
207 $code_sql = sqlFetchArray(sqlStatement("SELECT (ct_label) FROM code_types WHERE ct_id=?", array($code_type)));
208 $code_name = '';
210 if ($code_sql) {
211 $code_name = $code_sql['ct_label'];
214 $category_id = $_POST['form_superbill'];
215 $category_sql = sqlFetchArray(sqlStatement("SELECT (title) FROM list_options WHERE list_id='superbill'" .
216 " AND option_id=?", array($category_id)));
218 $category_name = '';
220 if ($category_sql) {
221 $category_name = $category_sql['title'];
224 $date = date('Y-m-d H:i:s');
225 $date = oeFormatShortDate($date);
226 $results = sqlStatement(
227 "INSERT INTO codes_history ( " .
228 "date, code, modifier, active,diagnosis_reporting,financial_reporting,category,code_type_name," .
229 "code_text,code_text_short,prices,action_type, update_by ) VALUES ( " .
230 "?, ?,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,?)",
231 array($date,$code,$modifier,$active,$reportable,$financial_reporting,$category_name,$code_name,$code_text,'',$fee,$action_type,$_SESSION['authUser'])
236 $related_desc = '';
237 if (!empty($related_code)) {
238 $related_desc = $related_code;
241 $fstart = ($_REQUEST['fstart'] ?? null) + 0;
242 if (isset($_REQUEST['filter'])) {
243 $filter = array();
244 $filter_key = array();
245 foreach ($_REQUEST['filter'] as $var) {
246 $var = $var + 0;
247 array_push($filter, $var);
248 $var_key = convert_type_id_to_key($var);
249 array_push($filter_key, $var_key);
253 $search = $_REQUEST['search'] ?? null;
254 $search_reportable = $_REQUEST['search_reportable'] ?? null;
255 $search_financial_reporting = $_REQUEST['search_financial_reporting'] ?? null;
257 $search_active = $_REQUEST['search_active'] ?? null;
259 //Build the filter_elements array
260 $filter_elements = array();
261 if (!empty($search_reportable)) {
262 $filter_elements['reportable'] = $search_reportable;
265 if (!empty($search_financial_reporting)) {
266 $filter_elements['financial_reporting'] = $search_financial_reporting;
269 if (!empty($search_active)) {
270 $filter_elements['active'] = $search_active;
273 if (isset($_REQUEST['filter'])) {
274 $count = main_code_set_search($filter_key, $search, null, null, false, null, true, null, null, $filter_elements);
277 if ($fstart >= ($count ?? null)) {
278 $fstart -= $pagesize;
281 if ($fstart < 0) {
282 $fstart = 0;
285 $fend = $fstart + $pagesize;
286 if ($fend > ($count ?? null)) {
287 $fend = $count ?? null;
291 <html>
292 <head>
293 <title><?php echo xlt("Codes"); ?></title>
295 <?php Header::setupHeader(['select2']); ?>
297 <style>
298 .ui-autocomplete {
299 max-height: 350px;
300 max-width: 35%;
301 overflow-y: auto;
302 overflow-x: hidden;
304 </style>
305 <script>
306 <?php if ($institutional) { ?>
307 $(function () {
308 $(".revcode").select2({
309 ajax: {
310 url: "<?php echo $GLOBALS['web_root'] ?>/interface/billing/ub04_helpers.php",
311 dataType: 'json',
312 data: function(params) {
313 return {
314 code_group: "revenue_code",
315 term: params.term
318 processResults: function(data) {
319 return {
320 results: $.map(data, function(item, index) {
321 return {
322 text: item.label,
323 id: index,
324 value: item.value
328 return x;
330 cache: true
334 <?php } ?>
336 // This is for callback by the find-code popup.
337 // Appends to or erases the current list of related codes.
338 function set_related(codetype, code, selector, codedesc) {
339 var f = document.forms[0];
340 var s = f.related_code.value;
341 if (code) {
342 if (s.length > 0) s += ';';
343 s += codetype + ':' + code;
344 } else {
345 s = '';
347 f.related_code.value = s;
348 f.related_desc.value = s;
351 // This is for callback by the find-code popup.
352 // Returns the array of currently selected codes with each element in codetype:code format.
353 function get_related() {
354 return document.forms[0].related_code.value.split(';');
357 // This is for callback by the find-code popup.
358 // Deletes the specified codetype:code from the currently selected list.
359 function del_related(s) {
360 my_del_related(s, document.forms[0].related_code, false);
361 my_del_related(s, document.forms[0].related_desc, false);
364 // This invokes the find-code popup.
365 function sel_related() {
366 var f = document.forms[0];
367 var i = f.code_type.selectedIndex;
368 var codetype = '';
369 if (i >= 0) {
370 var myid = f.code_type.options[i].value;
371 <?php
372 foreach ($code_types as $key => $value) {
373 $codeid = $value['id'];
374 $coderel = $value['rel'];
375 if (!$coderel) {
376 continue;
379 echo " if (myid == $codeid) codetype = '$coderel';";
383 if (!codetype) {
384 alert(<?php echo xlj('This code type does not accept relations.'); ?>);
385 return;
387 dlgopen('find_code_dynamic.php', '_blank', 900, 600);
390 // Some validation for saving a new code entry.
391 function validEntry(f) {
392 if (!f.code.value) {
393 alert(<?php echo xlj('No code was specified!'); ?>);
394 return false;
396 <?php if ($GLOBALS['ippf_specific']) { ?>
397 if (f.code_type.value == 12 && !f.related_code.value) {
398 alert(<?php echo xlj('A related IPPF code is required!'); ?>);
399 return false;
401 <?php } ?>
402 return true;
405 function submitAdd() {
406 var f = document.forms[0];
407 if (!validEntry(f)) return;
408 f.mode.value = 'add';
409 f.code_id.value = '';
410 f.submit();
413 function submitUpdate() {
414 var f = document.forms[0];
415 if (! parseInt(f.code_id.value)) {
416 alert(<?php echo xlj('Cannot update because you are not editing an existing entry!'); ?>);
417 return;
419 if (!validEntry(f)) return;
420 f.mode.value = 'add';
421 f.submit();
424 function submitModifyComplete() {
425 var f = document.forms[0];
426 f.mode.value = 'modify_complete';
427 f.submit();
430 function submitList(offset) {
431 var f = document.forms[0];
432 var i = parseInt(f.fstart.value) + offset;
433 if (i < 0) i = 0;
434 f.fstart.value = i;
435 f.submit();
438 function submitEdit(id) {
439 var f = document.forms[0];
440 f.mode.value = 'edit';
441 f.code_id.value = id;
442 f.submit();
445 function submitModify(code_type_name,code,id) {
446 var f = document.forms[0];
447 f.mode.value = 'modify';
448 f.code_external.value = code;
449 f.code_id.value = id;
450 f.code_type_name_external.value = code_type_name;
451 f.submit();
456 function submitDelete(id) {
457 var f = document.forms[0];
458 f.mode.value = 'delete';
459 f.code_id.value = id;
460 f.submit();
463 function getCTMask() {
464 var ctid = document.forms[0].code_type.value;
465 <?php
466 foreach ($code_types as $key => $value) {
467 $ctid = $value['id'];
468 $ctmask = $value['mask'];
469 echo " if (ctid == " . js_escape($ctid) . ") return " . js_escape($ctmask) . ";\n";
472 return '';
475 </script>
477 </head>
478 <body class="body_top" >
480 <form method='post' action='superbill_custom_full.php' name='theform'>
481 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
483 <input type='hidden' name='mode' value='' />
485 <br />
487 <div class="container">
488 <p><?php echo xlt('Not all fields are required for all codes or code types.'); ?></p>
489 <div class="form-group row">
490 <label for="code_type" class="col-form-label col-form-label-sm col-md-1"><?php echo xlt('Type'); ?>:</label>
491 <div class="col-md">
492 <?php if ($mode != "modify") { ?>
493 <select name="code_type" id="code_type" class='form-control form-control-sm'>
494 <?php } ?>
496 <?php $external_sets = array(); ?>
497 <?php foreach ($code_types as $key => $value) { ?>
498 <?php if (!($value['external'])) { ?>
499 <?php if ($mode != "modify") { ?>
500 <option value="<?php echo attr($value['id']) ?>"<?php if (!empty($code_type) && ($code_type == $value['id'])) {
501 echo " selected"; } ?>><?php echo xlt($value['label']) ?></option>
502 <?php } ?>
503 <?php } ?>
504 <?php if ($value['external']) {
505 array_push($external_sets, $key);
506 } ?>
507 <?php } // end foreach ?>
509 <?php if ($mode != "modify") { ?>
510 </select>
511 <?php } ?>
512 <?php if ($mode == "modify") { ?>
513 <input type='text' class='form-control form-control-sm' size='4' name='code_type' readonly='readonly' style='display:none' value='<?php echo attr($code_type) ?>' />
514 <?php echo text($code_type_name_external); ?>
515 <?php } ?>
516 </div>
517 <label class="col-form-label col-form-label-sm col-md-1"><?php echo xlt('Code'); ?>:</label>
518 <div class="col-md">
519 <?php if ($mode == "modify") { ?>
520 <input type='text' class='form-control form-control-sm' size='6' name='code' readonly='readonly' value='<?php echo attr($code) ?>' />
521 <?php } else { ?>
522 <input type='text' class='form-control form-control-sm' size='6' name='code' value='<?php echo attr($code ?? '') ?>' onkeyup='maskkeyup(this,getCTMask())' onblur='maskblur(this,getCTMask())' />
523 <?php } ?>
524 </div>
525 <?php if (modifiers_are_used()) { ?>
526 <label for="modifier" class="col-form-label col-form-label-sm col-md-1"><?php echo xlt('Modifier'); ?>:</label>
527 <div class="col-md">
528 <?php if ($mode == "modify") { ?>
529 <input type='text' size='6' class='form-control form-control-sm' name='modifier' readonly='readonly' value='<?php echo attr($modifier) ?>' />
530 <?php } else { ?>
531 <input type='text' size='6' class='form-control form-control-sm' name='modifier' value='<?php echo attr($modifier ?? '') ?>' />
532 <?php } ?>
533 <?php } else { ?>
534 <input type='hidden' name='modifier' value='' />
535 <?php } ?>
536 </div>
537 <div class="col-md">
538 <input type='checkbox' name='active' value='1'<?php if (!empty($active) || ($mode == 'modify' && $active == null)) {
539 echo ' checked'; } ?> />
540 <?php echo xlt('Active'); ?>
541 </div>
542 </div>
543 <div class="form-group row">
544 <label for="code_text" class="col-form-label col-form-label-sm col-md-1"><?php echo xlt('Description'); ?>:</label>
545 <div class="col-md">
546 <?php if ($mode == "modify") { ?>
547 <input type='text' size='50' class='form-control form-control-sm' name="code_text" readonly="readonly" value='<?php echo attr($code_text ?? '') ?>' />
548 <?php } else { ?>
549 <input type='text' size='50' class='form-control form-control-sm' name="code_text" value='<?php echo attr($code_text ?? '') ?>' />
550 <?php } ?>
551 </div>
552 <?php if ($institutional) { ?>
553 <label for="revenue_code" class="col-form-label col-form-label-sm col-md-1"><?php echo xlt('Revenue Code'); ?>:</label>
554 <div class="col-md">
555 <?php if ($mode == "modify") { ?>
556 <input type='text' size='6' class='form-control form-control-sm' name="revenue_code" readonly="readonly" value='<?php echo attr($revenue_code) ?>' />
557 <?php } else { ?>
558 <select size='6' style='width:150px' class='form-control form-control-sm revcode' name="revenue_code" title='<?php echo xla('Type to search and select revenue code'); ?>' value='<?php echo attr($revenue_code) ?>'> </select>
559 <?php } ?>
560 </div>
561 <?php } ?>
562 </div>
563 <div class="form-group row">
564 <label for="superbill" class="col-form-label col-form-label-sm col-md-1"><?php echo xlt('Category'); ?>:</label>
565 <div class="col-md">
566 <?php generate_form_field(array('data_type' => 1,'field_id' => 'superbill','list_id' => 'superbill', 'smallform' => 'true'), ($superbill ?? '')); ?>
567 </div>
568 <div class="col-md">
569 <input type='checkbox' title='<?php echo xla("Syndromic Surveillance Report") ?>' name='reportable' value='1'<?php if (!empty($reportable)) {
570 echo ' checked'; } ?> />
571 <?php echo xlt('Diagnosis Reporting'); ?>
572 </div>
573 <div class="col-md">
574 <input type='checkbox' title='<?php echo xla("Service Code Finance Reporting") ?>' name='financial_reporting' value='1'<?php if (!empty($financial_reporting)) {
575 echo ' checked'; } ?> />
576 <?php echo xlt('Service Reporting'); ?>
577 </div>
578 </div>
579 <div class="form-group row">
580 <label class="col-form-label col-form-label-sm col-md-1 <?php if (empty($GLOBALS['ippf_specific'])) {
581 echo 'd-none'; } ?>"><?php echo xlt('CYP Factor'); ?>:</label>
582 <div class="col-md <?php if (empty($GLOBALS['ippf_specific'])) {
583 echo 'd-none'; } ?>">
584 <input type='text' class='form-control form-control-sm' size='10' maxlength='20' name="cyp_factor" value='<?php echo attr($cyp_factor ?? '') ?>' />
585 </div>
586 <label class="col-form-label col-form-label-sm col-md-1 <?php if (!related_codes_are_used()) {
587 echo "d-none"; } ?>"><?php echo xlt('Relate To'); ?>:</label>
588 <div class="col-md <?php if (!related_codes_are_used()) {
589 echo "d-none"; } ?>">
590 <input type='text' class='form-control form-control-sm' size='50' name='related_desc'
591 value='<?php echo attr($related_desc) ?>' onclick="sel_related()"
592 title='<?php echo xla('Click to select related code'); ?>' readonly />
593 <input type='hidden' name='related_code' value='<?php echo attr($related_code) ?>' />
594 </div>
595 <label class="col-form-label col-form-label-sm col-md-1"><?php echo xlt('Fees'); ?>:</label>
596 <?php
597 $pres = sqlStatement("SELECT lo.option_id, lo.title, p.pr_price " .
598 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
599 "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
600 "WHERE lo.list_id = 'pricelevel' AND lo.activity = 1 ORDER BY lo.seq, lo.title", array($code_id));
601 for ($i = 0; $prow = sqlFetchArray($pres); ++$i) {
602 echo "<label class='col-form-label col-form-label-sm col-md-1'>" . text(xl_list_label($prow['title'])) . "</label>";
603 echo "<div class='col-md'><input type='text' class='form-control form-control-sm' size='6' name='fee[" . attr($prow['option_id']) . "]' " .
604 "value='" . attr($prow['pr_price']) . "' /></div>\n";
607 <?php
608 $taxline = '';
609 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
610 "WHERE list_id = 'taxrate' AND activity = 1 ORDER BY seq");
611 while ($prow = sqlFetchArray($pres)) {
612 $taxline .= "<input type='checkbox' name='taxrate[" . attr($prow['option_id']) . "]' value='1'";
613 if (strpos(":$taxrates", $prow['option_id']) !== false) {
614 $taxline .= " checked";
617 $taxline .= " />\n";
618 $taxline .= text(xl_list_label($prow['title'])) . "\n";
621 if ($taxline) { ?>
622 <div class="col-md"><?php echo xlt('Taxes'); ?>: <?php echo $taxline; ?></div>
623 <?php } ?>
624 </div>
625 <input type="hidden" name="code_id" value="<?php echo attr($code_id) ?>" />
626 <input type="hidden" name="code_type_name_external" value="<?php echo attr($code_type_name_external ?? '') ?>" />
627 <input type="hidden" name="code_external" value="<?php echo attr($code_external ?? '') ?>" />
628 <?php if ($thisauthwrite) { ?>
629 <p class="text-center">
630 <?php if ($mode == "modify") { ?>
631 <a href='javascript:submitModifyComplete();' class='link'>[<?php echo xlt('Update'); ?>]</a>
632 <?php } else { ?>
633 <a href='javascript:submitUpdate();' class='link'>[<?php echo xlt('Update'); ?>]</a>
634 &nbsp;&nbsp;
635 <a href='javascript:submitAdd();' class='link'>[<?php echo xlt('Add as New'); ?>]</a>
636 <?php } ?>
637 </p>
638 <?php } ?>
639 </div>
640 <div class="container-fluid">
641 <div class="row align-items-end">
642 <div class="col-md-2">
643 <select name='filter[]' class="form-control form-control-sm" multiple='multiple'>
644 <?php
645 foreach ($code_types as $key => $value) {
646 echo "<option value='" . attr($value['id']) . "'";
647 if (isset($filter) && in_array($value['id'], $filter)) {
648 echo " selected";
651 echo ">" . xlt($value['label']) . "</option>\n";
654 </select>
655 </div>
656 <div class="col-md">
657 <input type="text" name="search" class="form-control form-control-sm" size="5" value="<?php echo attr($search) ?>" />
658 </div>
659 <div class="col-md">
660 <input type="submit" class="btn btn-primary btn-sm" name="go" value='<?php echo xla('Search'); ?>' />
661 </div>
662 <div class="col-md">
663 <input type='checkbox' title='<?php echo xla("Only Show Diagnosis Reporting Codes") ?>' name='search_reportable' value='1'<?php if (!empty($search_reportable)) {
664 echo ' checked'; } ?> /><?php echo xlt('Diagnosis Reporting Only'); ?>
665 </div>
666 <div class="col-md">
667 <input type='checkbox' title='<?php echo xla("Only Show Service Code Finance Reporting Codes") ?>' name='search_financial_reporting' value='1'<?php if (!empty($search_financial_reporting)) {
668 echo ' checked'; } ?> /><?php echo xlt('Service Reporting Only'); ?>
669 <input type='hidden' name='fstart' value='<?php echo attr($fstart) ?>' />
670 </div>
671 <div class="col-md">
672 <input type='checkbox' title='<?php echo xla("Only Show Active Codes ") ?>' name='search_active' value='1'<?php if (!empty($search_active)) {
673 echo ' checked'; } ?> /><?php echo xlt('Active Codes'); ?>
674 </div>
675 <div class="col-md text-right">
676 <?php if ($fstart) { ?>
677 <a href="javascript:submitList(<?php echo attr_js($pagesize); ?>)">
678 &lt;&lt;
679 </a>
680 &nbsp;&nbsp;
681 <?php } ?>
682 <?php echo text(($fstart + 1)) . " - " . text($fend) . " of " . text($count ?? ''); ?>
683 <a href="javascript:submitList(<?php echo attr_js($pagesize); ?>)">
684 &gt;&gt;
685 </a>
686 </div>
687 </div>
688 </div>
689 </form>
691 <table class='table table-borderless' cellpadding='5' cellspacing='0'>
692 <tr>
693 <td><span class='font-weight-bold'><?php echo xlt('Code'); ?></span></td>
694 <td><span class='font-weight-bold'><?php echo xlt('Mod'); ?></span></td>
695 <?php if ($institutional) { ?>
696 <td><span class='font-weight-bold'><?php echo xlt('Revenue'); ?></span></td>
697 <?php } ?>
698 <td><span class='font-weight-bold'><?php echo xlt('Act'); ?></span></td>
699 <td><span class='font-weight-bold'><?php echo xlt('Category'); ?></span></td>
700 <td><span class='font-weight-bold'><?php echo xlt('Dx Rep'); ?></span></td>
701 <td><span class='font-weight-bold'><?php echo xlt('Serv Rep'); ?></span></td>
702 <td><span class='font-weight-bold'><?php echo xlt('Type'); ?></span></td>
703 <td><span class='font-weight-bold'><?php echo xlt('Description'); ?></span></td>
704 <td><span class='font-weight-bold'><?php echo xlt('Short Description'); ?></span></td>
705 <?php if (related_codes_are_used()) { ?>
706 <td><span class='font-weight-bold'><?php echo xlt('Related'); ?></span></td>
707 <?php } ?>
708 <?php
709 $pres = sqlStatement("SELECT title FROM list_options " .
710 "WHERE list_id = 'pricelevel' AND activity = 1 ORDER BY seq, title");
711 while ($prow = sqlFetchArray($pres)) {
712 echo " <td class='font-weight-bold text-right text-nowrap'>" . text(xl_list_label($prow['title'])) . "</td>\n";
715 <td></td>
716 <td></td>
717 </tr>
718 <?php
720 if (isset($_REQUEST['filter'])) {
721 $res = main_code_set_search($filter_key, $search, null, null, false, null, false, $fstart, ($fend - $fstart), $filter_elements);
724 for ($i = 0; $row = sqlFetchArray($res); $i++) {
725 $all[$i] = $row;
728 if (!empty($all)) {
729 $count = 0;
730 foreach ($all as $iter) {
731 $count++;
733 $has_fees = false;
734 foreach ($code_types as $key => $value) {
735 if ($value['id'] == $iter['code_type']) {
736 $has_fees = $value['fee'];
737 break;
741 echo " <tr>\n";
742 echo " <td class='text'>" . text($iter["code"]) . "</td>\n";
743 echo " <td class='text'>" . text($iter["modifier"]) . "</td>\n";
744 if ($institutional) {
745 echo " <td class='text'>" . ($iter['revenue_code'] > '' ? text($iter['revenue_code']) : 'none') . "</td>\n";
747 if ($iter["code_external"] > 0) {
748 // If there is no entry in codes sql table, then default to active
749 // (this is reason for including NULL below)
750 echo " <td class='text'>" . ( ($iter["active"] || $iter["active"] == null) ? xlt('Yes') : xlt('No')) . "</td>\n";
751 } else {
752 echo " <td class='text'>" . ( ($iter["active"]) ? xlt('Yes') : xlt('No')) . "</td>\n";
755 $sres = sqlStatement("SELECT title " .
756 "FROM list_options AS lo " .
757 "WHERE lo.list_id = 'superbill' AND lo.option_id = ?", array($iter['superbill']));
758 if ($srow = sqlFetchArray($sres)) {
759 echo " <td class='text'>" . text($srow['title']) . "</td>\n";
760 } else {
761 echo " <td class='text'>" . '' . "</td>\n";
763 echo " <td class='text'>" . ($iter["reportable"] ? xlt('Yes') : xlt('No')) . "</td>\n";
764 echo " <td class='text'>" . ($iter["financial_reporting"] ? xlt('Yes') : xlt('No')) . "</td>\n";
765 echo " <td class='text'>" . text($iter['code_type_name']) . "</td>\n";
766 echo " <td class='text'>" . text($iter['code_text']) . "</td>\n";
767 echo " <td class='text'>" . text($iter['code_text_short']) . "</td>\n";
769 if (related_codes_are_used() && $iter['related_code']) {
770 // Show related codes.
771 echo " <td class='text'>";
772 $arel = explode(';', $iter['related_code']);
773 foreach ($arel as $tmp) {
774 list($reltype, $relcode) = explode(':', $tmp);
775 $code_description = lookup_code_descriptions($reltype . ":" . $relcode);
776 echo text($relcode) . ' ' . text(trim($code_description)) . '<br />';
779 echo "</td>\n";
782 $pres = sqlStatement("SELECT p.pr_price " .
783 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
784 "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " .
785 "WHERE lo.list_id = 'pricelevel' AND lo.activity = 1 ORDER BY lo.seq", array($iter['id']));
786 while ($prow = sqlFetchArray($pres)) {
787 echo "<td class='text text-right'>" . text(bucks($prow['pr_price'])) . "</td>\n";
790 if ($thisauthwrite) {
791 if ($iter["code_external"] > 0) {
792 echo " <td class='text-right'><a class='link' href='javascript:submitModify(" . attr_js($iter['code_type_name']) . "," . attr_js($iter['code']) . "," . attr_js($iter['id']) . ")'>[" . xlt('Modify') . "]</a></td>\n";
793 } else {
794 echo " <td class='text-right'><a class='link' href='javascript:submitDelete(" . attr_js($iter['id']) . ")'>[" . xlt('Delete') . "]</a></td>\n";
795 echo " <td class='text-right'><a class='link' href='javascript:submitEdit(" . attr_js($iter['id']) . ")'>[" . xlt('Edit') . "]</a></td>\n";
799 echo " </tr>\n";
805 </table>
807 <script>
808 <?php
809 if ($alertmsg) {
810 echo "alert(" . js_escape($alertmsg) . ");\n";
813 </script>
815 </body>
816 </html>