DaySheet report (end of day report) , take 3.
[openemr.git] / interface / billing / billing_report.php
blob998c01119d7ce85b1d5bb4bb5c817bcc027b595c
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'] == 1) {
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;
70 // This is obsolete.
71 if ($_POST['mode'] == 'process') {
72 if (exec("ps x | grep 'process_bills[.]php'")) {
73 $alertmsg = xl('Request ignored - claims processing is already running!');
74 } else {
75 exec("cd $webserver_root/library/freeb;" .
76 "php -q process_bills.php bill > process_bills.log 2>&1 &");
77 $alertmsg = xl('Batch processing initiated; this may take a while.');
82 //global variables:
83 $from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
84 $to_date = isset($_POST['to_date' ]) ? $_POST['to_date' ] : '';
85 $code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
86 $unbilled = isset($_POST['unbilled' ]) ? $_POST['unbilled' ] : 'on';
87 $my_authorized = isset($_POST["authorized"]) ? $_POST["authorized"] : '';
90 // This tells us if only encounters that appear to be missing a "25" modifier
91 // are to be reported.
92 $missing_mods_only = (isset($_POST['missing_mods_only']) && !empty($_POST['missing_mods_only']));
94 $left_margin = isset($_POST["left_margin"]) ? $_POST["left_margin"] : 24;
95 $top_margin = isset($_POST["top_margin"] ) ? $_POST["top_margin" ] : 20;
97 $ofrom_date = $from_date;
98 $oto_date = $to_date;
99 $ocode_type = $code_type;
100 $ounbilled = $unbilled;
101 $oauthorized = $my_authorized;
104 <html>
105 <head>
106 <?php if (function_exists('html_header_show')) html_header_show(); ?>
107 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
108 <style>
109 .subbtn { margin-top:3px; margin-bottom:3px; margin-left:2px; margin-right:2px }
110 </style>
111 <script>
113 function select_all() {
114 for($i=0;$i < document.update_form.length;$i++) {
115 $name = document.update_form[$i].name;
116 if ($name.substring(0,7) == "claims[" && $name.substring($name.length -6) == "[bill]") {
117 document.update_form[$i].checked = true;
120 set_button_states();
123 function set_button_states() {
124 var f = document.update_form;
125 var count0 = 0; // selected and not billed or queued
126 var count1 = 0; // selected and queued
127 var count2 = 0; // selected and billed
128 for($i = 0; $i < f.length; ++$i) {
129 $name = f[$i].name;
130 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -6) == "[bill]" && f[$i].checked == true) {
131 if (f[$i].value == '0') ++count0;
132 else if (f[$i].value == '1' || f[$i].value == '5') ++count1;
133 else ++count2;
137 var can_generate = (count0 > 0 || count1 > 0 || count2 > 0);
138 var can_mark = (count1 > 0 || count0 > 0 || count2 > 0);
139 var can_bill = (count0 == 0 && count1 == 0 && count2 > 0);
141 <?php if (file_exists($EXPORT_INC)) { ?>
142 f.bn_external.disabled = !can_generate;
143 <?php } else { ?>
144 // f.bn_hcfa_print.disabled = !can_generate;
145 // f.bn_hcfa.disabled = !can_generate;
146 // f.bn_ub92_print.disabled = !can_generate;
147 // f.bn_ub92.disabled = !can_generate;
148 f.bn_x12.disabled = !can_generate;
149 <?php if ($GLOBALS['support_encounter_claims']) { ?>
150 f.bn_x12_encounter.disabled = !can_generate;
151 <?php } ?>
152 f.bn_process_hcfa.disabled = !can_generate;
153 f.bn_hcfa_txt_file.disabled = !can_generate;
154 // f.bn_electronic_file.disabled = !can_bill;
155 f.bn_reopen.disabled = !can_bill;
156 <?php } ?>
157 f.bn_mark.disabled = !can_mark;
160 // Process a click to go to an encounter.
161 function toencounter(pid, pubpid, pname, enc, datestr, dobstr) {
162 top.restoreSession();
163 <?php if ($GLOBALS['concurrent_layout']) { ?>
164 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
165 parent.left_nav.setPatient(pname,pid,pubpid,'',dobstr);
166 parent.left_nav.setEncounter(datestr, enc, othername);
167 parent.left_nav.setRadio(othername, 'enc');
168 parent.frames[othername].location.href =
169 '../patient_file/encounter/encounter_top.php?set_encounter='
170 + enc + '&pid=' + pid;
171 <?php } else { ?>
172 location.href = '../patient_file/encounter/patient_encounter.php?set_encounter='
173 + enc + '&pid=' + pid;
174 <?php } ?>
176 // Process a click to go to an patient.
177 function topatient(pid, pubpid, pname, enc, datestr, dobstr) {
178 top.restoreSession();
179 <?php if ($GLOBALS['concurrent_layout']) { ?>
180 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
181 parent.left_nav.setPatient(pname,pid,pubpid,'',dobstr);
182 parent.frames[othername].location.href =
183 '../patient_file/summary/demographics_full.php?pid=' + pid;
184 <?php } else { ?>
185 location.href = '../patient_file/summary/demographics_full.php?pid=' + pid;
186 <?php } ?>
188 </script>
189 <script language="javascript" type="text/javascript">
190 EncounterDateArray=new Array;
191 CalendarCategoryArray=new Array;
192 EncounterIdArray=new Array;
193 function SubmitTheScreen()
194 {//Action on Update List link
195 if(!ProcessBeforeSubmitting())
196 return false;
197 top.restoreSession();
198 document.the_form.mode.value='change';
199 document.the_form.target='_self';
200 document.the_form.action='billing_report.php';
201 document.the_form.submit();
202 return true;
204 function SubmitTheScreenPrint()
205 {//Action on View Printable Report link
206 if(!ProcessBeforeSubmitting())
207 return false;
208 top.restoreSession();
209 document.the_form.target='new';
210 document.the_form.action='print_billing_report.php';
211 document.the_form.submit();
212 return true;
214 function SubmitTheEndDayPrint()
215 {//Action on View End of Day Report link
216 if(!ProcessBeforeSubmitting())
217 return false;
218 top.restoreSession();
219 document.the_form.target='new';
220 document.the_form.action='print_daysheet_report.php';
221 document.the_form.submit();
222 return true;
224 function SubmitTheScreenExportOFX()
225 {//Action on Export OFX link
226 if(!ProcessBeforeSubmitting())
227 return false;
228 top.restoreSession();
229 document.the_form.mode.value='export';
230 document.the_form.target='_self';
231 document.the_form.action='billing_report.php';
232 document.the_form.submit();
233 return true;
235 function TestExpandCollapse()
236 {//Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
237 var set=-1;
238 for(i=1;i<=document.getElementById("divnos").value;i++)
240 var ele = document.getElementById("divid_"+i);
241 if(ele)
243 set=1;
244 break;
247 if(set==-1)
249 if(document.getElementById("ExpandAll"))
251 document.getElementById("ExpandAll").innerHTML='';
252 document.getElementById("CollapseAll").innerHTML='';
256 function expandcollapse(atr){
257 if(atr == "expand") {//Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
258 for(i=1;i<=document.getElementById("divnos").value;i++){
259 var mydivid="divid_"+i;var myspanid="spanid_"+i;
260 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
261 if(ele)
263 ele.style.display = "inline";text.innerHTML = "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
267 else {
268 for(i=1;i<=document.getElementById("divnos").value;i++){
269 var mydivid="divid_"+i;var myspanid="spanid_"+i;
270 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
271 if(ele)
273 ele.style.display = "none"; text.innerHTML = "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
279 function divtoggle(spanid, divid) {//Called in the Expand, Collapse links(This is for a single item)
280 var ele = document.getElementById(divid);
281 if(ele)
283 var text = document.getElementById(spanid);
284 if(ele.style.display == "inline") {
285 ele.style.display = "none";
286 text.innerHTML = "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
288 else {
289 ele.style.display = "inline";
290 text.innerHTML = "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
294 function MarkAsCleared(Type)
296 CheckBoxBillingCount=0;
297 for (var CheckBoxBillingIndex =0; ; CheckBoxBillingIndex++)
299 CheckBoxBillingObject=document.getElementById('CheckBoxBilling'+CheckBoxBillingIndex);
300 if(!CheckBoxBillingObject)
301 break;
302 if(CheckBoxBillingObject.checked)
304 ++CheckBoxBillingCount;
307 if(Type==1)
309 Message='<?php echo htmlspecialchars( xl('After saving your batch, click [View Log] to check for errors.'), ENT_QUOTES); ?>';
311 if(Type==2)
313 Message='<?php echo htmlspecialchars( xl('After saving the PDF, click [View Log] to check for errors.'), ENT_QUOTES); ?>';
315 if(Type==3)
317 Message='<?php echo htmlspecialchars( xl('After saving the TEXT file(s), click [View Log] to check for errors.'), ENT_QUOTES); ?>';
319 if(confirm(Message + "\n\n\n<?php echo addslashes( xl('Total') ); ?>" + ' ' + CheckBoxBillingCount + ' ' + "<?php echo addslashes( xl('Selected') ); ?>\n" +
320 "<?php echo addslashes( xl('Would You Like them to be Marked as Cleared.') ); ?>"))
322 document.getElementById('HiddenMarkAsCleared').value='yes';
324 else
326 document.getElementById('HiddenMarkAsCleared').value='';
329 </script>
330 <?php include_once("$srcdir/../interface/reports/report.script.php"); ?><!-- Criteria Section common javascript page-->
331 <!-- ================================================== -->
332 <!-- =============Included for Insurance ajax criteria==== -->
333 <!-- ================================================== -->
334 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
335 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
336 <script type="text/javascript" src="../../library/js/common.js"></script>
337 <style>
338 #ajax_div_insurance {
339 position: absolute;
340 z-index:10;
341 background-color: #FBFDD0;
342 border: 1px solid #ccc;
343 padding: 10px;
345 </style>
346 <script language="javascript" type="text/javascript">
347 document.onclick=TakeActionOnHide;
348 </script>
349 <!-- ================================================== -->
350 <!-- =============Included for Insurance ajax criteria==== -->
351 <!-- ================================================== -->
352 </head>
353 <body class="body_top" onLoad="TestExpandCollapse()">
355 <p style='margin-top:5px;margin-bottom:5px;margin-left:5px'>
357 <?php if ($GLOBALS['concurrent_layout']) { ?>
358 <font class='title'><?php echo xlt('Billing Manager') ?></font>
359 <?php } else if ($userauthorized) { ?>
360 <a href="../main/main.php" target='Main' onclick='top.restoreSession()'><font class=title><?php echo xlt('Billing Manager') ?></font><font class=more> <?php echo $tback; ?></font></a>
361 <?php } else { ?>
362 <a href="../main/onotes/office_comments.php" target='Main' onclick='top.restoreSession()'><font class=title><?php echo xlt('Billing Manager') ?></font><font class=more><?php echo $tback; ?></font></a>
363 <?php } ?>
365 </p>
367 <form name='the_form' method='post' action='billing_report.php' onsubmit='return top.restoreSession()' style="display:inline">
369 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
370 <script type="text/javascript" src="../../library/dialog.js"></script>
371 <script type="text/javascript" src="../../library/textformat.js"></script>
372 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
373 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
374 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
375 <script language='JavaScript'>
376 var mypcc = '1';
377 </script>
379 <input type='hidden' name='mode' value='change'>
380 <!-- ============================================================================================================================================= -->
381 <!-- Criteria section Starts -->
382 <!-- ============================================================================================================================================= -->
383 <?php
384 //The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
385 //Each item is seperated by a comma(,).
386 //$ThisPageSearchCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
387 //$ThisPageSearchCriteriaKeyMaster ==>Corresponding database fields in the same order.
388 //$ThisPageSearchCriteriaDataTypeMaster ==>Corresponding data type in the same order.
389 $ThisPageSearchCriteriaDisplayRadioMaster=array();
390 $ThisPageSearchCriteriaRadioKeyMaster=array();
391 $ThisPageSearchCriteriaQueryDropDownMaster=array();
392 $ThisPageSearchCriteriaQueryDropDownMasterDefault=array();
393 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey=array();
394 $ThisPageSearchCriteriaIncludeMaster=array();
396 if ($daysheet) {
397 $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") );
398 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
399 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
400 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id,billing.user";
401 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
402 "text,include,text,radio,radio,radio,".
403 "radio_like,radio,query_drop_down,text";
405 else
408 $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") );
409 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
410 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
411 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id";
412 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
413 "text,include,text,radio,radio,radio,".
414 "radio_like,radio,query_drop_down";
419 //The below section is needed if there is any 'radio' or 'radio_like' type in the $ThisPageSearchCriteriaDataTypeMaster
420 //$ThisPageSearchCriteriaDisplayRadioMaster,$ThisPageSearchCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
421 //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.
422 $ThisPageSearchCriteriaDisplayRadioMaster[1] = array( xl("All"),xl("eClaims"),xl("Paper") );//Display Value
423 $ThisPageSearchCriteriaRadioKeyMaster[1]="all,standard,hcfa";//Key
424 $ThisPageSearchCriteriaDisplayRadioMaster[2]= array( xl("All"),xl("Insured"),xl("Non-Insured") );//Display Value
425 $ThisPageSearchCriteriaRadioKeyMaster[2]="all,1,0";//Key
426 $ThisPageSearchCriteriaDisplayRadioMaster[3]= array( xl("All"),xl("Coded"),xl("Not Coded") );//Display Value
427 $ThisPageSearchCriteriaRadioKeyMaster[3]="all,not null,null";//Key
428 $ThisPageSearchCriteriaDisplayRadioMaster[4]= array( xl("All"),xl("Unbilled"),xl("Billed"),xl("Denied") );//Display Value
429 $ThisPageSearchCriteriaRadioKeyMaster[4]="all,0,1,7";//Key
430 $ThisPageSearchCriteriaDisplayRadioMaster[5]= array( xl("All"),xl("Authorized"),xl("Unauthorized") );
431 $ThisPageSearchCriteriaRadioKeyMaster[5]="%,1,0";
432 $ThisPageSearchCriteriaDisplayRadioMaster[6]= array( xl("All"),xl("None"),xl("Ins 1"),xl("Ins 2 or Ins 3") );
433 $ThisPageSearchCriteriaRadioKeyMaster[6]="all,0,1,2";
434 //The below section is needed if there is any 'query_drop_down' type in the $ThisPageSearchCriteriaDataTypeMaster
435 $ThisPageSearchCriteriaQueryDropDownMaster[1]="SELECT name,id FROM x12_partners;";
436 $ThisPageSearchCriteriaQueryDropDownMasterDefault[1]= xl("All");//Only one item will be here
437 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey[1]="all";//Only one item will be here
438 //The below section is needed if there is any 'include' type in the $ThisPageSearchCriteriaDataTypeMaster
439 //Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
440 //It is labled(Included for Insurance ajax criteria)(Line:-279-299).
441 $ThisPageSearchCriteriaIncludeMaster[1]="InsuranceCompanyDisplay";//This is php function defined in the file 'report.inc.php'
443 if(!isset($_REQUEST['mode']))//default case
445 $_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")."')";
446 $_REQUEST['final_this_page_criteria'][1]="billing.billed = '0'";
448 $_REQUEST['final_this_page_criteria_text'][0]=xl("Date of Service = Today");
449 $_REQUEST['final_this_page_criteria_text'][1]=xl("Billing Status = Unbilled");
451 $_REQUEST['date_master_criteria_form_encounter_date']="today";
452 $_REQUEST['master_from_date_form_encounter_date']=date("Y-m-d");
453 $_REQUEST['master_to_date_form_encounter_date']=date("Y-m-d");
455 $_REQUEST['radio_billing_billed']=0;
459 <table width='100%' border="0" cellspacing="0" cellpadding="0">
460 <tr>
461 <td width="25%">&nbsp;</td>
462 <td width="50%">
463 <?php include_once("$srcdir/../interface/reports/criteria.tab.php"); ?>
464 </td>
465 <td width="25%">
466 <?php
467 // ============================================================================================================================================= -->
468 // Criteria section Ends -->
469 // ============================================================================================================================================= -->
472 <table width="100%" border="0" cellspacing="0" cellpadding="0">
473 <tr>
474 <td width="15%">&nbsp;</td>
475 <td width="85%"><span class='text'><a onClick="javascript:return SubmitTheScreen();" href="#" class=link_submit>[<?php echo xlt('Update List') ?>]</a>
477 <a onClick="javascript:return SubmitTheScreenExportOFX();" href="#" class='link_submit'><?php echo '[' . xlt('Export OFX') .']' ?></a></span> </td>
478 </tr>
479 <tr>
480 <td>&nbsp;</td>
481 <td><a onClick="javascript:return SubmitTheScreenPrint();" href="#"
482 class='link_submit' ><?php echo '['. xlt('View Printable Report').']' ?></a></td>
483 </tr>
485 <?php if ($daysheet) { ?>
486 <tr>
487 <td>&nbsp;</td>
488 <td><a onClick="javascript:return SubmitTheEndDayPrint();" href="#"
489 class='link_submit' ><?php echo '['.xlt('End Of Day Report').']' ?></a>
490 <?php if ($daysheet_total) { ?>
491 <span class=text><?php echo xlt('Totals'); ?> </span>
492 <input type=checkbox name="end_of_day_totals_only" value="1" <?php if ($obj['end_of_day_totals_only'] === '1') echo "checked";?>>
493 <?php } ?>
494 <?php if ($provider_run) { ?>
495 <span class=text><?php echo xlt('Provider'); ?> </span>
496 <input type=checkbox name="end_of_day_provider_only" value="1" <?php if ($obj['end_of_day_provider_only'] === '1') echo "checked";?>>
497 <?php } ?>
498 </td>
499 </tr>
500 <?php } ?>
502 <tr>
503 <td>&nbsp;</td>
504 <td>
505 <?php
506 $acct_config = $GLOBALS['oer_config']['ws_accounting'];
507 if($acct_config['enabled']) {
508 if($acct_config['enabled'] !== 2) {
509 print '<span class=text><a href="javascript:void window.open(\'' . $acct_config['url_path'] . '\')">' . '['. xlt("SQL-Ledger") .']' . '</a> &nbsp; </span>';
511 if (acl_check('acct', 'rep')) {
512 print '<span class=text><a href="javascript:void window.open(\'sl_receipts_report.php\')" onclick="top.restoreSession()">' . '['. xlt('Reports') .']'. '</a> &nbsp; </span>';
514 if (acl_check('acct', 'eob')) {
515 print '<span class=text><a href="javascript:void window.open(\'sl_eob_search.php\')" onclick="top.restoreSession()">' . '['.xlt('EOBs') .']' . '</a></span>';
519 </td>
520 </tr>
521 <tr>
522 <td>&nbsp;</td>
523 <td>
524 <?php if (! file_exists($EXPORT_INC)) { ?>
525 <!--
526 <a href="javascript:top.restoreSession();document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
527 title="Process all queued bills to create electronic data (and print if requested)"><?php echo '['. xlt('Start Batch Processing') .']' ?></a>
528 &nbsp;
530 <a href='customize_log.php' onclick='top.restoreSession()' target='_blank' class='link_submit'
531 title='<?php xla('See messages from the last set of generated claims'); ?>'><?php echo '['. xlt('View Log') .']'?></a>
532 <?php } ?>
533 </td>
534 </tr>
535 <tr>
536 <td>&nbsp;</td>
537 <td><a href="javascript:select_all()" class="link_submit"><?php echo '['. xlt('Select All') .']'?></a></td>
538 </tr>
539 </table>
542 </td>
543 </tr>
544 </table>
545 <table width='100%' border="0" cellspacing="0" cellpadding="0" >
546 <tr>
547 <td>
548 <hr color="#000000">
549 </td>
550 </tr>
551 </table>
552 </form>
553 <form name='update_form' method='post' action='billing_process.php' onsubmit='return top.restoreSession()' style="display:inline">
554 <center>
555 <span class='text' style="display:inline">
556 <?php if (file_exists($EXPORT_INC)) { ?>
557 <input type="submit" class="subbtn" name="bn_external" value="Export Billing" title="<?php echo xla('Export to external billing system') ?>">
558 <input type="submit" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php echo xla('Mark as billed but skip billing') ?>">
559 <?php } else { ?>
560 <!--
561 <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') ?>">
562 <input type="submit" class="subbtn" name="bn_hcfa" value="Queue HCFA" title="<?php echo xla('Queue for HCFA batch processing')?>">
563 <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')?>">
564 <input type="submit" class="subbtn" name="bn_ub92" value="Queue UB92" title="<?php echo xla('Queue for UB-92 batch processing')?>">
566 <input type="submit" class="subbtn" name="bn_x12" value="<?php echo xla('Generate X12')?>"
567 title="<?php echo xla('Generate and download X12 batch')?>"
568 onclick="MarkAsCleared(1)">
569 <?php if ($GLOBALS['support_encounter_claims']) { ?>
570 <input type="submit" class="subbtn" name="bn_x12_encounter" value="<?php echo xla('Generate X12 Encounter')?>"
571 title="<?php echo xla('Generate and download X12 encounter claim batch')?>"
572 onclick="MarkAsCleared(1)">
573 <?php } ?>
574 <input type="submit" class="subbtn" style="width:175px;" name="bn_process_hcfa" value="<?php echo xla('Generate CMS 1500 PDF')?>"
575 title="<?php echo xla('Generate and download CMS 1500 paper claims')?>"
576 onclick="MarkAsCleared(2)">
577 <input type="submit" class="subbtn" style="width:175px;" name="bn_hcfa_txt_file" value="<?php echo xla('Generate CMS 1500 TEXT')?>"
578 title="<?php echo xla('Making batch text files for uploading to Clearing House and will mark as billed')?>"
579 onclick="MarkAsCleared(3)">
580 <input type="submit" class="subbtn" name="bn_mark" value="<?php echo xla('Mark as Cleared')?>" title="<?php echo xla('Post to accounting and mark as billed')?>">
581 <input type="submit" class="subbtn" name="bn_reopen" value="<?php echo xla('Re-Open')?>" title="<?php echo xla('Mark as not billed')?>">
582 <!--
583 <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')?>">
585 &nbsp;&nbsp;&nbsp;
586 <?php echo xlt('CMS 1500 Margins'); ?>:
587 &nbsp;<?php echo xlt('Left'); ?>:
588 <input type='text' size='2' name='left_margin'
589 value='<?php echo attr($left_margin); ?>'
590 title='<?php echo xla('HCFA left margin in points'); ?>' />
591 &nbsp;<?php echo xlt('Top'); ?>:
592 <input type='text' size='2' name='top_margin'
593 value='<?php echo attr($top_margin); ?>'
594 title='<?php echo xla('HCFA top margin in points'); ?>' />
595 </span>
596 <?php } ?>
598 </center>
599 <input type='hidden' name='HiddenMarkAsCleared' id='HiddenMarkAsCleared' value="" />
600 <input type='hidden' name='mode' value="bill" />
601 <input type='hidden' name='authorized' value="<?php echo attr($my_authorized); ?>" />
602 <input type='hidden' name='unbilled' value="<?php echo attr($unbilled); ?>" />
603 <input type='hidden' name='code_type' value="%" />
604 <input type='hidden' name='to_date' value="<?php echo attr($to_date); ?>" />
605 <input type='hidden' name='from_date' value="<?php echo attr($from_date); ?>" />
607 <?php
608 if ($my_authorized == "on" ) {
609 $my_authorized = "1";
610 } else {
611 $my_authorized = "%";
613 if ($unbilled == "on") {
614 $unbilled = "0";
615 } else {
616 $unbilled = "%";
618 $list = getBillsListBetween("%");
621 <input type='hidden' name='bill_list' value="<?php echo attr($list); ?>" />
623 <!-- new form for uploading -->
625 <?php
626 if (!isset($_POST["mode"])) {
627 if (!isset($_POST["from_date"])) {
628 $from_date = date("Y-m-d");
629 } else {
630 $from_date = $_POST["from_date"];
632 if (empty($_POST["to_date"])) {
633 $to_date = '';
634 } else {
635 $to_date = $_POST["to_date"];
637 if (!isset($_POST["code_type"])) {
638 $code_type="all";
639 } else {
640 $code_type = $_POST["code_type"];
642 if (!isset($_POST["unbilled"])) {
643 $unbilled = "on";
644 } else {
645 $unbilled = $_POST["unbilled"];
647 if (!isset($_POST["authorized"])) {
648 $my_authorized = "on";
649 } else {
650 $my_authorized = $_POST["authorized"];
652 } else {
653 $from_date = $_POST["from_date"];
654 $to_date = $_POST["to_date"];
655 $code_type = $_POST["code_type"];
656 $unbilled = $_POST["unbilled"];
657 $my_authorized = $_POST["authorized"];
660 if ($my_authorized == "on" ) {
661 $my_authorized = "1";
662 } else {
663 $my_authorized = "%";
666 if ($unbilled == "on") {
667 $unbilled = "0";
668 } else {
669 $unbilled = "%";
672 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
673 billCodesList($list);
677 <table border="0" cellspacing="0" cellpadding="0" width="100%">
679 <?php
680 $divnos=0;
681 if ($ret = getBillsBetween("%"))
683 if(is_array($ret))
686 <tr ><td colspan='8' align="right" ><table width="250" border="0" cellspacing="0" cellpadding="0">
687 <tr>
688 <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>
689 <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>
690 <td width="50">&nbsp;</td>
691 </tr>
692 </table>
693 </td></tr>
694 <?php
696 $loop = 0;
697 $oldcode = "";
698 $last_encounter_id = "";
699 $lhtml = "";
700 $rhtml = "";
701 $lcount = 0;
702 $rcount = 0;
703 $bgcolor = "";
704 $skipping = FALSE;
706 $mmo_empty_mod = false;
707 $mmo_num_charges = 0;
709 foreach ($ret as $iter) {
711 // We include encounters here that have never been billed. However
712 // if it had no selected billing items but does have non-selected
713 // billing items, then it is not of interest.
714 if (!$iter['id']) {
715 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
716 "encounter = ? AND " .
717 "pid=? AND " .
718 "activity = 1", array($iter['enc_encounter'],$iter['enc_pid']) );
719 if ($res['count'] > 0) continue;
722 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
724 if ($last_encounter_id != $this_encounter_id) {
726 // This dumps all HTML for the previous encounter.
728 if ($lhtml) {
729 while ($rcount < $lcount) {
730 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'></td></tr>";
731 ++$rcount;
733 // This test handles the case where we are only listing encounters
734 // that appear to have a missing "25" modifier.
735 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
736 if($DivPut=='yes')
738 $lhtml.='</div>';
739 $DivPut='no';
741 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
742 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n\n";
743 ++$encount;
747 $lhtml = "";
748 $rhtml = "";
749 $mmo_empty_mod = false;
750 $mmo_num_charges = 0;
752 // If there are ANY unauthorized items in this encounter and this is
753 // the normal case of viewing only authorized billing, then skip the
754 // entire encounter.
756 $skipping = FALSE;
757 if ($my_authorized == '1') {
758 $res = sqlQuery("select count(*) as count from billing where " .
759 "encounter = ? and " .
760 "pid=? and " .
761 "activity = 1 and authorized = 0", array($iter['enc_encounter'],$iter['enc_pid']) );
762 if ($res['count'] > 0) {
763 $skipping = TRUE;
764 $last_encounter_id = $this_encounter_id;
765 continue;
769 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
771 # Check if patient has primary insurance and a subscriber exists for it.
772 # If not we will highlight their name in red.
773 # TBD: more checking here.
775 $res = sqlQuery("select count(*) as count from insurance_data where " .
776 "pid = ? and " .
777 "type='primary' and " .
778 "subscriber_lname is not null and " .
779 "subscriber_lname != '' limit 1", array($iter['enc_pid']) );
780 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
782 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
783 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
784 $lcount = 1;
785 $rcount = 0;
786 $oldcode = "";
788 $ptname = $name['fname'] . " " . $name['lname'];
789 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
791 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
792 $lhtml .= "&nbsp;<span class=bold><font color='$namecolor'>". text($ptname) .
793 "</font></span><span class=small>&nbsp;(" . text($iter['enc_pid']) . "-" .
794 text($iter['enc_encounter']) . ")</span>";
796 //Encounter details are stored to javacript as array.
797 $result4 = sqlStatement("SELECT fe.encounter,fe.date,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
798 " 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']) );
799 if(sqlNumRows($result4)>0)
801 <script language='JavaScript'>
802 Count=0;
803 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
804 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
805 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
806 <?php
807 while($rowresult4 = sqlFetchArray($result4))
810 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars($rowresult4['encounter'], ENT_QUOTES); ?>';
811 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date']))), ENT_QUOTES); ?>';
812 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars( xl_appt_category($rowresult4['pc_catname']), ENT_QUOTES); ?>';
813 Count++;
814 <?php
817 </script>
818 <?php
820 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
821 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
822 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
823 ",'" . addslashes($name['pubpid']) .
824 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
825 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
826 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
827 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
828 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" .
829 xlt('To Enctr') . " " . text(oeFormatShortDate($raw_encounter_date)) . "]</a>";
831 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
832 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
833 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
834 ",'" . addslashes($name['pubpid']) .
835 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
836 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
837 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
838 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
839 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" . xlt('To Dems') . "]</a>";
840 $divnos=$divnos+1;
841 $lhtml .= "&nbsp;&nbsp;&nbsp;<a onclick='divtoggle(\"spanid_$divnos\",\"divid_$divnos\");' class='small' id='aid_$divnos' href=\"JavaScript:void(0);".
842 "\">(<span id=spanid_$divnos class=\"indicator\">" . htmlspecialchars( xl('Expand'), ENT_QUOTES) . "</span>)</a>";
844 if ($iter['id']) {
846 $lcount += 2;
847 $lhtml .= "<br />\n";
848 $lhtml .= "&nbsp;<span class=text>Bill: ";
849 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' style='background-color:$bgcolor'>";
851 $query = "SELECT id.provider AS id, id.type, id.date, " .
852 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
853 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
854 "ic.id = id.provider AND " .
855 "id.pid = ? AND " .
856 "id.date <= ? " .
857 "ORDER BY id.type ASC, id.date DESC";
859 $result = sqlStatement($query, array($iter['enc_pid'],$raw_encounter_date) );
860 $count = 0;
861 $default_x12_partner = $iter['ic_x12id'];
862 $prevtype = '';
864 while ($row = sqlFetchArray($result)) {
865 if (strcmp($row['type'], $prevtype) == 0) continue;
866 $prevtype = $row['type'];
867 if (strlen($row['provider']) > 0) {
868 // This preserves any existing insurance company selection, which is
869 // important when EOB posting has re-queued for secondary billing.
870 $lhtml .= "<option value=\"" . attr(substr($row['type'],0,1).$row['id']) . "\"";
871 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
872 $lhtml .= " selected";
873 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
875 $lhtml .= ">" . text($row['type']) . ": " . text($row['provider']) . "</option>";
877 $count++;
880 $lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
881 $lhtml .= "</select>&nbsp;&nbsp;\n";
882 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][partner]' style='background-color:$bgcolor'>";
883 $x = new X12Partner();
884 $partners = $x->_utility_array($x->x12_partner_factory());
885 foreach ($partners as $xid => $xname) {
886 $lhtml .= '<option label="' . attr($xname) . '" value="' . attr($xid) .'"';
887 if ($xid == $default_x12_partner) {
888 $lhtml .= "selected";
890 $lhtml .= '>' . text($xname) . '</option>';
892 $lhtml .= "</select>";
893 $DivPut='yes';
894 $lhtml .= "<br>\n&nbsp;<div id='divid_$divnos' style='display:none'>" . text(oeFormatShortDate(substr($iter['date'], 0, 10)))
895 . text(substr($iter['date'], 10, 6)) . " " . xlt("Encounter was coded");
897 $query = "SELECT * FROM claims WHERE " .
898 "patient_id = ? AND " .
899 "encounter_id = ? " .
900 "ORDER BY version";
901 $cres = sqlStatement($query, array($iter['enc_pid'],$iter['enc_encounter']) );
903 $lastcrow = false;
905 while ($crow = sqlFetchArray($cres)) {
906 $query = "SELECT id.type, ic.name " .
907 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
908 "id.pid = ? AND " .
909 "id.provider = ? AND " .
910 "id.date <= ? AND " .
911 "ic.id = id.provider " .
912 "ORDER BY id.type ASC, id.date DESC";
914 $irow= sqlQuery($query, array($iter['enc_pid'],$crow['payer_id'],$raw_encounter_date) );
916 if ($crow['bill_process']) {
917 $lhtml .= "<br>\n&nbsp;" .
918 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
919 text(substr($crow['bill_time'], 10, 6)) . " " .
920 xlt("Queued for") . " " . text($irow['type']) . " " . text($crow['target']) . " " .
921 xlt("billing to ") . text($irow['name']);
922 ++$lcount;
924 else if ($crow['status'] < 6) {
925 if ($crow['status'] > 1) {
926 $lhtml .= "<br>\n&nbsp;" .
927 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
928 text(substr($crow['bill_time'], 10, 6)) . " " .
929 htmlspecialchars( xl("Marked as cleared"), ENT_QUOTES);
930 ++$lcount;
932 else {
933 $lhtml .= "<br>\n&nbsp;" .
934 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
935 text(substr($crow['bill_time'], 10, 6)) . " " .
936 htmlspecialchars( xl("Re-opened"), ENT_QUOTES);
937 ++$lcount;
940 else if ($crow['status'] == 6) {
941 $lhtml .= "<br>\n&nbsp;" .
942 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
943 text(substr($crow['bill_time'], 10, 6)) . " " .
944 htmlspecialchars( xl("This claim has been forwarded to next level."), ENT_QUOTES);
945 ++$lcount;
947 else if ($crow['status'] == 7) {
948 $lhtml .= "<br>\n&nbsp;" .
949 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
950 text(substr($crow['bill_time'], 10, 6)) . " " .
951 htmlspecialchars( xl("This claim has been denied.Reason:-"), ENT_QUOTES);
952 if($crow['process_file'])
954 $code_array=split(',',$crow['process_file']);
955 foreach($code_array as $code_key => $code_value)
957 $lhtml .= "<br>\n&nbsp;&nbsp;&nbsp;";
958 $reason_array=split('_',$code_value);
959 if(!isset($adjustment_reasons[$reason_array[3]]))
961 $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]).']';
963 else
965 $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]]);
969 else
971 $lhtml .=htmlspecialchars( xl("Not Specified."), ENT_QUOTES);
973 ++$lcount;
976 if ($crow['process_time']) {
977 $lhtml .= "<br>\n&nbsp;" .
978 text(oeFormatShortDate(substr($crow['process_time'], 0, 10))) .
979 text(substr($crow['process_time'], 10, 6)) . " " .
980 xlt("Claim was generated to file") . " " .
981 "<a href='get_claim_file.php?key=" . attr($crow['process_file']) .
982 "' onclick='top.restoreSession()'>" .
983 text($crow['process_file']) . "</a>";
984 ++$lcount;
987 $lastcrow = $crow;
988 } // end while ($crow = sqlFetchArray($cres))
990 if ($lastcrow && $lastcrow['status'] == 4) {
991 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been closed.");
992 ++$lcount;
995 if ($lastcrow && $lastcrow['status'] == 5) {
996 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been canceled.");
997 ++$lcount;
999 } // end if ($iter['id'])
1001 } // end if ($last_encounter_id != $this_encounter_id)
1003 if ($skipping) continue;
1005 // Collect info related to the missing modifiers test.
1006 if ($iter['fee'] > 0) {
1007 ++$mmo_num_charges;
1008 $tmp = substr($iter['code'], 0, 3);
1009 if (($tmp == '992' || $tmp == '993') && empty($iter['modifier']))
1010 $mmo_empty_mod = true;
1013 ++$rcount;
1015 if ($rhtml) {
1016 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
1018 $rhtml .= "<td width='50'>";
1019 if ($iter['id'] && $oldcode != $iter['code_type']) {
1020 $rhtml .= "<span class=text>" . text($iter['code_type']) . ": </span>";
1023 $oldcode = $iter['code_type'];
1024 $rhtml .= "</td>\n";
1025 $justify = "";
1027 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
1028 $js = split(":",$iter['justify']);
1029 $counter = 0;
1030 foreach ($js as $j) {
1031 if(!empty($j)) {
1032 if ($counter == 0) {
1033 $justify .= " (<b>" . text($j) . "</b>)";
1035 else {
1036 $justify .= " (" . text($j) . ")";
1038 $counter++;
1043 $rhtml .= "<td><span class='text'>" .
1044 ($iter['code_type'] == 'COPAY' ? text(oeFormatMoney($iter['code'])) : text($iter['code']));
1045 if ($iter['modifier']) $rhtml .= ":" . text($iter['modifier']);
1046 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
1048 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1049 if ($iter['id'] && $iter['fee'] > 0) {
1050 $rhtml .= text(oeFormatMoney($iter['fee']));
1052 $rhtml .= "</span></td>\n";
1053 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1054 if ($iter['id']) $rhtml .= getProviderName(empty($iter['provider_id']) ? text($iter['enc_provider_id']) : text($iter['provider_id']));
1055 $rhtml .= "</span></td>\n";
1056 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1057 if ($iter['id']) $rhtml .= text(oeFormatSDFT(strtotime($iter{"date"})));
1058 $rhtml .= "</span></td>\n";
1059 if ($iter['id'] && $iter['authorized'] != 1) {
1060 $rhtml .= "<td><span class=alert>".xlt("Note: This code was not entered by an authorized user. Only authorized codes may be uploaded to the Open Medical Billing Network for processing. If you wish to upload these codes, please select an authorized user here.")."</span></td>\n";
1062 else {
1063 $rhtml .= "<td></td>\n";
1065 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
1066 $tmpbpr = $iter['bill_process'];
1067 if ($tmpbpr == '0' && $iter['billed']) $tmpbpr = '2';
1068 $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";
1069 $CheckBoxBilling++;
1071 else {
1072 $rhtml .= "<td></td>\n";
1074 if($last_encounter_id != $this_encounter_id){
1075 $rhtml2 = "";
1076 $rowcnt = 0;
1077 $resMoneyGot = sqlStatement("SELECT pay_amount as PatientPay,date(post_time) as date FROM ar_activity where ".
1078 "pid = ? and encounter = ? and payer_type=0 and account_code='PCP'",
1079 array($iter['enc_pid'],$iter['enc_encounter']));
1080 //new fees screen copay gives account_code='PCP'
1081 if(sqlNumRows($resMoneyGot) > 0){
1082 $lcount += 2;
1083 $rcount++;
1085 //checks whether a copay exists for the encounter and if exists displays it.
1086 while($rowMoneyGot = sqlFetchArray($resMoneyGot)){
1087 $rowcnt++;
1088 $PatientPay=$rowMoneyGot['PatientPay'];
1089 $date=$rowMoneyGot['date'];
1090 if($PatientPay > 0){
1091 if($rhtml){
1092 $rhtml2 .= "<tr bgcolor='$bgcolor'>\n";
1094 $rhtml2 .= "<td width='50'>";
1095 $rhtml2 .= "<span class='text'>".xlt('COPAY').": </span>";
1096 $rhtml2 .= "</td>\n";
1097 $rhtml2 .= "<td><span class='text'>".text(oeFormatMoney($PatientPay))."</span><span style='font-size:8pt;'>&nbsp;</span></td>\n";
1098 $rhtml2 .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1099 $rhtml2 .= "</span></td>\n";
1100 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1101 $rhtml2 .= "</span></td>\n";
1102 $rhtml2 .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1103 $rhtml2 .= text(oeFormatSDFT(strtotime($date)));
1104 $rhtml2 .= "</span></td>\n";
1105 if ($iter['id'] && $iter['authorized'] != 1) {
1106 $rhtml2 .= "<td><span class=alert>".xlt("Note: This code was not entered by an authorized user. Only authorized codes may be uploaded to the Open Medical Billing Network for processing. If you wish to upload these codes, please select an authorized user here.")."</span></td>\n";
1107 }else{
1108 $rhtml2 .= "<td></td>\n";
1110 if(!$iter['id'] && $rowcnt == 1){
1111 $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";
1112 $CheckBoxBilling++;
1113 }else{
1114 $rhtml2 .= "<td></td>\n";
1118 $rhtml .= $rhtml2;
1120 $rhtml .= "</tr>\n";
1121 $last_encounter_id = $this_encounter_id;
1123 } // end foreach
1125 if ($lhtml) {
1126 while ($rcount < $lcount) {
1127 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'></td></tr>";
1128 ++$rcount;
1130 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
1131 if($DivPut=='yes')
1133 $lhtml.='</div>';
1134 $DivPut='no';
1136 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
1137 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
1145 </table>
1146 </form>
1148 <script>
1149 set_button_states();
1150 <?php
1151 if ($alertmsg) {
1152 echo "alert('".addslashes($alertmsg)."');\n";
1155 </script>
1156 <input type="hidden" name="divnos" id="divnos" value="<?php echo attr($divnos) ?>"/>
1157 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1158 </body>
1159 </html>