using OemrUI class in Fees > Fee Sheet, Billing, Payment, Checkout, Batch Payments...
[openemr.git] / interface / billing / billing_report.php
blobf1c459eea50e02a58f74a02a5b40f113db96a1de
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;
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;
103 <!DOCTYPE html >
104 <html>
105 <head>
107 <?php Header::setupHeader(['datetime-picker', 'common']); ?>
108 <style>
109 /*.subbtn { margin-top:3px; margin-bottom:3px; margin-left:2px; margin-right:2px }*/
110 .btn-group-pinch > .btn:nth-last-child(4):not(.dropdown-toggle) {
111 border-top-right-radius: 3px !Important;
112 border-bottom-right-radius: 3px !Important;
114 </style>
115 <script>
116 function select_all() {
117 for ($i = 0; $i < document.update_form.length; $i++) {
118 $name = document.update_form[$i].name;
119 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -
120 6) == "[bill]") {
121 document.update_form[$i].checked = true;
124 set_button_states();
127 function set_button_states() {
128 var f = document.update_form;
129 var count0 = 0; // selected and not billed or queued
130 var count1 = 0; // selected and queued
131 var count2 = 0; // selected and billed
132 for ($i = 0; $i < f.length; ++$i) {
133 $name = f[$i].name;
134 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -
135 6) == "[bill]" && f[$i].checked == true) {
136 if (f[$i].value == '0') ++count0;
137 else if (f[$i].value == '1' || f[$i].value == '5') ++count1;
138 else ++count2;
141 var can_generate = (count0 > 0 || count1 > 0 || count2 > 0);
142 var can_mark = (count1 > 0 || count0 > 0 || count2 > 0);
143 var can_bill = (count0 == 0 && count1 == 0 && count2 > 0);
144 <?php if (file_exists($EXPORT_INC)) { ?>
145 f.bn_external.disabled = !can_generate;
146 <?php } else { ?>
147 f.bn_x12_support.disabled = !can_generate;
148 <?php if ($GLOBALS['support_encounter_claims']) { ?>
149 f.bn_x12_encounter.disabled = !can_generate;
150 <?php } ?>
151 f.bn_process_hcfa_support.disabled = !can_generate;
152 <?php if ($GLOBALS['preprinted_cms_1500']) { ?>
153 f.bn_process_hcfa_form.disabled = !can_generate;
154 <?php } ?>
155 <?php if ($GLOBALS['ub04_support']) { ?>
156 f.bn_process_ub04_support.disabled = !can_generate;
157 <?php } ?>
158 f.bn_hcfa_txt_file.disabled = !can_generate;
159 f.bn_reopen.disabled = !can_bill;
160 <?php } ?>
161 f.bn_mark.disabled = !can_mark;
164 // Process a click to go to an encounter.
165 function toencounter(pid, pubpid, pname, enc, datestr, dobstr) {
166 top.restoreSession();
167 encurl = 'patient_file/encounter/encounter_top.php?set_encounter=' + enc +
168 '&pid=' + pid;
169 parent.left_nav.setPatient(pname, pid, pubpid, '', dobstr);
170 <?php if ($GLOBALS['new_tabs_layout']) { ?>
171 parent.left_nav.setEncounter(datestr, enc, 'enc');
172 parent.left_nav.loadFrame('enc2', 'enc', encurl);
173 <?php } else { ?>
174 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
175 parent.left_nav.setEncounter(datestr, enc, othername);
176 parent.frames[othername].location.href = '../' + encurl;
177 <?php } ?>
180 // Process a click to go to an patient.
181 function topatient(pid, pubpid, pname, enc, datestr, dobstr) {
182 top.restoreSession();
183 paturl = 'patient_file/summary/demographics_full.php?pid=' + pid;
184 parent.left_nav.setPatient(pname, pid, pubpid, '', dobstr);
185 <?php if ($GLOBALS['new_tabs_layout']) { ?>
186 parent.left_nav.loadFrame('ens1', 'enc',
187 'patient_file/history/encounters.php?pid=' + pid);
188 parent.left_nav.loadFrame('dem1', 'pat', paturl);
189 <?php } else { ?>
190 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
191 parent.frames[othername].location.href = '../' + paturl;
192 <?php } ?>
195 function popMBO(pid, enc, mboid) {
196 if (!window.focus) return true;
197 if (!ProcessBeforeSubmitting()) return false;
198 top.restoreSession();
199 let qstring = "&pid=" + pid + "&enc=" + enc + "&id=" + mboid;
200 let href = "<?php echo $GLOBALS['web_root']?>/interface/patient_file/encounter/view_form.php?formname=misc_billing_options&isBilling=1" + qstring;
201 dlgopen(href, 'mbopop', 'modal-lg', 750, false, '', {
202 sizeHeight: 'full' // override min height auto size.
204 return true;
207 function popUB04(pid, enc) {
208 if (!window.focus) return true;
209 if (!ProcessBeforeSubmitting()) return false;
210 top.restoreSession();
211 let href = "<?php echo $GLOBALS['web_root']?>/interface/billing/ub04_form.php?pid=" + pid + "&enc=" + enc;
212 dlgopen(href, 'ub04pop', 1175, 750, false, '', {
213 sizeHeight: 'full' // override min height auto size.
215 return true;
217 </script>
218 <script>
219 var EncounterDateArray = new Array;
220 var CalendarCategoryArray = new Array;
221 var EncounterIdArray = new Array;
222 var EncounterNoteArray = new Array;
224 function SubmitTheScreen() { //Action on Update List link
225 if (!ProcessBeforeSubmitting()) return false;
226 $("#update-tooltip").replaceWith("<i class='fa fa-refresh fa-spin fa-1x' style=\"color:red\"></i>");
227 top.restoreSession();
228 document.the_form.mode.value = 'change';
229 document.the_form.target = '_self';
230 document.the_form.action = 'billing_report.php';
231 document.the_form.submit();
232 return true;
235 function SubmitTheScreenPrint() { //Action on View Printable Report link
236 if (!ProcessBeforeSubmitting()) return false;
237 top.restoreSession();
238 document.the_form.target = 'new';
239 document.the_form.action = 'print_billing_report.php';
240 document.the_form.submit();
241 return true;
244 function SubmitTheEndDayPrint() { //Action on View End of Day Report link
245 if (!ProcessBeforeSubmitting()) return false;
246 top.restoreSession();
247 document.the_form.target = 'new';
248 <?php if ($GLOBALS['use_custom_daysheet'] == 1) { ?>
249 document.the_form.action = 'print_daysheet_report_num1.php';
250 <?php } ?>
251 <?php if ($GLOBALS['use_custom_daysheet'] == 2) { ?>
252 document.the_form.action = 'print_daysheet_report_num2.php';
253 <?php } ?>
254 <?php if ($GLOBALS['use_custom_daysheet'] == 3) { ?>
255 document.the_form.action = 'print_daysheet_report_num3.php';
256 <?php } ?>
257 document.the_form.submit();
258 return true;
261 function SubmitTheScreenExportOFX() { //Action on Export OFX link
262 if (!ProcessBeforeSubmitting()) return false;
263 top.restoreSession();
264 document.the_form.mode.value = 'export';
265 document.the_form.target = '_self';
266 document.the_form.action = 'billing_report.php';
267 document.the_form.submit();
268 return true;
271 function TestExpandCollapse() { //Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
272 var set = -1;
273 for (i = 1; i <= document.getElementById("divnos").value; i++) {
274 var ele = document.getElementById("divid_" + i);
275 if (ele) {
276 set = 1;
277 break;
280 if (set == -1) {
281 if (document.getElementById("ExpandAll")) {
282 document.getElementById("ExpandAll").innerHTML = '';
283 document.getElementById("CollapseAll").innerHTML = '';
288 function expandcollapse(atr) {
289 if (atr == "expand") { //Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
290 for (i = 1; i <= document.getElementById("divnos").value; i++) {
291 var mydivid = "divid_" + i;
292 var myspanid = "spanid_" + i;
293 var ele = document.getElementById(mydivid);
294 var text = document.getElementById(myspanid);
295 if (ele) {
296 ele.style.display = "inline";
297 text.innerHTML =
298 "<?php echo xla('Collapse'); ?>";
301 } else {
302 for (i = 1; i <= document.getElementById("divnos").value; i++) {
303 var mydivid = "divid_" + i;
304 var myspanid = "spanid_" + i;
305 var ele = document.getElementById(mydivid);
306 var text = document.getElementById(myspanid);
307 if (ele) {
308 ele.style.display = "none";
309 text.innerHTML =
310 "<?php echo xla('Expand'); ?>";
316 function divtoggle(spanid, divid) { //Called in the Expand, Collapse links(This is for a single item)
317 var ele = document.getElementById(divid);
318 if (ele) {
319 var text = document.getElementById(spanid);
320 if (ele.style.display == "inline") {
321 ele.style.display = "none";
322 text.innerHTML =
323 "<?php echo xla('Expand'); ?>";
324 } else {
325 ele.style.display = "inline";
326 text.innerHTML =
327 "<?php echo xla('Collapse'); ?>";
332 function MarkAsCleared(Type) {
333 CheckBoxBillingCount = 0;
334 for (var CheckBoxBillingIndex = 0; ; CheckBoxBillingIndex++) {
335 CheckBoxBillingObject = document.getElementById('CheckBoxBilling' +
336 CheckBoxBillingIndex);
337 if (!CheckBoxBillingObject) break;
338 if (CheckBoxBillingObject.checked) {
339 ++CheckBoxBillingCount;
342 if (Type == 1) {
343 Message = '<?php echo xla('After saving your batch, click[View Log] to check for errors.'); ?>';
345 if (Type == 2) {
346 Message = '<?php echo xla('After saving the PDF, click[View Log] to check for errors.'); ?>';
348 if (Type == 3) {
349 Message = '<?php echo xla('After saving the TEXT file(s), click[View Log] to check for errors.'); ?>';
351 if (confirm(Message + "\n\n\n<?php echo xls('Total'); ?>" + ' ' +
352 CheckBoxBillingCount + ' ' +
353 "<?php echo xls('Selected'); ?>\n" +
354 "<?php echo xls('Would You Like them to be Marked as Cleared.'); ?>\n" +
355 "<?php echo xls('Click OK to Clear or Cancel to continue processing.'); ?>"
356 )) {
357 document.getElementById('HiddenMarkAsCleared').value = 'yes';
358 } else {
359 document.getElementById('HiddenMarkAsCleared').value = '';
362 </script>
363 <?php require_once "$srcdir/../interface/reports/report.script.php"; ?>
364 <!-- Criteria Section common javascript page-->
365 <!-- =============Included for Insurance ajax criteria==== -->
366 <?php require_once "{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"; ?>
367 <style>
368 #ajax_div_insurance {
369 position: absolute;
370 z-index: 10;
371 background-color: #FBFDD0;
372 border: 1px solid #ccc;
373 padding: 10px;
375 button[type="submit"].subbtn-warning {
376 background: #ec971f !important;
377 color: black !important;
379 button[type="submit"].subbtn-warning:hover {
380 background: #da8104 !important;
381 color: #fff !important;
383 @media only screen and (max-width: 1024px) {
384 [class*="col-"] {
385 width: 100%;
386 text-align: left !Important;
389 .table {
390 margin: auto;
392 @media (min-width: 992px) {
393 .modal-lg {
394 width: 1000px !Important;
397 .table th, .table td {
398 border-top: none !important;
400 .form-control {
401 font-family: "FontAwesome"
403 ul > li {
404 line-height: 1.86em;
406 a, a:visited, a:hover {
407 text-decoration: none;
408 color: #000000;
410 </style>
411 <script>
412 document.onclick = TakeActionOnHide;
413 </script>
414 <!-- =============Included for Insurance ajax criteria==== -->
415 <title><?php echo xlt('Billing Manager'); ?></title>
416 <?php
417 $arrOeUiSettings = array(
418 'heading_title' => xl('Billing Manager'),
419 'include_patient_name' => false,// use only in appropriate pages
420 'expandable' => true,
421 'expandable_files' => array('billing_report_xpd'),//all file names need suffix _xpd
422 'action' => "conceal",//conceal, reveal, search, reset, link or back
423 'action_title' => "",
424 'action_href' => "",//only for actions - reset, link or back
425 'show_help_icon' => false,
426 'help_file_name' => ""
428 $oemr_ui = new OemrUI($arrOeUiSettings);
430 </head>
431 <body class="body_top" onLoad="TestExpandCollapse()">
432 <div id="container_div" class="<?php echo $oemr_ui->oeContainer();?>">
433 <div class="row">
434 <div class="col-sm-12">
435 <div class="page-header">
436 <!--<h2>
437 <?php echo xlt('Billing Manager') ?> <i id="exp_cont_icon" class="fa <?php echo attr($expand_icon_class);?> oe-superscript-small expand_contract"
438 title="<?php echo attr($expand_title); ?>" aria-hidden="true"></i> <i id="show_hide" class="fa fa-eye-slash fa-2x small"
439 title="<?php echo xla('Click to Hide'); ?>"></i>
440 </h2>-->
441 <?php echo $oemr_ui->pageHeading() . "\r\n"; ?>
442 </div>
443 </div>
444 </div>
445 <div class="row">
446 <div class="col-sm-12">
447 <form name='the_form' method='post' action='billing_report.php' onsubmit='return top.restoreSession()' style="display:inline">
448 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
449 <input type='hidden' name='mode' value='change'>
450 <div class="col-xs-9">
451 <!-- ============================================================================================================================================= -->
452 <!-- Criteria section Starts -->
453 <!-- ============================================================================================================================================= -->
454 <?php
455 // The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
456 // Each item is seperated by a comma(,).
457 // $ThisPageSearchCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
458 // $ThisPageSearchCriteriaKeyMaster ==>Corresponding database fields in the same order.
459 // $ThisPageSearchCriteriaDataTypeMaster ==>Corresponding data type in the same order.
460 $ThisPageSearchCriteriaDisplayRadioMaster = array();
461 $ThisPageSearchCriteriaRadioKeyMaster = array();
462 $ThisPageSearchCriteriaQueryDropDownMaster = array();
463 $ThisPageSearchCriteriaQueryDropDownMasterDefault = array();
464 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey = array();
465 $ThisPageSearchCriteriaIncludeMaster = array();
467 if ($daysheet) {
468 $ThisPageSearchCriteriaDisplayMaster = array(
469 xl("Date of Service"),
470 xl("Date of Entry"),
471 xl("Date of Billing"),
472 xl("Claim Type"),
473 xl("Patient Name"),
474 xl("Patient Id"),
475 xl("Insurance Company"),
476 xl("Encounter"),
477 xl("Whether Insured"),
478 xl("Charge Coded"),
479 xl("Billing Status"),
480 xl("Authorization Status"),
481 xl("Last Level Billed"),
482 xl("X12 Partner"),
483 xl("User")
485 $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";
486 $ThisPageSearchCriteriaDataTypeMaster = "datetime,datetime,datetime,radio,text_like," . "text,include,text,radio,radio,radio," . "radio_like,radio,query_drop_down,text";
487 } else {
488 $ThisPageSearchCriteriaDisplayMaster = array(
489 xl("Date of Service"),
490 xl("Date of Entry"),
491 xl("Date of Billing"),
492 xl("Claim Type"),
493 xl("Patient Name"),
494 xl("Patient Id"),
495 xl("Insurance Company"),
496 xl("Encounter"),
497 xl("Whether Insured"),
498 xl("Charge Coded"),
499 xl("Billing Status"),
500 xl("Authorization Status"),
501 xl("Last Level Billed"),
502 xl("X12 Partner")
504 $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";
505 $ThisPageSearchCriteriaDataTypeMaster = "datetime,datetime,datetime,radio,text_like," . "text,include,text,radio,radio,radio," . "radio_like,radio,query_drop_down";
507 // The below section is needed if there is any 'radio' or 'radio_like' type in the $ThisPageSearchCriteriaDataTypeMaster
508 // $ThisPageSearchCriteriaDisplayRadioMaster,$ThisPageSearchCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
509 // 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.
510 $ThisPageSearchCriteriaDisplayRadioMaster[1] = array(
511 xl("All"),
512 xl("eClaims"),
513 xl("Paper")
514 ); // Display Value
515 $ThisPageSearchCriteriaRadioKeyMaster[1] = "all,standard,hcfa"; // Key
516 $ThisPageSearchCriteriaDisplayRadioMaster[2] = array(
517 xl("All"),
518 xl("Insured"),
519 xl("Non-Insured")
520 ); // Display Value
521 $ThisPageSearchCriteriaRadioKeyMaster[2] = "all,1,0"; // Key
522 $ThisPageSearchCriteriaDisplayRadioMaster[3] = array(
523 xl("All"),
524 xl("Coded"),
525 xl("Not Coded")
526 ); // Display Value
527 $ThisPageSearchCriteriaRadioKeyMaster[3] = "all,not null,null"; // Key
528 $ThisPageSearchCriteriaDisplayRadioMaster[4] = array(
529 xl("All"),
530 xl("Unbilled"),
531 xl("Billed"),
532 xl("Denied")
533 ); // Display Value
534 $ThisPageSearchCriteriaRadioKeyMaster[4] = "all,0,1,7"; // Key
535 $ThisPageSearchCriteriaDisplayRadioMaster[5] = array(
536 xl("All"),
537 xl("Authorized"),
538 xl("Unauthorized")
540 $ThisPageSearchCriteriaRadioKeyMaster[5] = "%,1,0";
541 $ThisPageSearchCriteriaDisplayRadioMaster[6] = array(
542 xl("All"),
543 xl("None"),
544 xl("Ins 1"),
545 xl("Ins 2 or Ins 3")
547 $ThisPageSearchCriteriaRadioKeyMaster[6] = "all,0,1,2";
548 // The below section is needed if there is any 'query_drop_down' type in the $ThisPageSearchCriteriaDataTypeMaster
549 $ThisPageSearchCriteriaQueryDropDownMaster[1] = "SELECT name,id FROM x12_partners;";
550 $ThisPageSearchCriteriaQueryDropDownMasterDefault[1] = xl("All"); // Only one item will be here
551 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey[1] = "all"; // Only one item will be here
552 // The below section is needed if there is any 'include' type in the $ThisPageSearchCriteriaDataTypeMaster
553 // Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
554 // It is labled(Included for Insurance ajax criteria)(Line:-279-299).
555 $ThisPageSearchCriteriaIncludeMaster[1] = "InsuranceCompanyDisplay"; // This is php function defined in the file 'report.inc.php'
557 if (!isset($_REQUEST['mode'])) {// default case
558 $_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") . "')";
559 $_REQUEST['final_this_page_criteria'][1] = "billing.billed = '0'";
560 $_REQUEST['final_this_page_criteria_text'][0] = xl("Date of Service = Today");
561 $_REQUEST['final_this_page_criteria_text'][1] = xl("Billing Status = Unbilled");
562 $_REQUEST['date_master_criteria_form_encounter_date'] = "today";
563 $_REQUEST['master_from_date_form_encounter_date'] = date("Y-m-d");
564 $_REQUEST['master_to_date_form_encounter_date'] = date("Y-m-d");
565 $_REQUEST['radio_billing_billed'] = 0;
568 <div class="hideaway">
569 <?php require_once "$srcdir/../interface/reports/criteria.tab.php"; ?>
570 </div>
571 <?php
572 // ============================================================================================================================================= -->
573 // Criteria section Ends -->
574 // ============================================================================================================================================= -->
577 </div>
578 <div class="form-group col-xs-3 hideaway">
579 <fieldset>
580 <legend><?php echo xlt('Select Action'); ?></legend>
581 <div class="form-group col-xs-12">
582 <div class='text'>
583 <ul>
584 <li><a class="link_submit" href="#"
585 onclick="javascript:return SubmitTheScreen();"><strong><?php echo xlt('Update List') ?></strong>
586 </a><i id='update-tooltip' class="fa fa-info-circle text-primary" aria-hidden="true"></i></li>
587 <li><a class='link_submit' href="#"
588 onclick="javascript:return SubmitTheScreenExportOFX();"><strong><?php echo xlt('Export OFX'); ?></strong></a>
589 </li>
590 <li><a class='link_submit' href="#" onclick="javascript:return SubmitTheScreenPrint();"><strong><?php echo xlt('View Printable Report'); ?></strong></a>
591 </li>
592 <span>
593 <?php if ($daysheet) { ?>
594 <li><a class='link_submit' href="#"
595 onclick="javascript:return SubmitTheEndDayPrint();"><strong><?php echo xlt('End Of Day Report') . ' - ' ?></strong></a>
596 <?php if ($daysheet_total) { ?>
597 <span class="text"><strong><?php echo xlt('Totals'); ?></strong></span>
598 <input name="end_of_day_totals_only" type="checkbox" value="1"></li>
599 <?php } ?>
600 <?php if ($provider_run) { ?>
601 <span class="text"><strong><?php echo xlt('Provider'); ?></strong></span>
602 <input name="end_of_day_provider_only" type="checkbox" value="1"></li>
603 <?php } ?>
604 <?php } ?>
605 </span>
606 <?php if (!file_exists($EXPORT_INC)) { ?>
607 <li><a href='#' id="view-log-link" data-toggle="modal" data-target="#myModal" class='link_submit'
608 title='<?php xla('See messages from the last set of generated claims'); ?>'><strong><?php echo xlt('View Log'); ?></strong></a>
609 </li>
610 <?php } ?>
611 <li><a class="link_submit"
612 href="JavaScript:void(0);" onclick="select_all(); return false;"><strong><?php echo xlt('Select All'); ?></strong></a>
613 </li>
614 </ul>
615 <ul>
616 </div>
617 </div>
618 </fieldset>
619 </div>
620 </form>
621 </div>
622 </div>
623 <div class="row">
624 <div class="col-sm-12">
625 <form class="form-inline" name='update_form' method='post' action='billing_process.php' onsubmit='return top.restoreSession()' style="display:inline">
626 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
627 <?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 ?>
628 <div class="form-group clearfix">
629 <div class="btn-group btn-group-pinch position-override" role="group">
630 <div class="btn-group">
631 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
632 name="bn_x12_support"
633 title="<?php echo xla('A claim must be selected to enable this menu.') ?>"><?php echo xla('X12 OPTIONS') ?>
634 <span class="caret"></span></button>
635 <ul class="dropdown-menu" role="menu">
636 <?php if (file_exists($EXPORT_INC)) { ?>
637 <li>
638 <button type="submit" data-open-popup="true" class="btn btn-default btn-download"
639 name="bn_external"
640 title="<?php echo xla('Export to external billing system') ?>"
641 value="<?php echo xla("Export Billing") ?>"><?php echo xla("Export Billing") ?></button>
642 </li>
643 <li>
644 <button type="submit" data-open-popup="true" class="btn btn-default btn-download"
645 name="bn_mark"
646 title="<?php echo xla('Mark as billed but skip billing') ?>"><?php echo xla("Mark as Cleared") ?></button>
647 </li>
648 <?php } else { ?>
649 <li>
650 <button type="submit" class="btn btn-default btn-download" name="bn_x12"
651 onclick="MarkAsCleared(1)"
652 title="<?php echo xla('Generate and download X12 batch') ?>"><?php echo xla('Generate X12') ?></button>
653 </li>
654 <?php } ?>
655 <?php if ($GLOBALS['ub04_support']) { ?>
656 <li>
657 <button type="submit" class="btn btn-default btn-download" name="bn_ub04_x12"
658 title="<?php echo xla('Generate Institutional X12 837I') ?>"><?php echo xla('Generate X12 837I') ?></button>
659 </li>
660 <?php } ?>
661 <?php if ($GLOBALS['support_encounter_claims']) { ?>
662 <li>
663 <button type="submit" class="btn btn-default btn-download" name="bn_x12_encounter"
664 onclick="MarkAsCleared(1)"
665 title="<?php echo xla('Generate and download X12 encounter claim batch') ?>"><?php echo xla('Generate X12 Encounter') ?></button>
666 </li>
667 <?php } ?>
668 </ul>
669 </div>
670 <div class="btn-group">
671 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
672 name="bn_process_hcfa_support"
673 title="<?php echo xla('A claim must be selected to enable this menu.') ?>"><?php echo xla('HCFA FORM') ?>
674 <span class="caret"></span></button>
675 <ul class="dropdown-menu" role="menu">
676 <li>
677 <button type="submit" class="btn btn-default btn-download" name="bn_process_hcfa"
678 onclick="MarkAsCleared(2)"
679 title="<?php echo xla('Generate and download CMS 1500 paper claims') ?>"><?php echo xla('CMS 1500 PDF') ?></button>
680 </li>
681 <?php if ($GLOBALS['preprinted_cms_1500']) { ?>
682 <li>
683 <button type="submit" class="btn btn-default btn-download"
684 name="bn_process_hcfa_form" onclick="MarkAsCleared(2)"
685 title="<?php echo xla('Generate and download CMS 1500 paper claims on Preprinted form') ?>"><?php echo xla('CMS 1500 incl FORM') ?></button>
686 </li>
687 <?php } ?>
688 <li>
689 <button type="submit" class="btn btn-default btn-download" name="bn_hcfa_txt_file"
690 onclick="MarkAsCleared(3)"
691 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>
692 </li>
693 </ul>
694 </div>
695 <?php if ($GLOBALS['ub04_support']) { ?>
696 <div class="btn-group">
697 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
698 name="bn_process_ub04_support"
699 title="<?php echo xla('A claim must be selected to enable this menu.') ?>"><?php echo xla('UB04 FORM') ?>
700 <span class="caret"></span></button>
701 <ul class="dropdown-menu" role="menu">
702 <li>
703 <button type="submit" class="btn btn-default btn-download"
704 name="bn_process_ub04_form"
705 title="<?php echo xla('Generate and download UB-04 CMS1450 with form') ?>"><?php echo xla('UB04 FORM PDF') ?></button>
706 </li>
707 <li>
708 <button type="submit" class="btn btn-default btn-download" name="bn_process_ub04"
709 title="<?php echo xla('Generate and download UB-04 CMS1450') ?>"><?php echo xla('UB04 TEXT PDF') ?></button>
710 </li>
711 </ul>
712 </div>
713 <?php } ?>
714 <button class="btn btn-default btn-download" data-open-popup="true" name="bn_mark"
715 title="<?php echo xla('Post to accounting and mark as billed') ?>"
716 type="submit"><?php echo xla('Mark as Cleared') ?></button>
717 <button class="btn btn-default btn-undo" data-open-popup="true" name="bn_reopen"
718 title="<?php echo xla('Mark as not billed') ?>"
719 type="submit"><?php echo xla('Re-Open') ?></button>
720 </div>
721 <div class="input-group">
722 <label for="left_margin"><?php echo xlt('CMS 1500 Margins Left'); ?>:</label>
723 <input type='text' size='2' id='left_margin' name='left_margin'
724 value='<?php echo attr($left_margin); ?>'
725 title='<?php echo xla('HCFA left margin in points'); ?>'/>
726 <label for="top_margin"><?php echo xlt('Top'); ?>:</label>
727 <input type='text' size='2' id='top_margin' name='top_margin'
728 value='<?php echo attr($top_margin); ?>'
729 title='<?php echo xla('HCFA top margin in points'); ?>'/>
730 </div>
731 <?php if ($ub04_support) { ?>
732 <div class="input-group">
733 <label for="left_ubmargin"><?php echo xlt('UB04 Margins Left'); ?>:</label>
734 <input type='text' size='2' id='left_ubmargin' name='left_ubmargin'
735 value='<?php echo attr($left_ubmargin); ?>'
736 title='<?php echo xla('UB04 left margin in points'); ?>'/>
737 <label for="top_ubmargin"><?php echo xlt('Top'); ?>:</label>
738 <input type='text' size='2' id='top_ubmargin' name='top_ubmargin'
739 value='<?php echo attr($top_ubmargin); ?>'
740 title='<?php echo xla('UB04 top margin in points'); ?>'/>
741 </div>
742 <?php } ?>
743 </div>
744 <input id='HiddenMarkAsCleared' name='HiddenMarkAsCleared' type='hidden' value="">
745 <input name='mode' type='hidden' value="bill">
746 <input name='authorized' type='hidden' value="<?php echo attr($my_authorized); ?>">
747 <input name='unbilled' type='hidden' value="<?php echo attr($unbilled); ?>">
748 <input name='code_type' type='hidden' value="%">
749 <input name='to_date' type='hidden' value="<?php echo attr($to_date); ?>">
750 <input name='from_date' type='hidden' value="<?php echo attr($from_date); ?>">
751 <?php
752 if ($my_authorized == "on") {
753 $my_authorized = "1";
754 } else {
755 $my_authorized = "%";
757 if ($unbilled == "on") {
758 $unbilled = "0";
759 } else {
760 $unbilled = "%";
762 $list = getBillsListBetween("%");
764 <input name='bill_list' type='hidden' value="<?php echo attr($list); ?>"> <!-- new form for uploading -->
765 <?php
766 if (!isset($_POST["mode"])) {
767 if (!isset($_POST["from_date"])) {
768 $from_date = date("Y-m-d");
769 } else {
770 $from_date = $_POST["from_date"];
772 if (empty($_POST["to_date"])) {
773 $to_date = '';
774 } else {
775 $to_date = $_POST["to_date"];
777 if (!isset($_POST["code_type"])) {
778 $code_type = "all";
779 } else {
780 $code_type = $_POST["code_type"];
782 if (!isset($_POST["unbilled"])) {
783 $unbilled = "on";
784 } else {
785 $unbilled = $_POST["unbilled"];
787 if (!isset($_POST["authorized"])) {
788 $my_authorized = "on";
789 } else {
790 $my_authorized = $_POST["authorized"];
792 } else {
793 $from_date = $_POST["from_date"];
794 $to_date = $_POST["to_date"];
795 $code_type = $_POST["code_type"];
796 $unbilled = $_POST["unbilled"];
797 $my_authorized = $_POST["authorized"];
800 if ($my_authorized == "on") {
801 $my_authorized = "1";
802 } else {
803 $my_authorized = "%";
806 if ($unbilled == "on") {
807 $unbilled = "0";
808 } else {
809 $unbilled = "%";
812 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
813 billCodesList($list);
816 <div class="table-responsive">
817 <table class="table table-condensed">
818 <?php
819 $divnos = 0;
820 if ($ret = getBillsBetween("%")) {
821 if (is_array($ret)) {
823 <tr>
824 <td colspan='9' align="right">
825 <table width="250" border="0" cellspacing="0" cellpadding="0">
826 <tr>
827 <td width="100" id='ExpandAll'><a
828 onclick="expandcollapse('expand');" class='small'
829 href="JavaScript:void(0);"><?php echo '(' . xla('Expand All') . ')' ?></a>
830 </td>
831 <td width="100" id='CollapseAll'><a
832 onclick="expandcollapse('collapse');" class='small'
833 href="JavaScript:void(0);"><?php echo '(' . xla('Collapse All') . ')' ?></a>
834 </td>
835 <td width="50">&nbsp;</td>
836 </tr>
837 </table>
838 </td>
839 </tr>
840 <?php
842 $loop = 0;
843 $oldcode = "";
844 $last_encounter_id = "";
845 $lhtml = "";
846 $rhtml = "";
847 $lcount = 0;
848 $rcount = 0;
849 $bgcolor = "";
850 $skipping = false;
852 $mmo_empty_mod = false;
853 $mmo_num_charges = 0;
855 foreach ($ret as $iter) {
856 // We include encounters here that have never been billed. However
857 // if it had no selected billing items but does have non-selected
858 // billing items, then it is not of interest.
859 if (!$iter['id']) {
860 $res = sqlQuery(
861 "SELECT count(*) AS count FROM billing WHERE " .
862 "encounter = ? AND " .
863 "pid=? AND " .
864 "activity = 1",
865 array(
866 $iter['enc_encounter'],
867 $iter['enc_pid']
870 if ($res['count'] > 0) {
871 continue;
875 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
877 if ($last_encounter_id != $this_encounter_id) {
878 // This dumps all HTML for the previous encounter.
880 if ($lhtml) {
881 while ($rcount < $lcount) {
882 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='9'></td></tr>";
883 ++$rcount;
885 // This test handles the case where we are only listing encounters
886 // that appear to have a missing "25" modifier.
887 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
888 if ($DivPut == 'yes') {
889 $lhtml .= '</div>';
890 $DivPut = 'no';
892 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='" . attr($rcount) . "' valign='top'>\n$lhtml</td>$rhtml\n";
893 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n\n";
894 ++$encount;
898 $lhtml = "";
899 $rhtml = "";
900 $mmo_empty_mod = false;
901 $mmo_num_charges = 0;
903 // If there are ANY unauthorized items in this encounter and this is
904 // the normal case of viewing only authorized billing, then skip the
905 // entire encounter.
907 $skipping = false;
908 if ($my_authorized == '1') {
909 $res = sqlQuery(
910 "SELECT count(*) AS count FROM billing WHERE " .
911 "encounter = ? AND " .
912 "pid=? AND " .
913 "activity = 1 AND authorized = 0",
914 array(
915 $iter['enc_encounter'],
916 $iter['enc_pid']
919 if ($res['count'] > 0) {
920 $skipping = true;
921 $last_encounter_id = $this_encounter_id;
922 continue;
925 // Is there a MBO
927 $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']));
928 $iter['mboid'] = $mboid ? attr($mboid['form_id']) : 0;
930 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, billing_note, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
932 // Check if patient has primary insurance and a subscriber exists for it.
933 // If not we will highlight their name in red.
934 // TBD: more checking here.
936 $res = sqlQuery(
937 "SELECT count(*) AS count FROM insurance_data WHERE " .
938 "pid = ? AND " .
939 "type='primary' AND " .
940 "subscriber_lname IS NOT NULL AND " .
941 "subscriber_lname != '' LIMIT 1",
942 array(
943 $iter['enc_pid']
946 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
948 $bgcolor = "#" . (($encount & 1) ? "FFFAEF" : "F8F8FF");
949 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
950 $lcount = 1;
951 $rcount = 0;
952 $oldcode = "";
954 $ptname = $name['fname'] . " " . $name['lname'];
955 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
956 $billing_note = $name['billing_note'];
957 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
958 $lhtml .= "<span class=bold><font color='$namecolor'>" . text($ptname) . "</font></span><span class=small>&nbsp;(" . text($iter['enc_pid']) . "-" . text($iter['enc_encounter']) . ")</span>";
960 // Encounter details are stored to javacript as array.
961 $result4 = sqlStatement(
962 "SELECT fe.encounter,fe.date,fe.billing_note,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe " .
963 " LEFT JOIN openemr_postcalendar_categories ON fe.pc_catid=openemr_postcalendar_categories.pc_catid WHERE fe.pid = ? ORDER BY fe.date DESC",
964 array(
965 $iter['enc_pid']
968 if (sqlNumRows($result4) > 0) {
970 } ?>
971 <script>
972 Count = 0;
973 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
974 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
975 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
976 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>] = new Array;
977 <?php
978 while ($rowresult4 = sqlFetchArray($result4)) {
980 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr($rowresult4['encounter']); ?>';
981 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date'])))); ?>';
982 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr(xl_appt_category($rowresult4['pc_catname'])); ?>';
983 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>][Count] = '<?php echo attr($rowresult4['billing_note']); ?>';
984 Count++;
985 <?php
986 $enc_billing_note = $rowresult4['billing_note'];
989 </script>
990 <?php
991 $lhtml .= "<div class='button-group'>";
992 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
993 $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']))) . "');
994 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>";
996 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
997 $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']))) . "');
998 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>";
999 $is_edited = $iter['mboid'] ? 'btn-success' : 'btn-default';
1000 $title = $iter['mboid'] ? xlt("This claim has HCFA 1500 miscellaneous billing options") : xlt("Click to add HCFA 1500 miscellaneous billing options");
1001 $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>";
1002 if ($ub04_support && isset($iter['billed'])) {
1003 $c = sqlQuery(
1004 "SELECT submitted_claim AS status FROM claims WHERE " .
1005 "encounter_id = ? AND " .
1006 "patient_id=? " .
1007 "ORDER BY version DESC LIMIT 1",
1008 array(
1009 $iter['enc_encounter'],
1010 $iter['enc_pid']
1013 $is_edited = $c['status'] ? 'btn-success' : 'btn-warning';
1014 $bname = $c['status'] ? xl('Reviewed') : xl('Review UB04');
1015 $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>";
1017 $lhtml .= "</div>";
1018 $divnos = $divnos + 1;
1019 $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>';
1020 if ($GLOBALS['notes_to_display_in_Billing'] == 2 || $GLOBALS['notes_to_display_in_Billing'] == 3) {
1021 $lhtml .= '<span style="margin-left: 20px; font-weight: bold; color: red">' . text($billing_note) . '</span>';
1024 if ($iter['id']) {
1025 $lcount += 2;
1026 $lhtml .= "<br />\n";
1027 $lhtml .= "&nbsp;<span class='form-group'>" . xlt('Bill') . ": ";
1028 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' style='background-color:$bgcolor'>";
1030 $query = "SELECT id.provider AS id, id.type, id.date, " .
1031 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
1032 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
1033 "ic.id = id.provider AND " .
1034 "id.pid = ? AND " .
1035 "id.date <= ? " .
1036 "ORDER BY id.type ASC, id.date DESC";
1038 $result = sqlStatement(
1039 $query,
1040 array(
1041 $iter['enc_pid'],
1042 $raw_encounter_date
1045 $count = 0;
1046 $default_x12_partner = $iter['ic_x12id'];
1047 $prevtype = '';
1049 while ($row = sqlFetchArray($result)) {
1050 if (strcmp($row['type'], $prevtype) == 0) {
1051 continue;
1053 $prevtype = $row['type'];
1054 if (strlen($row['provider']) > 0) {
1055 // This preserves any existing insurance company selection, which is
1056 // important when EOB posting has re-queued for secondary billing.
1057 $lhtml .= "<option value=\"" . attr(substr($row['type'], 0, 1) . $row['id']) . "\"";
1058 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
1059 $lhtml .= " selected";
1060 if (!is_numeric($default_x12_partner)) {
1061 $default_x12_partner = $row['ic_x12id'];
1064 $lhtml .= ">" . text($row['type']) . ": " . text($row['provider']) . "</option>";
1066 $count++;
1069 $lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
1070 $lhtml .= "</select>&nbsp;&nbsp;\n";
1071 $lhtml .= "&nbsp;<span class='form-group'>X12: ";
1072 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][partner]' style='background-color:$bgcolor'>";
1073 $x = new X12Partner();
1074 $partners = $x->_utility_array($x->x12_partner_factory());
1075 foreach ($partners as $xid => $xname) {
1076 $lhtml .= '<option label="' . attr($xname) . '" value="' . attr($xid) . '"';
1077 if ($xid == $default_x12_partner) {
1078 $lhtml .= "selected";
1080 $lhtml .= '>' . text($xname) . '</option>';
1082 $lhtml .= "<option value='-1' label='Unassigned'>" . xlt("Unassigned") . "</option>\n";
1083 $lhtml .= "</select></span>";
1084 $DivPut = 'yes';
1086 if ($GLOBALS['notes_to_display_in_Billing'] == 1 || $GLOBALS['notes_to_display_in_Billing'] == 3) {
1087 $lhtml .= "<br><span style='margin-left: 20px; font-weight: bold; color: green'>" . text($enc_billing_note) . "</span>";
1089 $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");
1091 $query = "SELECT * FROM claims WHERE patient_id = ? AND encounter_id = ? ORDER BY version";
1092 $cres = sqlStatement(
1093 $query,
1094 array(
1095 $iter['enc_pid'],
1096 $iter['enc_encounter']
1100 $lastcrow = false;
1102 while ($crow = sqlFetchArray($cres)) {
1103 $query = "SELECT id.type, ic.name " .
1104 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
1105 "id.pid = ? AND " .
1106 "id.provider = ? AND " .
1107 "id.date <= ? AND " .
1108 "ic.id = id.provider " .
1109 "ORDER BY id.type ASC, id.date DESC";
1111 $irow = sqlQuery(
1112 $query,
1113 array(
1114 $iter['enc_pid'],
1115 $crow['payer_id'],
1116 $raw_encounter_date
1120 if ($crow['bill_process']) {
1121 $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']);
1122 ++$lcount;
1123 } elseif ($crow['status'] < 6) {
1124 if ($crow['status'] > 1) {
1125 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) . text(substr($crow['bill_time'], 10, 6)) . " " . xlt("Marked as cleared");
1126 ++$lcount;
1127 } else {
1128 $lhtml .= "<br>\n&nbsp;" . text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) . text(substr($crow['bill_time'], 10, 6)) . " " . xlt("Re-opened");
1129 ++$lcount;
1131 } elseif ($crow['status'] == 6) {
1132 $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.");
1133 ++$lcount;
1134 } elseif ($crow['status'] == 7) {
1135 $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:-");
1136 if ($crow['process_file']) {
1137 $code_array = explode(',', $crow['process_file']);
1138 foreach ($code_array as $code_key => $code_value) {
1139 $lhtml .= "<br>\n&nbsp;&nbsp;&nbsp;";
1140 $reason_array = explode('_', $code_value);
1141 if (!isset($adjustment_reasons[$reason_array[3]])) {
1142 $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]) . ']';
1143 } else {
1144 $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]]);
1147 } else {
1148 $lhtml .= xlt("Not Specified.");
1150 ++$lcount;
1153 if ($crow['process_time']) {
1154 $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>";
1155 ++$lcount;
1158 $lastcrow = $crow;
1159 } // end while ($crow = sqlFetchArray($cres))
1161 if ($lastcrow && $lastcrow['status'] == 4) {
1162 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been closed.");
1163 ++$lcount;
1166 if ($lastcrow && $lastcrow['status'] == 5) {
1167 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been canceled.");
1168 ++$lcount;
1170 } // end if ($iter['id'])
1171 } // end if ($last_encounter_id != $this_encounter_id)
1173 if ($skipping) {
1174 continue;
1177 // Collect info related to the missing modifiers test.
1178 if ($iter['fee'] > 0) {
1179 ++$mmo_num_charges;
1180 $tmp = substr($iter['code'], 0, 3);
1181 if (($tmp == '992' || $tmp == '993') && empty($iter['modifier'])) {
1182 $mmo_empty_mod = true;
1186 ++$rcount;
1188 if ($rhtml) {
1189 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
1191 $rhtml .= "<td width='50'>";
1192 if ($iter['id'] && $oldcode != $iter['code_type']) {
1193 $rhtml .= "<span class=text>" . text($iter['code_type']) . ": </span>";
1196 $oldcode = $iter['code_type'];
1197 $rhtml .= "</td>\n";
1198 $justify = "";
1200 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
1201 $js = explode(":", $iter['justify']);
1202 $counter = 0;
1203 foreach ($js as $j) {
1204 if (!empty($j)) {
1205 if ($counter == 0) {
1206 $justify .= " (<b>" . text($j) . "</b>)";
1207 } else {
1208 $justify .= " (" . text($j) . ")";
1210 $counter++;
1215 $rhtml .= "<td><span class='text'>" . ($iter['code_type'] == 'COPAY' ? text(oeFormatMoney($iter['code'])) : text($iter['code']));
1216 if ($iter['modifier']) {
1217 $rhtml .= ":" . text($iter['modifier']);
1219 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
1221 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1222 if ($iter['id'] && $iter['fee'] > 0) {
1223 $rhtml .= text(oeFormatMoney($iter['fee']));
1225 $rhtml .= "</span></td>\n";
1226 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1227 if ($iter['id']) {
1228 $rhtml .= getProviderName(empty($iter['provider_id']) ? text($iter['enc_provider_id']) : text($iter['provider_id']));
1230 $rhtml .= "</span></td>\n";
1231 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1232 if ($GLOBALS['display_units_in_billing'] != 0) {
1233 if ($iter['id']) {
1234 $rhtml .= xlt("Units") . ":" . text($iter{"units"});
1237 $rhtml .= "</span></td>\n";
1238 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1239 if ($iter['id']) {
1240 $rhtml .= text(oeFormatSDFT(strtotime($iter{"date"})));
1242 $rhtml .= "</span></td>\n";
1243 // This error message is generated if the authorized check box is not checked
1244 if ($iter['id'] && $iter['authorized'] != 1) {
1245 $rhtml .= "<td><span class=alert>" . xlt("Note: This code has not been authorized.") . "</span></td>\n";
1246 } else {
1247 $rhtml .= "<td></td>\n";
1249 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
1250 $tmpbpr = $iter['bill_process'];
1251 if ($tmpbpr == '0' && $iter['billed']) {
1252 $tmpbpr = '2';
1254 $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";
1255 $CheckBoxBilling++;
1256 } else {
1257 $rhtml .= "<td></td>\n";
1259 if ($last_encounter_id != $this_encounter_id) {
1260 $rhtml2 = "";
1261 $rowcnt = 0;
1262 $resMoneyGot = sqlStatement(
1263 "SELECT pay_amount AS PatientPay,date(post_time) AS date FROM ar_activity WHERE " .
1264 "pid = ? AND encounter = ? AND payer_type=0 AND account_code='PCP'",
1265 array(
1266 $iter['enc_pid'],
1267 $iter['enc_encounter']
1270 // new fees screen copay gives account_code='PCP'
1271 if (sqlNumRows($resMoneyGot) > 0) {
1272 $lcount += 2;
1273 $rcount++;
1275 // checks whether a copay exists for the encounter and if exists displays it.
1276 while ($rowMoneyGot = sqlFetchArray($resMoneyGot)) {
1277 $rowcnt++;
1278 $PatientPay = $rowMoneyGot['PatientPay'];
1279 $date = $rowMoneyGot['date'];
1280 if ($PatientPay > 0) {
1281 if ($rhtml) {
1282 $rhtml2 .= "<tr bgcolor='$bgcolor'>\n";
1284 $rhtml2 .= "<td width='50'>";
1285 $rhtml2 .= "<span class='text'>" . xlt('COPAY') . ": </span>";
1286 $rhtml2 .= "</td>\n";
1287 $rhtml2 .= "<td><span class='text'>" . text(oeFormatMoney($PatientPay)) . "</span><span style='font-size:8pt;'>&nbsp;</span></td>\n";
1288 $rhtml2 .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1289 $rhtml2 .= "</span></td>\n";
1290 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1291 $rhtml2 .= "</span></td>\n";
1292 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1293 $rhtml2 .= "</span></td>\n";
1294 $rhtml2 .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1295 $rhtml2 .= text(oeFormatSDFT(strtotime($date)));
1296 $rhtml2 .= "</span></td>\n";
1297 if ($iter['id'] && $iter['authorized'] != 1) {
1298 $rhtml2 .= "<td><span class=alert>" . xlt("Note: This copay was entered against billing that has not been authorized. Please review status.") . "</span></td>\n";
1299 } else {
1300 $rhtml2 .= "<td></td>\n";
1302 if (!$iter['id'] && $rowcnt == 1) {
1303 $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";
1304 $CheckBoxBilling++;
1305 } else {
1306 $rhtml2 .= "<td></td>\n";
1310 $rhtml .= $rhtml2;
1312 $rhtml .= "</tr>\n";
1313 $last_encounter_id = $this_encounter_id;
1314 } // end foreach
1316 if ($lhtml) {
1317 while ($rcount < $lcount) {
1318 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='9'></td></tr>";
1319 ++$rcount;
1321 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
1322 if ($DivPut == 'yes') {
1323 $lhtml .= '</div>';
1324 $DivPut = 'no';
1326 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='" . attr($rcount) . "' valign='top' width='25%'>\n$lhtml</td>$rhtml\n";
1327 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
1334 </table>
1335 </form>
1336 </div>
1337 </div>
1338 </div><!--end of container div -->
1339 <?php $oemr_ui->oeBelowContainerDiv();?>
1340 <script>
1341 set_button_states();
1342 <?php
1343 if ($alertmsg) {
1344 echo "alert('" . addslashes($alertmsg) . "');\n";
1347 $(document).ready(function () {
1348 $('button[type="submit"]').click(function () {
1349 top.restoreSession();
1350 $(this).attr('data-clicked', true);
1353 $('form[name="update_form"]').submit(function (e) {
1354 var clickedButton = $("button[type=submit][data-clicked='true'")[0];
1355 // clear clicked button indicator
1356 $('button[type="submit"]').attr('data-clicked', false);
1358 if (!clickedButton || $(clickedButton).attr("data-open-popup") !== "true") {
1359 $(this).removeAttr("target");
1360 return top.restoreSession();
1361 } else {
1362 top.restoreSession();
1363 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');
1364 this.target = 'Popup_Window';
1368 $('.datepicker').datetimepicker({
1369 <?php $datetimepicker_timepicker = false; ?>
1370 <?php $datetimepicker_showseconds = false; ?>
1371 <?php $datetimepicker_formatInput = false; ?>
1372 <?php require $GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'; ?>
1373 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
1376 </script>
1377 <script>
1378 $(document).ready(function () {
1379 //using jquery-ui tooltip instead of bootstrap tooltip
1380 $('#update-tooltip').attr("title", "<?php echo xla('Click Update List to display billing information filtered by the selected Current Criteria'); ?>").tooltip();
1382 </script>
1383 <input type="hidden" name="divnos" id="divnos" value="<?php echo attr($divnos) ?>"/>
1384 <input type='hidden' name='ajax_mode' id='ajax_mode' value=''/>
1385 </body>
1386 </html>