Feature to add drug-drug interaction checking for the
[openemr.git] / interface / billing / billing_report.php
blobd12970d82612346d7927aedd73e4e7235c45e98b
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 * Added hooks for UB04 and End of day reporting Terry Hill 2014 terry@lillysystems.com
8 */
10 $fake_register_globals=false;
11 $sanitize_all_escapes=true;
13 require_once("../globals.php");
14 require_once("../../library/acl.inc");
15 require_once("../../custom/code_types.inc.php");
16 require_once("$srcdir/patient.inc");
17 include_once("$srcdir/../interface/reports/report.inc.php");//Criteria Section common php page
18 require_once("$srcdir/billrep.inc");
19 require_once(dirname(__FILE__) . "/../../library/classes/OFX.class.php");
20 require_once(dirname(__FILE__) . "/../../library/classes/X12Partner.class.php");
21 require_once("$srcdir/formatting.inc.php");
22 require_once("$srcdir/options.inc.php");
23 require_once("adjustment_reason_codes.php");
25 $EXPORT_INC = "$webserver_root/custom/BillingExport.php";
26 //echo $GLOBALS['daysheet_provider_totals'];
28 $daysheet = false;
29 $daysheet_total = false;
30 $provider_run = false;
32 if ($GLOBALS['use_custom_daysheet'] != 0) {
33 $daysheet = true;
34 if ($GLOBALS['daysheet_provider_totals'] == 1) {
35 $daysheet_total = true;
36 $provider_run = false;
38 if ($GLOBALS['daysheet_provider_totals'] == 0) {
39 $daysheet_total = false;
40 $provider_run = true;
44 $alertmsg = '';
46 if (isset($_POST['mode'])) {
47 if ($_POST['mode'] == 'export') {
48 $sql = ReturnOFXSql();
49 $db = get_db();
50 $results = $db->Execute($sql);
51 $billings = array();
52 if ($results->RecordCount() == 0) {
53 echo xlt("No Bills Found to Include in OFX Export")."<br>";
54 } else {
55 while(!$results->EOF) {
56 $billings[] = $results->fields;
57 $results->MoveNext();
59 $ofx = new OFX($billings);
60 header("Pragma: public");
61 header("Expires: 0");
62 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
63 header("Content-Disposition: attachment; filename=openemr_ofx.ofx");
64 header("Content-Type: text/xml");
65 echo $ofx->get_OFX();
66 exit;
71 //global variables:
72 $from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
73 $to_date = isset($_POST['to_date' ]) ? $_POST['to_date' ] : '';
74 $code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
75 $unbilled = isset($_POST['unbilled' ]) ? $_POST['unbilled' ] : 'on';
76 $my_authorized = isset($_POST["authorized"]) ? $_POST["authorized"] : '';
79 // This tells us if only encounters that appear to be missing a "25" modifier
80 // are to be reported.
81 $missing_mods_only = (isset($_POST['missing_mods_only']) && !empty($_POST['missing_mods_only']));
83 $left_margin = isset($_POST["left_margin"]) ? $_POST["left_margin"] : 24;
84 $top_margin = isset($_POST["top_margin"] ) ? $_POST["top_margin" ] : 20;
86 $ofrom_date = $from_date;
87 $oto_date = $to_date;
88 $ocode_type = $code_type;
89 $ounbilled = $unbilled;
90 $oauthorized = $my_authorized;
93 <html>
94 <head>
95 <?php if (function_exists('html_header_show')) html_header_show(); ?>
96 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
97 <style>
98 .subbtn { margin-top:3px; margin-bottom:3px; margin-left:2px; margin-right:2px }
99 </style>
100 <script>
102 function select_all() {
103 for($i=0;$i < document.update_form.length;$i++) {
104 $name = document.update_form[$i].name;
105 if ($name.substring(0,7) == "claims[" && $name.substring($name.length -6) == "[bill]") {
106 document.update_form[$i].checked = true;
109 set_button_states();
112 function set_button_states() {
113 var f = document.update_form;
114 var count0 = 0; // selected and not billed or queued
115 var count1 = 0; // selected and queued
116 var count2 = 0; // selected and billed
117 for($i = 0; $i < f.length; ++$i) {
118 $name = f[$i].name;
119 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -6) == "[bill]" && f[$i].checked == true) {
120 if (f[$i].value == '0') ++count0;
121 else if (f[$i].value == '1' || f[$i].value == '5') ++count1;
122 else ++count2;
126 var can_generate = (count0 > 0 || count1 > 0 || count2 > 0);
127 var can_mark = (count1 > 0 || count0 > 0 || count2 > 0);
128 var can_bill = (count0 == 0 && count1 == 0 && count2 > 0);
130 <?php if (file_exists($EXPORT_INC)) { ?>
131 f.bn_external.disabled = !can_generate;
132 <?php } else { ?>
133 // f.bn_hcfa_print.disabled = !can_generate;
134 // f.bn_hcfa.disabled = !can_generate;
135 // f.bn_ub92_print.disabled = !can_generate;
136 // f.bn_ub92.disabled = !can_generate;
137 f.bn_x12.disabled = !can_generate;
138 <?php if ($GLOBALS['support_encounter_claims']) { ?>
139 f.bn_x12_encounter.disabled = !can_generate;
140 <?php } ?>
141 f.bn_process_hcfa.disabled = !can_generate;
142 f.bn_hcfa_txt_file.disabled = !can_generate;
143 // f.bn_electronic_file.disabled = !can_bill;
144 f.bn_reopen.disabled = !can_bill;
145 <?php } ?>
146 f.bn_mark.disabled = !can_mark;
149 // Process a click to go to an encounter.
150 function toencounter(pid, pubpid, pname, enc, datestr, dobstr) {
151 top.restoreSession();
152 encurl = 'patient_file/encounter/encounter_top.php?set_encounter=' + enc + '&pid=' + pid;
153 parent.left_nav.setPatient(pname,pid,pubpid,'',dobstr);
154 <?php if ($GLOBALS['new_tabs_layout']) { ?>
155 parent.left_nav.setEncounter(datestr, enc, 'enc');
156 parent.left_nav.loadFrame('enc2', 'enc', encurl);
157 <?php } else { ?>
158 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
159 parent.left_nav.setEncounter(datestr, enc, othername);
160 parent.frames[othername].location.href = '../' + encurl;
161 <?php } ?>
163 // Process a click to go to an patient.
164 function topatient(pid, pubpid, pname, enc, datestr, dobstr) {
165 top.restoreSession();
166 paturl = 'patient_file/summary/demographics_full.php?pid=' + pid;
167 parent.left_nav.setPatient(pname,pid,pubpid,'',dobstr);
168 <?php if ($GLOBALS['new_tabs_layout']) { ?>
169 parent.left_nav.loadFrame('ens1', 'enc', 'patient_file/history/encounters.php?pid=' + pid);
170 parent.left_nav.loadFrame('dem1', 'pat', paturl);
171 <?php } else { ?>
172 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
173 parent.frames[othername].location.href = '../' + paturl;
174 <?php } ?>
176 </script>
177 <script language="javascript" type="text/javascript">
178 EncounterDateArray=new Array;
179 CalendarCategoryArray=new Array;
180 EncounterIdArray=new Array;
181 EncounterNoteArray=new Array;
182 function SubmitTheScreen()
183 {//Action on Update List link
184 if(!ProcessBeforeSubmitting())
185 return false;
186 top.restoreSession();
187 document.the_form.mode.value='change';
188 document.the_form.target='_self';
189 document.the_form.action='billing_report.php';
190 document.the_form.submit();
191 return true;
193 function SubmitTheScreenPrint()
194 {//Action on View Printable Report link
195 if(!ProcessBeforeSubmitting())
196 return false;
197 top.restoreSession();
198 document.the_form.target='new';
199 document.the_form.action='print_billing_report.php';
200 document.the_form.submit();
201 return true;
203 function SubmitTheEndDayPrint()
204 {//Action on View End of Day Report link
205 if(!ProcessBeforeSubmitting())
206 return false;
207 top.restoreSession();
208 document.the_form.target='new';
209 <?php if ($GLOBALS['use_custom_daysheet'] == 1) { ?>
210 document.the_form.action='print_daysheet_report_num1.php';
211 <?php } ?>
212 <?php if ($GLOBALS['use_custom_daysheet'] == 2) { ?>
213 document.the_form.action='print_daysheet_report_num2.php';
214 <?php } ?>
215 <?php if ($GLOBALS['use_custom_daysheet'] == 3) { ?>
216 document.the_form.action='print_daysheet_report_num3.php';
217 <?php } ?>
218 document.the_form.submit();
219 return true;
221 function SubmitTheScreenExportOFX()
222 {//Action on Export OFX link
223 if(!ProcessBeforeSubmitting())
224 return false;
225 top.restoreSession();
226 document.the_form.mode.value='export';
227 document.the_form.target='_self';
228 document.the_form.action='billing_report.php';
229 document.the_form.submit();
230 return true;
232 function TestExpandCollapse()
233 {//Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
234 var set=-1;
235 for(i=1;i<=document.getElementById("divnos").value;i++)
237 var ele = document.getElementById("divid_"+i);
238 if(ele)
240 set=1;
241 break;
244 if(set==-1)
246 if(document.getElementById("ExpandAll"))
248 document.getElementById("ExpandAll").innerHTML='';
249 document.getElementById("CollapseAll").innerHTML='';
253 function expandcollapse(atr){
254 if(atr == "expand") {//Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
255 for(i=1;i<=document.getElementById("divnos").value;i++){
256 var mydivid="divid_"+i;var myspanid="spanid_"+i;
257 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
258 if(ele)
260 ele.style.display = "inline";text.innerHTML = "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
264 else {
265 for(i=1;i<=document.getElementById("divnos").value;i++){
266 var mydivid="divid_"+i;var myspanid="spanid_"+i;
267 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
268 if(ele)
270 ele.style.display = "none"; text.innerHTML = "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
276 function divtoggle(spanid, divid) {//Called in the Expand, Collapse links(This is for a single item)
277 var ele = document.getElementById(divid);
278 if(ele)
280 var text = document.getElementById(spanid);
281 if(ele.style.display == "inline") {
282 ele.style.display = "none";
283 text.innerHTML = "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
285 else {
286 ele.style.display = "inline";
287 text.innerHTML = "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
291 function MarkAsCleared(Type)
293 CheckBoxBillingCount=0;
294 for (var CheckBoxBillingIndex =0; ; CheckBoxBillingIndex++)
296 CheckBoxBillingObject=document.getElementById('CheckBoxBilling'+CheckBoxBillingIndex);
297 if(!CheckBoxBillingObject)
298 break;
299 if(CheckBoxBillingObject.checked)
301 ++CheckBoxBillingCount;
304 if(Type==1)
306 Message='<?php echo htmlspecialchars( xl('After saving your batch, click [View Log] to check for errors.'), ENT_QUOTES); ?>';
308 if(Type==2)
310 Message='<?php echo htmlspecialchars( xl('After saving the PDF, click [View Log] to check for errors.'), ENT_QUOTES); ?>';
312 if(Type==3)
314 Message='<?php echo htmlspecialchars( xl('After saving the TEXT file(s), click [View Log] to check for errors.'), ENT_QUOTES); ?>';
316 if(confirm(Message + "\n\n\n<?php echo addslashes( xl('Total') ); ?>" + ' ' + CheckBoxBillingCount + ' ' + "<?php echo addslashes( xl('Selected') ); ?>\n" +
317 "<?php echo addslashes( xl('Would You Like them to be Marked as Cleared.') ); ?>"))
319 document.getElementById('HiddenMarkAsCleared').value='yes';
321 else
323 document.getElementById('HiddenMarkAsCleared').value='';
326 </script>
327 <?php include_once("$srcdir/../interface/reports/report.script.php"); ?><!-- Criteria Section common javascript page-->
328 <!-- ================================================== -->
329 <!-- =============Included for Insurance ajax criteria==== -->
330 <!-- ================================================== -->
331 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
332 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
333 <script type="text/javascript" src="../../library/js/common.js"></script>
334 <style>
335 #ajax_div_insurance {
336 position: absolute;
337 z-index:10;
338 background-color: #FBFDD0;
339 border: 1px solid #ccc;
340 padding: 10px;
342 </style>
343 <script language="javascript" type="text/javascript">
344 document.onclick=TakeActionOnHide;
345 </script>
346 <!-- ================================================== -->
347 <!-- =============Included for Insurance ajax criteria==== -->
348 <!-- ================================================== -->
349 </head>
350 <body class="body_top" onLoad="TestExpandCollapse()">
352 <p style='margin-top:5px;margin-bottom:5px;margin-left:5px'>
354 <font class='title'><?php echo xlt('Billing Manager') ?></font>
356 </p>
358 <form name='the_form' method='post' action='billing_report.php' onsubmit='return top.restoreSession()' style="display:inline">
360 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
361 <script type="text/javascript" src="../../library/dialog.js"></script>
362 <script type="text/javascript" src="../../library/textformat.js"></script>
363 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
364 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
365 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
366 <script language='JavaScript'>
367 var mypcc = '1';
368 </script>
370 <input type='hidden' name='mode' value='change'>
371 <!-- ============================================================================================================================================= -->
372 <!-- Criteria section Starts -->
373 <!-- ============================================================================================================================================= -->
374 <?php
375 //The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
376 //Each item is seperated by a comma(,).
377 //$ThisPageSearchCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
378 //$ThisPageSearchCriteriaKeyMaster ==>Corresponding database fields in the same order.
379 //$ThisPageSearchCriteriaDataTypeMaster ==>Corresponding data type in the same order.
380 $ThisPageSearchCriteriaDisplayRadioMaster=array();
381 $ThisPageSearchCriteriaRadioKeyMaster=array();
382 $ThisPageSearchCriteriaQueryDropDownMaster=array();
383 $ThisPageSearchCriteriaQueryDropDownMasterDefault=array();
384 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey=array();
385 $ThisPageSearchCriteriaIncludeMaster=array();
387 if ($daysheet) {
388 $ThisPageSearchCriteriaDisplayMaster= 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") );
389 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
390 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
391 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id,billing.user";
392 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
393 "text,include,text,radio,radio,radio,".
394 "radio_like,radio,query_drop_down,text";
396 else
399 $ThisPageSearchCriteriaDisplayMaster= 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") );
400 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
401 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
402 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id";
403 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
404 "text,include,text,radio,radio,radio,".
405 "radio_like,radio,query_drop_down";
410 //The below section is needed if there is any 'radio' or 'radio_like' type in the $ThisPageSearchCriteriaDataTypeMaster
411 //$ThisPageSearchCriteriaDisplayRadioMaster,$ThisPageSearchCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
412 //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.
413 $ThisPageSearchCriteriaDisplayRadioMaster[1] = array( xl("All"),xl("eClaims"),xl("Paper") );//Display Value
414 $ThisPageSearchCriteriaRadioKeyMaster[1]="all,standard,hcfa";//Key
415 $ThisPageSearchCriteriaDisplayRadioMaster[2]= array( xl("All"),xl("Insured"),xl("Non-Insured") );//Display Value
416 $ThisPageSearchCriteriaRadioKeyMaster[2]="all,1,0";//Key
417 $ThisPageSearchCriteriaDisplayRadioMaster[3]= array( xl("All"),xl("Coded"),xl("Not Coded") );//Display Value
418 $ThisPageSearchCriteriaRadioKeyMaster[3]="all,not null,null";//Key
419 $ThisPageSearchCriteriaDisplayRadioMaster[4]= array( xl("All"),xl("Unbilled"),xl("Billed"),xl("Denied") );//Display Value
420 $ThisPageSearchCriteriaRadioKeyMaster[4]="all,0,1,7";//Key
421 $ThisPageSearchCriteriaDisplayRadioMaster[5]= array( xl("All"),xl("Authorized"),xl("Unauthorized") );
422 $ThisPageSearchCriteriaRadioKeyMaster[5]="%,1,0";
423 $ThisPageSearchCriteriaDisplayRadioMaster[6]= array( xl("All"),xl("None"),xl("Ins 1"),xl("Ins 2 or Ins 3") );
424 $ThisPageSearchCriteriaRadioKeyMaster[6]="all,0,1,2";
425 //The below section is needed if there is any 'query_drop_down' type in the $ThisPageSearchCriteriaDataTypeMaster
426 $ThisPageSearchCriteriaQueryDropDownMaster[1]="SELECT name,id FROM x12_partners;";
427 $ThisPageSearchCriteriaQueryDropDownMasterDefault[1]= xl("All");//Only one item will be here
428 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey[1]="all";//Only one item will be here
429 //The below section is needed if there is any 'include' type in the $ThisPageSearchCriteriaDataTypeMaster
430 //Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
431 //It is labled(Included for Insurance ajax criteria)(Line:-279-299).
432 $ThisPageSearchCriteriaIncludeMaster[1]="InsuranceCompanyDisplay";//This is php function defined in the file 'report.inc.php'
434 if(!isset($_REQUEST['mode']))//default case
436 $_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")."')";
437 $_REQUEST['final_this_page_criteria'][1]="billing.billed = '0'";
439 $_REQUEST['final_this_page_criteria_text'][0]=xl("Date of Service = Today");
440 $_REQUEST['final_this_page_criteria_text'][1]=xl("Billing Status = Unbilled");
442 $_REQUEST['date_master_criteria_form_encounter_date']="today";
443 $_REQUEST['master_from_date_form_encounter_date']=date("Y-m-d");
444 $_REQUEST['master_to_date_form_encounter_date']=date("Y-m-d");
446 $_REQUEST['radio_billing_billed']=0;
450 <table width='100%' border="0" cellspacing="0" cellpadding="0">
451 <tr>
452 <td width="25%">&nbsp;</td>
453 <td width="50%">
454 <?php include_once("$srcdir/../interface/reports/criteria.tab.php"); ?>
455 </td>
456 <td width="25%">
457 <?php
458 // ============================================================================================================================================= -->
459 // Criteria section Ends -->
460 // ============================================================================================================================================= -->
463 <table width="100%" border="0" cellspacing="0" cellpadding="0">
464 <tr>
465 <td width="15%">&nbsp;</td>
466 <td width="85%"><span class='text'><a onClick="javascript:return SubmitTheScreen();" href="#" class=link_submit>[<?php echo xlt('Update List') ?>]</a>
468 <a onClick="javascript:return SubmitTheScreenExportOFX();" href="#" class='link_submit'><?php echo '[' . xlt('Export OFX') .']' ?></a></span> </td>
469 </tr>
470 <tr>
471 <td>&nbsp;</td>
472 <td><a onClick="javascript:return SubmitTheScreenPrint();" href="#"
473 class='link_submit' ><?php echo '['. xlt('View Printable Report').']' ?></a></td>
474 </tr>
476 <?php if ($daysheet) { ?>
477 <tr>
478 <td>&nbsp;</td>
479 <td><a onClick="javascript:return SubmitTheEndDayPrint();" href="#"
480 class='link_submit' ><?php echo '['.xlt('End Of Day Report').']' ?></a>
481 <?php if ($daysheet_total) { ?>
482 <span class=text><?php echo xlt('Totals'); ?> </span>
483 <input type=checkbox name="end_of_day_totals_only" value="1" <?php if ($obj['end_of_day_totals_only'] === '1') echo "checked";?>>
484 <?php } ?>
485 <?php if ($provider_run) { ?>
486 <span class=text><?php echo xlt('Provider'); ?> </span>
487 <input type=checkbox name="end_of_day_provider_only" value="1" <?php if ($obj['end_of_day_provider_only'] === '1') echo "checked";?>>
488 <?php } ?>
489 </td>
490 </tr>
491 <?php } ?>
492 <tr>
493 <td>&nbsp;</td>
494 <td>
495 <?php if (! file_exists($EXPORT_INC)) { ?>
496 <!--
497 <a href="javascript:top.restoreSession();document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
498 title="Process all queued bills to create electronic data (and print if requested)"><?php echo '['. xlt('Start Batch Processing') .']' ?></a>
499 &nbsp;
501 <a href='#' id="view-log-link" class='link_submit'
502 title='<?php xla('See messages from the last set of generated claims'); ?>'><?php echo '['. xlt('View Log') .']'?></a>
503 <?php } ?>
504 </td>
505 </tr>
506 <tr>
507 <td>&nbsp;</td>
508 <td><a href="javascript:select_all()" class="link_submit"><?php echo '['. xlt('Select All') .']'?></a></td>
509 </tr>
510 </table>
513 </td>
514 </tr>
515 </table>
516 <table width='100%' border="0" cellspacing="0" cellpadding="0" >
517 <tr>
518 <td>
519 <hr color="#000000">
520 </td>
521 </tr>
522 </table>
523 </form>
524 <form name='update_form' method='post' action='billing_process.php' onsubmit='return top.restoreSession()' style="display:inline">
525 <center>
526 <span class='text' style="display:inline">
527 <?php if (file_exists($EXPORT_INC)) { ?>
528 <input type="submit" data-open-popup="true" class="subbtn" name="bn_external" value="Export Billing" title="<?php echo xla('Export to external billing system') ?>">
529 <input type="submit" data-open-popup="true" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php echo xla('Mark as billed but skip billing') ?>">
530 <?php } else { ?>
531 <!--
532 <input type="submit" class="subbtn" name="bn_hcfa_print" value="Queue HCFA &amp; Print" title="<?php echo xla('Queue for HCFA batch processing and printing') ?>">
533 <input type="submit" class="subbtn" name="bn_hcfa" value="Queue HCFA" title="<?php echo xla('Queue for HCFA batch processing')?>">
534 <input type="submit" class="subbtn" name="bn_ub92_print" value="Queue UB92 &amp; Print" title="<?php echo xla('Queue for UB-92 batch processing and printing')?>">
535 <input type="submit" class="subbtn" name="bn_ub92" value="Queue UB92" title="<?php echo xla('Queue for UB-92 batch processing')?>">
537 <input type="submit" class="subbtn" name="bn_x12" value="<?php echo xla('Generate X12')?>"
538 title="<?php echo xla('Generate and download X12 batch')?>"
539 onclick="MarkAsCleared(1)">
540 <?php if ($GLOBALS['support_encounter_claims']) { ?>
541 <input type="submit" class="subbtn" name="bn_x12_encounter" value="<?php echo xla('Generate X12 Encounter')?>"
542 title="<?php echo xla('Generate and download X12 encounter claim batch')?>"
543 onclick="MarkAsCleared(1)">
544 <?php } ?>
545 <input type="submit" class="subbtn" style="width:175px;" name="bn_process_hcfa" value="<?php echo xla('Generate CMS 1500 PDF')?>"
546 title="<?php echo xla('Generate and download CMS 1500 paper claims')?>"
547 onclick="MarkAsCleared(2)">
548 <input type="submit" class="subbtn" style="width:175px;" name="bn_hcfa_txt_file" value="<?php echo xla('Generate CMS 1500 TEXT')?>"
549 title="<?php echo xla('Making batch text files for uploading to Clearing House and will mark as billed')?>"
550 onclick="MarkAsCleared(3)">
551 <input type="submit" data-open-popup="true" class="subbtn" name="bn_mark" value="<?php echo xla('Mark as Cleared')?>" title="<?php echo xla('Post to accounting and mark as billed')?>">
552 <input type="submit" data-open-popup="true" class="subbtn" name="bn_reopen" value="<?php echo xla('Re-Open')?>" title="<?php echo xla('Mark as not billed')?>">
553 <!--
554 <input type="submit" class="subbtn" name="bn_electronic_file" value="Make Electronic Batch &amp; Clear" title="<?php echo xla('Download billing file, post to accounting and mark as billed')?>">
556 &nbsp;&nbsp;&nbsp;
557 <?php echo xlt('CMS 1500 Margins'); ?>:
558 &nbsp;<?php echo xlt('Left'); ?>:
559 <input type='text' size='2' name='left_margin'
560 value='<?php echo attr($left_margin); ?>'
561 title='<?php echo xla('HCFA left margin in points'); ?>' />
562 &nbsp;<?php echo xlt('Top'); ?>:
563 <input type='text' size='2' name='top_margin'
564 value='<?php echo attr($top_margin); ?>'
565 title='<?php echo xla('HCFA top margin in points'); ?>' />
566 </span>
567 <?php } ?>
569 </center>
570 <input type='hidden' name='HiddenMarkAsCleared' id='HiddenMarkAsCleared' value="" />
571 <input type='hidden' name='mode' value="bill" />
572 <input type='hidden' name='authorized' value="<?php echo attr($my_authorized); ?>" />
573 <input type='hidden' name='unbilled' value="<?php echo attr($unbilled); ?>" />
574 <input type='hidden' name='code_type' value="%" />
575 <input type='hidden' name='to_date' value="<?php echo attr($to_date); ?>" />
576 <input type='hidden' name='from_date' value="<?php echo attr($from_date); ?>" />
578 <?php
579 if ($my_authorized == "on" ) {
580 $my_authorized = "1";
581 } else {
582 $my_authorized = "%";
584 if ($unbilled == "on") {
585 $unbilled = "0";
586 } else {
587 $unbilled = "%";
589 $list = getBillsListBetween("%");
592 <input type='hidden' name='bill_list' value="<?php echo attr($list); ?>" />
594 <!-- new form for uploading -->
596 <?php
597 if (!isset($_POST["mode"])) {
598 if (!isset($_POST["from_date"])) {
599 $from_date = date("Y-m-d");
600 } else {
601 $from_date = $_POST["from_date"];
603 if (empty($_POST["to_date"])) {
604 $to_date = '';
605 } else {
606 $to_date = $_POST["to_date"];
608 if (!isset($_POST["code_type"])) {
609 $code_type="all";
610 } else {
611 $code_type = $_POST["code_type"];
613 if (!isset($_POST["unbilled"])) {
614 $unbilled = "on";
615 } else {
616 $unbilled = $_POST["unbilled"];
618 if (!isset($_POST["authorized"])) {
619 $my_authorized = "on";
620 } else {
621 $my_authorized = $_POST["authorized"];
623 } else {
624 $from_date = $_POST["from_date"];
625 $to_date = $_POST["to_date"];
626 $code_type = $_POST["code_type"];
627 $unbilled = $_POST["unbilled"];
628 $my_authorized = $_POST["authorized"];
631 if ($my_authorized == "on" ) {
632 $my_authorized = "1";
633 } else {
634 $my_authorized = "%";
637 if ($unbilled == "on") {
638 $unbilled = "0";
639 } else {
640 $unbilled = "%";
643 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
644 billCodesList($list);
648 <table border="0" cellspacing="0" cellpadding="0" width="100%">
650 <?php
651 $divnos=0;
652 if ($ret = getBillsBetween("%"))
654 if(is_array($ret))
657 <tr ><td colspan='9' align="right" ><table width="250" border="0" cellspacing="0" cellpadding="0">
658 <tr>
659 <td width="100" id='ExpandAll'><a onclick="expandcollapse('expand');" class='small' href="JavaScript:void(0);"><?php echo '('.htmlspecialchars( xl('Expand All'), ENT_QUOTES).')' ?></a></td>
660 <td width="100" id='CollapseAll'><a onclick="expandcollapse('collapse');" class='small' href="JavaScript:void(0);"><?php echo '('.htmlspecialchars( xl('Collapse All'), ENT_QUOTES).')' ?></a></td>
661 <td width="50">&nbsp;</td>
662 </tr>
663 </table>
664 </td></tr>
665 <?php
667 $loop = 0;
668 $oldcode = "";
669 $last_encounter_id = "";
670 $lhtml = "";
671 $rhtml = "";
672 $lcount = 0;
673 $rcount = 0;
674 $bgcolor = "";
675 $skipping = FALSE;
677 $mmo_empty_mod = false;
678 $mmo_num_charges = 0;
680 foreach ($ret as $iter) {
682 // We include encounters here that have never been billed. However
683 // if it had no selected billing items but does have non-selected
684 // billing items, then it is not of interest.
685 if (!$iter['id']) {
686 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
687 "encounter = ? AND " .
688 "pid=? AND " .
689 "activity = 1", array($iter['enc_encounter'],$iter['enc_pid']) );
690 if ($res['count'] > 0) continue;
693 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
695 if ($last_encounter_id != $this_encounter_id) {
697 // This dumps all HTML for the previous encounter.
699 if ($lhtml) {
700 while ($rcount < $lcount) {
701 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='8'></td></tr>";
702 ++$rcount;
704 // This test handles the case where we are only listing encounters
705 // that appear to have a missing "25" modifier.
706 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
707 if($DivPut=='yes')
709 $lhtml.='</div>';
710 $DivPut='no';
712 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
713 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n\n";
714 ++$encount;
718 $lhtml = "";
719 $rhtml = "";
720 $mmo_empty_mod = false;
721 $mmo_num_charges = 0;
723 // If there are ANY unauthorized items in this encounter and this is
724 // the normal case of viewing only authorized billing, then skip the
725 // entire encounter.
727 $skipping = FALSE;
728 if ($my_authorized == '1') {
729 $res = sqlQuery("select count(*) as count from billing where " .
730 "encounter = ? and " .
731 "pid=? and " .
732 "activity = 1 and authorized = 0", array($iter['enc_encounter'],$iter['enc_pid']) );
733 if ($res['count'] > 0) {
734 $skipping = TRUE;
735 $last_encounter_id = $this_encounter_id;
736 continue;
740 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, billing_note, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
742 # Check if patient has primary insurance and a subscriber exists for it.
743 # If not we will highlight their name in red.
744 # TBD: more checking here.
746 $res = sqlQuery("select count(*) as count from insurance_data where " .
747 "pid = ? and " .
748 "type='primary' and " .
749 "subscriber_lname is not null and " .
750 "subscriber_lname != '' limit 1", array($iter['enc_pid']) );
751 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
753 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
754 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
755 $lcount = 1;
756 $rcount = 0;
757 $oldcode = "";
759 $ptname = $name['fname'] . " " . $name['lname'];
760 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
761 $billing_note = $name['billing_note'];
762 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
763 $lhtml .= "&nbsp;<span class=bold><font color='$namecolor'>". text($ptname) .
764 "</font></span><span class=small>&nbsp;(" . text($iter['enc_pid']) . "-" .
765 text($iter['enc_encounter']) . ")</span>";
767 //Encounter details are stored to javacript as array.
768 $result4 = sqlStatement("SELECT fe.encounter,fe.date,fe.billing_note,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
769 " left join openemr_postcalendar_categories on fe.pc_catid=openemr_postcalendar_categories.pc_catid WHERE fe.pid = ? order by fe.date desc", array($iter['enc_pid']) );
770 if(sqlNumRows($result4)>0)
772 <script language='JavaScript'>
773 Count=0;
774 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
775 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
776 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
777 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
778 <?php
779 while($rowresult4 = sqlFetchArray($result4))
782 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars($rowresult4['encounter'], ENT_QUOTES); ?>';
783 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date']))), ENT_QUOTES); ?>';
784 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars( xl_appt_category($rowresult4['pc_catname']), ENT_QUOTES); ?>';
785 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars($rowresult4['billing_note'], ENT_QUOTES); ?>';
786 Count++;
787 <?php
788 $enc_billing_note = $rowresult4['billing_note'];
791 </script>
792 <?php
794 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
795 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
796 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
797 ",'" . addslashes($name['pubpid']) .
798 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
799 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
800 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
801 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
802 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" .
803 xlt('To Enctr') . " " . text(oeFormatShortDate($raw_encounter_date)) . "]</a>";
805 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
806 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
807 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
808 ",'" . addslashes($name['pubpid']) .
809 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
810 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
811 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
812 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
813 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" . xlt('To Dems') . "]</a>";
814 $divnos=$divnos+1;
815 $lhtml .= "&nbsp;&nbsp;&nbsp;<a onclick='divtoggle(\"spanid_$divnos\",\"divid_$divnos\");' class='small' id='aid_$divnos' href=\"JavaScript:void(0);".
816 "\">(<span id=spanid_$divnos class=\"indicator\">" . htmlspecialchars( xl('Expand'), ENT_QUOTES) . '</span>)<br></a>';
817 if($GLOBALS['notes_to_display_in_Billing'] == 2 || $GLOBALS['notes_to_display_in_Billing'] == 3){
818 $lhtml .= '<span style="margin-left: 20px; font-weight bold; color: red">'.text($billing_note).'</span>';
821 if ($iter['id']) {
823 $lcount += 2;
824 $lhtml .= "<br />\n";
825 $lhtml .= "&nbsp;<span class=text>Bill: ";
826 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' style='background-color:$bgcolor'>";
828 $query = "SELECT id.provider AS id, id.type, id.date, " .
829 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
830 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
831 "ic.id = id.provider AND " .
832 "id.pid = ? AND " .
833 "id.date <= ? " .
834 "ORDER BY id.type ASC, id.date DESC";
836 $result = sqlStatement($query, array($iter['enc_pid'],$raw_encounter_date) );
837 $count = 0;
838 $default_x12_partner = $iter['ic_x12id'];
839 $prevtype = '';
841 while ($row = sqlFetchArray($result)) {
842 if (strcmp($row['type'], $prevtype) == 0) continue;
843 $prevtype = $row['type'];
844 if (strlen($row['provider']) > 0) {
845 // This preserves any existing insurance company selection, which is
846 // important when EOB posting has re-queued for secondary billing.
847 $lhtml .= "<option value=\"" . attr(substr($row['type'],0,1).$row['id']) . "\"";
848 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
849 $lhtml .= " selected";
850 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
852 $lhtml .= ">" . text($row['type']) . ": " . text($row['provider']) . "</option>";
854 $count++;
857 $lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
858 $lhtml .= "</select>&nbsp;&nbsp;\n";
859 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][partner]' style='background-color:$bgcolor'>";
860 $x = new X12Partner();
861 $partners = $x->_utility_array($x->x12_partner_factory());
862 foreach ($partners as $xid => $xname) {
863 $lhtml .= '<option label="' . attr($xname) . '" value="' . attr($xid) .'"';
864 if ($xid == $default_x12_partner) {
865 $lhtml .= "selected";
867 $lhtml .= '>' . text($xname) . '</option>';
869 $lhtml .= "</select>";
870 $DivPut='yes';
872 if($GLOBALS['notes_to_display_in_Billing'] == 1 || $GLOBALS['notes_to_display_in_Billing'] == 3) {
873 $lhtml .= "<br><span style='margin-left: 20px; font-weight bold; color: red'>".text($enc_billing_note)."</span>";
875 $lhtml .= "<br>\n&nbsp;<div id='divid_$divnos' style='display:none'>" . text(oeFormatShortDate(substr($iter['date'], 0, 10)))
876 . text(substr($iter['date'], 10, 6)) . " " . xlt("Encounter was coded");
878 $query = "SELECT * FROM claims WHERE " .
879 "patient_id = ? AND " .
880 "encounter_id = ? " .
881 "ORDER BY version";
882 $cres = sqlStatement($query, array($iter['enc_pid'],$iter['enc_encounter']) );
884 $lastcrow = false;
886 while ($crow = sqlFetchArray($cres)) {
887 $query = "SELECT id.type, ic.name " .
888 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
889 "id.pid = ? AND " .
890 "id.provider = ? AND " .
891 "id.date <= ? AND " .
892 "ic.id = id.provider " .
893 "ORDER BY id.type ASC, id.date DESC";
895 $irow= sqlQuery($query, array($iter['enc_pid'],$crow['payer_id'],$raw_encounter_date) );
897 if ($crow['bill_process']) {
898 $lhtml .= "<br>\n&nbsp;" .
899 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
900 text(substr($crow['bill_time'], 10, 6)) . " " .
901 xlt("Queued for") . " " . text($irow['type']) . " " . text($crow['target']) . " " .
902 xlt("billing to ") . text($irow['name']);
903 ++$lcount;
905 else if ($crow['status'] < 6) {
906 if ($crow['status'] > 1) {
907 $lhtml .= "<br>\n&nbsp;" .
908 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
909 text(substr($crow['bill_time'], 10, 6)) . " " .
910 htmlspecialchars( xl("Marked as cleared"), ENT_QUOTES);
911 ++$lcount;
913 else {
914 $lhtml .= "<br>\n&nbsp;" .
915 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
916 text(substr($crow['bill_time'], 10, 6)) . " " .
917 htmlspecialchars( xl("Re-opened"), ENT_QUOTES);
918 ++$lcount;
921 else if ($crow['status'] == 6) {
922 $lhtml .= "<br>\n&nbsp;" .
923 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
924 text(substr($crow['bill_time'], 10, 6)) . " " .
925 htmlspecialchars( xl("This claim has been forwarded to next level."), ENT_QUOTES);
926 ++$lcount;
928 else if ($crow['status'] == 7) {
929 $lhtml .= "<br>\n&nbsp;" .
930 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
931 text(substr($crow['bill_time'], 10, 6)) . " " .
932 htmlspecialchars( xl("This claim has been denied.Reason:-"), ENT_QUOTES);
933 if($crow['process_file'])
935 $code_array=explode(',',$crow['process_file']);
936 foreach($code_array as $code_key => $code_value)
938 $lhtml .= "<br>\n&nbsp;&nbsp;&nbsp;";
939 $reason_array=explode('_',$code_value);
940 if(!isset($adjustment_reasons[$reason_array[3]]))
942 $lhtml .=htmlspecialchars( xl("For code"), ENT_QUOTES).' ['.text($reason_array[0]).'] '.htmlspecialchars( xl("and modifier"), ENT_QUOTES).' ['.text($reason_array[1]).'] '.htmlspecialchars( xl("the Denial code is"), ENT_QUOTES).' ['.text($reason_array[2]).' '.text($reason_array[3]).']';
944 else
946 $lhtml .=htmlspecialchars( xl("For code"), ENT_QUOTES).' ['.text($reason_array[0]).'] '.htmlspecialchars( xl("and modifier"), ENT_QUOTES).' ['.text($reason_array[1]).'] '.htmlspecialchars( xl("the Denial Group code is"), ENT_QUOTES).' ['.text($reason_array[2]).'] '.htmlspecialchars( xl("and the Reason is"), ENT_QUOTES).':- '.text($adjustment_reasons[$reason_array[3]]);
950 else
952 $lhtml .=htmlspecialchars( xl("Not Specified."), ENT_QUOTES);
954 ++$lcount;
957 if ($crow['process_time']) {
958 $lhtml .= "<br>\n&nbsp;" .
959 text(oeFormatShortDate(substr($crow['process_time'], 0, 10))) .
960 text(substr($crow['process_time'], 10, 6)) . " " .
961 xlt("Claim was generated to file") . " " .
962 "<a href='get_claim_file.php?key=" . attr($crow['process_file']) .
963 "' onclick='top.restoreSession()'>" .
964 text($crow['process_file']) . "</a>";
965 ++$lcount;
968 $lastcrow = $crow;
969 } // end while ($crow = sqlFetchArray($cres))
971 if ($lastcrow && $lastcrow['status'] == 4) {
972 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been closed.");
973 ++$lcount;
976 if ($lastcrow && $lastcrow['status'] == 5) {
977 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been canceled.");
978 ++$lcount;
980 } // end if ($iter['id'])
982 } // end if ($last_encounter_id != $this_encounter_id)
984 if ($skipping) continue;
986 // Collect info related to the missing modifiers test.
987 if ($iter['fee'] > 0) {
988 ++$mmo_num_charges;
989 $tmp = substr($iter['code'], 0, 3);
990 if (($tmp == '992' || $tmp == '993') && empty($iter['modifier']))
991 $mmo_empty_mod = true;
994 ++$rcount;
996 if ($rhtml) {
997 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
999 $rhtml .= "<td width='50'>";
1000 if ($iter['id'] && $oldcode != $iter['code_type']) {
1001 $rhtml .= "<span class=text>" . text($iter['code_type']) . ": </span>";
1004 $oldcode = $iter['code_type'];
1005 $rhtml .= "</td>\n";
1006 $justify = "";
1008 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
1009 $js = explode(":",$iter['justify']);
1010 $counter = 0;
1011 foreach ($js as $j) {
1012 if(!empty($j)) {
1013 if ($counter == 0) {
1014 $justify .= " (<b>" . text($j) . "</b>)";
1016 else {
1017 $justify .= " (" . text($j) . ")";
1019 $counter++;
1024 $rhtml .= "<td><span class='text'>" .
1025 ($iter['code_type'] == 'COPAY' ? text(oeFormatMoney($iter['code'])) : text($iter['code']));
1026 if ($iter['modifier']) $rhtml .= ":" . text($iter['modifier']);
1027 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
1029 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1030 if ($iter['id'] && $iter['fee'] > 0) {
1031 $rhtml .= text(oeFormatMoney($iter['fee']));
1033 $rhtml .= "</span></td>\n";
1034 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1035 if ($iter['id']) $rhtml .= getProviderName(empty($iter['provider_id']) ? text($iter['enc_provider_id']) : text($iter['provider_id']));
1036 $rhtml .= "</span></td>\n";
1037 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1038 if($GLOBALS['display_units_in_billing'] != 0) {
1039 if ($iter['id']) $rhtml .= xlt("Units") . ":" . text($iter{"units"});
1041 $rhtml .= "</span></td>\n";
1042 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1043 if ($iter['id']) $rhtml .= text(oeFormatSDFT(strtotime($iter{"date"})));
1044 $rhtml .= "</span></td>\n";
1045 # This error message is generated if the authorized check box is not checked
1046 if ($iter['id'] && $iter['authorized'] != 1) {
1047 $rhtml .= "<td><span class=alert>".xlt("Note: This code has not been authorized.")."</span></td>\n";
1049 else {
1050 $rhtml .= "<td></td>\n";
1052 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
1053 $tmpbpr = $iter['bill_process'];
1054 if ($tmpbpr == '0' && $iter['billed']) $tmpbpr = '2';
1055 $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";
1056 $CheckBoxBilling++;
1058 else {
1059 $rhtml .= "<td></td>\n";
1061 if($last_encounter_id != $this_encounter_id){
1062 $rhtml2 = "";
1063 $rowcnt = 0;
1064 $resMoneyGot = sqlStatement("SELECT pay_amount as PatientPay,date(post_time) as date FROM ar_activity where ".
1065 "pid = ? and encounter = ? and payer_type=0 and account_code='PCP'",
1066 array($iter['enc_pid'],$iter['enc_encounter']));
1067 //new fees screen copay gives account_code='PCP'
1068 if(sqlNumRows($resMoneyGot) > 0){
1069 $lcount += 2;
1070 $rcount++;
1072 //checks whether a copay exists for the encounter and if exists displays it.
1073 while($rowMoneyGot = sqlFetchArray($resMoneyGot)){
1074 $rowcnt++;
1075 $PatientPay=$rowMoneyGot['PatientPay'];
1076 $date=$rowMoneyGot['date'];
1077 if($PatientPay > 0){
1078 if($rhtml){
1079 $rhtml2 .= "<tr bgcolor='$bgcolor'>\n";
1081 $rhtml2 .= "<td width='50'>";
1082 $rhtml2 .= "<span class='text'>".xlt('COPAY').": </span>";
1083 $rhtml2 .= "</td>\n";
1084 $rhtml2 .= "<td><span class='text'>".text(oeFormatMoney($PatientPay))."</span><span style='font-size:8pt;'>&nbsp;</span></td>\n";
1085 $rhtml2 .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1086 $rhtml2 .= "</span></td>\n";
1087 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1088 $rhtml2 .= "</span></td>\n";
1089 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1090 $rhtml2 .= "</span></td>\n";
1091 $rhtml2 .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1092 $rhtml2 .= text(oeFormatSDFT(strtotime($date)));
1093 $rhtml2 .= "</span></td>\n";
1094 if ($iter['id'] && $iter['authorized'] != 1) {
1095 $rhtml2 .= "<td><span class=alert>".xlt("Note: This copay was entered against billing that has not been authorized. Please review status.")."</span></td>\n";
1096 }else{
1097 $rhtml2 .= "<td></td>\n";
1099 if(!$iter['id'] && $rowcnt == 1){
1100 $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";
1101 $CheckBoxBilling++;
1102 }else{
1103 $rhtml2 .= "<td></td>\n";
1107 $rhtml .= $rhtml2;
1109 $rhtml .= "</tr>\n";
1110 $last_encounter_id = $this_encounter_id;
1112 } // end foreach
1114 if ($lhtml) {
1115 while ($rcount < $lcount) {
1116 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='8'></td></tr>";
1117 ++$rcount;
1119 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
1120 if($DivPut=='yes')
1122 $lhtml.='</div>';
1123 $DivPut='no';
1125 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
1126 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
1134 </table>
1135 </form>
1137 <script>
1138 set_button_states();
1139 <?php
1140 if ($alertmsg) {
1141 echo "alert('".addslashes($alertmsg)."');\n";
1144 $(document).ready(function() {
1145 $("#view-log-link").click( function() {
1146 top.restoreSession();
1147 dlgopen('customize_log.php', '_blank', 500, 400);
1150 $('input[type="submit"]').click( function() {
1151 top.restoreSession();
1152 $(this).attr('data-clicked', true);
1155 $('form[name="update_form"]').submit( function(e) {
1156 var clickedButton = $("input[type=submit][data-clicked='true'")[0];
1158 // clear clicked button indicator
1159 $('input[type="submit"]').attr('data-clicked', false);
1161 if ( !clickedButton || $(clickedButton).attr("data-open-popup") !== "true" ) {
1162 $(this).removeAttr("target");
1163 return top.restoreSession();
1164 } else {
1165 top.restoreSession();
1166 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');
1167 this.target = 'Popup_Window';
1171 </script>
1172 <input type="hidden" name="divnos" id="divnos" value="<?php echo attr($divnos) ?>"/>
1173 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1174 </body>
1175 </html>