Fix - Calendar (day view) - missing recurring event indicator symbol for recurrtype...
[openemr.git] / interface / billing / billing_report.php
blob2c1ef3ad04fdcda9fa1cdca13bf6cefbd459842d
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;
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 <?php if ($GLOBALS['use_custom_daysheet'] == 1) { ?>
221 document.the_form.action='print_daysheet_report_num1.php';
222 <?php } ?>
223 <?php if ($GLOBALS['use_custom_daysheet'] == 2) { ?>
224 document.the_form.action='print_daysheet_report_num2.php';
225 <?php } ?>
226 <?php if ($GLOBALS['use_custom_daysheet'] == 3) { ?>
227 document.the_form.action='print_daysheet_report_num3.php';
228 <?php } ?>
229 document.the_form.submit();
230 return true;
232 function SubmitTheScreenExportOFX()
233 {//Action on Export OFX link
234 if(!ProcessBeforeSubmitting())
235 return false;
236 top.restoreSession();
237 document.the_form.mode.value='export';
238 document.the_form.target='_self';
239 document.the_form.action='billing_report.php';
240 document.the_form.submit();
241 return true;
243 function TestExpandCollapse()
244 {//Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
245 var set=-1;
246 for(i=1;i<=document.getElementById("divnos").value;i++)
248 var ele = document.getElementById("divid_"+i);
249 if(ele)
251 set=1;
252 break;
255 if(set==-1)
257 if(document.getElementById("ExpandAll"))
259 document.getElementById("ExpandAll").innerHTML='';
260 document.getElementById("CollapseAll").innerHTML='';
264 function expandcollapse(atr){
265 if(atr == "expand") {//Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
266 for(i=1;i<=document.getElementById("divnos").value;i++){
267 var mydivid="divid_"+i;var myspanid="spanid_"+i;
268 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
269 if(ele)
271 ele.style.display = "inline";text.innerHTML = "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
275 else {
276 for(i=1;i<=document.getElementById("divnos").value;i++){
277 var mydivid="divid_"+i;var myspanid="spanid_"+i;
278 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
279 if(ele)
281 ele.style.display = "none"; text.innerHTML = "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
287 function divtoggle(spanid, divid) {//Called in the Expand, Collapse links(This is for a single item)
288 var ele = document.getElementById(divid);
289 if(ele)
291 var text = document.getElementById(spanid);
292 if(ele.style.display == "inline") {
293 ele.style.display = "none";
294 text.innerHTML = "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
296 else {
297 ele.style.display = "inline";
298 text.innerHTML = "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
302 function MarkAsCleared(Type)
304 CheckBoxBillingCount=0;
305 for (var CheckBoxBillingIndex =0; ; CheckBoxBillingIndex++)
307 CheckBoxBillingObject=document.getElementById('CheckBoxBilling'+CheckBoxBillingIndex);
308 if(!CheckBoxBillingObject)
309 break;
310 if(CheckBoxBillingObject.checked)
312 ++CheckBoxBillingCount;
315 if(Type==1)
317 Message='<?php echo htmlspecialchars( xl('After saving your batch, click [View Log] to check for errors.'), ENT_QUOTES); ?>';
319 if(Type==2)
321 Message='<?php echo htmlspecialchars( xl('After saving the PDF, click [View Log] to check for errors.'), ENT_QUOTES); ?>';
323 if(Type==3)
325 Message='<?php echo htmlspecialchars( xl('After saving the TEXT file(s), click [View Log] to check for errors.'), ENT_QUOTES); ?>';
327 if(confirm(Message + "\n\n\n<?php echo addslashes( xl('Total') ); ?>" + ' ' + CheckBoxBillingCount + ' ' + "<?php echo addslashes( xl('Selected') ); ?>\n" +
328 "<?php echo addslashes( xl('Would You Like them to be Marked as Cleared.') ); ?>"))
330 document.getElementById('HiddenMarkAsCleared').value='yes';
332 else
334 document.getElementById('HiddenMarkAsCleared').value='';
337 </script>
338 <?php include_once("$srcdir/../interface/reports/report.script.php"); ?><!-- Criteria Section common javascript page-->
339 <!-- ================================================== -->
340 <!-- =============Included for Insurance ajax criteria==== -->
341 <!-- ================================================== -->
342 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
343 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
344 <script type="text/javascript" src="../../library/js/common.js"></script>
345 <style>
346 #ajax_div_insurance {
347 position: absolute;
348 z-index:10;
349 background-color: #FBFDD0;
350 border: 1px solid #ccc;
351 padding: 10px;
353 </style>
354 <script language="javascript" type="text/javascript">
355 document.onclick=TakeActionOnHide;
356 </script>
357 <!-- ================================================== -->
358 <!-- =============Included for Insurance ajax criteria==== -->
359 <!-- ================================================== -->
360 </head>
361 <body class="body_top" onLoad="TestExpandCollapse()">
363 <p style='margin-top:5px;margin-bottom:5px;margin-left:5px'>
365 <?php if ($GLOBALS['concurrent_layout']) { ?>
366 <font class='title'><?php echo xlt('Billing Manager') ?></font>
367 <?php } else if ($userauthorized) { ?>
368 <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>
369 <?php } else { ?>
370 <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>
371 <?php } ?>
373 </p>
375 <form name='the_form' method='post' action='billing_report.php' onsubmit='return top.restoreSession()' style="display:inline">
377 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
378 <script type="text/javascript" src="../../library/dialog.js"></script>
379 <script type="text/javascript" src="../../library/textformat.js"></script>
380 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
381 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
382 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
383 <script language='JavaScript'>
384 var mypcc = '1';
385 </script>
387 <input type='hidden' name='mode' value='change'>
388 <!-- ============================================================================================================================================= -->
389 <!-- Criteria section Starts -->
390 <!-- ============================================================================================================================================= -->
391 <?php
392 //The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
393 //Each item is seperated by a comma(,).
394 //$ThisPageSearchCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
395 //$ThisPageSearchCriteriaKeyMaster ==>Corresponding database fields in the same order.
396 //$ThisPageSearchCriteriaDataTypeMaster ==>Corresponding data type in the same order.
397 $ThisPageSearchCriteriaDisplayRadioMaster=array();
398 $ThisPageSearchCriteriaRadioKeyMaster=array();
399 $ThisPageSearchCriteriaQueryDropDownMaster=array();
400 $ThisPageSearchCriteriaQueryDropDownMasterDefault=array();
401 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey=array();
402 $ThisPageSearchCriteriaIncludeMaster=array();
404 if ($daysheet) {
405 $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") );
406 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
407 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
408 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id,billing.user";
409 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
410 "text,include,text,radio,radio,radio,".
411 "radio_like,radio,query_drop_down,text";
413 else
416 $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") );
417 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
418 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
419 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id";
420 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
421 "text,include,text,radio,radio,radio,".
422 "radio_like,radio,query_drop_down";
427 //The below section is needed if there is any 'radio' or 'radio_like' type in the $ThisPageSearchCriteriaDataTypeMaster
428 //$ThisPageSearchCriteriaDisplayRadioMaster,$ThisPageSearchCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
429 //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.
430 $ThisPageSearchCriteriaDisplayRadioMaster[1] = array( xl("All"),xl("eClaims"),xl("Paper") );//Display Value
431 $ThisPageSearchCriteriaRadioKeyMaster[1]="all,standard,hcfa";//Key
432 $ThisPageSearchCriteriaDisplayRadioMaster[2]= array( xl("All"),xl("Insured"),xl("Non-Insured") );//Display Value
433 $ThisPageSearchCriteriaRadioKeyMaster[2]="all,1,0";//Key
434 $ThisPageSearchCriteriaDisplayRadioMaster[3]= array( xl("All"),xl("Coded"),xl("Not Coded") );//Display Value
435 $ThisPageSearchCriteriaRadioKeyMaster[3]="all,not null,null";//Key
436 $ThisPageSearchCriteriaDisplayRadioMaster[4]= array( xl("All"),xl("Unbilled"),xl("Billed"),xl("Denied") );//Display Value
437 $ThisPageSearchCriteriaRadioKeyMaster[4]="all,0,1,7";//Key
438 $ThisPageSearchCriteriaDisplayRadioMaster[5]= array( xl("All"),xl("Authorized"),xl("Unauthorized") );
439 $ThisPageSearchCriteriaRadioKeyMaster[5]="%,1,0";
440 $ThisPageSearchCriteriaDisplayRadioMaster[6]= array( xl("All"),xl("None"),xl("Ins 1"),xl("Ins 2 or Ins 3") );
441 $ThisPageSearchCriteriaRadioKeyMaster[6]="all,0,1,2";
442 //The below section is needed if there is any 'query_drop_down' type in the $ThisPageSearchCriteriaDataTypeMaster
443 $ThisPageSearchCriteriaQueryDropDownMaster[1]="SELECT name,id FROM x12_partners;";
444 $ThisPageSearchCriteriaQueryDropDownMasterDefault[1]= xl("All");//Only one item will be here
445 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey[1]="all";//Only one item will be here
446 //The below section is needed if there is any 'include' type in the $ThisPageSearchCriteriaDataTypeMaster
447 //Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
448 //It is labled(Included for Insurance ajax criteria)(Line:-279-299).
449 $ThisPageSearchCriteriaIncludeMaster[1]="InsuranceCompanyDisplay";//This is php function defined in the file 'report.inc.php'
451 if(!isset($_REQUEST['mode']))//default case
453 $_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")."')";
454 $_REQUEST['final_this_page_criteria'][1]="billing.billed = '0'";
456 $_REQUEST['final_this_page_criteria_text'][0]=xl("Date of Service = Today");
457 $_REQUEST['final_this_page_criteria_text'][1]=xl("Billing Status = Unbilled");
459 $_REQUEST['date_master_criteria_form_encounter_date']="today";
460 $_REQUEST['master_from_date_form_encounter_date']=date("Y-m-d");
461 $_REQUEST['master_to_date_form_encounter_date']=date("Y-m-d");
463 $_REQUEST['radio_billing_billed']=0;
467 <table width='100%' border="0" cellspacing="0" cellpadding="0">
468 <tr>
469 <td width="25%">&nbsp;</td>
470 <td width="50%">
471 <?php include_once("$srcdir/../interface/reports/criteria.tab.php"); ?>
472 </td>
473 <td width="25%">
474 <?php
475 // ============================================================================================================================================= -->
476 // Criteria section Ends -->
477 // ============================================================================================================================================= -->
480 <table width="100%" border="0" cellspacing="0" cellpadding="0">
481 <tr>
482 <td width="15%">&nbsp;</td>
483 <td width="85%"><span class='text'><a onClick="javascript:return SubmitTheScreen();" href="#" class=link_submit>[<?php echo xlt('Update List') ?>]</a>
485 <a onClick="javascript:return SubmitTheScreenExportOFX();" href="#" class='link_submit'><?php echo '[' . xlt('Export OFX') .']' ?></a></span> </td>
486 </tr>
487 <tr>
488 <td>&nbsp;</td>
489 <td><a onClick="javascript:return SubmitTheScreenPrint();" href="#"
490 class='link_submit' ><?php echo '['. xlt('View Printable Report').']' ?></a></td>
491 </tr>
493 <?php if ($daysheet) { ?>
494 <tr>
495 <td>&nbsp;</td>
496 <td><a onClick="javascript:return SubmitTheEndDayPrint();" href="#"
497 class='link_submit' ><?php echo '['.xlt('End Of Day Report').']' ?></a>
498 <?php if ($daysheet_total) { ?>
499 <span class=text><?php echo xlt('Totals'); ?> </span>
500 <input type=checkbox name="end_of_day_totals_only" value="1" <?php if ($obj['end_of_day_totals_only'] === '1') echo "checked";?>>
501 <?php } ?>
502 <?php if ($provider_run) { ?>
503 <span class=text><?php echo xlt('Provider'); ?> </span>
504 <input type=checkbox name="end_of_day_provider_only" value="1" <?php if ($obj['end_of_day_provider_only'] === '1') echo "checked";?>>
505 <?php } ?>
506 </td>
507 </tr>
508 <?php } ?>
510 <tr>
511 <td>&nbsp;</td>
512 <td>
513 <?php
514 $acct_config = $GLOBALS['oer_config']['ws_accounting'];
515 if($acct_config['enabled']) {
516 if($acct_config['enabled'] !== 2) {
517 print '<span class=text><a href="javascript:void window.open(\'' . $acct_config['url_path'] . '\')">' . '['. xlt("SQL-Ledger") .']' . '</a> &nbsp; </span>';
519 if (acl_check('acct', 'rep')) {
520 print '<span class=text><a href="javascript:void window.open(\'sl_receipts_report.php\')" onclick="top.restoreSession()">' . '['. xlt('Reports') .']'. '</a> &nbsp; </span>';
522 if (acl_check('acct', 'eob')) {
523 print '<span class=text><a href="javascript:void window.open(\'sl_eob_search.php\')" onclick="top.restoreSession()">' . '['.xlt('EOBs') .']' . '</a></span>';
527 </td>
528 </tr>
529 <tr>
530 <td>&nbsp;</td>
531 <td>
532 <?php if (! file_exists($EXPORT_INC)) { ?>
533 <!--
534 <a href="javascript:top.restoreSession();document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
535 title="Process all queued bills to create electronic data (and print if requested)"><?php echo '['. xlt('Start Batch Processing') .']' ?></a>
536 &nbsp;
538 <a href='customize_log.php' onclick='top.restoreSession()' target='_blank' class='link_submit'
539 title='<?php xla('See messages from the last set of generated claims'); ?>'><?php echo '['. xlt('View Log') .']'?></a>
540 <?php } ?>
541 </td>
542 </tr>
543 <tr>
544 <td>&nbsp;</td>
545 <td><a href="javascript:select_all()" class="link_submit"><?php echo '['. xlt('Select All') .']'?></a></td>
546 </tr>
547 </table>
550 </td>
551 </tr>
552 </table>
553 <table width='100%' border="0" cellspacing="0" cellpadding="0" >
554 <tr>
555 <td>
556 <hr color="#000000">
557 </td>
558 </tr>
559 </table>
560 </form>
561 <form name='update_form' method='post' action='billing_process.php' onsubmit='return top.restoreSession()' style="display:inline">
562 <center>
563 <span class='text' style="display:inline">
564 <?php if (file_exists($EXPORT_INC)) { ?>
565 <input type="submit" class="subbtn" name="bn_external" value="Export Billing" title="<?php echo xla('Export to external billing system') ?>">
566 <input type="submit" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php echo xla('Mark as billed but skip billing') ?>">
567 <?php } else { ?>
568 <!--
569 <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') ?>">
570 <input type="submit" class="subbtn" name="bn_hcfa" value="Queue HCFA" title="<?php echo xla('Queue for HCFA batch processing')?>">
571 <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')?>">
572 <input type="submit" class="subbtn" name="bn_ub92" value="Queue UB92" title="<?php echo xla('Queue for UB-92 batch processing')?>">
574 <input type="submit" class="subbtn" name="bn_x12" value="<?php echo xla('Generate X12')?>"
575 title="<?php echo xla('Generate and download X12 batch')?>"
576 onclick="MarkAsCleared(1)">
577 <?php if ($GLOBALS['support_encounter_claims']) { ?>
578 <input type="submit" class="subbtn" name="bn_x12_encounter" value="<?php echo xla('Generate X12 Encounter')?>"
579 title="<?php echo xla('Generate and download X12 encounter claim batch')?>"
580 onclick="MarkAsCleared(1)">
581 <?php } ?>
582 <input type="submit" class="subbtn" style="width:175px;" name="bn_process_hcfa" value="<?php echo xla('Generate CMS 1500 PDF')?>"
583 title="<?php echo xla('Generate and download CMS 1500 paper claims')?>"
584 onclick="MarkAsCleared(2)">
585 <input type="submit" class="subbtn" style="width:175px;" name="bn_hcfa_txt_file" value="<?php echo xla('Generate CMS 1500 TEXT')?>"
586 title="<?php echo xla('Making batch text files for uploading to Clearing House and will mark as billed')?>"
587 onclick="MarkAsCleared(3)">
588 <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')?>">
589 <input type="submit" class="subbtn" name="bn_reopen" value="<?php echo xla('Re-Open')?>" title="<?php echo xla('Mark as not billed')?>">
590 <!--
591 <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')?>">
593 &nbsp;&nbsp;&nbsp;
594 <?php echo xlt('CMS 1500 Margins'); ?>:
595 &nbsp;<?php echo xlt('Left'); ?>:
596 <input type='text' size='2' name='left_margin'
597 value='<?php echo attr($left_margin); ?>'
598 title='<?php echo xla('HCFA left margin in points'); ?>' />
599 &nbsp;<?php echo xlt('Top'); ?>:
600 <input type='text' size='2' name='top_margin'
601 value='<?php echo attr($top_margin); ?>'
602 title='<?php echo xla('HCFA top margin in points'); ?>' />
603 </span>
604 <?php } ?>
606 </center>
607 <input type='hidden' name='HiddenMarkAsCleared' id='HiddenMarkAsCleared' value="" />
608 <input type='hidden' name='mode' value="bill" />
609 <input type='hidden' name='authorized' value="<?php echo attr($my_authorized); ?>" />
610 <input type='hidden' name='unbilled' value="<?php echo attr($unbilled); ?>" />
611 <input type='hidden' name='code_type' value="%" />
612 <input type='hidden' name='to_date' value="<?php echo attr($to_date); ?>" />
613 <input type='hidden' name='from_date' value="<?php echo attr($from_date); ?>" />
615 <?php
616 if ($my_authorized == "on" ) {
617 $my_authorized = "1";
618 } else {
619 $my_authorized = "%";
621 if ($unbilled == "on") {
622 $unbilled = "0";
623 } else {
624 $unbilled = "%";
626 $list = getBillsListBetween("%");
629 <input type='hidden' name='bill_list' value="<?php echo attr($list); ?>" />
631 <!-- new form for uploading -->
633 <?php
634 if (!isset($_POST["mode"])) {
635 if (!isset($_POST["from_date"])) {
636 $from_date = date("Y-m-d");
637 } else {
638 $from_date = $_POST["from_date"];
640 if (empty($_POST["to_date"])) {
641 $to_date = '';
642 } else {
643 $to_date = $_POST["to_date"];
645 if (!isset($_POST["code_type"])) {
646 $code_type="all";
647 } else {
648 $code_type = $_POST["code_type"];
650 if (!isset($_POST["unbilled"])) {
651 $unbilled = "on";
652 } else {
653 $unbilled = $_POST["unbilled"];
655 if (!isset($_POST["authorized"])) {
656 $my_authorized = "on";
657 } else {
658 $my_authorized = $_POST["authorized"];
660 } else {
661 $from_date = $_POST["from_date"];
662 $to_date = $_POST["to_date"];
663 $code_type = $_POST["code_type"];
664 $unbilled = $_POST["unbilled"];
665 $my_authorized = $_POST["authorized"];
668 if ($my_authorized == "on" ) {
669 $my_authorized = "1";
670 } else {
671 $my_authorized = "%";
674 if ($unbilled == "on") {
675 $unbilled = "0";
676 } else {
677 $unbilled = "%";
680 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
681 billCodesList($list);
685 <table border="0" cellspacing="0" cellpadding="0" width="100%">
687 <?php
688 $divnos=0;
689 if ($ret = getBillsBetween("%"))
691 if(is_array($ret))
694 <tr ><td colspan='8' align="right" ><table width="250" border="0" cellspacing="0" cellpadding="0">
695 <tr>
696 <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>
697 <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>
698 <td width="50">&nbsp;</td>
699 </tr>
700 </table>
701 </td></tr>
702 <?php
704 $loop = 0;
705 $oldcode = "";
706 $last_encounter_id = "";
707 $lhtml = "";
708 $rhtml = "";
709 $lcount = 0;
710 $rcount = 0;
711 $bgcolor = "";
712 $skipping = FALSE;
714 $mmo_empty_mod = false;
715 $mmo_num_charges = 0;
717 foreach ($ret as $iter) {
719 // We include encounters here that have never been billed. However
720 // if it had no selected billing items but does have non-selected
721 // billing items, then it is not of interest.
722 if (!$iter['id']) {
723 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
724 "encounter = ? AND " .
725 "pid=? AND " .
726 "activity = 1", array($iter['enc_encounter'],$iter['enc_pid']) );
727 if ($res['count'] > 0) continue;
730 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
732 if ($last_encounter_id != $this_encounter_id) {
734 // This dumps all HTML for the previous encounter.
736 if ($lhtml) {
737 while ($rcount < $lcount) {
738 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'></td></tr>";
739 ++$rcount;
741 // This test handles the case where we are only listing encounters
742 // that appear to have a missing "25" modifier.
743 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
744 if($DivPut=='yes')
746 $lhtml.='</div>';
747 $DivPut='no';
749 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
750 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n\n";
751 ++$encount;
755 $lhtml = "";
756 $rhtml = "";
757 $mmo_empty_mod = false;
758 $mmo_num_charges = 0;
760 // If there are ANY unauthorized items in this encounter and this is
761 // the normal case of viewing only authorized billing, then skip the
762 // entire encounter.
764 $skipping = FALSE;
765 if ($my_authorized == '1') {
766 $res = sqlQuery("select count(*) as count from billing where " .
767 "encounter = ? and " .
768 "pid=? and " .
769 "activity = 1 and authorized = 0", array($iter['enc_encounter'],$iter['enc_pid']) );
770 if ($res['count'] > 0) {
771 $skipping = TRUE;
772 $last_encounter_id = $this_encounter_id;
773 continue;
777 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
779 # Check if patient has primary insurance and a subscriber exists for it.
780 # If not we will highlight their name in red.
781 # TBD: more checking here.
783 $res = sqlQuery("select count(*) as count from insurance_data where " .
784 "pid = ? and " .
785 "type='primary' and " .
786 "subscriber_lname is not null and " .
787 "subscriber_lname != '' limit 1", array($iter['enc_pid']) );
788 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
790 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
791 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
792 $lcount = 1;
793 $rcount = 0;
794 $oldcode = "";
796 $ptname = $name['fname'] . " " . $name['lname'];
797 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
799 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
800 $lhtml .= "&nbsp;<span class=bold><font color='$namecolor'>". text($ptname) .
801 "</font></span><span class=small>&nbsp;(" . text($iter['enc_pid']) . "-" .
802 text($iter['enc_encounter']) . ")</span>";
804 //Encounter details are stored to javacript as array.
805 $result4 = sqlStatement("SELECT fe.encounter,fe.date,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
806 " 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']) );
807 if(sqlNumRows($result4)>0)
809 <script language='JavaScript'>
810 Count=0;
811 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
812 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
813 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
814 <?php
815 while($rowresult4 = sqlFetchArray($result4))
818 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars($rowresult4['encounter'], ENT_QUOTES); ?>';
819 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date']))), ENT_QUOTES); ?>';
820 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars( xl_appt_category($rowresult4['pc_catname']), ENT_QUOTES); ?>';
821 Count++;
822 <?php
825 </script>
826 <?php
828 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
829 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
830 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
831 ",'" . addslashes($name['pubpid']) .
832 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
833 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
834 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
835 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
836 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" .
837 xlt('To Enctr') . " " . text(oeFormatShortDate($raw_encounter_date)) . "]</a>";
839 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
840 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
841 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
842 ",'" . addslashes($name['pubpid']) .
843 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
844 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
845 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
846 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
847 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" . xlt('To Dems') . "]</a>";
848 $divnos=$divnos+1;
849 $lhtml .= "&nbsp;&nbsp;&nbsp;<a onclick='divtoggle(\"spanid_$divnos\",\"divid_$divnos\");' class='small' id='aid_$divnos' href=\"JavaScript:void(0);".
850 "\">(<span id=spanid_$divnos class=\"indicator\">" . htmlspecialchars( xl('Expand'), ENT_QUOTES) . "</span>)</a>";
852 if ($iter['id']) {
854 $lcount += 2;
855 $lhtml .= "<br />\n";
856 $lhtml .= "&nbsp;<span class=text>Bill: ";
857 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' style='background-color:$bgcolor'>";
859 $query = "SELECT id.provider AS id, id.type, id.date, " .
860 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
861 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
862 "ic.id = id.provider AND " .
863 "id.pid = ? AND " .
864 "id.date <= ? " .
865 "ORDER BY id.type ASC, id.date DESC";
867 $result = sqlStatement($query, array($iter['enc_pid'],$raw_encounter_date) );
868 $count = 0;
869 $default_x12_partner = $iter['ic_x12id'];
870 $prevtype = '';
872 while ($row = sqlFetchArray($result)) {
873 if (strcmp($row['type'], $prevtype) == 0) continue;
874 $prevtype = $row['type'];
875 if (strlen($row['provider']) > 0) {
876 // This preserves any existing insurance company selection, which is
877 // important when EOB posting has re-queued for secondary billing.
878 $lhtml .= "<option value=\"" . attr(substr($row['type'],0,1).$row['id']) . "\"";
879 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
880 $lhtml .= " selected";
881 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
883 $lhtml .= ">" . text($row['type']) . ": " . text($row['provider']) . "</option>";
885 $count++;
888 $lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
889 $lhtml .= "</select>&nbsp;&nbsp;\n";
890 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][partner]' style='background-color:$bgcolor'>";
891 $x = new X12Partner();
892 $partners = $x->_utility_array($x->x12_partner_factory());
893 foreach ($partners as $xid => $xname) {
894 $lhtml .= '<option label="' . attr($xname) . '" value="' . attr($xid) .'"';
895 if ($xid == $default_x12_partner) {
896 $lhtml .= "selected";
898 $lhtml .= '>' . text($xname) . '</option>';
900 $lhtml .= "</select>";
901 $DivPut='yes';
902 $lhtml .= "<br>\n&nbsp;<div id='divid_$divnos' style='display:none'>" . text(oeFormatShortDate(substr($iter['date'], 0, 10)))
903 . text(substr($iter['date'], 10, 6)) . " " . xlt("Encounter was coded");
905 $query = "SELECT * FROM claims WHERE " .
906 "patient_id = ? AND " .
907 "encounter_id = ? " .
908 "ORDER BY version";
909 $cres = sqlStatement($query, array($iter['enc_pid'],$iter['enc_encounter']) );
911 $lastcrow = false;
913 while ($crow = sqlFetchArray($cres)) {
914 $query = "SELECT id.type, ic.name " .
915 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
916 "id.pid = ? AND " .
917 "id.provider = ? AND " .
918 "id.date <= ? AND " .
919 "ic.id = id.provider " .
920 "ORDER BY id.type ASC, id.date DESC";
922 $irow= sqlQuery($query, array($iter['enc_pid'],$crow['payer_id'],$raw_encounter_date) );
924 if ($crow['bill_process']) {
925 $lhtml .= "<br>\n&nbsp;" .
926 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
927 text(substr($crow['bill_time'], 10, 6)) . " " .
928 xlt("Queued for") . " " . text($irow['type']) . " " . text($crow['target']) . " " .
929 xlt("billing to ") . text($irow['name']);
930 ++$lcount;
932 else if ($crow['status'] < 6) {
933 if ($crow['status'] > 1) {
934 $lhtml .= "<br>\n&nbsp;" .
935 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
936 text(substr($crow['bill_time'], 10, 6)) . " " .
937 htmlspecialchars( xl("Marked as cleared"), ENT_QUOTES);
938 ++$lcount;
940 else {
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("Re-opened"), ENT_QUOTES);
945 ++$lcount;
948 else if ($crow['status'] == 6) {
949 $lhtml .= "<br>\n&nbsp;" .
950 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
951 text(substr($crow['bill_time'], 10, 6)) . " " .
952 htmlspecialchars( xl("This claim has been forwarded to next level."), ENT_QUOTES);
953 ++$lcount;
955 else if ($crow['status'] == 7) {
956 $lhtml .= "<br>\n&nbsp;" .
957 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
958 text(substr($crow['bill_time'], 10, 6)) . " " .
959 htmlspecialchars( xl("This claim has been denied.Reason:-"), ENT_QUOTES);
960 if($crow['process_file'])
962 $code_array=split(',',$crow['process_file']);
963 foreach($code_array as $code_key => $code_value)
965 $lhtml .= "<br>\n&nbsp;&nbsp;&nbsp;";
966 $reason_array=split('_',$code_value);
967 if(!isset($adjustment_reasons[$reason_array[3]]))
969 $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]).']';
971 else
973 $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]]);
977 else
979 $lhtml .=htmlspecialchars( xl("Not Specified."), ENT_QUOTES);
981 ++$lcount;
984 if ($crow['process_time']) {
985 $lhtml .= "<br>\n&nbsp;" .
986 text(oeFormatShortDate(substr($crow['process_time'], 0, 10))) .
987 text(substr($crow['process_time'], 10, 6)) . " " .
988 xlt("Claim was generated to file") . " " .
989 "<a href='get_claim_file.php?key=" . attr($crow['process_file']) .
990 "' onclick='top.restoreSession()'>" .
991 text($crow['process_file']) . "</a>";
992 ++$lcount;
995 $lastcrow = $crow;
996 } // end while ($crow = sqlFetchArray($cres))
998 if ($lastcrow && $lastcrow['status'] == 4) {
999 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been closed.");
1000 ++$lcount;
1003 if ($lastcrow && $lastcrow['status'] == 5) {
1004 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been canceled.");
1005 ++$lcount;
1007 } // end if ($iter['id'])
1009 } // end if ($last_encounter_id != $this_encounter_id)
1011 if ($skipping) continue;
1013 // Collect info related to the missing modifiers test.
1014 if ($iter['fee'] > 0) {
1015 ++$mmo_num_charges;
1016 $tmp = substr($iter['code'], 0, 3);
1017 if (($tmp == '992' || $tmp == '993') && empty($iter['modifier']))
1018 $mmo_empty_mod = true;
1021 ++$rcount;
1023 if ($rhtml) {
1024 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
1026 $rhtml .= "<td width='50'>";
1027 if ($iter['id'] && $oldcode != $iter['code_type']) {
1028 $rhtml .= "<span class=text>" . text($iter['code_type']) . ": </span>";
1031 $oldcode = $iter['code_type'];
1032 $rhtml .= "</td>\n";
1033 $justify = "";
1035 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
1036 $js = split(":",$iter['justify']);
1037 $counter = 0;
1038 foreach ($js as $j) {
1039 if(!empty($j)) {
1040 if ($counter == 0) {
1041 $justify .= " (<b>" . text($j) . "</b>)";
1043 else {
1044 $justify .= " (" . text($j) . ")";
1046 $counter++;
1051 $rhtml .= "<td><span class='text'>" .
1052 ($iter['code_type'] == 'COPAY' ? text(oeFormatMoney($iter['code'])) : text($iter['code']));
1053 if ($iter['modifier']) $rhtml .= ":" . text($iter['modifier']);
1054 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
1056 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1057 if ($iter['id'] && $iter['fee'] > 0) {
1058 $rhtml .= text(oeFormatMoney($iter['fee']));
1060 $rhtml .= "</span></td>\n";
1061 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1062 if ($iter['id']) $rhtml .= getProviderName(empty($iter['provider_id']) ? text($iter['enc_provider_id']) : text($iter['provider_id']));
1063 $rhtml .= "</span></td>\n";
1064 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1065 if ($iter['id']) $rhtml .= text(oeFormatSDFT(strtotime($iter{"date"})));
1066 $rhtml .= "</span></td>\n";
1067 if ($iter['id'] && $iter['authorized'] != 1) {
1068 $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";
1070 else {
1071 $rhtml .= "<td></td>\n";
1073 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
1074 $tmpbpr = $iter['bill_process'];
1075 if ($tmpbpr == '0' && $iter['billed']) $tmpbpr = '2';
1076 $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";
1077 $CheckBoxBilling++;
1079 else {
1080 $rhtml .= "<td></td>\n";
1082 if($last_encounter_id != $this_encounter_id){
1083 $rhtml2 = "";
1084 $rowcnt = 0;
1085 $resMoneyGot = sqlStatement("SELECT pay_amount as PatientPay,date(post_time) as date FROM ar_activity where ".
1086 "pid = ? and encounter = ? and payer_type=0 and account_code='PCP'",
1087 array($iter['enc_pid'],$iter['enc_encounter']));
1088 //new fees screen copay gives account_code='PCP'
1089 if(sqlNumRows($resMoneyGot) > 0){
1090 $lcount += 2;
1091 $rcount++;
1093 //checks whether a copay exists for the encounter and if exists displays it.
1094 while($rowMoneyGot = sqlFetchArray($resMoneyGot)){
1095 $rowcnt++;
1096 $PatientPay=$rowMoneyGot['PatientPay'];
1097 $date=$rowMoneyGot['date'];
1098 if($PatientPay > 0){
1099 if($rhtml){
1100 $rhtml2 .= "<tr bgcolor='$bgcolor'>\n";
1102 $rhtml2 .= "<td width='50'>";
1103 $rhtml2 .= "<span class='text'>".xlt('COPAY').": </span>";
1104 $rhtml2 .= "</td>\n";
1105 $rhtml2 .= "<td><span class='text'>".text(oeFormatMoney($PatientPay))."</span><span style='font-size:8pt;'>&nbsp;</span></td>\n";
1106 $rhtml2 .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1107 $rhtml2 .= "</span></td>\n";
1108 $rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1109 $rhtml2 .= "</span></td>\n";
1110 $rhtml2 .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1111 $rhtml2 .= text(oeFormatSDFT(strtotime($date)));
1112 $rhtml2 .= "</span></td>\n";
1113 if ($iter['id'] && $iter['authorized'] != 1) {
1114 $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";
1115 }else{
1116 $rhtml2 .= "<td></td>\n";
1118 if(!$iter['id'] && $rowcnt == 1){
1119 $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";
1120 $CheckBoxBilling++;
1121 }else{
1122 $rhtml2 .= "<td></td>\n";
1126 $rhtml .= $rhtml2;
1128 $rhtml .= "</tr>\n";
1129 $last_encounter_id = $this_encounter_id;
1131 } // end foreach
1133 if ($lhtml) {
1134 while ($rcount < $lcount) {
1135 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'></td></tr>";
1136 ++$rcount;
1138 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
1139 if($DivPut=='yes')
1141 $lhtml.='</div>';
1142 $DivPut='no';
1144 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
1145 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
1153 </table>
1154 </form>
1156 <script>
1157 set_button_states();
1158 <?php
1159 if ($alertmsg) {
1160 echo "alert('".addslashes($alertmsg)."');\n";
1163 </script>
1164 <input type="hidden" name="divnos" id="divnos" value="<?php echo attr($divnos) ?>"/>
1165 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1166 </body>
1167 </html>