consolidate attr_url function (#2143)
[openemr.git] / interface / billing / billing_report.php
blobecc828c35ff52d0104ef266c9c22450840549ad9
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-2019 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";
24 use OpenEMR\Billing\BillingUtilities;
25 use OpenEMR\Core\Header;
26 use OpenEMR\OeUI\OemrUI;
28 $EXPORT_INC = "$webserver_root/custom/BillingExport.php";
29 // echo $GLOBALS['daysheet_provider_totals'];
31 $daysheet = false;
32 $daysheet_total = false;
33 $provider_run = false;
35 if ($GLOBALS['use_custom_daysheet'] != 0) {
36 $daysheet = true;
37 if ($GLOBALS['daysheet_provider_totals'] == 1) {
38 $daysheet_total = true;
39 $provider_run = false;
41 if ($GLOBALS['daysheet_provider_totals'] == 0) {
42 $daysheet_total = false;
43 $provider_run = true;
47 $alertmsg = '';
49 if (isset($_POST['mode'])) {
50 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
51 csrfNotVerified();
54 if ($_POST['mode'] == 'export') {
55 $sql = ReturnOFXSql();
56 $db = get_db();
57 $results = $db->Execute($sql);
58 $billings = array();
59 if ($results->RecordCount() == 0) {
60 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;'>";
61 echo xlt("No Bills Found to Include in OFX Export") . "<br>";
62 echo "</fieldset>";
63 } else {
64 while (!$results->EOF) {
65 $billings[] = $results->fields;
66 $results->MoveNext();
68 $ofx = new OFX($billings);
69 header("Pragma: public");
70 header("Expires: 0");
71 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
72 header("Content-Disposition: attachment; filename=openemr_ofx.ofx");
73 header("Content-Type: text/xml");
74 echo $ofx->get_OFX();
75 exit();
80 // global variables:
81 $from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
82 $to_date = isset($_POST['to_date']) ? $_POST['to_date'] : '';
83 $code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
84 $unbilled = isset($_POST['unbilled']) ? $_POST['unbilled'] : 'on';
85 $my_authorized = isset($_POST["authorized"]) ? $_POST["authorized"] : '';
87 // This tells us if only encounters that appear to be missing a "25" modifier
88 // are to be reported.
89 $missing_mods_only = (isset($_POST['missing_mods_only']) && !empty($_POST['missing_mods_only']));
91 $left_margin = isset($_POST["left_margin"]) ? $_POST["left_margin"] : $GLOBALS['cms_left_margin_default'];
92 $top_margin = isset($_POST["top_margin"]) ? $_POST["top_margin"] : $GLOBALS['cms_top_margin_default'];
93 if ($ub04_support) {
94 $left_ubmargin = isset($_POST["left_ubmargin"]) ? $_POST["left_ubmargin"] : $GLOBALS['left_ubmargin_default'];
95 $top_ubmargin = isset($_POST["top_ubmargin"]) ? $_POST["top_ubmargin"] : $GLOBALS['top_ubmargin_default'];
97 $ofrom_date = $from_date;
98 $oto_date = $to_date;
99 $ocode_type = $code_type;
100 $ounbilled = $unbilled;
101 $oauthorized = $my_authorized;
102 $x = new X12Partner();
103 $partners = $x->_utility_array($x->x12_partner_factory());
105 <!DOCTYPE html >
106 <html>
107 <head>
109 <?php Header::setupHeader(['datetime-picker', 'common']); ?>
110 <style>
111 /*.subbtn { margin-top:3px; margin-bottom:3px; margin-left:2px; margin-right:2px }*/
112 .btn-group-pinch > .btn:nth-last-child(4):not(.dropdown-toggle) {
113 border-top-right-radius: 3px !Important;
114 border-bottom-right-radius: 3px !Important;
116 </style>
117 <script>
118 var partners = <?php echo json_encode($partners); ?>;
119 function onNewPayer(oEvent) {
120 let p = oEvent.target.options[event.target.selectedIndex].dataset.partner;
121 let partnerSelect = oEvent.target.options[event.target.selectedIndex].dataset.partner;
122 partnerSelect = partnerSelect ? partnerSelect : -1;
123 document.getElementById("partners").value = partnerSelect;
126 function select_all() {
127 for ($i = 0; $i < document.update_form.length; $i++) {
128 $name = document.update_form[$i].name;
129 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -
130 6) == "[bill]") {
131 document.update_form[$i].checked = true;
134 set_button_states();
137 function set_button_states() {
138 var f = document.update_form;
139 var count0 = 0; // selected and not billed or queued
140 var count1 = 0; // selected and queued
141 var count2 = 0; // selected and billed
142 for ($i = 0; $i < f.length; ++$i) {
143 $name = f[$i].name;
144 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -
145 6) == "[bill]" && f[$i].checked == true) {
146 if (f[$i].value == '0') ++count0;
147 else if (f[$i].value == '1' || f[$i].value == '5') ++count1;
148 else ++count2;
151 var can_generate = (count0 > 0 || count1 > 0 || count2 > 0);
152 var can_mark = (count1 > 0 || count0 > 0 || count2 > 0);
153 var can_bill = (count0 == 0 && count1 == 0 && count2 > 0);
154 <?php if (file_exists($EXPORT_INC)) { ?>
155 f.bn_external.disabled = !can_generate;
156 <?php } else { ?>
157 f.bn_x12_support.disabled = !can_generate;
158 <?php if ($GLOBALS['support_encounter_claims']) { ?>
159 f.bn_x12_encounter.disabled = !can_generate;
160 <?php } ?>
161 f.bn_process_hcfa_support.disabled = !can_generate;
162 <?php if ($GLOBALS['preprinted_cms_1500']) { ?>
163 f.bn_process_hcfa_form.disabled = !can_generate;
164 <?php } ?>
165 <?php if ($GLOBALS['ub04_support']) { ?>
166 f.bn_process_ub04_support.disabled = !can_generate;
167 <?php } ?>
168 f.bn_hcfa_txt_file.disabled = !can_generate;
169 f.bn_reopen.disabled = !can_bill;
170 <?php } ?>
171 f.bn_mark.disabled = !can_mark;
174 // Process a click to go to an encounter.
175 function toencounter(pid, pubpid, pname, enc, datestr, dobstr) {
176 top.restoreSession();
177 encurl = 'patient_file/encounter/encounter_top.php?set_encounter=' + enc +
178 '&pid=' + pid;
179 parent.left_nav.setPatient(pname, pid, pubpid, '', dobstr);
180 <?php if ($GLOBALS['new_tabs_layout']) { ?>
181 parent.left_nav.setEncounter(datestr, enc, 'enc');
182 parent.left_nav.loadFrame('enc2', 'enc', encurl);
183 <?php } else { ?>
184 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
185 parent.left_nav.setEncounter(datestr, enc, othername);
186 parent.frames[othername].location.href = '../' + encurl;
187 <?php } ?>
190 // Process a click to go to an patient.
191 function topatient(pid, pubpid, pname, enc, datestr, dobstr) {
192 top.restoreSession();
193 paturl = 'patient_file/summary/demographics_full.php?pid=' + pid;
194 parent.left_nav.setPatient(pname, pid, pubpid, '', dobstr);
195 <?php if ($GLOBALS['new_tabs_layout']) { ?>
196 parent.left_nav.loadFrame('ens1', 'enc',
197 'patient_file/history/encounters.php?pid=' + pid);
198 parent.left_nav.loadFrame('dem1', 'pat', paturl);
199 <?php } else { ?>
200 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
201 parent.frames[othername].location.href = '../' + paturl;
202 <?php } ?>
205 function popMBO(pid, enc, mboid) {
206 if (!window.focus) return true;
207 if (!ProcessBeforeSubmitting()) return false;
208 top.restoreSession();
209 let qstring = "&pid=" + pid + "&enc=" + enc + "&id=" + mboid;
210 let href = "<?php echo $GLOBALS['web_root']?>/interface/patient_file/encounter/view_form.php?formname=misc_billing_options&isBilling=1" + qstring;
211 dlgopen(href, 'mbopop', 'modal-lg', 750, false, '', {
212 sizeHeight: 'full' // override min height auto size.
214 return true;
217 function popUB04(pid, enc) {
218 if (!window.focus) return true;
219 if (!ProcessBeforeSubmitting()) return false;
220 top.restoreSession();
221 let href = "<?php echo $GLOBALS['web_root']?>/interface/billing/ub04_form.php?pid=" + pid + "&enc=" + enc;
222 dlgopen(href, 'ub04pop', 1175, 750, false, '', {
223 sizeHeight: 'full' // override min height auto size.
225 return true;
228 var EncounterDateArray = new Array;
229 var CalendarCategoryArray = new Array;
230 var EncounterIdArray = new Array;
231 var EncounterNoteArray = new Array;
233 function SubmitTheScreen() { //Action on Update List link
234 if (!ProcessBeforeSubmitting()) return false;
235 $("#update-tooltip").replaceWith("<i class='fa fa-refresh fa-spin fa-1x' style=\"color:red\"></i>");
236 top.restoreSession();
237 document.the_form.mode.value = 'change';
238 document.the_form.target = '_self';
239 document.the_form.action = 'billing_report.php';
240 document.the_form.submit();
241 return true;
244 function SubmitTheScreenPrint() { //Action on View Printable Report link
245 if (!ProcessBeforeSubmitting()) return false;
246 top.restoreSession();
247 document.the_form.target = 'new';
248 document.the_form.action = 'print_billing_report.php';
249 document.the_form.submit();
250 return true;
253 function SubmitTheEndDayPrint() { //Action on View End of Day Report link
254 if (!ProcessBeforeSubmitting()) return false;
255 top.restoreSession();
256 document.the_form.target = 'new';
257 <?php if ($GLOBALS['use_custom_daysheet'] == 1) { ?>
258 document.the_form.action = 'print_daysheet_report_num1.php';
259 <?php } ?>
260 <?php if ($GLOBALS['use_custom_daysheet'] == 2) { ?>
261 document.the_form.action = 'print_daysheet_report_num2.php';
262 <?php } ?>
263 <?php if ($GLOBALS['use_custom_daysheet'] == 3) { ?>
264 document.the_form.action = 'print_daysheet_report_num3.php';
265 <?php } ?>
266 document.the_form.submit();
267 return true;
270 function SubmitTheScreenExportOFX() { //Action on Export OFX link
271 if (!ProcessBeforeSubmitting()) return false;
272 top.restoreSession();
273 document.the_form.mode.value = 'export';
274 document.the_form.target = '_self';
275 document.the_form.action = 'billing_report.php';
276 document.the_form.submit();
277 return true;
280 function TestExpandCollapse() { //Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
281 var set = -1;
282 for (i = 1; i <= document.getElementById("divnos").value; i++) {
283 var ele = document.getElementById("divid_" + i);
284 if (ele) {
285 set = 1;
286 break;
289 if (set == -1) {
290 if (document.getElementById("ExpandAll")) {
291 document.getElementById("ExpandAll").innerHTML = '';
292 document.getElementById("CollapseAll").innerHTML = '';
297 function expandcollapse(atr) {
298 if (atr == "expand") { //Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
299 for (i = 1; i <= document.getElementById("divnos").value; i++) {
300 var mydivid = "divid_" + i;
301 var myspanid = "spanid_" + i;
302 var ele = document.getElementById(mydivid);
303 var text = document.getElementById(myspanid);
304 if (ele) {
305 ele.style.display = "inline";
306 text.innerHTML =
307 "<?php echo xla('Collapse'); ?>";
310 } else {
311 for (i = 1; i <= document.getElementById("divnos").value; i++) {
312 var mydivid = "divid_" + i;
313 var myspanid = "spanid_" + i;
314 var ele = document.getElementById(mydivid);
315 var text = document.getElementById(myspanid);
316 if (ele) {
317 ele.style.display = "none";
318 text.innerHTML =
319 "<?php echo xla('Expand'); ?>";
325 function divtoggle(spanid, divid) { //Called in the Expand, Collapse links(This is for a single item)
326 var ele = document.getElementById(divid);
327 if (ele) {
328 var text = document.getElementById(spanid);
329 if (ele.style.display == "inline") {
330 ele.style.display = "none";
331 text.innerHTML =
332 "<?php echo xla('Expand'); ?>";
333 } else {
334 ele.style.display = "inline";
335 text.innerHTML =
336 "<?php echo xla('Collapse'); ?>";
341 function MarkAsCleared(Type) {
342 CheckBoxBillingCount = 0;
343 for (var CheckBoxBillingIndex = 0; ; CheckBoxBillingIndex++) {
344 CheckBoxBillingObject = document.getElementById('CheckBoxBilling' +
345 CheckBoxBillingIndex);
346 if (!CheckBoxBillingObject) break;
347 if (CheckBoxBillingObject.checked) {
348 ++CheckBoxBillingCount;
351 if (Type == 1) {
352 Message = '<?php echo xla('After saving your batch, click[View Log] to check for errors.'); ?>';
354 if (Type == 2) {
355 Message = '<?php echo xla('After saving the PDF, click[View Log] to check for errors.'); ?>';
357 if (Type == 3) {
358 Message = '<?php echo xla('After saving the TEXT file(s), click[View Log] to check for errors.'); ?>';
360 if (confirm(Message + "\n\n\n<?php echo xls('Total'); ?>" + ' ' +
361 CheckBoxBillingCount + ' ' +
362 "<?php echo xls('Selected'); ?>\n" +
363 "<?php echo xls('Would You Like them to be Marked as Cleared.'); ?>\n" +
364 "<?php echo xls('Click OK to Clear or Cancel to continue processing.'); ?>"
365 )) {
366 document.getElementById('HiddenMarkAsCleared').value = 'yes';
367 } else {
368 document.getElementById('HiddenMarkAsCleared').value = '';
371 </script>
372 <?php require_once "$srcdir/../interface/reports/report.script.php"; ?>
373 <!-- Criteria Section common javascript page-->
374 <!-- =============Included for Insurance ajax criteria==== -->
375 <?php require_once "{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"; ?>
376 <style>
377 #ajax_div_insurance {
378 position: absolute;
379 z-index: 10;
380 background-color: #FBFDD0;
381 border: 1px solid #ccc;
382 padding: 10px;
384 button[type="submit"].subbtn-warning {
385 background: #ec971f !important;
386 color: black !important;
388 button[type="submit"].subbtn-warning:hover {
389 background: #da8104 !important;
390 color: #fff !important;
392 @media only screen and (max-width: 1024px) {
393 [class*="col-"] {
394 width: 100%;
395 text-align: left !Important;
398 .table {
399 margin: auto;
401 @media (min-width: 992px) {
402 .modal-lg {
403 width: 1000px !Important;
406 .table th, .table td {
407 border-top: none !important;
409 .form-control {
410 font-family: "FontAwesome"
412 ul > li {
413 line-height: 1.86em;
415 a, a:visited, a:hover {
416 text-decoration: none;
417 color: #000000;
419 </style>
420 <script>
421 document.onclick = TakeActionOnHide;
422 </script>
423 <!-- =============Included for Insurance ajax criteria==== -->
424 <title><?php echo xlt('Billing Manager'); ?></title>
425 <?php
426 $arrOeUiSettings = array(
427 'heading_title' => xl('Billing Manager'),
428 'include_patient_name' => false,// use only in appropriate pages
429 'expandable' => true,
430 'expandable_files' => array('billing_report_xpd'),//all file names need suffix _xpd
431 'action' => "conceal",//conceal, reveal, search, reset, link or back
432 'action_title' => "",
433 'action_href' => "",//only for actions - reset, link or back
434 'show_help_icon' => false,
435 'help_file_name' => ""
437 $oemr_ui = new OemrUI($arrOeUiSettings);
439 </head>
440 <body class="body_top" onLoad="TestExpandCollapse()">
441 <div id="container_div" class="<?php echo $oemr_ui->oeContainer();?>">
442 <div class="row">
443 <div class="col-sm-12">
444 <div class="page-header">
445 <!--<h2>
446 <?php echo xlt('Billing Manager') ?> <i id="exp_cont_icon" class="fa <?php echo attr($expand_icon_class);?> oe-superscript-small expand_contract"
447 title="<?php echo attr($expand_title); ?>" aria-hidden="true"></i> <i id="show_hide" class="fa fa-eye-slash fa-2x small"
448 title="<?php echo xla('Click to Hide'); ?>"></i>
449 </h2>-->
450 <?php echo $oemr_ui->pageHeading() . "\r\n"; ?>
451 </div>
452 </div>
453 </div>
454 <div class="row">
455 <div class="col-sm-12">
456 <form name='the_form' method='post' action='billing_report.php' onsubmit='return top.restoreSession()' style="display:inline">
457 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
458 <input type='hidden' name='mode' value='change'>
459 <div class="col-xs-9">
460 <!-- ============================================================================================================================================= -->
461 <!-- Criteria section Starts -->
462 <!-- ============================================================================================================================================= -->
463 <?php
464 // The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
465 // Each item is seperated by a comma(,).
466 // $ThisPageSearchCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
467 // $ThisPageSearchCriteriaKeyMaster ==>Corresponding database fields in the same order.
468 // $ThisPageSearchCriteriaDataTypeMaster ==>Corresponding data type in the same order.
469 $ThisPageSearchCriteriaDisplayRadioMaster = array();
470 $ThisPageSearchCriteriaRadioKeyMaster = array();
471 $ThisPageSearchCriteriaQueryDropDownMaster = array();
472 $ThisPageSearchCriteriaQueryDropDownMasterDefault = array();
473 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey = array();
474 $ThisPageSearchCriteriaIncludeMaster = array();
476 if ($daysheet) {
477 $ThisPageSearchCriteriaDisplayMaster = array(
478 xl("Date of Service"),
479 xl("Date of Entry"),
480 xl("Date of Billing"),
481 xl("Claim Type"),
482 xl("Patient Name"),
483 xl("Patient Id"),
484 xl("Insurance Company"),
485 xl("Encounter"),
486 xl("Whether Insured"),
487 xl("Charge Coded"),
488 xl("Billing Status"),
489 xl("Authorization Status"),
490 xl("Last Level Billed"),
491 xl("X12 Partner"),
492 xl("User")
494 $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";
495 $ThisPageSearchCriteriaDataTypeMaster = "datetime,datetime,datetime,radio,text_like," . "text,include,text,radio,radio,radio," . "radio_like,radio,query_drop_down,text";
496 } else {
497 $ThisPageSearchCriteriaDisplayMaster = array(
498 xl("Date of Service"),
499 xl("Date of Entry"),
500 xl("Date of Billing"),
501 xl("Claim Type"),
502 xl("Patient Name"),
503 xl("Patient Id"),
504 xl("Insurance Company"),
505 xl("Encounter"),
506 xl("Whether Insured"),
507 xl("Charge Coded"),
508 xl("Billing Status"),
509 xl("Authorization Status"),
510 xl("Last Level Billed"),
511 xl("X12 Partner")
513 $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";
514 $ThisPageSearchCriteriaDataTypeMaster = "datetime,datetime,datetime,radio,text_like," . "text,include,text,radio,radio,radio," . "radio_like,radio,query_drop_down";
516 // The below section is needed if there is any 'radio' or 'radio_like' type in the $ThisPageSearchCriteriaDataTypeMaster
517 // $ThisPageSearchCriteriaDisplayRadioMaster,$ThisPageSearchCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
518 // 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.
519 $ThisPageSearchCriteriaDisplayRadioMaster[1] = array(
520 xl("All"),
521 xl("eClaims"),
522 xl("Paper")
523 ); // Display Value
524 $ThisPageSearchCriteriaRadioKeyMaster[1] = "all,standard,hcfa"; // Key
525 $ThisPageSearchCriteriaDisplayRadioMaster[2] = array(
526 xl("All"),
527 xl("Insured"),
528 xl("Non-Insured")
529 ); // Display Value
530 $ThisPageSearchCriteriaRadioKeyMaster[2] = "all,1,0"; // Key
531 $ThisPageSearchCriteriaDisplayRadioMaster[3] = array(
532 xl("All"),
533 xl("Coded"),
534 xl("Not Coded")
535 ); // Display Value
536 $ThisPageSearchCriteriaRadioKeyMaster[3] = "all,not null,null"; // Key
537 $ThisPageSearchCriteriaDisplayRadioMaster[4] = array(
538 xl("All"),
539 xl("Unbilled"),
540 xl("Billed"),
541 xl("Denied")
542 ); // Display Value
543 $ThisPageSearchCriteriaRadioKeyMaster[4] = "all,0,1,7"; // Key
544 $ThisPageSearchCriteriaDisplayRadioMaster[5] = array(
545 xl("All"),
546 xl("Authorized"),
547 xl("Unauthorized")
549 $ThisPageSearchCriteriaRadioKeyMaster[5] = "%,1,0";
550 $ThisPageSearchCriteriaDisplayRadioMaster[6] = array(
551 xl("All"),
552 xl("None"),
553 xl("Ins 1"),
554 xl("Ins 2 or Ins 3")
556 $ThisPageSearchCriteriaRadioKeyMaster[6] = "all,0,1,2";
557 // The below section is needed if there is any 'query_drop_down' type in the $ThisPageSearchCriteriaDataTypeMaster
558 $ThisPageSearchCriteriaQueryDropDownMaster[1] = "SELECT name,id FROM x12_partners;";
559 $ThisPageSearchCriteriaQueryDropDownMasterDefault[1] = xl("All"); // Only one item will be here
560 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey[1] = "all"; // Only one item will be here
561 // The below section is needed if there is any 'include' type in the $ThisPageSearchCriteriaDataTypeMaster
562 // Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
563 // It is labled(Included for Insurance ajax criteria)(Line:-279-299).
564 $ThisPageSearchCriteriaIncludeMaster[1] = "InsuranceCompanyDisplay"; // This is php function defined in the file 'report.inc.php'
566 if (!isset($_REQUEST['mode'])) {// default case
567 $_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") . "')";
568 $_REQUEST['final_this_page_criteria'][1] = "billing.billed = '0'";
569 $_REQUEST['final_this_page_criteria_text'][0] = xl("Date of Service = Today");
570 $_REQUEST['final_this_page_criteria_text'][1] = xl("Billing Status = Unbilled");
571 $_REQUEST['date_master_criteria_form_encounter_date'] = "today";
572 $_REQUEST['master_from_date_form_encounter_date'] = date("Y-m-d");
573 $_REQUEST['master_to_date_form_encounter_date'] = date("Y-m-d");
574 $_REQUEST['radio_billing_billed'] = 0;
577 <div class="hideaway">
578 <?php require_once "$srcdir/../interface/reports/criteria.tab.php"; ?>
579 </div>
580 <?php
581 // ============================================================================================================================================= -->
582 // Criteria section Ends -->
583 // ============================================================================================================================================= -->
586 </div>
587 <div class="form-group col-xs-3 hideaway">
588 <fieldset>
589 <legend><?php echo xlt('Select Action'); ?></legend>
590 <div class="form-group col-xs-12">
591 <div class='text'>
592 <ul>
593 <li><a class="link_submit" href="#"
594 onclick="javascript:return SubmitTheScreen();"><strong><?php echo xlt('Update List') ?></strong>
595 </a><i id='update-tooltip' class="fa fa-info-circle text-primary" aria-hidden="true"></i></li>
596 <li><a class='link_submit' href="#"
597 onclick="javascript:return SubmitTheScreenExportOFX();"><strong><?php echo xlt('Export OFX'); ?></strong></a>
598 </li>
599 <li><a class='link_submit' href="#" onclick="javascript:return SubmitTheScreenPrint();"><strong><?php echo xlt('View Printable Report'); ?></strong></a>
600 </li>
601 <span>
602 <?php if ($daysheet) { ?>
603 <li><a class='link_submit' href="#"
604 onclick="javascript:return SubmitTheEndDayPrint();"><strong><?php echo xlt('End Of Day Report') . ' - ' ?></strong></a>
605 <?php if ($daysheet_total) { ?>
606 <span class="text"><strong><?php echo xlt('Totals'); ?></strong></span>
607 <input name="end_of_day_totals_only" type="checkbox" value="1"></li>
608 <?php } ?>
609 <?php if ($provider_run) { ?>
610 <span class="text"><strong><?php echo xlt('Provider'); ?></strong></span>
611 <input name="end_of_day_provider_only" type="checkbox" value="1"></li>
612 <?php } ?>
613 <?php } ?>
614 </span>
615 <?php if (!file_exists($EXPORT_INC)) { ?>
616 <li><a href='#' id="view-log-link" data-toggle="modal" data-target="#myModal" class='link_submit'
617 title='<?php xla('See messages from the last set of generated claims'); ?>'><strong><?php echo xlt('View Log'); ?></strong></a>
618 </li>
619 <?php } ?>
620 <li><a class="link_submit"
621 href="JavaScript:void(0);" onclick="select_all(); return false;"><strong><?php echo xlt('Select All'); ?></strong></a>
622 </li>
623 </ul>
624 <ul>
625 </div>
626 </div>
627 </fieldset>
628 </div>
629 </form>
630 </div>
631 </div>
632 <div class="row">
633 <div class="col-sm-12">
634 <form class="form-inline" name='update_form' method='post' action='billing_process.php' onsubmit='return top.restoreSession()' style="display:inline">
635 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
636 <?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 ?>
637 <div class="form-group clearfix">
638 <div class="btn-group btn-group-pinch position-override" role="group">
639 <div class="btn-group">
640 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
641 name="bn_x12_support"
642 title="<?php echo xla('A claim must be selected to enable this menu.') ?>"><?php echo xla('X12 OPTIONS') ?>
643 <span class="caret"></span></button>
644 <ul class="dropdown-menu" role="menu">
645 <?php if (file_exists($EXPORT_INC)) { ?>
646 <li>
647 <button type="submit" data-open-popup="true" class="btn btn-default btn-download"
648 name="bn_external"
649 title="<?php echo xla('Export to external billing system') ?>"
650 value="<?php echo xla("Export Billing") ?>"><?php echo xla("Export Billing") ?></button>
651 </li>
652 <li>
653 <button type="submit" data-open-popup="true" class="btn btn-default btn-download"
654 name="bn_mark"
655 title="<?php echo xla('Mark as billed but skip billing') ?>"><?php echo xla("Mark as Cleared") ?></button>
656 </li>
657 <?php } else { ?>
658 <li>
659 <button type="submit" class="btn btn-default btn-download" name="bn_x12"
660 onclick="MarkAsCleared(1)"
661 title="<?php echo xla('Generate and download X12 batch') ?>"><?php echo xla('Generate X12') ?></button>
662 </li>
663 <?php } ?>
664 <?php if ($GLOBALS['ub04_support']) { ?>
665 <li>
666 <button type="submit" class="btn btn-default btn-download" name="bn_ub04_x12"
667 title="<?php echo xla('Generate Institutional X12 837I') ?>"><?php echo xla('Generate X12 837I') ?></button>
668 </li>
669 <?php } ?>
670 <?php if ($GLOBALS['support_encounter_claims']) { ?>
671 <li>
672 <button type="submit" class="btn btn-default btn-download" name="bn_x12_encounter"
673 onclick="MarkAsCleared(1)"
674 title="<?php echo xla('Generate and download X12 encounter claim batch') ?>"><?php echo xla('Generate X12 Encounter') ?></button>
675 </li>
676 <?php } ?>
677 </ul>
678 </div>
679 <div class="btn-group">
680 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
681 name="bn_process_hcfa_support"
682 title="<?php echo xla('A claim must be selected to enable this menu.') ?>"><?php echo xla('HCFA FORM') ?>
683 <span class="caret"></span></button>
684 <ul class="dropdown-menu" role="menu">
685 <li>
686 <button type="submit" class="btn btn-default btn-download" name="bn_process_hcfa"
687 onclick="MarkAsCleared(2)"
688 title="<?php echo xla('Generate and download CMS 1500 paper claims') ?>"><?php echo xla('CMS 1500 PDF') ?></button>
689 </li>
690 <?php if ($GLOBALS['preprinted_cms_1500']) { ?>
691 <li>
692 <button type="submit" class="btn btn-default btn-download"
693 name="bn_process_hcfa_form" onclick="MarkAsCleared(2)"
694 title="<?php echo xla('Generate and download CMS 1500 paper claims on Preprinted form') ?>"><?php echo xla('CMS 1500 incl FORM') ?></button>
695 </li>
696 <?php } ?>
697 <li>
698 <button type="submit" class="btn btn-default btn-download" name="bn_hcfa_txt_file"
699 onclick="MarkAsCleared(3)"
700 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>
701 </li>
702 </ul>
703 </div>
704 <?php if ($GLOBALS['ub04_support']) { ?>
705 <div class="btn-group">
706 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
707 name="bn_process_ub04_support"
708 title="<?php echo xla('A claim must be selected to enable this menu.') ?>"><?php echo xla('UB04 FORM') ?>
709 <span class="caret"></span></button>
710 <ul class="dropdown-menu" role="menu">
711 <li>
712 <button type="submit" class="btn btn-default btn-download"
713 name="bn_process_ub04_form"
714 title="<?php echo xla('Generate and download UB-04 CMS1450 with form') ?>"><?php echo xla('UB04 FORM PDF') ?></button>
715 </li>
716 <li>
717 <button type="submit" class="btn btn-default btn-download" name="bn_process_ub04"
718 title="<?php echo xla('Generate and download UB-04 CMS1450') ?>"><?php echo xla('UB04 TEXT PDF') ?></button>
719 </li>
720 </ul>
721 </div>
722 <?php } ?>
723 <button class="btn btn-default btn-download" data-open-popup="true" name="bn_mark"
724 title="<?php echo xla('Post to accounting and mark as billed') ?>"
725 type="submit"><?php echo xla('Mark as Cleared') ?></button>
726 <button class="btn btn-default btn-undo" data-open-popup="true" name="bn_reopen"
727 title="<?php echo xla('Mark as not billed') ?>"
728 type="submit"><?php echo xla('Re-Open') ?></button>
729 </div>
730 <div class="input-group">
731 <label for="left_margin"><?php echo xlt('CMS 1500 Margins Left'); ?>:</label>
732 <input type='text' size='2' id='left_margin' name='left_margin'
733 value='<?php echo attr($left_margin); ?>'
734 title='<?php echo xla('HCFA left margin in points'); ?>'/>
735 <label for="top_margin"><?php echo xlt('Top'); ?>:</label>
736 <input type='text' size='2' id='top_margin' name='top_margin'
737 value='<?php echo attr($top_margin); ?>'
738 title='<?php echo xla('HCFA top margin in points'); ?>'/>
739 </div>
740 <?php if ($ub04_support) { ?>
741 <div class="input-group">
742 <label for="left_ubmargin"><?php echo xlt('UB04 Margins Left'); ?>:</label>
743 <input type='text' size='2' id='left_ubmargin' name='left_ubmargin'
744 value='<?php echo attr($left_ubmargin); ?>'
745 title='<?php echo xla('UB04 left margin in points'); ?>'/>
746 <label for="top_ubmargin"><?php echo xlt('Top'); ?>:</label>
747 <input type='text' size='2' id='top_ubmargin' name='top_ubmargin'
748 value='<?php echo attr($top_ubmargin); ?>'
749 title='<?php echo xla('UB04 top margin in points'); ?>'/>
750 </div>
751 <?php } ?>
752 </div>
753 <input id='HiddenMarkAsCleared' name='HiddenMarkAsCleared' type='hidden' value="">
754 <input name='mode' type='hidden' value="bill">
755 <input name='authorized' type='hidden' value="<?php echo attr($my_authorized); ?>">
756 <input name='unbilled' type='hidden' value="<?php echo attr($unbilled); ?>">
757 <input name='code_type' type='hidden' value="%">
758 <input name='to_date' type='hidden' value="<?php echo attr($to_date); ?>">
759 <input name='from_date' type='hidden' value="<?php echo attr($from_date); ?>">
760 <?php
761 if ($my_authorized == "on") {
762 $my_authorized = "1";
763 } else {
764 $my_authorized = "%";
766 if ($unbilled == "on") {
767 $unbilled = "0";
768 } else {
769 $unbilled = "%";
771 $list = getBillsListBetween("%");
773 <input name='bill_list' type='hidden' value="<?php echo attr($list); ?>"> <!-- new form for uploading -->
774 <?php
775 if (!isset($_POST["mode"])) {
776 if (!isset($_POST["from_date"])) {
777 $from_date = date("Y-m-d");
778 } else {
779 $from_date = $_POST["from_date"];
781 if (empty($_POST["to_date"])) {
782 $to_date = '';
783 } else {
784 $to_date = $_POST["to_date"];
786 if (!isset($_POST["code_type"])) {
787 $code_type = "all";
788 } else {
789 $code_type = $_POST["code_type"];
791 if (!isset($_POST["unbilled"])) {
792 $unbilled = "on";
793 } else {
794 $unbilled = $_POST["unbilled"];
796 if (!isset($_POST["authorized"])) {
797 $my_authorized = "on";
798 } else {
799 $my_authorized = $_POST["authorized"];
801 } else {
802 $from_date = $_POST["from_date"];
803 $to_date = $_POST["to_date"];
804 $code_type = $_POST["code_type"];
805 $unbilled = $_POST["unbilled"];
806 $my_authorized = $_POST["authorized"];
809 if ($my_authorized == "on") {
810 $my_authorized = "1";
811 } else {
812 $my_authorized = "%";
815 if ($unbilled == "on") {
816 $unbilled = "0";
817 } else {
818 $unbilled = "%";
821 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
822 billCodesList($list);
825 <div class="table-responsive">
826 <table class="table table-condensed">
827 <?php
828 $divnos = 0;
829 if ($ret = getBillsBetween("%")) {
830 if (is_array($ret)) {
832 <tr>
833 <td colspan='9' align="right">
834 <table width="250" border="0" cellspacing="0" cellpadding="0">
835 <tr>
836 <td width="100" id='ExpandAll'><a
837 onclick="expandcollapse('expand');" class='small'
838 href="JavaScript:void(0);"><?php echo '(' . xla('Expand All') . ')' ?></a>
839 </td>
840 <td width="100" id='CollapseAll'><a
841 onclick="expandcollapse('collapse');" class='small'
842 href="JavaScript:void(0);"><?php echo '(' . xla('Collapse All') . ')' ?></a>
843 </td>
844 <td width="50">&nbsp;</td>
845 </tr>
846 </table>
847 </td>
848 </tr>
849 <?php
851 $loop = 0;
852 $oldcode = "";
853 $last_encounter_id = "";
854 $lhtml = "";
855 $rhtml = "";
856 $lcount = 0;
857 $rcount = 0;
858 $bgcolor = "";
859 $skipping = false;
861 $mmo_empty_mod = false;
862 $mmo_num_charges = 0;
864 foreach ($ret as $iter) {
865 // We include encounters here that have never been billed. However
866 // if it had no selected billing items but does have non-selected
867 // billing items, then it is not of interest.
868 if (!$iter['id']) {
869 $res = sqlQuery(
870 "SELECT count(*) AS count FROM billing WHERE " .
871 "encounter = ? AND " .
872 "pid=? AND " .
873 "activity = 1",
874 array(
875 $iter['enc_encounter'],
876 $iter['enc_pid']
879 if ($res['count'] > 0) {
880 continue;
884 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
886 if ($last_encounter_id != $this_encounter_id) {
887 // This dumps all HTML for the previous encounter.
889 if ($lhtml) {
890 while ($rcount < $lcount) {
891 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='9'></td></tr>";
892 ++$rcount;
894 // This test handles the case where we are only listing encounters
895 // that appear to have a missing "25" modifier.
896 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
897 if ($DivPut == 'yes') {
898 $lhtml .= '</div>';
899 $DivPut = 'no';
901 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='" . attr($rcount) . "' valign='top'>\n$lhtml</td>$rhtml\n";
902 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n\n";
903 ++$encount;
907 $lhtml = "";
908 $rhtml = "";
909 $mmo_empty_mod = false;
910 $mmo_num_charges = 0;
912 // If there are ANY unauthorized items in this encounter and this is
913 // the normal case of viewing only authorized billing, then skip the
914 // entire encounter.
916 $skipping = false;
917 if ($my_authorized == '1') {
918 $res = sqlQuery(
919 "SELECT count(*) AS count FROM billing WHERE " .
920 "encounter = ? AND " .
921 "pid=? AND " .
922 "activity = 1 AND authorized = 0",
923 array(
924 $iter['enc_encounter'],
925 $iter['enc_pid']
928 if ($res['count'] > 0) {
929 $skipping = true;
930 $last_encounter_id = $this_encounter_id;
931 continue;
934 // Is there a MBO
936 $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']));
937 $iter['mboid'] = $mboid ? attr($mboid['form_id']) : 0;
939 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, billing_note, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
941 // Check if patient has primary insurance and a subscriber exists for it.
942 // If not we will highlight their name in red.
943 // TBD: more checking here.
945 $res = sqlQuery(
946 "SELECT count(*) AS count FROM insurance_data WHERE " .
947 "pid = ? AND " .
948 "type='primary' AND " .
949 "subscriber_lname IS NOT NULL AND " .
950 "subscriber_lname != '' LIMIT 1",
951 array(
952 $iter['enc_pid']
955 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
957 $bgcolor = "#" . (($encount & 1) ? "FFFAEF" : "F8F8FF");
958 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
959 $lcount = 1;
960 $rcount = 0;
961 $oldcode = "";
963 $ptname = $name['fname'] . " " . $name['lname'];
964 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
965 $billing_note = $name['billing_note'];
966 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
967 $lhtml .= "<span class=bold><font color='$namecolor'>" . text($ptname) . "</font></span><span class=small>&nbsp;(" . text($iter['enc_pid']) . "-" . text($iter['enc_encounter']) . ")</span>";
969 // Encounter details are stored to javacript as array.
970 $result4 = sqlStatement(
971 "SELECT fe.encounter,fe.date,fe.billing_note,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe " .
972 " LEFT JOIN openemr_postcalendar_categories ON fe.pc_catid=openemr_postcalendar_categories.pc_catid WHERE fe.pid = ? ORDER BY fe.date DESC",
973 array(
974 $iter['enc_pid']
977 if (sqlNumRows($result4) > 0) {
979 } ?>
980 <script>
981 Count = 0;
982 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
983 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
984 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
985 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
986 <?php
987 while ($rowresult4 = sqlFetchArray($result4)) {
989 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr($rowresult4['encounter']); ?>';
990 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date'])))); ?>';
991 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr(xl_appt_category($rowresult4['pc_catname'])); ?>';
992 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr($rowresult4['billing_note']); ?>';
993 Count++;
994 <?php
995 $enc_billing_note = $rowresult4['billing_note'];
998 </script>
999 <?php
1000 $lhtml .= "<div class='button-group'>";
1001 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
1002 $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']))) . "');
1003 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>";
1005 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
1006 $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']))) . "');
1007 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>";
1008 $is_edited = $iter['mboid'] ? 'btn-success' : 'btn-default';
1009 $title = $iter['mboid'] ? xlt("This claim has HCFA 1500 miscellaneous billing options") : xlt("Click to add HCFA 1500 miscellaneous billing options");
1010 $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>";
1011 if ($ub04_support && isset($iter['billed'])) {
1012 $c = sqlQuery(
1013 "SELECT submitted_claim AS status FROM claims WHERE " .
1014 "encounter_id = ? AND " .
1015 "patient_id=? " .
1016 "ORDER BY version DESC LIMIT 1",
1017 array(
1018 $iter['enc_encounter'],
1019 $iter['enc_pid']
1022 $is_edited = $c['status'] ? 'btn-success' : 'btn-warning';
1023 $bname = $c['status'] ? xl('Reviewed') : xl('Review UB04');
1024 $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>";
1026 $lhtml .= "</div>";
1027 $divnos = $divnos + 1;
1028 $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>';
1029 if ($GLOBALS['notes_to_display_in_Billing'] == 2 || $GLOBALS['notes_to_display_in_Billing'] == 3) {
1030 $lhtml .= '<span style="margin-left: 20px; font-weight: bold; color: red">' . text($billing_note) . '</span>';
1033 if ($iter['id']) {
1034 $lcount += 2;
1035 $lhtml .= "<br />\n";
1036 $lhtml .= "&nbsp;<span class='form-group'>" . xlt('Bill') . ": ";
1037 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' onchange='onNewPayer(event)' style='background-color:$bgcolor'>";
1039 $query = "SELECT id.provider AS id, id.type, id.date, " .
1040 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
1041 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
1042 "ic.id = id.provider AND " .
1043 "id.pid = ? AND " .
1044 "id.date <= ? " .
1045 "ORDER BY id.type ASC, id.date DESC";
1047 $result = sqlStatement(
1048 $query,
1049 array(
1050 $iter['enc_pid'],
1051 $raw_encounter_date
1054 $count = 0;
1055 $default_x12_partner = $iter['ic_x12id'];
1056 $prevtype = '';
1058 while ($row = sqlFetchArray($result)) {
1059 if (strcmp($row['type'], $prevtype) == 0) {
1060 continue;
1062 $prevtype = $row['type'];
1063 if (strlen($row['provider']) > 0) {
1064 // This preserves any existing insurance company selection, which is
1065 // important when EOB posting has re-queued for secondary billing.
1066 $lhtml .= "<option value=\"" . attr(substr($row['type'], 0, 1) . $row['id']) . "\"";
1067 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
1068 $lhtml .= " selected";
1069 if (!is_numeric($default_x12_partner)) {
1070 $default_x12_partner = $row['ic_x12id'];
1073 $lhtml .= " data-partner='" . attr($row['ic_x12id']) . "'>" . text($row['type']) . ": " . text($row['provider']) . "</option>";
1075 $count++;
1078 $lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
1079 $lhtml .= "</select>&nbsp;&nbsp;\n";
1080 $lhtml .= "&nbsp;<span class='form-group'>X12: ";
1081 $lhtml .= "<select id='partners' name='claims[" . attr($this_encounter_id) . "][partner]' style='margin-top:5px; background-color:$bgcolor'>";
1082 $lhtml .= "<option value='-1' label='Unassigned'>" . xlt("Partner not configured") . "</option>\n";
1083 foreach ($partners as $xid => $xname) {
1084 if (empty(trim($xname))) {
1085 continue;
1087 $lhtml .= '<option label="' . attr($xname) . '" value="' . attr($xid) . '"';
1088 if ($xid == $default_x12_partner) {
1089 $lhtml .= "selected";
1091 $lhtml .= '>' . text($xname) . '</option>';
1093 $lhtml .= "</select></span>";
1094 $DivPut = 'yes';
1096 if ($GLOBALS['notes_to_display_in_Billing'] == 1 || $GLOBALS['notes_to_display_in_Billing'] == 3) {
1097 $lhtml .= "<br><span style='margin-left: 20px; font-weight: bold; color: green'>" . text($enc_billing_note) . "</span>";
1099 $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");
1101 $query = "SELECT * FROM claims WHERE patient_id = ? AND encounter_id = ? ORDER BY version";
1102 $cres = sqlStatement(
1103 $query,
1104 array(
1105 $iter['enc_pid'],
1106 $iter['enc_encounter']
1110 $lastcrow = false;
1112 while ($crow = sqlFetchArray($cres)) {
1113 $query = "SELECT id.type, ic.name " .
1114 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
1115 "id.pid = ? AND " .
1116 "id.provider = ? AND " .
1117 "id.date <= ? AND " .
1118 "ic.id = id.provider " .
1119 "ORDER BY id.type ASC, id.date DESC";
1121 $irow = sqlQuery(
1122 $query,
1123 array(
1124 $iter['enc_pid'],
1125 $crow['payer_id'],
1126 $raw_encounter_date
1130 if ($crow['bill_process']) {
1131 $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']);
1132 ++$lcount;
1133 } elseif ($crow['status'] < 6) {
1134 if ($crow['status'] > 1) {
1135 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) . text(substr($crow['bill_time'], 10, 6)) . " " . xlt("Marked as cleared");
1136 ++$lcount;
1137 } else {
1138 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) . text(substr($crow['bill_time'], 10, 6)) . " " . xlt("Re-opened");
1139 ++$lcount;
1141 } elseif ($crow['status'] == 6) {
1142 $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.");
1143 ++$lcount;
1144 } elseif ($crow['status'] == 7) {
1145 $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:-");
1146 if ($crow['process_file']) {
1147 $code_array = explode(',', $crow['process_file']);
1148 foreach ($code_array as $code_key => $code_value) {
1149 $lhtml .= "<br>\n&nbsp;&nbsp;&nbsp;";
1150 $reason_array = explode('_', $code_value);
1151 if (!isset($adjustment_reasons[$reason_array[3]])) {
1152 $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]) . ']';
1153 } else {
1154 $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]]);
1157 } else {
1158 $lhtml .= xlt("Not Specified.");
1160 ++$lcount;
1163 if ($crow['process_time']) {
1164 $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_url($crow['process_file']) . "&csrf_token_form=" . attr_url(collectCsrfToken()) . "' onclick='top.restoreSession()'>" . text($crow['process_file']) . "</a>";
1165 ++$lcount;
1168 $lastcrow = $crow;
1169 } // end while ($crow = sqlFetchArray($cres))
1171 if ($lastcrow && $lastcrow['status'] == 4) {
1172 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been closed.");
1173 ++$lcount;
1176 if ($lastcrow && $lastcrow['status'] == 5) {
1177 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been canceled.");
1178 ++$lcount;
1180 } // end if ($iter['id'])
1181 } // end if ($last_encounter_id != $this_encounter_id)
1183 if ($skipping) {
1184 continue;
1187 // Collect info related to the missing modifiers test.
1188 if ($iter['fee'] > 0) {
1189 ++$mmo_num_charges;
1190 $tmp = substr($iter['code'], 0, 3);
1191 if (($tmp == '992' || $tmp == '993') && empty($iter['modifier'])) {
1192 $mmo_empty_mod = true;
1196 ++$rcount;
1198 if ($rhtml) {
1199 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
1201 $rhtml .= "<td width='50'>";
1202 if ($iter['id'] && $oldcode != $iter['code_type']) {
1203 $rhtml .= "<span class=text>" . text($iter['code_type']) . ": </span>";
1206 $oldcode = $iter['code_type'];
1207 $rhtml .= "</td>\n";
1208 $justify = "";
1210 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
1211 $js = explode(":", $iter['justify']);
1212 $counter = 0;
1213 foreach ($js as $j) {
1214 if (!empty($j)) {
1215 if ($counter == 0) {
1216 $justify .= " (<b>" . text($j) . "</b>)";
1217 } else {
1218 $justify .= " (" . text($j) . ")";
1220 $counter++;
1225 $rhtml .= "<td><span class='text'>" . ($iter['code_type'] == 'COPAY' ? text(oeFormatMoney($iter['code'])) : text($iter['code']));
1226 if ($iter['modifier']) {
1227 $rhtml .= ":" . text($iter['modifier']);
1229 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
1231 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1232 if ($iter['id'] && $iter['fee'] > 0) {
1233 $rhtml .= text(oeFormatMoney($iter['fee']));
1235 $rhtml .= "</span></td>\n";
1236 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1237 if ($iter['id']) {
1238 $rhtml .= getProviderName(empty($iter['provider_id']) ? text($iter['enc_provider_id']) : text($iter['provider_id']));
1240 $rhtml .= "</span></td>\n";
1241 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1242 if ($GLOBALS['display_units_in_billing'] != 0) {
1243 if ($iter['id']) {
1244 $rhtml .= xlt("Units") . ":" . text($iter{"units"});
1247 $rhtml .= "</span></td>\n";
1248 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1249 if ($iter['id']) {
1250 $rhtml .= text(oeFormatSDFT(strtotime($iter{"date"})));
1252 $rhtml .= "</span></td>\n";
1253 // This error message is generated if the authorized check box is not checked
1254 if ($iter['id'] && $iter['authorized'] != 1) {
1255 $rhtml .= "<td><span class=alert>" . xlt("Note: This code has not been authorized.") . "</span></td>\n";
1256 } else {
1257 $rhtml .= "<td></td>\n";
1259 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
1260 $tmpbpr = $iter['bill_process'];
1261 if ($tmpbpr == '0' && $iter['billed']) {
1262 $tmpbpr = '2';
1264 $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";
1265 $CheckBoxBilling++;
1266 } else {
1267 $rhtml .= "<td></td>\n";
1269 if ($last_encounter_id != $this_encounter_id) {
1270 $rhtml2 = "";
1271 $rowcnt = 0;
1272 $resMoneyGot = sqlStatement(
1273 "SELECT pay_amount AS PatientPay,date(post_time) AS date FROM ar_activity WHERE " .
1274 "pid = ? AND encounter = ? AND payer_type=0 AND account_code='PCP'",
1275 array(
1276 $iter['enc_pid'],
1277 $iter['enc_encounter']
1280 // new fees screen copay gives account_code='PCP'
1281 if (sqlNumRows($resMoneyGot) > 0) {
1282 $lcount += 2;
1283 $rcount++;
1285 // checks whether a copay exists for the encounter and if exists displays it.
1286 while ($rowMoneyGot = sqlFetchArray($resMoneyGot)) {
1287 $rowcnt++;
1288 $PatientPay = $rowMoneyGot['PatientPay'];
1289 $date = $rowMoneyGot['date'];
1290 if ($PatientPay > 0) {
1291 if ($rhtml) {
1292 $rhtml2 .= "<tr bgcolor='$bgcolor'>\n";
1294 $rhtml2 .= "<td width='50'>";
1295 $rhtml2 .= "<span class='text'>" . xlt('COPAY') . ": </span>";
1296 $rhtml2 .= "</td>\n";
1297 $rhtml2 .= "<td><span class='text'>" . text(oeFormatMoney($PatientPay)) . "</span><span style='font-size:8pt;'>&nbsp;</span></td>\n";
1298 $rhtml2 .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1299 $rhtml2 .= "</span></td>\n";
1300 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1301 $rhtml2 .= "</span></td>\n";
1302 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1303 $rhtml2 .= "</span></td>\n";
1304 $rhtml2 .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1305 $rhtml2 .= text(oeFormatSDFT(strtotime($date)));
1306 $rhtml2 .= "</span></td>\n";
1307 if ($iter['id'] && $iter['authorized'] != 1) {
1308 $rhtml2 .= "<td><span class=alert>" . xlt("Note: This copay was entered against billing that has not been authorized. Please review status.") . "</span></td>\n";
1309 } else {
1310 $rhtml2 .= "<td></td>\n";
1312 if (!$iter['id'] && $rowcnt == 1) {
1313 $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";
1314 $CheckBoxBilling++;
1315 } else {
1316 $rhtml2 .= "<td></td>\n";
1320 $rhtml .= $rhtml2;
1322 $rhtml .= "</tr>\n";
1323 $last_encounter_id = $this_encounter_id;
1324 } // end foreach
1326 if ($lhtml) {
1327 while ($rcount < $lcount) {
1328 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='9'></td></tr>";
1329 ++$rcount;
1331 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
1332 if ($DivPut == 'yes') {
1333 $lhtml .= '</div>';
1334 $DivPut = 'no';
1336 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='" . attr($rcount) . "' valign='top' width='25%'>\n$lhtml</td>$rhtml\n";
1337 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
1344 </table>
1345 </form>
1346 </div>
1347 </div>
1348 </div><!--end of container div -->
1349 <?php $oemr_ui->oeBelowContainerDiv();?>
1350 <script>
1351 set_button_states();
1352 <?php
1353 if ($alertmsg) {
1354 echo "alert('" . addslashes($alertmsg) . "');\n";
1357 $(document).ready(function () {
1358 $('button[type="submit"]').click(function () {
1359 top.restoreSession();
1360 $(this).attr('data-clicked', true);
1363 $('form[name="update_form"]').submit(function (e) {
1364 var clickedButton = $("button[type=submit][data-clicked='true'")[0];
1365 // clear clicked button indicator
1366 $('button[type="submit"]').attr('data-clicked', false);
1368 if (!clickedButton || $(clickedButton).attr("data-open-popup") !== "true") {
1369 $(this).removeAttr("target");
1370 return top.restoreSession();
1371 } else {
1372 top.restoreSession();
1373 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');
1374 this.target = 'Popup_Window';
1378 $('.datepicker').datetimepicker({
1379 <?php $datetimepicker_timepicker = false; ?>
1380 <?php $datetimepicker_showseconds = false; ?>
1381 <?php $datetimepicker_formatInput = false; ?>
1382 <?php require $GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'; ?>
1383 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
1385 // jquery-ui tooltip converted to bootstrap tooltip
1386 $('#update-tooltip').attr("title", "<?php echo xla('Click Update List to display billing information filtered by the selected Current Criteria'); ?>").tooltip();
1389 </script>
1390 <input type="hidden" name="divnos" id="divnos" value="<?php echo attr($divnos) ?>"/>
1391 <input type='hidden' name='ajax_mode' id='ajax_mode' value=''/>
1392 </body>
1393 </html>