continued bug fixes (#1876)
[openemr.git] / interface / billing / billing_report.php
blobd9174b6798c525e2935aa49d985cc7e604d46603
1 <?php
2 /**
3 * Billing Report Program
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Terry Hill <terry@lilysystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @author Jerry Padgett <sjpadgett@gmail.com>
10 * @copyright Copyright (c) 2016 Terry Hill <terry@lillysystems.com>
11 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
12 * @copyright Copyright (c) 2018 Jerry Padgett <sjpadgett@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once "../globals.php";
17 require_once "../../library/acl.inc";
18 require_once "../../custom/code_types.inc.php";
19 require_once "$srcdir/patient.inc";
20 require_once "$srcdir/../interface/reports/report.inc.php"; // Criteria Section common php page
21 require_once "$srcdir/billrep.inc";
22 require_once "$srcdir/options.inc.php";
23 require_once "adjustment_reason_codes.php";
25 use OpenEMR\Core\Header;
27 $EXPORT_INC = "$webserver_root/custom/BillingExport.php";
28 // echo $GLOBALS['daysheet_provider_totals'];
30 $daysheet = false;
31 $daysheet_total = false;
32 $provider_run = false;
34 if ($GLOBALS['use_custom_daysheet'] != 0) {
35 $daysheet = true;
36 if ($GLOBALS['daysheet_provider_totals'] == 1) {
37 $daysheet_total = true;
38 $provider_run = false;
40 if ($GLOBALS['daysheet_provider_totals'] == 0) {
41 $daysheet_total = false;
42 $provider_run = true;
46 $alertmsg = '';
48 if (isset($_POST['mode'])) {
49 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
50 die(xlt('Authentication Error'));
53 if ($_POST['mode'] == 'export') {
54 $sql = ReturnOFXSql();
55 $db = get_db();
56 $results = $db->Execute($sql);
57 $billings = array();
58 if ($results->RecordCount() == 0) {
59 echo "<fieldset id='error_info' style='border:1px solid #ff5d5a !Important; background-color: #ff5d5a !Important; color: #fff ! Important; font-weight: bold; font-family:sans-serif; border-radius:5px; padding:20px 5px !Important;'>";
60 echo xlt("No Bills Found to Include in OFX Export") . "<br>";
61 echo "</fieldset>";
62 } else {
63 while (!$results->EOF) {
64 $billings[] = $results->fields;
65 $results->MoveNext();
67 $ofx = new OFX($billings);
68 header("Pragma: public");
69 header("Expires: 0");
70 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
71 header("Content-Disposition: attachment; filename=openemr_ofx.ofx");
72 header("Content-Type: text/xml");
73 echo $ofx->get_OFX();
74 exit();
79 // global variables:
80 $from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
81 $to_date = isset($_POST['to_date']) ? $_POST['to_date'] : '';
82 $code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
83 $unbilled = isset($_POST['unbilled']) ? $_POST['unbilled'] : 'on';
84 $my_authorized = isset($_POST["authorized"]) ? $_POST["authorized"] : '';
86 // This tells us if only encounters that appear to be missing a "25" modifier
87 // are to be reported.
88 $missing_mods_only = (isset($_POST['missing_mods_only']) && !empty($_POST['missing_mods_only']));
90 $left_margin = isset($_POST["left_margin"]) ? $_POST["left_margin"] : $GLOBALS['cms_left_margin_default'];
91 $top_margin = isset($_POST["top_margin"]) ? $_POST["top_margin"] : $GLOBALS['cms_top_margin_default'];
92 if ($ub04_support) {
93 $left_ubmargin = isset($_POST["left_ubmargin"]) ? $_POST["left_ubmargin"] : $GLOBALS['left_ubmargin_default'];
94 $top_ubmargin = isset($_POST["top_ubmargin"]) ? $_POST["top_ubmargin"] : $GLOBALS['top_ubmargin_default'];
96 $ofrom_date = $from_date;
97 $oto_date = $to_date;
98 $ocode_type = $code_type;
99 $ounbilled = $unbilled;
100 $oauthorized = $my_authorized;
102 <!DOCTYPE html >
103 <html>
104 <head>
106 <?php Header::setupHeader(['datetime-picker', 'common']); ?>
107 <style>
108 /*.subbtn { margin-top:3px; margin-bottom:3px; margin-left:2px; margin-right:2px }*/
109 .btn-group-pinch > .btn:nth-last-child(4):not(.dropdown-toggle) {
110 border-top-right-radius: 3px !Important;
111 border-bottom-right-radius: 3px !Important;
113 </style>
114 <script>
115 function select_all() {
116 for ($i = 0; $i < document.update_form.length; $i++) {
117 $name = document.update_form[$i].name;
118 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -
119 6) == "[bill]") {
120 document.update_form[$i].checked = true;
123 set_button_states();
126 function set_button_states() {
127 var f = document.update_form;
128 var count0 = 0; // selected and not billed or queued
129 var count1 = 0; // selected and queued
130 var count2 = 0; // selected and billed
131 for ($i = 0; $i < f.length; ++$i) {
132 $name = f[$i].name;
133 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -
134 6) == "[bill]" && f[$i].checked == true) {
135 if (f[$i].value == '0') ++count0;
136 else if (f[$i].value == '1' || f[$i].value == '5') ++count1;
137 else ++count2;
140 var can_generate = (count0 > 0 || count1 > 0 || count2 > 0);
141 var can_mark = (count1 > 0 || count0 > 0 || count2 > 0);
142 var can_bill = (count0 == 0 && count1 == 0 && count2 > 0);
143 <?php if (file_exists($EXPORT_INC)) { ?>
144 f.bn_external.disabled = !can_generate;
145 <?php } else { ?>
146 f.bn_x12_support.disabled = !can_generate;
147 <?php if ($GLOBALS['support_encounter_claims']) { ?>
148 f.bn_x12_encounter.disabled = !can_generate;
149 <?php } ?>
150 f.bn_process_hcfa_support.disabled = !can_generate;
151 <?php if ($GLOBALS['preprinted_cms_1500']) { ?>
152 f.bn_process_hcfa_form.disabled = !can_generate;
153 <?php } ?>
154 <?php if ($GLOBALS['ub04_support']) { ?>
155 f.bn_process_ub04_support.disabled = !can_generate;
156 <?php } ?>
157 f.bn_hcfa_txt_file.disabled = !can_generate;
158 f.bn_reopen.disabled = !can_bill;
159 <?php } ?>
160 f.bn_mark.disabled = !can_mark;
163 // Process a click to go to an encounter.
164 function toencounter(pid, pubpid, pname, enc, datestr, dobstr) {
165 top.restoreSession();
166 encurl = 'patient_file/encounter/encounter_top.php?set_encounter=' + enc +
167 '&pid=' + pid;
168 parent.left_nav.setPatient(pname, pid, pubpid, '', dobstr);
169 <?php if ($GLOBALS['new_tabs_layout']) { ?>
170 parent.left_nav.setEncounter(datestr, enc, 'enc');
171 parent.left_nav.loadFrame('enc2', 'enc', encurl);
172 <?php } else { ?>
173 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
174 parent.left_nav.setEncounter(datestr, enc, othername);
175 parent.frames[othername].location.href = '../' + encurl;
176 <?php } ?>
179 // Process a click to go to an patient.
180 function topatient(pid, pubpid, pname, enc, datestr, dobstr) {
181 top.restoreSession();
182 paturl = 'patient_file/summary/demographics_full.php?pid=' + pid;
183 parent.left_nav.setPatient(pname, pid, pubpid, '', dobstr);
184 <?php if ($GLOBALS['new_tabs_layout']) { ?>
185 parent.left_nav.loadFrame('ens1', 'enc',
186 'patient_file/history/encounters.php?pid=' + pid);
187 parent.left_nav.loadFrame('dem1', 'pat', paturl);
188 <?php } else { ?>
189 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
190 parent.frames[othername].location.href = '../' + paturl;
191 <?php } ?>
194 function popMBO(pid, enc, mboid) {
195 if (!window.focus) return true;
196 if (!ProcessBeforeSubmitting()) return false;
197 top.restoreSession();
198 let qstring = "&pid=" + pid + "&enc=" + enc + "&id=" + mboid;
199 let href = "<?php echo $GLOBALS['web_root']?>/interface/patient_file/encounter/view_form.php?formname=misc_billing_options&isBilling=1" + qstring;
200 dlgopen(href, 'mbopop', 'modal-lg', 750, false, '', {
201 sizeHeight: 'full' // override min height auto size.
203 return true;
206 function popUB04(pid, enc) {
207 if (!window.focus) return true;
208 if (!ProcessBeforeSubmitting()) return false;
209 top.restoreSession();
210 let href = "<?php echo $GLOBALS['web_root']?>/interface/billing/ub04_form.php?pid=" + pid + "&enc=" + enc;
211 dlgopen(href, 'ub04pop', 1175, 750, false, '', {
212 sizeHeight: 'full' // override min height auto size.
214 return true;
216 </script>
217 <script>
218 var EncounterDateArray = new Array;
219 var CalendarCategoryArray = new Array;
220 var EncounterIdArray = new Array;
221 var EncounterNoteArray = new Array;
223 function SubmitTheScreen() { //Action on Update List link
224 if (!ProcessBeforeSubmitting()) return false;
225 $("#update-tooltip").replaceWith("<i class='fa fa-refresh fa-spin fa-1x' style=\"color:red\"></i>");
226 top.restoreSession();
227 document.the_form.mode.value = 'change';
228 document.the_form.target = '_self';
229 document.the_form.action = 'billing_report.php';
230 document.the_form.submit();
231 return true;
234 function SubmitTheScreenPrint() { //Action on View Printable Report link
235 if (!ProcessBeforeSubmitting()) return false;
236 top.restoreSession();
237 document.the_form.target = 'new';
238 document.the_form.action = 'print_billing_report.php';
239 document.the_form.submit();
240 return true;
243 function SubmitTheEndDayPrint() { //Action on View End of Day Report link
244 if (!ProcessBeforeSubmitting()) return false;
245 top.restoreSession();
246 document.the_form.target = 'new';
247 <?php if ($GLOBALS['use_custom_daysheet'] == 1) { ?>
248 document.the_form.action = 'print_daysheet_report_num1.php';
249 <?php } ?>
250 <?php if ($GLOBALS['use_custom_daysheet'] == 2) { ?>
251 document.the_form.action = 'print_daysheet_report_num2.php';
252 <?php } ?>
253 <?php if ($GLOBALS['use_custom_daysheet'] == 3) { ?>
254 document.the_form.action = 'print_daysheet_report_num3.php';
255 <?php } ?>
256 document.the_form.submit();
257 return true;
260 function SubmitTheScreenExportOFX() { //Action on Export OFX link
261 if (!ProcessBeforeSubmitting()) return false;
262 top.restoreSession();
263 document.the_form.mode.value = 'export';
264 document.the_form.target = '_self';
265 document.the_form.action = 'billing_report.php';
266 document.the_form.submit();
267 return true;
270 function TestExpandCollapse() { //Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
271 var set = -1;
272 for (i = 1; i <= document.getElementById("divnos").value; i++) {
273 var ele = document.getElementById("divid_" + i);
274 if (ele) {
275 set = 1;
276 break;
279 if (set == -1) {
280 if (document.getElementById("ExpandAll")) {
281 document.getElementById("ExpandAll").innerHTML = '';
282 document.getElementById("CollapseAll").innerHTML = '';
287 function expandcollapse(atr) {
288 if (atr == "expand") { //Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
289 for (i = 1; i <= document.getElementById("divnos").value; i++) {
290 var mydivid = "divid_" + i;
291 var myspanid = "spanid_" + i;
292 var ele = document.getElementById(mydivid);
293 var text = document.getElementById(myspanid);
294 if (ele) {
295 ele.style.display = "inline";
296 text.innerHTML =
297 "<?php echo xla('Collapse'); ?>";
300 } else {
301 for (i = 1; i <= document.getElementById("divnos").value; i++) {
302 var mydivid = "divid_" + i;
303 var myspanid = "spanid_" + i;
304 var ele = document.getElementById(mydivid);
305 var text = document.getElementById(myspanid);
306 if (ele) {
307 ele.style.display = "none";
308 text.innerHTML =
309 "<?php echo xla('Expand'); ?>";
315 function divtoggle(spanid, divid) { //Called in the Expand, Collapse links(This is for a single item)
316 var ele = document.getElementById(divid);
317 if (ele) {
318 var text = document.getElementById(spanid);
319 if (ele.style.display == "inline") {
320 ele.style.display = "none";
321 text.innerHTML =
322 "<?php echo xla('Expand'); ?>";
323 } else {
324 ele.style.display = "inline";
325 text.innerHTML =
326 "<?php echo xla('Collapse'); ?>";
331 function MarkAsCleared(Type) {
332 CheckBoxBillingCount = 0;
333 for (var CheckBoxBillingIndex = 0; ; CheckBoxBillingIndex++) {
334 CheckBoxBillingObject = document.getElementById('CheckBoxBilling' +
335 CheckBoxBillingIndex);
336 if (!CheckBoxBillingObject) break;
337 if (CheckBoxBillingObject.checked) {
338 ++CheckBoxBillingCount;
341 if (Type == 1) {
342 Message = '<?php echo xla('After saving your batch, click[View Log] to check for errors.'); ?>';
344 if (Type == 2) {
345 Message = '<?php echo xla('After saving the PDF, click[View Log] to check for errors.'); ?>';
347 if (Type == 3) {
348 Message = '<?php echo xla('After saving the TEXT file(s), click[View Log] to check for errors.'); ?>';
350 if (confirm(Message + "\n\n\n<?php echo xls('Total'); ?>" + ' ' +
351 CheckBoxBillingCount + ' ' +
352 "<?php echo xls('Selected'); ?>\n" +
353 "<?php echo xls('Would You Like them to be Marked as Cleared.'); ?>\n" +
354 "<?php echo xls('Click OK to Clear or Cancel to continue processing.'); ?>"
355 )) {
356 document.getElementById('HiddenMarkAsCleared').value = 'yes';
357 } else {
358 document.getElementById('HiddenMarkAsCleared').value = '';
361 </script>
362 <?php require_once "$srcdir/../interface/reports/report.script.php"; ?>
363 <!-- Criteria Section common javascript page-->
364 <!-- =============Included for Insurance ajax criteria==== -->
365 <?php require_once "{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"; ?>
366 <style>
367 #ajax_div_insurance {
368 position: absolute;
369 z-index: 10;
370 background-color: #FBFDD0;
371 border: 1px solid #ccc;
372 padding: 10px;
374 button[type="submit"].subbtn-warning {
375 background: #ec971f !important;
376 color: black !important;
378 button[type="submit"].subbtn-warning:hover {
379 background: #da8104 !important;
380 color: #fff !important;
382 @media only screen and (max-width: 1024px) {
383 [class*="col-"] {
384 width: 100%;
385 text-align: left !Important;
388 .table {
389 margin: auto;
391 @media (min-width: 992px) {
392 .modal-lg {
393 width: 1000px !Important;
396 .table th, .table td {
397 border-top: none !important;
399 .form-control {
400 font-family: "FontAwesome"
402 ul > li {
403 line-height: 1.86em;
405 a, a:visited, a:hover {
406 text-decoration: none;
407 color: #000000;
409 </style>
410 <script>
411 document.onclick = TakeActionOnHide;
412 </script>
413 <!-- =============Included for Insurance ajax criteria==== -->
414 <title><?php echo xlt('Billing Manager'); ?></title>
415 </head>
416 <body class="body_top" onLoad="TestExpandCollapse()">
417 <div class="container">
418 <div class="row">
419 <div class="page-header">
420 <h2><?php echo xlt('Billing Manager') ?> &nbsp <i id="show_hide" class="fa fa-eye-slash fa-2x small"
421 title="<?php echo xla('Click to Hide'); ?>"></i></h2>
422 </div>
423 </div>
424 <div class="row">
425 <form name='the_form' method='post' action='billing_report.php' onsubmit='return top.restoreSession()' style="display:inline">
426 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
427 <input type='hidden' name='mode' value='change'>
428 <div class="col-xs-9">
429 <!-- ============================================================================================================================================= -->
430 <!-- Criteria section Starts -->
431 <!-- ============================================================================================================================================= -->
432 <?php
433 // The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
434 // Each item is seperated by a comma(,).
435 // $ThisPageSearchCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
436 // $ThisPageSearchCriteriaKeyMaster ==>Corresponding database fields in the same order.
437 // $ThisPageSearchCriteriaDataTypeMaster ==>Corresponding data type in the same order.
438 $ThisPageSearchCriteriaDisplayRadioMaster = array();
439 $ThisPageSearchCriteriaRadioKeyMaster = array();
440 $ThisPageSearchCriteriaQueryDropDownMaster = array();
441 $ThisPageSearchCriteriaQueryDropDownMasterDefault = array();
442 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey = array();
443 $ThisPageSearchCriteriaIncludeMaster = array();
445 if ($daysheet) {
446 $ThisPageSearchCriteriaDisplayMaster = array(
447 xl("Date of Service"),
448 xl("Date of Entry"),
449 xl("Date of Billing"),
450 xl("Claim Type"),
451 xl("Patient Name"),
452 xl("Patient Id"),
453 xl("Insurance Company"),
454 xl("Encounter"),
455 xl("Whether Insured"),
456 xl("Charge Coded"),
457 xl("Billing Status"),
458 xl("Authorization Status"),
459 xl("Last Level Billed"),
460 xl("X12 Partner"),
461 xl("User")
463 $ThisPageSearchCriteriaKeyMaster = "form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname," . "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed," . "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id,billing.user";
464 $ThisPageSearchCriteriaDataTypeMaster = "datetime,datetime,datetime,radio,text_like," . "text,include,text,radio,radio,radio," . "radio_like,radio,query_drop_down,text";
465 } else {
466 $ThisPageSearchCriteriaDisplayMaster = array(
467 xl("Date of Service"),
468 xl("Date of Entry"),
469 xl("Date of Billing"),
470 xl("Claim Type"),
471 xl("Patient Name"),
472 xl("Patient Id"),
473 xl("Insurance Company"),
474 xl("Encounter"),
475 xl("Whether Insured"),
476 xl("Charge Coded"),
477 xl("Billing Status"),
478 xl("Authorization Status"),
479 xl("Last Level Billed"),
480 xl("X12 Partner")
482 $ThisPageSearchCriteriaKeyMaster = "form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname," . "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed," . "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id";
483 $ThisPageSearchCriteriaDataTypeMaster = "datetime,datetime,datetime,radio,text_like," . "text,include,text,radio,radio,radio," . "radio_like,radio,query_drop_down";
485 // The below section is needed if there is any 'radio' or 'radio_like' type in the $ThisPageSearchCriteriaDataTypeMaster
486 // $ThisPageSearchCriteriaDisplayRadioMaster,$ThisPageSearchCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
487 // The key value 'all' indicates that no action need to be taken based on this.For that the key must be 'all'.Display value can be any thing.
488 $ThisPageSearchCriteriaDisplayRadioMaster[1] = array(
489 xl("All"),
490 xl("eClaims"),
491 xl("Paper")
492 ); // Display Value
493 $ThisPageSearchCriteriaRadioKeyMaster[1] = "all,standard,hcfa"; // Key
494 $ThisPageSearchCriteriaDisplayRadioMaster[2] = array(
495 xl("All"),
496 xl("Insured"),
497 xl("Non-Insured")
498 ); // Display Value
499 $ThisPageSearchCriteriaRadioKeyMaster[2] = "all,1,0"; // Key
500 $ThisPageSearchCriteriaDisplayRadioMaster[3] = array(
501 xl("All"),
502 xl("Coded"),
503 xl("Not Coded")
504 ); // Display Value
505 $ThisPageSearchCriteriaRadioKeyMaster[3] = "all,not null,null"; // Key
506 $ThisPageSearchCriteriaDisplayRadioMaster[4] = array(
507 xl("All"),
508 xl("Unbilled"),
509 xl("Billed"),
510 xl("Denied")
511 ); // Display Value
512 $ThisPageSearchCriteriaRadioKeyMaster[4] = "all,0,1,7"; // Key
513 $ThisPageSearchCriteriaDisplayRadioMaster[5] = array(
514 xl("All"),
515 xl("Authorized"),
516 xl("Unauthorized")
518 $ThisPageSearchCriteriaRadioKeyMaster[5] = "%,1,0";
519 $ThisPageSearchCriteriaDisplayRadioMaster[6] = array(
520 xl("All"),
521 xl("None"),
522 xl("Ins 1"),
523 xl("Ins 2 or Ins 3")
525 $ThisPageSearchCriteriaRadioKeyMaster[6] = "all,0,1,2";
526 // The below section is needed if there is any 'query_drop_down' type in the $ThisPageSearchCriteriaDataTypeMaster
527 $ThisPageSearchCriteriaQueryDropDownMaster[1] = "SELECT name,id FROM x12_partners;";
528 $ThisPageSearchCriteriaQueryDropDownMasterDefault[1] = xl("All"); // Only one item will be here
529 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey[1] = "all"; // Only one item will be here
530 // The below section is needed if there is any 'include' type in the $ThisPageSearchCriteriaDataTypeMaster
531 // Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
532 // It is labled(Included for Insurance ajax criteria)(Line:-279-299).
533 $ThisPageSearchCriteriaIncludeMaster[1] = "InsuranceCompanyDisplay"; // This is php function defined in the file 'report.inc.php'
535 if (!isset($_REQUEST['mode'])) {// default case
536 $_REQUEST['final_this_page_criteria'][0] = "(form_encounter.date between '" . date("Y-m-d 00:00:00") . "' and '" . date("Y-m-d 23:59:59") . "')";
537 $_REQUEST['final_this_page_criteria'][1] = "billing.billed = '0'";
538 $_REQUEST['final_this_page_criteria_text'][0] = xl("Date of Service = Today");
539 $_REQUEST['final_this_page_criteria_text'][1] = xl("Billing Status = Unbilled");
540 $_REQUEST['date_master_criteria_form_encounter_date'] = "today";
541 $_REQUEST['master_from_date_form_encounter_date'] = date("Y-m-d");
542 $_REQUEST['master_to_date_form_encounter_date'] = date("Y-m-d");
543 $_REQUEST['radio_billing_billed'] = 0;
546 <div class="hideaway">
547 <?php require_once "$srcdir/../interface/reports/criteria.tab.php"; ?>
548 </div>
549 <?php
550 // ============================================================================================================================================= -->
551 // Criteria section Ends -->
552 // ============================================================================================================================================= -->
555 </div>
556 <div class="form-group col-xs-3 hideaway">
557 <fieldset>
558 <legend><?php echo xlt('Select Action'); ?></legend>
559 <div class="form-group col-xs-12">
560 <div class='text'>
561 <ul>
562 <li><a class="link_submit" href="#"
563 onclick="javascript:return SubmitTheScreen();"><strong><?php echo xlt('Update List') ?></strong>
564 </a><i id='update-tooltip' class="fa fa-info-circle text-primary" aria-hidden="true"></i></li>
565 <li><a class='link_submit' href="#"
566 onclick="javascript:return SubmitTheScreenExportOFX();"><strong><?php echo xlt('Export OFX'); ?></strong></a>
567 </li>
568 <li><a class='link_submit' href="#" onclick="javascript:return SubmitTheScreenPrint();"><strong><?php echo xlt('View Printable Report'); ?></strong></a>
569 </li>
570 <span>
571 <?php if ($daysheet) { ?>
572 <li><a class='link_submit' href="#"
573 onclick="javascript:return SubmitTheEndDayPrint();"><strong><?php echo xlt('End Of Day Report') . ' - ' ?></strong></a>
574 <?php if ($daysheet_total) { ?>
575 <span class="text"><strong><?php echo xlt('Totals'); ?></strong></span>
576 <input name="end_of_day_totals_only" type="checkbox" value="1"></li>
577 <?php } ?>
578 <?php if ($provider_run) { ?>
579 <span class="text"><strong><?php echo xlt('Provider'); ?></strong></span>
580 <input name="end_of_day_provider_only" type="checkbox" value="1"></li>
581 <?php } ?>
582 <?php } ?>
583 </span>
584 <?php if (!file_exists($EXPORT_INC)) { ?>
585 <li><a href='#' id="view-log-link" data-toggle="modal" data-target="#myModal" class='link_submit'
586 title='<?php xla('See messages from the last set of generated claims'); ?>'><strong><?php echo xlt('View Log'); ?></strong></a>
587 </li>
588 <?php } ?>
589 <li><a class="link_submit"
590 href="JavaScript:void(0);" onclick="select_all(); return false;"><strong><?php echo xlt('Select All'); ?></strong></a>
591 </li>
592 </ul>
593 <ul>
594 </div>
595 </div>
596 </fieldset>
597 </div>
598 </form>
599 </div>
600 <div class="row">
601 <form class="form-inline" name='update_form' method='post' action='billing_process.php' onsubmit='return top.restoreSession()' style="display:inline">
602 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
603 <?php //can change position of buttons by creating a class 'position-override' and adding rule text-alig:center or right as the case may be in individual stylesheets ?>
604 <div class="form-group clearfix">
605 <div class="btn-group btn-group-pinch position-override" role="group">
606 <div class="btn-group">
607 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
608 name="bn_x12_support"
609 title="<?php echo xla('A claim must be selected to enable this menu.') ?>"><?php echo xla('X12 OPTIONS') ?>
610 <span class="caret"></span></button>
611 <ul class="dropdown-menu" role="menu">
612 <?php if (file_exists($EXPORT_INC)) { ?>
613 <li>
614 <button type="submit" data-open-popup="true" class="btn btn-default btn-download"
615 name="bn_external"
616 title="<?php echo xla('Export to external billing system') ?>"
617 value="<?php echo xla("Export Billing") ?>"><?php echo xla("Export Billing") ?></button>
618 </li>
619 <li>
620 <button type="submit" data-open-popup="true" class="btn btn-default btn-download"
621 name="bn_mark"
622 title="<?php echo xla('Mark as billed but skip billing') ?>"><?php echo xla("Mark as Cleared") ?></button>
623 </li>
624 <?php } else { ?>
625 <li>
626 <button type="submit" class="btn btn-default btn-download" name="bn_x12"
627 onclick="MarkAsCleared(1)"
628 title="<?php echo xla('Generate and download X12 batch') ?>"><?php echo xla('Generate X12') ?></button>
629 </li>
630 <?php } ?>
631 <?php if ($GLOBALS['ub04_support']) { ?>
632 <li>
633 <button type="submit" class="btn btn-default btn-download" name="bn_ub04_x12"
634 title="<?php echo xla('Generate Institutional X12 837I') ?>"><?php echo xla('Generate X12 837I') ?></button>
635 </li>
636 <?php } ?>
637 <?php if ($GLOBALS['support_encounter_claims']) { ?>
638 <li>
639 <button type="submit" class="btn btn-default btn-download" name="bn_x12_encounter"
640 onclick="MarkAsCleared(1)"
641 title="<?php echo xla('Generate and download X12 encounter claim batch') ?>"><?php echo xla('Generate X12 Encounter') ?></button>
642 </li>
643 <?php } ?>
644 </ul>
645 </div>
646 <div class="btn-group">
647 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
648 name="bn_process_hcfa_support"
649 title="<?php echo xla('A claim must be selected to enable this menu.') ?>"><?php echo xla('HCFA FORM') ?>
650 <span class="caret"></span></button>
651 <ul class="dropdown-menu" role="menu">
652 <li>
653 <button type="submit" class="btn btn-default btn-download" name="bn_process_hcfa"
654 onclick="MarkAsCleared(2)"
655 title="<?php echo xla('Generate and download CMS 1500 paper claims') ?>"><?php echo xla('CMS 1500 PDF') ?></button>
656 </li>
657 <?php if ($GLOBALS['preprinted_cms_1500']) { ?>
658 <li>
659 <button type="submit" class="btn btn-default btn-download"
660 name="bn_process_hcfa_form" onclick="MarkAsCleared(2)"
661 title="<?php echo xla('Generate and download CMS 1500 paper claims on Preprinted form') ?>"><?php echo xla('CMS 1500 incl FORM') ?></button>
662 </li>
663 <?php } ?>
664 <li>
665 <button type="submit" class="btn btn-default btn-download" name="bn_hcfa_txt_file"
666 onclick="MarkAsCleared(3)"
667 title="<?php echo xla('Making batch text files for uploading to Clearing House and will mark as billed') ?>"><?php echo xla('CMS 1500 TEXT') ?></button>
668 </li>
669 </ul>
670 </div>
671 <?php if ($GLOBALS['ub04_support']) { ?>
672 <div class="btn-group">
673 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
674 name="bn_process_ub04_support"
675 title="<?php echo xla('A claim must be selected to enable this menu.') ?>"><?php echo xla('UB04 FORM') ?>
676 <span class="caret"></span></button>
677 <ul class="dropdown-menu" role="menu">
678 <li>
679 <button type="submit" class="btn btn-default btn-download"
680 name="bn_process_ub04_form"
681 title="<?php echo xla('Generate and download UB-04 CMS1450 with form') ?>"><?php echo xla('UB04 FORM PDF') ?></button>
682 </li>
683 <li>
684 <button type="submit" class="btn btn-default btn-download" name="bn_process_ub04"
685 title="<?php echo xla('Generate and download UB-04 CMS1450') ?>"><?php echo xla('UB04 TEXT PDF') ?></button>
686 </li>
687 </ul>
688 </div>
689 <?php } ?>
690 <button class="btn btn-default btn-download" data-open-popup="true" name="bn_mark"
691 title="<?php echo xla('Post to accounting and mark as billed') ?>"
692 type="submit"><?php echo xla('Mark as Cleared') ?></button>
693 <button class="btn btn-default btn-undo" data-open-popup="true" name="bn_reopen"
694 title="<?php echo xla('Mark as not billed') ?>"
695 type="submit"><?php echo xla('Re-Open') ?></button>
696 </div>
697 <div class="input-group">
698 <label for="left_margin"><?php echo xlt('CMS 1500 Margins Left'); ?>:</label>
699 <input type='text' size='2' id='left_margin' name='left_margin'
700 value='<?php echo attr($left_margin); ?>'
701 title='<?php echo xla('HCFA left margin in points'); ?>'/>
702 <label for="top_margin"><?php echo xlt('Top'); ?>:</label>
703 <input type='text' size='2' id='top_margin' name='top_margin'
704 value='<?php echo attr($top_margin); ?>'
705 title='<?php echo xla('HCFA top margin in points'); ?>'/>
706 </div>
707 <?php if ($ub04_support) { ?>
708 <div class="input-group">
709 <label for="left_ubmargin"><?php echo xlt('UB04 Margins Left'); ?>:</label>
710 <input type='text' size='2' id='left_ubmargin' name='left_ubmargin'
711 value='<?php echo attr($left_ubmargin); ?>'
712 title='<?php echo xla('UB04 left margin in points'); ?>'/>
713 <label for="top_ubmargin"><?php echo xlt('Top'); ?>:</label>
714 <input type='text' size='2' id='top_ubmargin' name='top_ubmargin'
715 value='<?php echo attr($top_ubmargin); ?>'
716 title='<?php echo xla('UB04 top margin in points'); ?>'/>
717 </div>
718 <?php } ?>
719 </div>
720 <input id='HiddenMarkAsCleared' name='HiddenMarkAsCleared' type='hidden' value="">
721 <input name='mode' type='hidden' value="bill">
722 <input name='authorized' type='hidden' value="<?php echo attr($my_authorized); ?>">
723 <input name='unbilled' type='hidden' value="<?php echo attr($unbilled); ?>">
724 <input name='code_type' type='hidden' value="%">
725 <input name='to_date' type='hidden' value="<?php echo attr($to_date); ?>">
726 <input name='from_date' type='hidden' value="<?php echo attr($from_date); ?>">
727 <?php
728 if ($my_authorized == "on") {
729 $my_authorized = "1";
730 } else {
731 $my_authorized = "%";
733 if ($unbilled == "on") {
734 $unbilled = "0";
735 } else {
736 $unbilled = "%";
738 $list = getBillsListBetween("%");
740 <input name='bill_list' type='hidden' value="<?php echo attr($list); ?>"> <!-- new form for uploading -->
741 <?php
742 if (!isset($_POST["mode"])) {
743 if (!isset($_POST["from_date"])) {
744 $from_date = date("Y-m-d");
745 } else {
746 $from_date = $_POST["from_date"];
748 if (empty($_POST["to_date"])) {
749 $to_date = '';
750 } else {
751 $to_date = $_POST["to_date"];
753 if (!isset($_POST["code_type"])) {
754 $code_type = "all";
755 } else {
756 $code_type = $_POST["code_type"];
758 if (!isset($_POST["unbilled"])) {
759 $unbilled = "on";
760 } else {
761 $unbilled = $_POST["unbilled"];
763 if (!isset($_POST["authorized"])) {
764 $my_authorized = "on";
765 } else {
766 $my_authorized = $_POST["authorized"];
768 } else {
769 $from_date = $_POST["from_date"];
770 $to_date = $_POST["to_date"];
771 $code_type = $_POST["code_type"];
772 $unbilled = $_POST["unbilled"];
773 $my_authorized = $_POST["authorized"];
776 if ($my_authorized == "on") {
777 $my_authorized = "1";
778 } else {
779 $my_authorized = "%";
782 if ($unbilled == "on") {
783 $unbilled = "0";
784 } else {
785 $unbilled = "%";
788 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
789 billCodesList($list);
792 <div class="table-responsive">
793 <table class="table table-condensed">
794 <?php
795 $divnos = 0;
796 if ($ret = getBillsBetween("%")) {
797 if (is_array($ret)) {
799 <tr>
800 <td colspan='9' align="right">
801 <table width="250" border="0" cellspacing="0" cellpadding="0">
802 <tr>
803 <td width="100" id='ExpandAll'><a
804 onclick="expandcollapse('expand');" class='small'
805 href="JavaScript:void(0);"><?php echo '(' . xla('Expand All') . ')' ?></a>
806 </td>
807 <td width="100" id='CollapseAll'><a
808 onclick="expandcollapse('collapse');" class='small'
809 href="JavaScript:void(0);"><?php echo '(' . xla('Collapse All') . ')' ?></a>
810 </td>
811 <td width="50">&nbsp;</td>
812 </tr>
813 </table>
814 </td>
815 </tr>
816 <?php
818 $loop = 0;
819 $oldcode = "";
820 $last_encounter_id = "";
821 $lhtml = "";
822 $rhtml = "";
823 $lcount = 0;
824 $rcount = 0;
825 $bgcolor = "";
826 $skipping = false;
828 $mmo_empty_mod = false;
829 $mmo_num_charges = 0;
831 foreach ($ret as $iter) {
832 // We include encounters here that have never been billed. However
833 // if it had no selected billing items but does have non-selected
834 // billing items, then it is not of interest.
835 if (!$iter['id']) {
836 $res = sqlQuery(
837 "SELECT count(*) AS count FROM billing WHERE " .
838 "encounter = ? AND " .
839 "pid=? AND " .
840 "activity = 1",
841 array(
842 $iter['enc_encounter'],
843 $iter['enc_pid']
846 if ($res['count'] > 0) {
847 continue;
851 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
853 if ($last_encounter_id != $this_encounter_id) {
854 // This dumps all HTML for the previous encounter.
856 if ($lhtml) {
857 while ($rcount < $lcount) {
858 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='9'></td></tr>";
859 ++$rcount;
861 // This test handles the case where we are only listing encounters
862 // that appear to have a missing "25" modifier.
863 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
864 if ($DivPut == 'yes') {
865 $lhtml .= '</div>';
866 $DivPut = 'no';
868 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='" . attr($rcount) . "' valign='top'>\n$lhtml</td>$rhtml\n";
869 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n\n";
870 ++$encount;
874 $lhtml = "";
875 $rhtml = "";
876 $mmo_empty_mod = false;
877 $mmo_num_charges = 0;
879 // If there are ANY unauthorized items in this encounter and this is
880 // the normal case of viewing only authorized billing, then skip the
881 // entire encounter.
883 $skipping = false;
884 if ($my_authorized == '1') {
885 $res = sqlQuery(
886 "SELECT count(*) AS count FROM billing WHERE " .
887 "encounter = ? AND " .
888 "pid=? AND " .
889 "activity = 1 AND authorized = 0",
890 array(
891 $iter['enc_encounter'],
892 $iter['enc_pid']
895 if ($res['count'] > 0) {
896 $skipping = true;
897 $last_encounter_id = $this_encounter_id;
898 continue;
901 // Is there a MBO
903 $mboid = sqlQuery("SELECT forms.form_id FROM forms WHERE forms.encounter = ? AND forms.authorized = 1 AND forms.formdir = 'misc_billing_options' AND forms.deleted != 1 LIMIT 1", array($iter['enc_encounter']));
904 $iter['mboid'] = $mboid ? attr($mboid['form_id']) : 0;
906 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, billing_note, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
908 // Check if patient has primary insurance and a subscriber exists for it.
909 // If not we will highlight their name in red.
910 // TBD: more checking here.
912 $res = sqlQuery(
913 "SELECT count(*) AS count FROM insurance_data WHERE " .
914 "pid = ? AND " .
915 "type='primary' AND " .
916 "subscriber_lname IS NOT NULL AND " .
917 "subscriber_lname != '' LIMIT 1",
918 array(
919 $iter['enc_pid']
922 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
924 $bgcolor = "#" . (($encount & 1) ? "FFFAEF" : "F8F8FF");
925 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
926 $lcount = 1;
927 $rcount = 0;
928 $oldcode = "";
930 $ptname = $name['fname'] . " " . $name['lname'];
931 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
932 $billing_note = $name['billing_note'];
933 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
934 $lhtml .= "<span class=bold><font color='$namecolor'>" . text($ptname) . "</font></span><span class=small>&nbsp;(" . text($iter['enc_pid']) . "-" . text($iter['enc_encounter']) . ")</span>";
936 // Encounter details are stored to javacript as array.
937 $result4 = sqlStatement(
938 "SELECT fe.encounter,fe.date,fe.billing_note,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe " .
939 " LEFT JOIN openemr_postcalendar_categories ON fe.pc_catid=openemr_postcalendar_categories.pc_catid WHERE fe.pid = ? ORDER BY fe.date DESC",
940 array(
941 $iter['enc_pid']
944 if (sqlNumRows($result4) > 0) {
946 } ?>
947 <script>
948 Count = 0;
949 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
950 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
951 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
952 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
953 <?php
954 while ($rowresult4 = sqlFetchArray($result4)) {
956 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr($rowresult4['encounter']); ?>';
957 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date'])))); ?>';
958 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr(xl_appt_category($rowresult4['pc_catname'])); ?>';
959 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr($rowresult4['billing_note']); ?>';
960 Count++;
961 <?php
962 $enc_billing_note = $rowresult4['billing_note'];
965 </script>
966 <?php
967 $lhtml .= "<div class='button-group'>";
968 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
969 $lhtml .= "<a class=\"btn btn-xs btn-default\" role=\"button\" " . "href=\"javascript:window.toencounter(" . attr(addslashes($iter['enc_pid'])) . ",'" . attr(addslashes($name['pubpid'])) . "','" . attr(addslashes($ptname)) . "'," . attr(addslashes($iter['enc_encounter'])) . ",'" . attr(addslashes(oeFormatShortDate($raw_encounter_date))) . "',' " . attr(xls('DOB')) . ": " . attr(addslashes(oeFormatShortDate($name['DOB_YMD']))) . " " . attr(xls('Age')) . ": " . attr(addslashes(getPatientAge($name['DOB_YMD']))) . "');
970 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . attr(addslashes($iter['enc_pid'])) . "],EncounterDateArray[" . attr(addslashes($iter['enc_pid'])) . "], CalendarCategoryArray[" . attr(addslashes($iter['enc_pid'])) . "])\">" . xlt('Encounter') . " " . text(oeFormatShortDate($raw_encounter_date)) . "</a>";
972 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
973 $lhtml .= "<a class=\"btn btn-xs btn-default\" role=\"button\" " . "href=\"javascript:window.topatient(" . attr(addslashes($iter['enc_pid'])) . ",'" . attr(addslashes($name['pubpid'])) . "','" . attr(addslashes($ptname)) . "'," . attr(addslashes($iter['enc_encounter'])) . ",'" . attr(addslashes(oeFormatShortDate($raw_encounter_date))) . "',' " . attr(xls('DOB')) . ": " . attr(addslashes(oeFormatShortDate($name['DOB_YMD']))) . " " . attr(xls('Age')) . ": " . attr(addslashes(getPatientAge($name['DOB_YMD']))) . "');
974 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . attr(addslashes($iter['enc_pid'])) . "],EncounterDateArray[" . attr(addslashes($iter['enc_pid'])) . "], CalendarCategoryArray[" . attr(addslashes($iter['enc_pid'])) . "])\">" . xlt('Patient') . "</a>";
975 $is_edited = $iter['mboid'] ? 'btn-success' : 'btn-default';
976 $title = $iter['mboid'] ? xlt("This claim has HCFA 1500 miscellaneous billing options") : xlt("Click to add HCFA 1500 miscellaneous billing options");
977 $lhtml .= "<a class='btn btn-xs $is_edited' role='button' title='" . attr($title) . "' onclick='popMBO(" . attr(addslashes($iter['enc_pid'])) . "," . attr(addslashes($iter['enc_encounter'])) . "," . attr(addslashes($iter['mboid'])) . "); return false;'>" . xlt('MBO ') . "</a>";
978 if ($ub04_support && isset($iter['billed'])) {
979 $c = sqlQuery(
980 "SELECT submitted_claim AS status FROM claims WHERE " .
981 "encounter_id = ? AND " .
982 "patient_id=? " .
983 "ORDER BY version DESC LIMIT 1",
984 array(
985 $iter['enc_encounter'],
986 $iter['enc_pid']
989 $is_edited = $c['status'] ? 'btn-success' : 'btn-warning';
990 $bname = $c['status'] ? xl('Reviewed') : xl('Review UB04');
991 $lhtml .= "<a class='btn btn-xs $is_edited' role='button' onclick='popUB04(" . attr(addslashes($iter['enc_pid'])) . "," . attr(addslashes($iter['enc_encounter'])) . "); return false;'>" . text($bname) . "</a>";
993 $lhtml .= "</div>";
994 $divnos = $divnos + 1;
995 $lhtml .= "&nbsp;&nbsp;&nbsp;<a onclick='divtoggle(\"spanid_" . attr(addslashes($divnos)) . "\",\"divid_" . attr(addslashes($divnos)) . "\");' class='small' id='aid_" . attr($divnos) . "' href=\"JavaScript:void(0);" . "\">(<span id=spanid_" . attr($divnos) . " class=\"indicator\">" . xlt('Expand') . '</span>)<br></a>';
996 if ($GLOBALS['notes_to_display_in_Billing'] == 2 || $GLOBALS['notes_to_display_in_Billing'] == 3) {
997 $lhtml .= '<span style="margin-left: 20px; font-weight: bold; color: red">' . text($billing_note) . '</span>';
1000 if ($iter['id']) {
1001 $lcount += 2;
1002 $lhtml .= "<br />\n";
1003 $lhtml .= "&nbsp;<span class='form-group'>" . xlt('Bill') . ": ";
1004 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' style='background-color:$bgcolor'>";
1006 $query = "SELECT id.provider AS id, id.type, id.date, " .
1007 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
1008 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
1009 "ic.id = id.provider AND " .
1010 "id.pid = ? AND " .
1011 "id.date <= ? " .
1012 "ORDER BY id.type ASC, id.date DESC";
1014 $result = sqlStatement(
1015 $query,
1016 array(
1017 $iter['enc_pid'],
1018 $raw_encounter_date
1021 $count = 0;
1022 $default_x12_partner = $iter['ic_x12id'];
1023 $prevtype = '';
1025 while ($row = sqlFetchArray($result)) {
1026 if (strcmp($row['type'], $prevtype) == 0) {
1027 continue;
1029 $prevtype = $row['type'];
1030 if (strlen($row['provider']) > 0) {
1031 // This preserves any existing insurance company selection, which is
1032 // important when EOB posting has re-queued for secondary billing.
1033 $lhtml .= "<option value=\"" . attr(substr($row['type'], 0, 1) . $row['id']) . "\"";
1034 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
1035 $lhtml .= " selected";
1036 if (!is_numeric($default_x12_partner)) {
1037 $default_x12_partner = $row['ic_x12id'];
1040 $lhtml .= ">" . text($row['type']) . ": " . text($row['provider']) . "</option>";
1042 $count++;
1045 $lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
1046 $lhtml .= "</select>&nbsp;&nbsp;\n";
1047 $lhtml .= "&nbsp;<span class='form-group'>X12: ";
1048 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][partner]' style='background-color:$bgcolor'>";
1049 $x = new X12Partner();
1050 $partners = $x->_utility_array($x->x12_partner_factory());
1051 foreach ($partners as $xid => $xname) {
1052 $lhtml .= '<option label="' . attr($xname) . '" value="' . attr($xid) . '"';
1053 if ($xid == $default_x12_partner) {
1054 $lhtml .= "selected";
1056 $lhtml .= '>' . text($xname) . '</option>';
1058 $lhtml .= "<option value='-1' label='Unassigned'>" . xlt("Unassigned") . "</option>\n";
1059 $lhtml .= "</select></span>";
1060 $DivPut = 'yes';
1062 if ($GLOBALS['notes_to_display_in_Billing'] == 1 || $GLOBALS['notes_to_display_in_Billing'] == 3) {
1063 $lhtml .= "<br><span style='margin-left: 20px; font-weight: bold; color: green'>" . text($enc_billing_note) . "</span>";
1065 $lhtml .= "<br>\n&nbsp;<div id='divid_$divnos' style='display:none'>" . text(oeFormatShortDate(substr($iter['date'], 0, 10))) . text(substr($iter['date'], 10, 6)) . " " . xlt("Encounter was coded");
1067 $query = "SELECT * FROM claims WHERE patient_id = ? AND encounter_id = ? ORDER BY version";
1068 $cres = sqlStatement(
1069 $query,
1070 array(
1071 $iter['enc_pid'],
1072 $iter['enc_encounter']
1076 $lastcrow = false;
1078 while ($crow = sqlFetchArray($cres)) {
1079 $query = "SELECT id.type, ic.name " .
1080 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
1081 "id.pid = ? AND " .
1082 "id.provider = ? AND " .
1083 "id.date <= ? AND " .
1084 "ic.id = id.provider " .
1085 "ORDER BY id.type ASC, id.date DESC";
1087 $irow = sqlQuery(
1088 $query,
1089 array(
1090 $iter['enc_pid'],
1091 $crow['payer_id'],
1092 $raw_encounter_date
1096 if ($crow['bill_process']) {
1097 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) . text(substr($crow['bill_time'], 10, 6)) . " " . xlt("Queued for") . " " . text($irow['type']) . " " . text($crow['target']) . " " . xlt("billing to ") . text($irow['name']);
1098 ++$lcount;
1099 } elseif ($crow['status'] < 6) {
1100 if ($crow['status'] > 1) {
1101 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) . text(substr($crow['bill_time'], 10, 6)) . " " . xlt("Marked as cleared");
1102 ++$lcount;
1103 } else {
1104 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) . text(substr($crow['bill_time'], 10, 6)) . " " . xlt("Re-opened");
1105 ++$lcount;
1107 } elseif ($crow['status'] == 6) {
1108 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) . text(substr($crow['bill_time'], 10, 6)) . " " . xlt("This claim has been forwarded to next level.");
1109 ++$lcount;
1110 } elseif ($crow['status'] == 7) {
1111 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) . text(substr($crow['bill_time'], 10, 6)) . " " . xlt("This claim has been denied.Reason:-");
1112 if ($crow['process_file']) {
1113 $code_array = explode(',', $crow['process_file']);
1114 foreach ($code_array as $code_key => $code_value) {
1115 $lhtml .= "<br>\n&nbsp;&nbsp;&nbsp;";
1116 $reason_array = explode('_', $code_value);
1117 if (!isset($adjustment_reasons[$reason_array[3]])) {
1118 $lhtml .= xlt("For code") . ' [' . text($reason_array[0]) . '] ' . xlt("and modifier") . ' [' . text($reason_array[1]) . '] ' . xlt("the Denial code is") . ' [' . text($reason_array[2]) . ' ' . text($reason_array[3]) . ']';
1119 } else {
1120 $lhtml .= xlt("For code") . ' [' . text($reason_array[0]) . '] ' . xlt("and modifier") . ' [' . text($reason_array[1]) . '] ' . xlt("the Denial Group code is") . ' [' . text($reason_array[2]) . '] ' . xlt("and the Reason is") . ':- ' . text($adjustment_reasons[$reason_array[3]]);
1123 } else {
1124 $lhtml .= xlt("Not Specified.");
1126 ++$lcount;
1129 if ($crow['process_time']) {
1130 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['process_time'], 0, 10))) . text(substr($crow['process_time'], 10, 6)) . " " . xlt("Claim was generated to file") . " " . "<a href='get_claim_file.php?key=" . attr($crow['process_file']) . "&csrf_token_form=" . attr(urlencode(collectCsrfToken())) . "' onclick='top.restoreSession()'>" . text($crow['process_file']) . "</a>";
1131 ++$lcount;
1134 $lastcrow = $crow;
1135 } // end while ($crow = sqlFetchArray($cres))
1137 if ($lastcrow && $lastcrow['status'] == 4) {
1138 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been closed.");
1139 ++$lcount;
1142 if ($lastcrow && $lastcrow['status'] == 5) {
1143 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been canceled.");
1144 ++$lcount;
1146 } // end if ($iter['id'])
1147 } // end if ($last_encounter_id != $this_encounter_id)
1149 if ($skipping) {
1150 continue;
1153 // Collect info related to the missing modifiers test.
1154 if ($iter['fee'] > 0) {
1155 ++$mmo_num_charges;
1156 $tmp = substr($iter['code'], 0, 3);
1157 if (($tmp == '992' || $tmp == '993') && empty($iter['modifier'])) {
1158 $mmo_empty_mod = true;
1162 ++$rcount;
1164 if ($rhtml) {
1165 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
1167 $rhtml .= "<td width='50'>";
1168 if ($iter['id'] && $oldcode != $iter['code_type']) {
1169 $rhtml .= "<span class=text>" . text($iter['code_type']) . ": </span>";
1172 $oldcode = $iter['code_type'];
1173 $rhtml .= "</td>\n";
1174 $justify = "";
1176 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
1177 $js = explode(":", $iter['justify']);
1178 $counter = 0;
1179 foreach ($js as $j) {
1180 if (!empty($j)) {
1181 if ($counter == 0) {
1182 $justify .= " (<b>" . text($j) . "</b>)";
1183 } else {
1184 $justify .= " (" . text($j) . ")";
1186 $counter++;
1191 $rhtml .= "<td><span class='text'>" . ($iter['code_type'] == 'COPAY' ? text(oeFormatMoney($iter['code'])) : text($iter['code']));
1192 if ($iter['modifier']) {
1193 $rhtml .= ":" . text($iter['modifier']);
1195 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
1197 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1198 if ($iter['id'] && $iter['fee'] > 0) {
1199 $rhtml .= text(oeFormatMoney($iter['fee']));
1201 $rhtml .= "</span></td>\n";
1202 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1203 if ($iter['id']) {
1204 $rhtml .= getProviderName(empty($iter['provider_id']) ? text($iter['enc_provider_id']) : text($iter['provider_id']));
1206 $rhtml .= "</span></td>\n";
1207 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1208 if ($GLOBALS['display_units_in_billing'] != 0) {
1209 if ($iter['id']) {
1210 $rhtml .= xlt("Units") . ":" . text($iter{"units"});
1213 $rhtml .= "</span></td>\n";
1214 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1215 if ($iter['id']) {
1216 $rhtml .= text(oeFormatSDFT(strtotime($iter{"date"})));
1218 $rhtml .= "</span></td>\n";
1219 // This error message is generated if the authorized check box is not checked
1220 if ($iter['id'] && $iter['authorized'] != 1) {
1221 $rhtml .= "<td><span class=alert>" . xlt("Note: This code has not been authorized.") . "</span></td>\n";
1222 } else {
1223 $rhtml .= "<td></td>\n";
1225 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
1226 $tmpbpr = $iter['bill_process'];
1227 if ($tmpbpr == '0' && $iter['billed']) {
1228 $tmpbpr = '2';
1230 $rhtml .= "<td><input type='checkbox' value='" . attr($tmpbpr) . "' name='claims[" . attr($this_encounter_id) . "][bill]' onclick='set_button_states()' id='CheckBoxBilling" . attr($CheckBoxBilling * 1) . "'>&nbsp;</td>\n";
1231 $CheckBoxBilling++;
1232 } else {
1233 $rhtml .= "<td></td>\n";
1235 if ($last_encounter_id != $this_encounter_id) {
1236 $rhtml2 = "";
1237 $rowcnt = 0;
1238 $resMoneyGot = sqlStatement(
1239 "SELECT pay_amount AS PatientPay,date(post_time) AS date FROM ar_activity WHERE " .
1240 "pid = ? AND encounter = ? AND payer_type=0 AND account_code='PCP'",
1241 array(
1242 $iter['enc_pid'],
1243 $iter['enc_encounter']
1246 // new fees screen copay gives account_code='PCP'
1247 if (sqlNumRows($resMoneyGot) > 0) {
1248 $lcount += 2;
1249 $rcount++;
1251 // checks whether a copay exists for the encounter and if exists displays it.
1252 while ($rowMoneyGot = sqlFetchArray($resMoneyGot)) {
1253 $rowcnt++;
1254 $PatientPay = $rowMoneyGot['PatientPay'];
1255 $date = $rowMoneyGot['date'];
1256 if ($PatientPay > 0) {
1257 if ($rhtml) {
1258 $rhtml2 .= "<tr bgcolor='$bgcolor'>\n";
1260 $rhtml2 .= "<td width='50'>";
1261 $rhtml2 .= "<span class='text'>" . xlt('COPAY') . ": </span>";
1262 $rhtml2 .= "</td>\n";
1263 $rhtml2 .= "<td><span class='text'>" . text(oeFormatMoney($PatientPay)) . "</span><span style='font-size:8pt;'>&nbsp;</span></td>\n";
1264 $rhtml2 .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1265 $rhtml2 .= "</span></td>\n";
1266 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1267 $rhtml2 .= "</span></td>\n";
1268 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1269 $rhtml2 .= "</span></td>\n";
1270 $rhtml2 .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1271 $rhtml2 .= text(oeFormatSDFT(strtotime($date)));
1272 $rhtml2 .= "</span></td>\n";
1273 if ($iter['id'] && $iter['authorized'] != 1) {
1274 $rhtml2 .= "<td><span class=alert>" . xlt("Note: This copay was entered against billing that has not been authorized. Please review status.") . "</span></td>\n";
1275 } else {
1276 $rhtml2 .= "<td></td>\n";
1278 if (!$iter['id'] && $rowcnt == 1) {
1279 $rhtml2 .= "<td><input type='checkbox' value='0' name='claims[" . attr($this_encounter_id) . "][bill]' onclick='set_button_states()' id='CheckBoxBilling" . attr($CheckBoxBilling * 1) . "'>&nbsp;</td>\n";
1280 $CheckBoxBilling++;
1281 } else {
1282 $rhtml2 .= "<td></td>\n";
1286 $rhtml .= $rhtml2;
1288 $rhtml .= "</tr>\n";
1289 $last_encounter_id = $this_encounter_id;
1290 } // end foreach
1292 if ($lhtml) {
1293 while ($rcount < $lcount) {
1294 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='9'></td></tr>";
1295 ++$rcount;
1297 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
1298 if ($DivPut == 'yes') {
1299 $lhtml .= '</div>';
1300 $DivPut = 'no';
1302 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='" . attr($rcount) . "' valign='top' width='25%'>\n$lhtml</td>$rhtml\n";
1303 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
1310 </table>
1311 </form>
1312 </div>
1313 </div><!--end of container div -->
1314 <div class="row">
1315 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
1316 <div class="modal-dialog oe-modal-dialog modal-lg">
1317 <div class="modal-content oe-modal-content">
1318 <div class="modal-header clearfix">
1319 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"
1320 style="color:#000000; font-size:1.5em;">×</span>
1321 </button>
1322 </div>
1323 <div class="modal-body">
1324 <iframe src="" id="targetiframe" style="height:650px; width:100%; overflow-x: hidden; border:none"
1325 allowtransparency="true"></iframe>
1326 </div>
1327 <div class="modal-footer" style="margin-top:0px;">
1328 <button class="btn btn-link btn-cancel pull-right" data-dismiss="modal"
1329 type="button"><?php echo xlt('close'); ?></button>
1330 </div>
1331 </div>
1332 </div>
1333 </div>
1334 </div>
1335 <script>
1336 $(document).ready(function () {
1337 $('#help-href').click(function () {
1338 document.getElementById('targetiframe').src = '';
1340 $('#view-log-link').click(function () {
1341 document.getElementById('targetiframe').src = 'customize_log.php';
1344 </script>
1345 <script>
1346 $('#show_hide').click(function () {
1347 var elementTitle = $('#show_hide').prop('title');
1348 var hideTitle = '<?php echo xla('Click to Hide'); ?>';
1349 var showTitle = '<?php echo xla('Click to Show'); ?>';
1350 $('.hideaway').toggle('1000');
1351 $(this).toggleClass('fa-eye-slash fa-eye');
1352 if (elementTitle == hideTitle) {
1353 elementTitle = showTitle;
1354 } else if (elementTitle == showTitle) {
1355 elementTitle = hideTitle;
1357 $('#show_hide').prop('title', elementTitle);
1359 </script>
1360 <script>
1361 set_button_states();
1362 <?php
1363 if ($alertmsg) {
1364 echo "alert('" . addslashes($alertmsg) . "');\n";
1367 $(document).ready(function () {
1368 $('button[type="submit"]').click(function () {
1369 top.restoreSession();
1370 $(this).attr('data-clicked', true);
1373 $('form[name="update_form"]').submit(function (e) {
1374 var clickedButton = $("button[type=submit][data-clicked='true'")[0];
1375 // clear clicked button indicator
1376 $('button[type="submit"]').attr('data-clicked', false);
1378 if (!clickedButton || $(clickedButton).attr("data-open-popup") !== "true") {
1379 $(this).removeAttr("target");
1380 return top.restoreSession();
1381 } else {
1382 top.restoreSession();
1383 var w = window.open('about:blank', 'Popup_Window', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300,left = 312,top = 234');
1384 this.target = 'Popup_Window';
1388 $('.datepicker').datetimepicker({
1389 <?php $datetimepicker_timepicker = false; ?>
1390 <?php $datetimepicker_showseconds = false; ?>
1391 <?php $datetimepicker_formatInput = false; ?>
1392 <?php require $GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'; ?>
1393 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
1396 </script>
1397 <script>
1398 $(document).ready(function () {
1399 $('#update-tooltip').tooltip({title: "<?php echo xla('Click Update List to display billing information filtered by the selected Current Criteria'); ?>"});
1401 </script>
1402 <input type="hidden" name="divnos" id="divnos" value="<?php echo attr($divnos) ?>"/>
1403 <input type='hidden' name='ajax_mode' id='ajax_mode' value=''/>
1404 </body>
1405 </html>