forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
billing_report.php
1459 lines (1364 loc) · 81.1 KB
/
billing_report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Billing Report Program
*
* @package OpenEMR
* @link http:https://www.open-emr.org
* @author Terry Hill <[email protected]>
* @author Brady Miller <[email protected]>
* @author Jerry Padgett <[email protected]>
* @author Sherwin Gaddis <[email protected]>
* @copyright Copyright (c) 2016 Terry Hill <[email protected]>
* @copyright Copyright (c) 2017-2020 Brady Miller <[email protected]>
* @copyright Copyright (c) 2018-2020 Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2019-2020 Sherwin Gaddis <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
require_once "../globals.php";
require_once "../../custom/code_types.inc.php";
require_once "$srcdir/patient.inc";
require_once "$srcdir/options.inc.php";
use OpenEMR\Billing\BillingReport;
use OpenEMR\Billing\BillingUtilities;
use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Core\Header;
use OpenEMR\OeUI\OemrUI;
$EXPORT_INC = "$webserver_root/custom/BillingExport.php";
// echo $GLOBALS['daysheet_provider_totals'];
$daysheet = false;
$daysheet_total = false;
$provider_run = false;
if ($GLOBALS['use_custom_daysheet'] != 0) {
$daysheet = true;
if ($GLOBALS['daysheet_provider_totals'] == 1) {
$daysheet_total = true;
$provider_run = false;
}
if ($GLOBALS['daysheet_provider_totals'] == 0) {
$daysheet_total = false;
$provider_run = true;
}
}
$alertmsg = '';
if (isset($_POST['mode'])) {
if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
CsrfUtils::csrfNotVerified();
}
if ($_POST['mode'] == 'export') {
$sql = BillingReport::ReturnOFXSql();
$db = get_db();
$results = $db->Execute($sql);
$billings = array();
if ($results->RecordCount() == 0) {
echo "<fieldset id='error_info' style='border:1px solid var(--danger) !important; background-color: var(--danger) !important; color: var(--white) !important; font-weight: bold; font-family: sans-serif; border-radius: 5px; padding: 20px 5px !important;'>";
echo xlt("No Bills Found to Include in OFX Export") . "<br />";
echo "</fieldset>";
} else {
while (!$results->EOF) {
$billings[] = $results->fields;
$results->MoveNext();
}
$ofx = new OFX($billings);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Disposition: attachment; filename=openemr_ofx.ofx");
header("Content-Type: text/xml");
echo $ofx->get_OFX();
exit();
}
}
}
// global variables:
$from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
$to_date = isset($_POST['to_date']) ? $_POST['to_date'] : '';
$code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
$unbilled = isset($_POST['unbilled']) ? $_POST['unbilled'] : 'on';
$my_authorized = isset($_POST["authorized"]) ? $_POST["authorized"] : '';
// This tells us if only encounters that appear to be missing a "25" modifier
// are to be reported.
$missing_mods_only = (isset($_POST['missing_mods_only']) && !empty($_POST['missing_mods_only']));
$left_margin = isset($_POST["left_margin"]) ? $_POST["left_margin"] : $GLOBALS['cms_left_margin_default'];
$top_margin = isset($_POST["top_margin"]) ? $_POST["top_margin"] : $GLOBALS['cms_top_margin_default'];
if ($left_margin + 0 === 20 && $top_margin + 0 === 24) {
// defaults are flipped. No easy way to reset existing. Global defaults fixed.
$left_margin = '24';
$top_margin = '20';
}
if ($ub04_support) {
$left_ubmargin = isset($_POST["left_ubmargin"]) ? $_POST["left_ubmargin"] : $GLOBALS['left_ubmargin_default'];
$top_ubmargin = isset($_POST["top_ubmargin"]) ? $_POST["top_ubmargin"] : $GLOBALS['top_ubmargin_default'];
}
$ofrom_date = $from_date;
$oto_date = $to_date;
$ocode_type = $code_type;
$ounbilled = $unbilled;
$oauthorized = $my_authorized;
$x = new X12Partner();
$partners = $x->_utility_array($x->x12_partner_factory());
?>
<!DOCTYPE html>
<html>
<head>
<?php Header::setupHeader(['datetime-picker', 'common']); ?>
<style>
.btn-group-pinch > .btn:nth-last-child(4):not(.dropdown-toggle) {
border-top-right-radius: 3px !important;
border-bottom-right-radius: 3px !important;
}
.modal {
overflow-y: auto;
}
.modal-open {
overflow: auto;
}
.modal-open[style] {
padding-right: 0px !important;
}
</style>
<script>
var partners = <?php echo json_encode($partners); ?>;
// next set of 4 functions are for a wait confirm action then submit.
// I wrote this a little more involved than it needs to be
// to example the pattern. Ideal submit part would be via a fetch or ajax
// then could do refresh or after submit actions.
//
function doSubmit(action) {
top.restoreSession();
return new Promise(function(resolve, reject) {
if (action !== 'btn-continue') {
var showLog = function() {
$("#view-log-link").click();
};
// Pre-open a dialog and target dialogs iframe for content from billing_process
// text or PDF.
dlgopen('', 'ValidateShowBatch', 875, 500, false, '', {
buttons: [{
text: '<?php echo xlt("Logs"); ?>',
close: false,
style: 'default btn-sm',
click: showLog
},
{
text: '<i class="fa fa-thumbs-up"></i> <?php echo xlt("Close"); ?>',
close: true,
style: 'default btn-sm'
}
],
//onClosed: 'SubmitTheScreen', // future and/or example of onClosed.
sizeHeight: 'full'
});
// target content from submit to dialogs iframe
document.update_form.target = 'ValidateShowBatch';
}
// Now submit form and populate dialog.
document.update_form.submit();
// go fulfill the promise.
resolve(true);
});
}
function doConfirm(Message) {
placeModal(Message);
return new Promise(function(resolve, reject) {
$('#confirmDialog').modal('show');
$('#confirmDialog .btn-continue').click(function() {
$(this).off();
resolve("btn-continue");
});
$('#confirmDialog .btn-clear').click(function() {
$(this).off();
resolve("btn-clear");
});
$('#confirmDialog .btn-validate').click(function() {
$(this).off();
resolve("btn-validate");
});
$('#confirmDialog .btn-danger').click(function() {
$(this).off();
reject("btn-cancel");
});
});
}
async function confirmActions(e, mType) {
e.preventDefault();
let Message = "";
let ClaimCount = 0;
for (var CheckBoxBillingIndex = 0;; CheckBoxBillingIndex++) {
CheckBoxBillingObject = document.getElementById('CheckBoxBilling' +
CheckBoxBillingIndex);
if (!CheckBoxBillingObject) break;
if (CheckBoxBillingObject.checked) {
++ClaimCount;
}
}
let addOn = <?php echo xlj('click View Log and review for errors.'); ?>;
if (mType == '1') {
Message = <?php echo xlj('After saving your batch'); ?> + ", " + addOn;
} else if (mType == '2') {
Message = <?php echo xlj('After saving the PDF'); ?> + ", " + addOn;
} else if (mType == '3') {
Message = <?php echo xlj('After saving the TEXT file'); ?> + "(s), " + addOn;
}
Message += "<br/><br/>" + <?php echo xlj('Validate and Clear validates then sets claims status only, to billed, leaving billing process unaltered and claim submission resets to unsubmitted.'); ?>;
Message += "<br/><br/>" + <?php echo xlj('Validate Only does a claim validation dry run for errors leaving claim status unaltered.'); ?>;
Message += "<br/><br/>" + <?php echo xlj('Continue completes selected billing option normally.'); ?>;
Message += "<br/><br/>" + <?php echo xlj('Total of'); ?> + ' ' + ClaimCount + ' ' + <?php echo xlj('claims selected.'); ?> + "\n";
let sName = e.currentTarget.name;
// wait for confirm result
await doConfirm(Message).then(action => {
console.log(sName, action);
// set post button for form submit
$('<input>').attr({
type: 'hidden',
id: "submitTask",
name: sName,
value: 'true'
}).prependTo(document.update_form);
// passing confirm clicked button
$('<input>').attr({
type: 'hidden',
id: "confirmTask",
name: action,
value: 1
}).prependTo(document.update_form);
return action;
}).then(action => {
// submit update_form then cleanup
doSubmit(action).then(function() {
$("#submitTask").remove();
$("#confirmTask").remove();
});
}).catch(function(why) {
// cancel clicked in confirm. do nothing...
console.warn("Task was canceled", why);
});
return false;
}
function placeModal(Message) {
let mConfirm = <?php echo xlj('Please Confirm') ?>;
let mClear = <?php echo xlj('Validate and Clear') ?>;
let mVal = <?php echo xlj('Validate Only') ?>;
let mCont = <?php echo xlj('Continue') ?>;
let mCancel = <?php echo xlj('Cancel') ?>;
let dModal = "<div class='modal fade' id='confirmDialog' aria-hidden='true'><div class='modal-dialog'><div class='modal-content'>" +
"<div class='modal-header'><h4 class='modal-title'>" + mConfirm + "</h4></div><div class='modal-body'>" +
"<label>" + Message + "</label></div><div class='modal-footer'>" +
"<button type='button' class='btn btn-secondary btn-clear' data-dismiss='modal'>" + mClear + "</button>" +
"<button type='button' class='btn btn-secondary btn-validate' data-dismiss='modal'>" + mVal + "</button>" +
"<button type='button' class='btn btn-secondary btn-continue' data-dismiss='modal'>" + mCont + "</button>" +
"<a class='btn btn-danger' data-dismiss='modal'>" + mCancel + "</a>" +
"</div></div></div></div>";
$("body").append(dModal);
$('#confirmDialog').on('hidden.bs.modal', function(e) {
// remove modal
$(this).remove();
console.log("Confirm Modal Removed");
// remove this event for next time.
$(this).off(e);
});
}
function onNewPayer(oEvent) {
let p = oEvent.target.options[event.target.selectedIndex].dataset.partner;
let partnerSelect = oEvent.target.options[event.target.selectedIndex].dataset.partner;
partnerSelect = partnerSelect ? partnerSelect : -1;
document.getElementById("partners").value = partnerSelect;
}
function select_all() {
for ($i = 0; $i < document.update_form.length; $i++) {
$name = document.update_form[$i].name;
if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -
6) == "[bill]") {
document.update_form[$i].checked = true;
}
}
set_button_states();
}
function set_button_states() {
var f = document.update_form;
var count0 = 0; // selected and not billed or queued
var count1 = 0; // selected and queued
var count2 = 0; // selected and billed
for ($i = 0; $i < f.length; ++$i) {
$name = f[$i].name;
if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -
6) == "[bill]" && f[$i].checked == true) {
if (f[$i].value == '0') ++count0;
else if (f[$i].value == '1' || f[$i].value == '5') ++count1;
else ++count2;
}
}
var can_generate = (count0 > 0 || count1 > 0 || count2 > 0);
var can_mark = (count1 > 0 || count0 > 0 || count2 > 0);
var can_bill = (count0 == 0 && count1 == 0 && count2 > 0);
<?php if (file_exists($EXPORT_INC)) { ?>
f.bn_external.disabled = !can_generate;
<?php } else { ?>
f.bn_x12_support.disabled = !can_generate;
<?php if ($GLOBALS['support_encounter_claims']) { ?>
f.bn_x12_encounter.disabled = !can_generate;
<?php } ?>
f.bn_process_hcfa_support.disabled = !can_generate;
<?php if ($GLOBALS['preprinted_cms_1500']) { ?>
f.bn_process_hcfa_form.disabled = !can_generate;
<?php } ?>
<?php if ($GLOBALS['ub04_support']) { ?>
f.bn_process_ub04_support.disabled = !can_generate;
<?php } ?>
f.bn_hcfa_txt_file.disabled = !can_generate;
f.bn_reopen.disabled = !can_bill;
<?php } ?>
f.bn_mark.disabled = !can_mark;
}
// Process a click to go to an encounter.
function toencounter(pid, pubpid, pname, enc, datestr, dobstr) {
top.restoreSession();
encurl = 'patient_file/encounter/encounter_top.php?set_encounter=' + encodeURIComponent(enc) +
'&pid=' + encodeURIComponent(pid);
parent.left_nav.setPatient(pname, pid, pubpid, '', dobstr);
parent.left_nav.setEncounter(datestr, enc, 'enc');
parent.left_nav.loadFrame('enc2', 'enc', encurl);
}
// Process a click to go to an patient.
function topatient(pid, pubpid, pname, enc, datestr, dobstr) {
top.restoreSession();
paturl = 'patient_file/summary/demographics_full.php?pid=' + encodeURIComponent(pid);
parent.left_nav.setPatient(pname, pid, pubpid, '', dobstr);
parent.left_nav.loadFrame('ens1', 'enc',
'patient_file/history/encounters.php?pid=' + encodeURIComponent(pid));
parent.left_nav.loadFrame('dem1', 'pat', paturl);
}
function popMBO(pid, enc, mboid) {
if (!window.focus) return true;
if (!ProcessBeforeSubmitting()) return false;
top.restoreSession();
let qstring = "&pid=" + encodeURIComponent(pid) + "&enc=" + encodeURIComponent(enc) + "&id=" + encodeURIComponent(mboid);
let href = "<?php echo $GLOBALS['web_root']?>/interface/patient_file/encounter/view_form.php?formname=misc_billing_options&isBilling=1" + qstring;
dlgopen(href, 'mbopop', 'modal-lg', 750, false, '', {
sizeHeight: 'full' // override min height auto size.
});
return true;
}
function popUB04(pid, enc) {
if (!window.focus) return true;
if (!ProcessBeforeSubmitting()) return false;
top.restoreSession();
let href = "<?php echo $GLOBALS['web_root']?>/interface/billing/ub04_form.php?pid=" + encodeURIComponent(pid) + "&enc=" + encodeURIComponent(enc);
dlgopen(href, 'ub04pop', 1175, 750, false, '', {
sizeHeight: 'full' // override min height auto size.
});
return true;
}
var EncounterDateArray = new Array;
var CalendarCategoryArray = new Array;
var EncounterIdArray = new Array;
var EncounterNoteArray = new Array;
function SubmitTheScreen() { //Action on Update List link
if (!ProcessBeforeSubmitting()) return false;
$("#update-tooltip").replaceWith("<i class='fa fa-refresh fa-spin fa-1x' style=\"color:red\"></i>");
top.restoreSession();
document.the_form.mode.value = 'change';
document.the_form.target = '_self';
document.the_form.action = 'billing_report.php';
document.the_form.submit();
return true;
}
function SubmitTheScreenPrint() { //Action on View Printable Report link
if (!ProcessBeforeSubmitting()) return false;
top.restoreSession();
document.the_form.target = 'new';
document.the_form.action = 'print_billing_report.php';
document.the_form.submit();
return true;
}
function SubmitTheEndDayPrint() { //Action on View End of Day Report link
if (!ProcessBeforeSubmitting()) return false;
top.restoreSession();
document.the_form.target = 'new';
<?php if ($GLOBALS['use_custom_daysheet'] == 1) { ?>
document.the_form.action = 'print_daysheet_report_num1.php';
<?php } ?>
<?php if ($GLOBALS['use_custom_daysheet'] == 2) { ?>
document.the_form.action = 'print_daysheet_report_num2.php';
<?php } ?>
<?php if ($GLOBALS['use_custom_daysheet'] == 3) { ?>
document.the_form.action = 'print_daysheet_report_num3.php';
<?php } ?>
document.the_form.submit();
return true;
}
function SubmitTheScreenExportOFX() { //Action on Export OFX link
if (!ProcessBeforeSubmitting()) return false;
top.restoreSession();
document.the_form.mode.value = 'export';
document.the_form.target = '_self';
document.the_form.action = 'billing_report.php';
document.the_form.submit();
return true;
}
function TestExpandCollapse() { //Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
var set = -1;
for (i = 1; i <= document.getElementById("divnos").value; i++) {
var ele = document.getElementById("divid_" + i);
if (ele) {
set = 1;
break;
}
}
if (set == -1) {
if (document.getElementById("ExpandAll")) {
document.getElementById("ExpandAll").innerHTML = '';
document.getElementById("CollapseAll").innerHTML = '';
}
}
}
function expandcollapse(atr) {
if (atr == "expand") { //Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
for (i = 1; i <= document.getElementById("divnos").value; i++) {
var mydivid = "divid_" + i;
var myspanid = "spanid_" + i;
var ele = document.getElementById(mydivid);
var text = document.getElementById(myspanid);
if (ele) {
ele.style.display = "inline";
text.innerHTML =
"<?php echo xla('Collapse'); ?>";
}
}
} else {
for (i = 1; i <= document.getElementById("divnos").value; i++) {
var mydivid = "divid_" + i;
var myspanid = "spanid_" + i;
var ele = document.getElementById(mydivid);
var text = document.getElementById(myspanid);
if (ele) {
ele.style.display = "none";
text.innerHTML =
<?php echo xlj('Expand'); ?>;
}
}
}
}
function divtoggle(spanid, divid) { //Called in the Expand, Collapse links(This is for a single item)
var ele = document.getElementById(divid);
if (ele) {
var text = document.getElementById(spanid);
if (ele.style.display == "inline") {
ele.style.display = "none";
text.innerHTML =
<?php echo xlj('Expand'); ?>;
} else {
ele.style.display = "inline";
text.innerHTML =
<?php echo xlj('Collapse'); ?>;
}
}
}
</script>
<?php require_once "$srcdir/../interface/reports/report.script.php"; ?>
<!-- Criteria Section common javascript page-->
<!-- =============Included for Insurance ajax criteria==== -->
<?php require_once "{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"; ?>
<style>
#ajax_div_insurance {
position: absolute;
z-index: 10;
background-color: #FBFDD0;
border: 1px solid #ccc;
padding: 10px;
}
button[type="submit"].subbtn-warning {
background: #ec971f !important;
color: black !important;
}
button[type="submit"].subbtn-warning:hover {
background: #da8104 !important;
color: var(--white) !important;
}
@media only screen and (max-width: 1024px) {
[class*="col-"] {
width: 100%;
text-align: left !Important;
}
}
.table {
margin: auto;
}
@media (min-width: 992px) {
.modal-lg {
width: 1000px !Important;
}
}
.table th,
.table td {
border-top: none !important;
}
a,
a:visited,
a:hover {
text-decoration: none;
color: var(--black);
}
</style>
<script>
document.onclick = TakeActionOnHide;
</script>
<!-- =============Included for Insurance ajax criteria==== -->
<title><?php echo xlt('Billing Manager'); ?></title>
<?php
$arrOeUiSettings = array(
'heading_title' => xl('Billing Manager'),
'include_patient_name' => false,// use only in appropriate pages
'expandable' => false,
'expandable_files' => array('billing_report_xpd'),//all file names need suffix _xpd
'action' => "conceal",//conceal, reveal, search, reset, link or back
'action_title' => "",
'action_href' => "",//only for actions - reset, link or back
'show_help_icon' => false,
'help_file_name' => ""
);
$oemr_ui = new OemrUI($arrOeUiSettings);
?>
</head>
<body class="body_top" onLoad="TestExpandCollapse()">
<div id="container_div" class="<?php echo attr($oemr_ui->oeContainer()); ?>">
<div class="row">
<div class="col-sm-12">
<div class="page-header">
<?php echo $oemr_ui->pageHeading() . "\r\n"; ?>
</div>
</div>
</div>
<div class="hideaway">
<div>
<form class="form" name='the_form' method='post' action='billing_report.php' onsubmit='return top.restoreSession()'>
<input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
<input type='hidden' name='mode' value='change'>
<!-- Criteria section Starts -->
<?php
// TPS = This Page Search
// The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
// Each item is seperated by a comma(,).
// $TPSCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
// $TPSCriteriaKeyMaster ==>Corresponding database fields in the same order.
// $TPSCriteriaDataTypeMaster ==>Corresponding data type in the same order.
$TPSCriteriaDisplayRadioMaster = array();
$TPSCriteriaRadioKeyMaster = array();
$TPSCriteriaQueryDropDownMaster = array();
$TPSCriteriaQueryDropDownMasterDefault = array();
$TPSCriteriaQueryDropDownMasterDefaultKey = array();
$TPSCriteriaIncludeMaster = array();
if ($daysheet) {
$TPSCriteriaDisplayMaster = array(
xl("Date of Service"),
xl("Date of Entry"),
xl("Date of Billing"),
xl("Claim Type"),
xl("Patient Name"),
xl("Patient Id"),
xl("Insurance Company"),
xl("Encounter"),
xl("Whether Insured"),
xl("Charge Coded"),
xl("Billing Status"),
xl("Authorization Status"),
xl("Last Level Billed"),
xl("X12 Partner"),
xl("User")
);
$TPSCriteriaKeyMaster = "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";
$TPSCriteriaDataTypeMaster = "datetime,datetime,datetime,radio,text_like," . "text,include,text,radio,radio,radio," . "radio_like,radio,query_drop_down,text";
} else {
$TPSCriteriaDisplayMaster = array(
xl("Date of Service"),
xl("Date of Entry"),
xl("Date of Billing"),
xl("Claim Type"),
xl("Patient Name"),
xl("Patient Id"),
xl("Insurance Company"),
xl("Encounter"),
xl("Whether Insured"),
xl("Charge Coded"),
xl("Billing Status"),
xl("Authorization Status"),
xl("Last Level Billed"),
xl("X12 Partner")
);
$TPSCriteriaKeyMaster = "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";
$TPSCriteriaDataTypeMaster = "datetime,datetime,datetime,radio,text_like," . "text,include,text,radio,radio,radio," . "radio_like,radio,query_drop_down";
}
// The below section is needed if there is any 'radio' or 'radio_like' type in the $TPSCriteriaDataTypeMaster
// $TPSCriteriaDisplayRadioMaster,$TPSCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
// 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.
$TPSCriteriaDisplayRadioMaster[1] = array(
xl("All"),
xl("eClaims"),
xl("Paper")
); // Display Value
$TPSCriteriaRadioKeyMaster[1] = "all,standard,hcfa"; // Key
$TPSCriteriaDisplayRadioMaster[2] = array(
xl("All"),
xl("Insured"),
xl("Non-Insured")
); // Display Value
$TPSCriteriaRadioKeyMaster[2] = "all,1,0"; // Key
$TPSCriteriaDisplayRadioMaster[3] = array(
xl("All"),
xl("Coded"),
xl("Not Coded")
); // Display Value
$TPSCriteriaRadioKeyMaster[3] = "all,not null,null"; // Key
$TPSCriteriaDisplayRadioMaster[4] = array(
xl("All"),
xl("Unbilled"),
xl("Billed"),
xl("Denied")
); // Display Value
$TPSCriteriaRadioKeyMaster[4] = "all,0,1,7"; // Key
$TPSCriteriaDisplayRadioMaster[5] = array(
xl("All"),
xl("Authorized"),
xl("Unauthorized")
);
$TPSCriteriaRadioKeyMaster[5] = "%,1,0";
$TPSCriteriaDisplayRadioMaster[6] = array(
xl("All"),
xl("None{{Insurance}}"),
xl("Ins 1"),
xl("Ins 2 or Ins 3")
);
$TPSCriteriaRadioKeyMaster[6] = "all,0,1,2";
// The below section is needed if there is any 'query_drop_down' type in the $TPSCriteriaDataTypeMaster
$TPSCriteriaQueryDropDownMaster[1] = "SELECT name,id FROM x12_partners;";
$TPSCriteriaQueryDropDownMasterDefault[1] = xl("All"); // Only one item will be here
$TPSCriteriaQueryDropDownMasterDefaultKey[1] = "all"; // Only one item will be here
// The below section is needed if there is any 'include' type in the $TPSCriteriaDataTypeMaster
// Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
// It is labled(Included for Insurance ajax criteria)(Line:-279-299).
$TPSCriteriaIncludeMaster[1] = "OpenEMR\Billing\BillingReport::InsuranceCompanyDisplay";
if (!isset($_REQUEST['mode'])) {// default case
$_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") . "')";
$_REQUEST['final_this_page_criteria'][1] = "billing.billed = '0'";
$_REQUEST['final_this_page_criteria_text'][0] = xl("Date of Service = Today");
$_REQUEST['final_this_page_criteria_text'][1] = xl("Billing Status = Unbilled");
$_REQUEST['date_master_criteria_form_encounter_date'] = "today";
$_REQUEST['master_from_date_form_encounter_date'] = date("Y-m-d");
$_REQUEST['master_to_date_form_encounter_date'] = date("Y-m-d");
$_REQUEST['radio_billing_billed'] = 0;
}
?>
<?php
require_once "$srcdir/../interface/reports/criteria.tab.php";
?>
<!-- end criteria -->
</form>
</div>
</div>
</div>
<div class="container-fluid mt-1">
<form class="form-inline" name='update_form' method='post' action='billing_process.php'>
<nav class="nav navbar-expand-md navbar-light bg-light px-3 py-2">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#billing-nav-detail" aria-controls="" aria-expanded="false" aria-label="Actions">
<span><?php echo xlt('More Actions'); ?></span>
</button>
<!-- begin detail nav -->
<div class="collapse navbar-collapse clearfix" id="billing-nav-detail" role="group">
<div class="btn-group dropdown">
<button type="button" class="btn nav-link btn-link dropdown-toggle" data-toggle="dropdown" name="bn_x12_support" title=""><?php echo xla('X12 OPTIONS') ?>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<?php if (file_exists($EXPORT_INC)) { ?>
<li class="nav-item">
<button type="submit" data-open-popup="true" class="btn nav-link btn-link btn-download" name="bn_external" title="<?php echo xla('Export to external billing system') ?>" value="<?php echo xla("Export Billing") ?>"><?php echo xlt("Export Billing") ?>
</button>
</li>
<li class="nav-item">
<button type="submit" data-open-popup="true" class="btn nav-link btn-link btn-download" name="bn_mark" title="<?php echo xla('Mark as billed but skip billing') ?>"><?php echo xlt("Mark as Cleared") ?>
</button>
</li>
<?php } else { ?>
<li class="nav-item">
<button type="button" class="btn nav-link btn-link btn-download" name="bn_x12" onclick="confirmActions(event, '1');" title="<?php echo xla('Generate and download X12 batch') ?>"><?php echo xlt('Generate X12') ?>
</button>
</li>
<?php } ?>
<?php if ($GLOBALS['ub04_support']) { ?>
<li class="nav-item">
<button type="submit" class="btn nav-link btn-link btn-download" name="bn_ub04_x12" title="<?php echo xla('Generate Institutional X12 837I') ?>"><?php echo xlt('Generate X12 837I') ?>
</button>
</li>
<?php } ?>
<?php if ($GLOBALS['support_encounter_claims']) { ?>
<li class="nav-item">
<button type="submit" class="btn nav-link btn-link btn-download" name="bn_x12_encounter" onclick="confirmActions(event, '1');" title="<?php echo xla('Generate and download X12 encounter claim batch') ?>"><?php echo xlt('Generate X12 Encounter') ?>
</button>
</li>
<?php } ?>
</ul>
</div>
<div class="btn-group dropdown">
<button type="button" class="btn nav-link btn-link dropdown-toggle" data-toggle="dropdown" name="bn_process_hcfa_support" title=""><?php echo xlt('HCFA FORM') ?>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li class="nav-item">
<button type="button" class="btn nav-link btn-link btn-download" name="bn_process_hcfa" onclick="confirmActions(event, '2');" title="<?php echo xla('Generate and download CMS 1500 paper claims') ?>"><?php echo xlt('CMS 1500 PDF') ?>
</button>
</li>
<?php if ($GLOBALS['preprinted_cms_1500']) { ?>
<li class="nav-item">
<button type="button" class="btn nav-link btn-link btn-download" onclick="confirmActions(event, '2');" name="bn_process_hcfa_form" title="<?php echo xla('Generate and download CMS 1500 paper claims on Preprinted form') ?>"><?php echo xlt('CMS 1500 Form') ?>
</button>
</li>
<?php } ?>
<li class="nav-item">
<button type="button" class="btn nav-link btn-link btn-download" name="bn_hcfa_txt_file" onclick="confirmActions(event, '3');" title="<?php echo xla('Making batch text files for uploading to Clearing House and will mark as billed') ?>"><?php echo xlt('CMS 1500 TEXT') ?>
</button>
</li>
</ul>
</div>
<?php if ($GLOBALS['ub04_support']) { ?>
<div class="btn-group dropdown">
<button type="button" class="btn nav-link btn-link dropdown-toggle" data-toggle="dropdown" name="bn_process_ub04_support" title=""><?php echo xlt('UB04 FORM') ?>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li class="nav-item">
<button type="submit" class="btn nav-link btn-link btn-download" name="bn_process_ub04_form" title="<?php echo xla('Generate and download UB-04 CMS1450 with form') ?>"><?php echo xlt('UB04 FORM PDF') ?>
</button>
</li>
<li class="nav-item">
<button type="submit" class="btn nav-link btn-link btn-download" name="bn_process_ub04" title="<?php echo xla('Generate and download UB-04 CMS1450') ?>"><?php echo xlt('UB04 TEXT PDF') ?>
</button>
</li>
</ul>
</div>
<?php } ?>
<button class="btn nav-link btn-secondary btn-download" data-open-popup="true" name="bn_mark" title="<?php echo xla('Post to accounting and mark as billed') ?>" type="submit"><?php echo xla('Mark as Cleared') ?>
</button>
<button class="btn nav-link btn-secondary btn-undo" data-open-popup="true" name="bn_reopen" title="<?php echo xla('Mark as not billed') ?>" type="submit"><?php echo xlt('Re-Open') ?>
</button>
<span class="input-group">
<label for="left_margin"><?php echo xlt('CMS Margins Left'); ?>:</label>
<input type='text' size='2' id='left_margin' name='left_margin' value='<?php echo attr($left_margin); ?>' title='<?php echo xla('HCFA left margin in points'); ?>' />
<label for="top_margin"><?php echo xlt('Top'); ?>:</label>
<input type='text' size='2' id='top_margin' name='top_margin' value='<?php echo attr($top_margin); ?>' title='<?php echo xla('HCFA top margin in points'); ?>' />
</span>
<?php if ($ub04_support) { ?>
<span class="input-group">
<label for="left_ubmargin"><?php echo xlt('UB04 Margins Left'); ?>:</label>
<input type='text' size='2' id='left_ubmargin' name='left_ubmargin' value='<?php echo attr($left_ubmargin); ?>' title='<?php echo xla('UB04 left margin in points'); ?>' />
<label for="top_ubmargin"><?php echo xlt('Top'); ?>:</label>
<input type='text' size='2' id='top_ubmargin' name='top_ubmargin' value='<?php echo attr($top_ubmargin); ?>' title='<?php echo xla('UB04 top margin in points'); ?>' />
</span>
<?php } ?>
</div>
</nav>
<input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
<input name='mode' type='hidden' value="bill">
<input name='authorized' type='hidden' value="<?php echo attr($my_authorized); ?>">
<input name='unbilled' type='hidden' value="<?php echo attr($unbilled); ?>">
<input name='code_type' type='hidden' value="%">
<input name='to_date' type='hidden' value="<?php echo attr($to_date); ?>">
<input name='from_date' type='hidden' value="<?php echo attr($from_date); ?>">
<?php
if ($my_authorized == "on") {
$my_authorized = "1";
} else {
$my_authorized = "%";
}
if ($unbilled == "on") {
$unbilled = "0";
} else {
$unbilled = "%";
}
$list = BillingReport::getBillsListBetween("%");
?>
<?php
if (!isset($_POST["mode"])) {
if (!isset($_POST["from_date"])) {
$from_date = date("Y-m-d");
} else {
$from_date = $_POST["from_date"];
}
if (empty($_POST["to_date"])) {
$to_date = '';
} else {
$to_date = $_POST["to_date"];
}
if (!isset($_POST["code_type"])) {
$code_type = "all";
} else {
$code_type = $_POST["code_type"];
}
if (!isset($_POST["unbilled"])) {
$unbilled = "on";
} else {
$unbilled = $_POST["unbilled"];
}
if (!isset($_POST["authorized"])) {
$my_authorized = "on";
} else {
$my_authorized = $_POST["authorized"];
}
} else {
$from_date = $_POST["from_date"];
$to_date = $_POST["to_date"];
$code_type = $_POST["code_type"];
$unbilled = $_POST["unbilled"];
$my_authorized = $_POST["authorized"];
}
if ($my_authorized == "on") {
$my_authorized = "1";
} else {
$my_authorized = "%";
}
if ($unbilled == "on") {
$unbilled = "0";
} else {
$unbilled = "%";
}
if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
billCodesList($list);
}
?>
<div class="table-responsive">
<table class="table table-sm">
<?php
$divnos = 0;
if ($ret = BillingReport::getBillsBetween("%")) {
if (is_array($ret)) {
?>
<tr>
<td colspan='9' align="right">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" id='ExpandAll'><a onclick="expandcollapse('expand');" class='small' href="JavaScript:void(0);"><?php echo '(' . xlt('Expand All') . ')' ?></a>
</td>
<td width="100" id='CollapseAll'><a onclick="expandcollapse('collapse');" class='small' href="JavaScript:void(0);"><?php echo '(' . xlt('Collapse All') . ')' ?></a>
</td>
<td width="50"> </td>
</tr>
</table>
</td>
</tr>
<?php
}
$loop = 0;
$oldcode = "";
$last_encounter_id = "";
$lhtml = "";
$rhtml = "";
$lcount = 0;
$rcount = 0;
$bgcolor = "";
$skipping = false;
$mmo_empty_mod = false;
$mmo_num_charges = 0;
foreach ($ret as $iter) {
// We include encounters here that have never been billed. However
// if it had no selected billing items but does have non-selected
// billing items, then it is not of interest.
if (!$iter['id']) {
$res = sqlQuery(
"SELECT count(*) AS count FROM billing WHERE " .
"encounter = ? AND " .
"pid=? AND " .
"activity = 1",
array(
$iter['enc_encounter'],
$iter['enc_pid']
)
);
if ($res['count'] > 0) {
continue;
}
}
$this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
if ($last_encounter_id != $this_encounter_id) {
// This dumps all HTML for the previous encounter.
//
if ($lhtml) {
while ($rcount < $lcount) {
$rhtml .= "<tr bgcolor='" . attr($bgcolor) . "'><td colspan='9'></td></tr>";
++$rcount;
}
// This test handles the case where we are only listing encounters
// that appear to have a missing "25" modifier.
if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
if ($DivPut == 'yes') {
$lhtml .= '</div>';
$DivPut = 'no';
}
echo "<tr bgcolor='" . attr($bgcolor) . "'>\n<td rowspan='" . attr($rcount) . "' valign='top'>\n$lhtml</td>$rhtml\n";
echo "<tr bgcolor='" . attr($bgcolor) . "'><td colspan='9' height='5'></td></tr>\n\n";
++$encount;
}
}
$lhtml = "";
$rhtml = "";
$mmo_empty_mod = false;
$mmo_num_charges = 0;
// If there are ANY unauthorized items in this encounter and this is
// the normal case of viewing only authorized billing, then skip the
// entire encounter.
//
$skipping = false;
if ($my_authorized == '1') {
$res = sqlQuery(
"SELECT count(*) AS count FROM billing WHERE " .
"encounter = ? AND " .
"pid=? AND " .
"activity = 1 AND authorized = 0",
array(
$iter['enc_encounter'],
$iter['enc_pid']
)
);
if ($res['count'] > 0) {
$skipping = true;
$last_encounter_id = $this_encounter_id;
continue;
}
}
// Is there a MBO
//
$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']));
$iter['mboid'] = $mboid ? attr($mboid['form_id']) : 0;
$name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, billing_note, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
// Check if patient has primary insurance and a subscriber exists for it.
// If not we will highlight their name in red.
// TBD: more checking here.
//
$res = sqlQuery(
"SELECT count(*) AS count FROM insurance_data WHERE " .
"pid = ? AND " .
"type='primary' AND " .
"subscriber_lname IS NOT NULL AND " .
"subscriber_lname != '' LIMIT 1",
array(
$iter['enc_pid']
)