changes to prior commit
[openemr.git] / interface / billing / billing_report.php
blob01cf962aa0a3a27735aad0f2bac086c0a3a0da2d
1 <?php
2 /*
3 * Billing Report Program
5 * This program displays the main search and select screen for claims generation
7 * Copyright (C) 2016 Terry Hill <terry@lillysystems.com>
8 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see http://opensource.org/licenses/gpl-license.php.
21 * @package OpenEMR
22 * @author Terry Hill <terry@lilysystems.com>
23 * @author Brady Miller <brady.g.miller@gmail.com>
24 * @link http://www.open-emr.org
30 require_once("../globals.php");
31 require_once("../../library/acl.inc");
32 require_once("../../custom/code_types.inc.php");
33 require_once("$srcdir/patient.inc");
34 include_once("$srcdir/../interface/reports/report.inc.php");//Criteria Section common php page
35 require_once("$srcdir/billrep.inc");
36 require_once("$srcdir/options.inc.php");
37 require_once("adjustment_reason_codes.php");
39 $EXPORT_INC = "$webserver_root/custom/BillingExport.php";
40 //echo $GLOBALS['daysheet_provider_totals'];
42 $daysheet = false;
43 $daysheet_total = false;
44 $provider_run = false;
46 if ($GLOBALS['use_custom_daysheet'] != 0) {
47 $daysheet = true;
48 if ($GLOBALS['daysheet_provider_totals'] == 1) {
49 $daysheet_total = true;
50 $provider_run = false;
52 if ($GLOBALS['daysheet_provider_totals'] == 0) {
53 $daysheet_total = false;
54 $provider_run = true;
58 $alertmsg = '';
60 if (isset($_POST['mode'])) {
61 if ($_POST['mode'] == 'export') {
62 $sql = ReturnOFXSql();
63 $db = get_db();
64 $results = $db->Execute($sql);
65 $billings = array();
66 if ($results->RecordCount() == 0) {
67 echo xlt("No Bills Found to Include in OFX Export")."<br>";
68 } else {
69 while(!$results->EOF) {
70 $billings[] = $results->fields;
71 $results->MoveNext();
73 $ofx = new OFX($billings);
74 header("Pragma: public");
75 header("Expires: 0");
76 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
77 header("Content-Disposition: attachment; filename=openemr_ofx.ofx");
78 header("Content-Type: text/xml");
79 echo $ofx->get_OFX();
80 exit;
85 //global variables:
86 $from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
87 $to_date = isset($_POST['to_date' ]) ? $_POST['to_date' ] : '';
88 $code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
89 $unbilled = isset($_POST['unbilled' ]) ? $_POST['unbilled' ] : 'on';
90 $my_authorized = isset($_POST["authorized"]) ? $_POST["authorized"] : '';
93 // This tells us if only encounters that appear to be missing a "25" modifier
94 // are to be reported.
95 $missing_mods_only = (isset($_POST['missing_mods_only']) && !empty($_POST['missing_mods_only']));
97 $left_margin = isset($_POST["left_margin"]) ? $_POST["left_margin"] : $GLOBALS['cms_left_margin_default'];
98 $top_margin = isset($_POST["top_margin"] ) ? $_POST["top_margin" ] : $GLOBALS['cms_top_margin_default'];
100 $ofrom_date = $from_date;
101 $oto_date = $to_date;
102 $ocode_type = $code_type;
103 $ounbilled = $unbilled;
104 $oauthorized = $my_authorized;
107 <html>
108 <head>
109 <?php if (function_exists('html_header_show')) html_header_show(); ?>
110 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
111 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
113 <style>
114 .subbtn { margin-top:3px; margin-bottom:3px; margin-left:2px; margin-right:2px }
115 </style>
116 <script>
118 function select_all() {
119 for($i=0;$i < document.update_form.length;$i++) {
120 $name = document.update_form[$i].name;
121 if ($name.substring(0,7) == "claims[" && $name.substring($name.length -6) == "[bill]") {
122 document.update_form[$i].checked = true;
125 set_button_states();
128 function set_button_states() {
129 var f = document.update_form;
130 var count0 = 0; // selected and not billed or queued
131 var count1 = 0; // selected and queued
132 var count2 = 0; // selected and billed
133 for($i = 0; $i < f.length; ++$i) {
134 $name = f[$i].name;
135 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -6) == "[bill]" && f[$i].checked == true) {
136 if (f[$i].value == '0') ++count0;
137 else if (f[$i].value == '1' || f[$i].value == '5') ++count1;
138 else ++count2;
142 var can_generate = (count0 > 0 || count1 > 0 || count2 > 0);
143 var can_mark = (count1 > 0 || count0 > 0 || count2 > 0);
144 var can_bill = (count0 == 0 && count1 == 0 && count2 > 0);
146 <?php if (file_exists($EXPORT_INC)) { ?>
147 f.bn_external.disabled = !can_generate;
148 <?php } else { ?>
149 // f.bn_hcfa_print.disabled = !can_generate;
150 // f.bn_hcfa.disabled = !can_generate;
151 // f.bn_ub92_print.disabled = !can_generate;
152 // f.bn_ub92.disabled = !can_generate;
153 f.bn_x12.disabled = !can_generate;
154 <?php if ($GLOBALS['support_encounter_claims']) { ?>
155 f.bn_x12_encounter.disabled = !can_generate;
156 <?php } ?>
157 f.bn_process_hcfa.disabled = !can_generate;
158 <?php if ($GLOBALS['preprinted_cms_1500']) { ?>
159 f.bn_process_hcfa_form.disabled = !can_generate;
160 <?php } ?>
161 f.bn_hcfa_txt_file.disabled = !can_generate;
162 // f.bn_electronic_file.disabled = !can_bill;
163 f.bn_reopen.disabled = !can_bill;
164 <?php } ?>
165 f.bn_mark.disabled = !can_mark;
168 // Process a click to go to an encounter.
169 function toencounter(pid, pubpid, pname, enc, datestr, dobstr) {
170 top.restoreSession();
171 encurl = 'patient_file/encounter/encounter_top.php?set_encounter=' + enc + '&pid=' + pid;
172 parent.left_nav.setPatient(pname,pid,pubpid,'',dobstr);
173 <?php if ($GLOBALS['new_tabs_layout']) { ?>
174 parent.left_nav.setEncounter(datestr, enc, 'enc');
175 parent.left_nav.loadFrame('enc2', 'enc', encurl);
176 <?php } else { ?>
177 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
178 parent.left_nav.setEncounter(datestr, enc, othername);
179 parent.frames[othername].location.href = '../' + encurl;
180 <?php } ?>
182 // Process a click to go to an patient.
183 function topatient(pid, pubpid, pname, enc, datestr, dobstr) {
184 top.restoreSession();
185 paturl = 'patient_file/summary/demographics_full.php?pid=' + pid;
186 parent.left_nav.setPatient(pname,pid,pubpid,'',dobstr);
187 <?php if ($GLOBALS['new_tabs_layout']) { ?>
188 parent.left_nav.loadFrame('ens1', 'enc', 'patient_file/history/encounters.php?pid=' + pid);
189 parent.left_nav.loadFrame('dem1', 'pat', paturl);
190 <?php } else { ?>
191 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
192 parent.frames[othername].location.href = '../' + paturl;
193 <?php } ?>
195 </script>
196 <script language="javascript" type="text/javascript">
197 EncounterDateArray=new Array;
198 CalendarCategoryArray=new Array;
199 EncounterIdArray=new Array;
200 EncounterNoteArray=new Array;
201 function SubmitTheScreen()
202 {//Action on Update List link
203 if(!ProcessBeforeSubmitting())
204 return false;
205 top.restoreSession();
206 document.the_form.mode.value='change';
207 document.the_form.target='_self';
208 document.the_form.action='billing_report.php';
209 document.the_form.submit();
210 return true;
212 function SubmitTheScreenPrint()
213 {//Action on View Printable Report link
214 if(!ProcessBeforeSubmitting())
215 return false;
216 top.restoreSession();
217 document.the_form.target='new';
218 document.the_form.action='print_billing_report.php';
219 document.the_form.submit();
220 return true;
222 function SubmitTheEndDayPrint()
223 {//Action on View End of Day Report link
224 if(!ProcessBeforeSubmitting())
225 return false;
226 top.restoreSession();
227 document.the_form.target='new';
228 <?php if ($GLOBALS['use_custom_daysheet'] == 1) { ?>
229 document.the_form.action='print_daysheet_report_num1.php';
230 <?php } ?>
231 <?php if ($GLOBALS['use_custom_daysheet'] == 2) { ?>
232 document.the_form.action='print_daysheet_report_num2.php';
233 <?php } ?>
234 <?php if ($GLOBALS['use_custom_daysheet'] == 3) { ?>
235 document.the_form.action='print_daysheet_report_num3.php';
236 <?php } ?>
237 document.the_form.submit();
238 return true;
240 function SubmitTheScreenExportOFX()
241 {//Action on Export OFX link
242 if(!ProcessBeforeSubmitting())
243 return false;
244 top.restoreSession();
245 document.the_form.mode.value='export';
246 document.the_form.target='_self';
247 document.the_form.action='billing_report.php';
248 document.the_form.submit();
249 return true;
251 function TestExpandCollapse()
252 {//Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
253 var set=-1;
254 for(i=1;i<=document.getElementById("divnos").value;i++)
256 var ele = document.getElementById("divid_"+i);
257 if(ele)
259 set=1;
260 break;
263 if(set==-1)
265 if(document.getElementById("ExpandAll"))
267 document.getElementById("ExpandAll").innerHTML='';
268 document.getElementById("CollapseAll").innerHTML='';
272 function expandcollapse(atr){
273 if(atr == "expand") {//Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
274 for(i=1;i<=document.getElementById("divnos").value;i++){
275 var mydivid="divid_"+i;var myspanid="spanid_"+i;
276 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
277 if(ele)
279 ele.style.display = "inline";text.innerHTML = "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
283 else {
284 for(i=1;i<=document.getElementById("divnos").value;i++){
285 var mydivid="divid_"+i;var myspanid="spanid_"+i;
286 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
287 if(ele)
289 ele.style.display = "none"; text.innerHTML = "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
295 function divtoggle(spanid, divid) {//Called in the Expand, Collapse links(This is for a single item)
296 var ele = document.getElementById(divid);
297 if(ele)
299 var text = document.getElementById(spanid);
300 if(ele.style.display == "inline") {
301 ele.style.display = "none";
302 text.innerHTML = "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
304 else {
305 ele.style.display = "inline";
306 text.innerHTML = "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
310 function MarkAsCleared(Type)
312 CheckBoxBillingCount=0;
313 for (var CheckBoxBillingIndex =0; ; CheckBoxBillingIndex++)
315 CheckBoxBillingObject=document.getElementById('CheckBoxBilling'+CheckBoxBillingIndex);
316 if(!CheckBoxBillingObject)
317 break;
318 if(CheckBoxBillingObject.checked)
320 ++CheckBoxBillingCount;
323 if(Type==1)
325 Message='<?php echo htmlspecialchars( xl('After saving your batch, click [View Log] to check for errors.'), ENT_QUOTES); ?>';
327 if(Type==2)
329 Message='<?php echo htmlspecialchars( xl('After saving the PDF, click [View Log] to check for errors.'), ENT_QUOTES); ?>';
331 if(Type==3)
333 Message='<?php echo htmlspecialchars( xl('After saving the TEXT file(s), click [View Log] to check for errors.'), ENT_QUOTES); ?>';
335 if(confirm(Message + "\n\n\n<?php echo addslashes( xl('Total') ); ?>" + ' ' + CheckBoxBillingCount + ' ' + "<?php echo addslashes( xl('Selected') ); ?>\n" +
336 "<?php echo addslashes( xl('Would You Like them to be Marked as Cleared.') ); ?>"))
338 document.getElementById('HiddenMarkAsCleared').value='yes';
340 else
342 document.getElementById('HiddenMarkAsCleared').value='';
345 </script>
346 <?php include_once("$srcdir/../interface/reports/report.script.php"); ?><!-- Criteria Section common javascript page-->
347 <!-- ================================================== -->
348 <!-- =============Included for Insurance ajax criteria==== -->
349 <!-- ================================================== -->
350 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script>
351 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
352 <script type="text/javascript" src="../../library/js/common.js?v=<?php echo $v_js_includes; ?>"></script>
353 <style>
354 #ajax_div_insurance {
355 position: absolute;
356 z-index:10;
357 background-color: #FBFDD0;
358 border: 1px solid #ccc;
359 padding: 10px;
361 </style>
362 <script language="javascript" type="text/javascript">
363 document.onclick=TakeActionOnHide;
364 </script>
365 <!-- ================================================== -->
366 <!-- =============Included for Insurance ajax criteria==== -->
367 <!-- ================================================== -->
368 </head>
369 <body class="body_top" onLoad="TestExpandCollapse()">
371 <p style='margin-top:5px;margin-bottom:5px;margin-left:5px'>
373 <font class='title'><?php echo xlt('Billing Manager') ?></font>
375 </p>
377 <form name='the_form' method='post' action='billing_report.php' onsubmit='return top.restoreSession()' style="display:inline">
379 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
380 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
381 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
382 <script language='JavaScript'>
383 var mypcc = '1';
384 </script>
386 <input type='hidden' name='mode' value='change'>
387 <!-- ============================================================================================================================================= -->
388 <!-- Criteria section Starts -->
389 <!-- ============================================================================================================================================= -->
390 <?php
391 //The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
392 //Each item is seperated by a comma(,).
393 //$ThisPageSearchCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
394 //$ThisPageSearchCriteriaKeyMaster ==>Corresponding database fields in the same order.
395 //$ThisPageSearchCriteriaDataTypeMaster ==>Corresponding data type in the same order.
396 $ThisPageSearchCriteriaDisplayRadioMaster=array();
397 $ThisPageSearchCriteriaRadioKeyMaster=array();
398 $ThisPageSearchCriteriaQueryDropDownMaster=array();
399 $ThisPageSearchCriteriaQueryDropDownMasterDefault=array();
400 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey=array();
401 $ThisPageSearchCriteriaIncludeMaster=array();
403 if ($daysheet) {
404 $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") );
405 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
406 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
407 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id,billing.user";
408 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
409 "text,include,text,radio,radio,radio,".
410 "radio_like,radio,query_drop_down,text";
412 else
415 $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") );
416 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
417 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
418 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id";
419 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
420 "text,include,text,radio,radio,radio,".
421 "radio_like,radio,query_drop_down";
426 //The below section is needed if there is any 'radio' or 'radio_like' type in the $ThisPageSearchCriteriaDataTypeMaster
427 //$ThisPageSearchCriteriaDisplayRadioMaster,$ThisPageSearchCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
428 //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.
429 $ThisPageSearchCriteriaDisplayRadioMaster[1] = array( xl("All"),xl("eClaims"),xl("Paper") );//Display Value
430 $ThisPageSearchCriteriaRadioKeyMaster[1]="all,standard,hcfa";//Key
431 $ThisPageSearchCriteriaDisplayRadioMaster[2]= array( xl("All"),xl("Insured"),xl("Non-Insured") );//Display Value
432 $ThisPageSearchCriteriaRadioKeyMaster[2]="all,1,0";//Key
433 $ThisPageSearchCriteriaDisplayRadioMaster[3]= array( xl("All"),xl("Coded"),xl("Not Coded") );//Display Value
434 $ThisPageSearchCriteriaRadioKeyMaster[3]="all,not null,null";//Key
435 $ThisPageSearchCriteriaDisplayRadioMaster[4]= array( xl("All"),xl("Unbilled"),xl("Billed"),xl("Denied") );//Display Value
436 $ThisPageSearchCriteriaRadioKeyMaster[4]="all,0,1,7";//Key
437 $ThisPageSearchCriteriaDisplayRadioMaster[5]= array( xl("All"),xl("Authorized"),xl("Unauthorized") );
438 $ThisPageSearchCriteriaRadioKeyMaster[5]="%,1,0";
439 $ThisPageSearchCriteriaDisplayRadioMaster[6]= array( xl("All"),xl("None"),xl("Ins 1"),xl("Ins 2 or Ins 3") );
440 $ThisPageSearchCriteriaRadioKeyMaster[6]="all,0,1,2";
441 //The below section is needed if there is any 'query_drop_down' type in the $ThisPageSearchCriteriaDataTypeMaster
442 $ThisPageSearchCriteriaQueryDropDownMaster[1]="SELECT name,id FROM x12_partners;";
443 $ThisPageSearchCriteriaQueryDropDownMasterDefault[1]= xl("All");//Only one item will be here
444 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey[1]="all";//Only one item will be here
445 //The below section is needed if there is any 'include' type in the $ThisPageSearchCriteriaDataTypeMaster
446 //Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
447 //It is labled(Included for Insurance ajax criteria)(Line:-279-299).
448 $ThisPageSearchCriteriaIncludeMaster[1]="InsuranceCompanyDisplay";//This is php function defined in the file 'report.inc.php'
450 if(!isset($_REQUEST['mode']))//default case
452 $_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")."')";
453 $_REQUEST['final_this_page_criteria'][1]="billing.billed = '0'";
455 $_REQUEST['final_this_page_criteria_text'][0]=xl("Date of Service = Today");
456 $_REQUEST['final_this_page_criteria_text'][1]=xl("Billing Status = Unbilled");
458 $_REQUEST['date_master_criteria_form_encounter_date']="today";
459 $_REQUEST['master_from_date_form_encounter_date']=date("Y-m-d");
460 $_REQUEST['master_to_date_form_encounter_date']=date("Y-m-d");
462 $_REQUEST['radio_billing_billed']=0;
466 <table width='100%' border="0" cellspacing="0" cellpadding="0">
467 <tr>
468 <td width="25%">&nbsp;</td>
469 <td width="50%">
470 <?php include_once("$srcdir/../interface/reports/criteria.tab.php"); ?>
471 </td>
472 <td width="25%">
473 <?php
474 // ============================================================================================================================================= -->
475 // Criteria section Ends -->
476 // ============================================================================================================================================= -->
479 <table width="100%" border="0" cellspacing="0" cellpadding="0">
480 <tr>
481 <td width="15%">&nbsp;</td>
482 <td width="85%"><span class='text'><a onClick="javascript:return SubmitTheScreen();" href="#" class=link_submit>[<?php echo xlt('Update List') ?>]</a>
484 <a onClick="javascript:return SubmitTheScreenExportOFX();" href="#" class='link_submit'><?php echo '[' . xlt('Export OFX') .']' ?></a></span> </td>
485 </tr>
486 <tr>
487 <td>&nbsp;</td>
488 <td><a onClick="javascript:return SubmitTheScreenPrint();" href="#"
489 class='link_submit' ><?php echo '['. xlt('View Printable Report').']' ?></a></td>
490 </tr>
492 <?php if ($daysheet) { ?>
493 <tr>
494 <td>&nbsp;</td>
495 <td><a onClick="javascript:return SubmitTheEndDayPrint();" href="#"
496 class='link_submit' ><?php echo '['.xlt('End Of Day Report').']' ?></a>
497 <?php if ($daysheet_total) { ?>
498 <span class=text><?php echo xlt('Totals'); ?> </span>
499 <input type=checkbox name="end_of_day_totals_only" value="1" <?php if ($obj['end_of_day_totals_only'] === '1') echo "checked";?>>
500 <?php } ?>
501 <?php if ($provider_run) { ?>
502 <span class=text><?php echo xlt('Provider'); ?> </span>
503 <input type=checkbox name="end_of_day_provider_only" value="1" <?php if ($obj['end_of_day_provider_only'] === '1') echo "checked";?>>
504 <?php } ?>
505 </td>
506 </tr>
507 <?php } ?>
508 <tr>
509 <td>&nbsp;</td>
510 <td>
511 <?php if (! file_exists($EXPORT_INC)) { ?>
512 <!--
513 <a href="javascript:top.restoreSession();document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
514 title="Process all queued bills to create electronic data (and print if requested)"><?php echo '['. xlt('Start Batch Processing') .']' ?></a>
515 &nbsp;
517 <a href='#' id="view-log-link" class='link_submit'
518 title='<?php xla('See messages from the last set of generated claims'); ?>'><?php echo '['. xlt('View Log') .']'?></a>
519 <?php } ?>
520 </td>
521 </tr>
522 <tr>
523 <td>&nbsp;</td>
524 <td><a href="javascript:select_all()" class="link_submit"><?php echo '['. xlt('Select All') .']'?></a></td>
525 </tr>
526 </table>
529 </td>
530 </tr>
531 </table>
532 <table width='100%' border="0" cellspacing="0" cellpadding="0" >
533 <tr>
534 <td>
535 <hr color="#000000">
536 </td>
537 </tr>
538 </table>
539 </form>
540 <form name='update_form' method='post' action='billing_process.php' onsubmit='return top.restoreSession()' style="display:inline">
541 <center>
542 <span class='text' style="display:inline">
543 <?php if (file_exists($EXPORT_INC)) { ?>
544 <input type="submit" data-open-popup="true" class="subbtn" name="bn_external" value="Export Billing" title="<?php echo xla('Export to external billing system') ?>">
545 <input type="submit" data-open-popup="true" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php echo xla('Mark as billed but skip billing') ?>">
546 <?php } else { ?>
547 <!--
548 <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') ?>">
549 <input type="submit" class="subbtn" name="bn_hcfa" value="Queue HCFA" title="<?php echo xla('Queue for HCFA batch processing')?>">
550 <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')?>">
551 <input type="submit" class="subbtn" name="bn_ub92" value="Queue UB92" title="<?php echo xla('Queue for UB-92 batch processing')?>">
553 <input type="submit" class="subbtn" name="bn_x12" value="<?php echo xla('Generate X12')?>"
554 title="<?php echo xla('Generate and download X12 batch')?>"
555 onclick="MarkAsCleared(1)">
556 <?php if ($GLOBALS['support_encounter_claims']) { ?>
557 <input type="submit" class="subbtn" name="bn_x12_encounter" value="<?php echo xla('Generate X12 Encounter')?>"
558 title="<?php echo xla('Generate and download X12 encounter claim batch')?>"
559 onclick="MarkAsCleared(1)">
560 <?php } ?>
561 <input type="submit" class="subbtn" style="width:105px;" name="bn_process_hcfa" value="<?php echo xla('CMS 1500 PDF')?>"
562 title="<?php echo xla('Generate and download CMS 1500 paper claims')?>"
563 onclick="MarkAsCleared(2)">
564 <?php if ($GLOBALS['preprinted_cms_1500']) { ?>
565 <input type="submit" class="subbtn" style="width:210px;" name="bn_process_hcfa_form" value="<?php echo xla('CMS 1500 PREPRINTED FORM')?>"
566 title="<?php echo xla('Generate and download CMS 1500 paper claims on Preprinted form')?>"
567 onclick="MarkAsCleared(2)">
568 <?php } ?>
569 <input type="submit" class="subbtn" style="width:120px;" name="bn_hcfa_txt_file" value="<?php echo xla('CMS 1500 TEXT')?>"
570 title="<?php echo xla('Making batch text files for uploading to Clearing House and will mark as billed')?>"
571 onclick="MarkAsCleared(3)">
572 <input type="submit" data-open-popup="true" class="subbtn" name="bn_mark" value="<?php echo xla('Mark as Cleared')?>" title="<?php echo xla('Post to accounting and mark as billed')?>">
573 <input type="submit" data-open-popup="true" class="subbtn" name="bn_reopen" value="<?php echo xla('Re-Open')?>" title="<?php echo xla('Mark as not billed')?>">
574 <!--
575 <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')?>">
577 &nbsp;&nbsp;&nbsp;
578 <?php echo xlt('CMS 1500 Margins'); ?>:
579 &nbsp;<?php echo xlt('Left'); ?>:
580 <input type='text' size='2' name='left_margin'
581 value='<?php echo attr($left_margin); ?>'
582 title='<?php echo xla('HCFA left margin in points'); ?>' />
583 &nbsp;<?php echo xlt('Top'); ?>:
584 <input type='text' size='2' name='top_margin'
585 value='<?php echo attr($top_margin); ?>'
586 title='<?php echo xla('HCFA top margin in points'); ?>' />
587 </span>
588 <?php } ?>
590 </center>
591 <input type='hidden' name='HiddenMarkAsCleared' id='HiddenMarkAsCleared' value="" />
592 <input type='hidden' name='mode' value="bill" />
593 <input type='hidden' name='authorized' value="<?php echo attr($my_authorized); ?>" />
594 <input type='hidden' name='unbilled' value="<?php echo attr($unbilled); ?>" />
595 <input type='hidden' name='code_type' value="%" />
596 <input type='hidden' name='to_date' value="<?php echo attr($to_date); ?>" />
597 <input type='hidden' name='from_date' value="<?php echo attr($from_date); ?>" />
599 <?php
600 if ($my_authorized == "on" ) {
601 $my_authorized = "1";
602 } else {
603 $my_authorized = "%";
605 if ($unbilled == "on") {
606 $unbilled = "0";
607 } else {
608 $unbilled = "%";
610 $list = getBillsListBetween("%");
613 <input type='hidden' name='bill_list' value="<?php echo attr($list); ?>" />
615 <!-- new form for uploading -->
617 <?php
618 if (!isset($_POST["mode"])) {
619 if (!isset($_POST["from_date"])) {
620 $from_date = date("Y-m-d");
621 } else {
622 $from_date = $_POST["from_date"];
624 if (empty($_POST["to_date"])) {
625 $to_date = '';
626 } else {
627 $to_date = $_POST["to_date"];
629 if (!isset($_POST["code_type"])) {
630 $code_type="all";
631 } else {
632 $code_type = $_POST["code_type"];
634 if (!isset($_POST["unbilled"])) {
635 $unbilled = "on";
636 } else {
637 $unbilled = $_POST["unbilled"];
639 if (!isset($_POST["authorized"])) {
640 $my_authorized = "on";
641 } else {
642 $my_authorized = $_POST["authorized"];
644 } else {
645 $from_date = $_POST["from_date"];
646 $to_date = $_POST["to_date"];
647 $code_type = $_POST["code_type"];
648 $unbilled = $_POST["unbilled"];
649 $my_authorized = $_POST["authorized"];
652 if ($my_authorized == "on" ) {
653 $my_authorized = "1";
654 } else {
655 $my_authorized = "%";
658 if ($unbilled == "on") {
659 $unbilled = "0";
660 } else {
661 $unbilled = "%";
664 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
665 billCodesList($list);
669 <table border="0" cellspacing="0" cellpadding="0" width="100%">
671 <?php
672 $divnos=0;
673 if ($ret = getBillsBetween("%"))
675 if(is_array($ret))
678 <tr ><td colspan='9' align="right" ><table width="250" border="0" cellspacing="0" cellpadding="0">
679 <tr>
680 <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>
681 <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>
682 <td width="50">&nbsp;</td>
683 </tr>
684 </table>
685 </td></tr>
686 <?php
688 $loop = 0;
689 $oldcode = "";
690 $last_encounter_id = "";
691 $lhtml = "";
692 $rhtml = "";
693 $lcount = 0;
694 $rcount = 0;
695 $bgcolor = "";
696 $skipping = FALSE;
698 $mmo_empty_mod = false;
699 $mmo_num_charges = 0;
701 foreach ($ret as $iter) {
703 // We include encounters here that have never been billed. However
704 // if it had no selected billing items but does have non-selected
705 // billing items, then it is not of interest.
706 if (!$iter['id']) {
707 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
708 "encounter = ? AND " .
709 "pid=? AND " .
710 "activity = 1", array($iter['enc_encounter'],$iter['enc_pid']) );
711 if ($res['count'] > 0) continue;
714 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
716 if ($last_encounter_id != $this_encounter_id) {
718 // This dumps all HTML for the previous encounter.
720 if ($lhtml) {
721 while ($rcount < $lcount) {
722 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='8'></td></tr>";
723 ++$rcount;
725 // This test handles the case where we are only listing encounters
726 // that appear to have a missing "25" modifier.
727 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
728 if($DivPut=='yes')
730 $lhtml.='</div>';
731 $DivPut='no';
733 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
734 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n\n";
735 ++$encount;
739 $lhtml = "";
740 $rhtml = "";
741 $mmo_empty_mod = false;
742 $mmo_num_charges = 0;
744 // If there are ANY unauthorized items in this encounter and this is
745 // the normal case of viewing only authorized billing, then skip the
746 // entire encounter.
748 $skipping = FALSE;
749 if ($my_authorized == '1') {
750 $res = sqlQuery("select count(*) as count from billing where " .
751 "encounter = ? and " .
752 "pid=? and " .
753 "activity = 1 and authorized = 0", array($iter['enc_encounter'],$iter['enc_pid']) );
754 if ($res['count'] > 0) {
755 $skipping = TRUE;
756 $last_encounter_id = $this_encounter_id;
757 continue;
761 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, billing_note, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
763 # Check if patient has primary insurance and a subscriber exists for it.
764 # If not we will highlight their name in red.
765 # TBD: more checking here.
767 $res = sqlQuery("select count(*) as count from insurance_data where " .
768 "pid = ? and " .
769 "type='primary' and " .
770 "subscriber_lname is not null and " .
771 "subscriber_lname != '' limit 1", array($iter['enc_pid']) );
772 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
774 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
775 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
776 $lcount = 1;
777 $rcount = 0;
778 $oldcode = "";
780 $ptname = $name['fname'] . " " . $name['lname'];
781 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
782 $billing_note = $name['billing_note'];
783 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
784 $lhtml .= "&nbsp;<span class=bold><font color='$namecolor'>". text($ptname) .
785 "</font></span><span class=small>&nbsp;(" . text($iter['enc_pid']) . "-" .
786 text($iter['enc_encounter']) . ")</span>";
788 //Encounter details are stored to javacript as array.
789 $result4 = sqlStatement("SELECT fe.encounter,fe.date,fe.billing_note,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
790 " 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']) );
791 if(sqlNumRows($result4)>0)
793 <script language='JavaScript'>
794 Count=0;
795 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
796 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
797 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
798 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>]=new Array;
799 <?php
800 while($rowresult4 = sqlFetchArray($result4))
803 EncounterIdArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars($rowresult4['encounter'], ENT_QUOTES); ?>';
804 EncounterDateArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date']))), ENT_QUOTES); ?>';
805 CalendarCategoryArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars( xl_appt_category($rowresult4['pc_catname']), ENT_QUOTES); ?>';
806 EncounterNoteArray[<?php echo attr($iter['enc_pid']); ?>][Count]='<?php echo htmlspecialchars($rowresult4['billing_note'], ENT_QUOTES); ?>';
807 Count++;
808 <?php
809 $enc_billing_note = $rowresult4['billing_note'];
812 </script>
813 <?php
815 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
816 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
817 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
818 ",'" . addslashes($name['pubpid']) .
819 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
820 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
821 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
822 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
823 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" .
824 xlt('To Enctr') . " " . text(oeFormatShortDate($raw_encounter_date)) . "]</a>";
826 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
827 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
828 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
829 ",'" . addslashes($name['pubpid']) .
830 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
831 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
832 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
833 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
834 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" . xlt('To Dems') . "]</a>";
835 $divnos=$divnos+1;
836 $lhtml .= "&nbsp;&nbsp;&nbsp;<a onclick='divtoggle(\"spanid_$divnos\",\"divid_$divnos\");' class='small' id='aid_$divnos' href=\"JavaScript:void(0);".
837 "\">(<span id=spanid_$divnos class=\"indicator\">" . htmlspecialchars( xl('Expand'), ENT_QUOTES) . '</span>)<br></a>';
838 if($GLOBALS['notes_to_display_in_Billing'] == 2 || $GLOBALS['notes_to_display_in_Billing'] == 3){
839 $lhtml .= '<span style="margin-left: 20px; font-weight bold; color: red">'.text($billing_note).'</span>';
842 if ($iter['id']) {
844 $lcount += 2;
845 $lhtml .= "<br />\n";
846 $lhtml .= "&nbsp;<span class=text>Bill: ";
847 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' style='background-color:$bgcolor'>";
849 $query = "SELECT id.provider AS id, id.type, id.date, " .
850 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
851 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
852 "ic.id = id.provider AND " .
853 "id.pid = ? AND " .
854 "id.date <= ? " .
855 "ORDER BY id.type ASC, id.date DESC";
857 $result = sqlStatement($query, array($iter['enc_pid'],$raw_encounter_date) );
858 $count = 0;
859 $default_x12_partner = $iter['ic_x12id'];
860 $prevtype = '';
862 while ($row = sqlFetchArray($result)) {
863 if (strcmp($row['type'], $prevtype) == 0) continue;
864 $prevtype = $row['type'];
865 if (strlen($row['provider']) > 0) {
866 // This preserves any existing insurance company selection, which is
867 // important when EOB posting has re-queued for secondary billing.
868 $lhtml .= "<option value=\"" . attr(substr($row['type'],0,1).$row['id']) . "\"";
869 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
870 $lhtml .= " selected";
871 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
873 $lhtml .= ">" . text($row['type']) . ": " . text($row['provider']) . "</option>";
875 $count++;
878 $lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
879 $lhtml .= "</select>&nbsp;&nbsp;\n";
880 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][partner]' style='background-color:$bgcolor'>";
881 $x = new X12Partner();
882 $partners = $x->_utility_array($x->x12_partner_factory());
883 foreach ($partners as $xid => $xname) {
884 $lhtml .= '<option label="' . attr($xname) . '" value="' . attr($xid) .'"';
885 if ($xid == $default_x12_partner) {
886 $lhtml .= "selected";
888 $lhtml .= '>' . text($xname) . '</option>';
890 $lhtml .= "</select>";
891 $DivPut='yes';
893 if($GLOBALS['notes_to_display_in_Billing'] == 1 || $GLOBALS['notes_to_display_in_Billing'] == 3) {
894 $lhtml .= "<br><span style='margin-left: 20px; font-weight bold; color: green'>".text($enc_billing_note)."</span>";
896 $lhtml .= "<br>\n&nbsp;<div id='divid_$divnos' style='display:none'>" . text(oeFormatShortDate(substr($iter['date'], 0, 10)))
897 . text(substr($iter['date'], 10, 6)) . " " . xlt("Encounter was coded");
899 $query = "SELECT * FROM claims WHERE " .
900 "patient_id = ? AND " .
901 "encounter_id = ? " .
902 "ORDER BY version";
903 $cres = sqlStatement($query, array($iter['enc_pid'],$iter['enc_encounter']) );
905 $lastcrow = false;
907 while ($crow = sqlFetchArray($cres)) {
908 $query = "SELECT id.type, ic.name " .
909 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
910 "id.pid = ? AND " .
911 "id.provider = ? AND " .
912 "id.date <= ? AND " .
913 "ic.id = id.provider " .
914 "ORDER BY id.type ASC, id.date DESC";
916 $irow= sqlQuery($query, array($iter['enc_pid'],$crow['payer_id'],$raw_encounter_date) );
918 if ($crow['bill_process']) {
919 $lhtml .= "<br>\n&nbsp;" .
920 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
921 text(substr($crow['bill_time'], 10, 6)) . " " .
922 xlt("Queued for") . " " . text($irow['type']) . " " . text($crow['target']) . " " .
923 xlt("billing to ") . text($irow['name']);
924 ++$lcount;
926 else if ($crow['status'] < 6) {
927 if ($crow['status'] > 1) {
928 $lhtml .= "<br>\n&nbsp;" .
929 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
930 text(substr($crow['bill_time'], 10, 6)) . " " .
931 htmlspecialchars( xl("Marked as cleared"), ENT_QUOTES);
932 ++$lcount;
934 else {
935 $lhtml .= "<br>\n&nbsp;" .
936 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
937 text(substr($crow['bill_time'], 10, 6)) . " " .
938 htmlspecialchars( xl("Re-opened"), ENT_QUOTES);
939 ++$lcount;
942 else if ($crow['status'] == 6) {
943 $lhtml .= "<br>\n&nbsp;" .
944 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
945 text(substr($crow['bill_time'], 10, 6)) . " " .
946 htmlspecialchars( xl("This claim has been forwarded to next level."), ENT_QUOTES);
947 ++$lcount;
949 else if ($crow['status'] == 7) {
950 $lhtml .= "<br>\n&nbsp;" .
951 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
952 text(substr($crow['bill_time'], 10, 6)) . " " .
953 htmlspecialchars( xl("This claim has been denied.Reason:-"), ENT_QUOTES);
954 if($crow['process_file'])
956 $code_array=explode(',',$crow['process_file']);
957 foreach($code_array as $code_key => $code_value)
959 $lhtml .= "<br>\n&nbsp;&nbsp;&nbsp;";
960 $reason_array=explode('_',$code_value);
961 if(!isset($adjustment_reasons[$reason_array[3]]))
963 $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]).']';
965 else
967 $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]]);
971 else
973 $lhtml .=htmlspecialchars( xl("Not Specified."), ENT_QUOTES);
975 ++$lcount;
978 if ($crow['process_time']) {
979 $lhtml .= "<br>\n&nbsp;" .
980 text(oeFormatShortDate(substr($crow['process_time'], 0, 10))) .
981 text(substr($crow['process_time'], 10, 6)) . " " .
982 xlt("Claim was generated to file") . " " .
983 "<a href='get_claim_file.php?key=" . attr($crow['process_file']) .
984 "' onclick='top.restoreSession()'>" .
985 text($crow['process_file']) . "</a>";
986 ++$lcount;
989 $lastcrow = $crow;
990 } // end while ($crow = sqlFetchArray($cres))
992 if ($lastcrow && $lastcrow['status'] == 4) {
993 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been closed.");
994 ++$lcount;
997 if ($lastcrow && $lastcrow['status'] == 5) {
998 $lhtml .= "<br>\n&nbsp;" . xlt("This claim has been canceled.");
999 ++$lcount;
1001 } // end if ($iter['id'])
1003 } // end if ($last_encounter_id != $this_encounter_id)
1005 if ($skipping) continue;
1007 // Collect info related to the missing modifiers test.
1008 if ($iter['fee'] > 0) {
1009 ++$mmo_num_charges;
1010 $tmp = substr($iter['code'], 0, 3);
1011 if (($tmp == '992' || $tmp == '993') && empty($iter['modifier']))
1012 $mmo_empty_mod = true;
1015 ++$rcount;
1017 if ($rhtml) {
1018 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
1020 $rhtml .= "<td width='50'>";
1021 if ($iter['id'] && $oldcode != $iter['code_type']) {
1022 $rhtml .= "<span class=text>" . text($iter['code_type']) . ": </span>";
1025 $oldcode = $iter['code_type'];
1026 $rhtml .= "</td>\n";
1027 $justify = "";
1029 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
1030 $js = explode(":",$iter['justify']);
1031 $counter = 0;
1032 foreach ($js as $j) {
1033 if(!empty($j)) {
1034 if ($counter == 0) {
1035 $justify .= " (<b>" . text($j) . "</b>)";
1037 else {
1038 $justify .= " (" . text($j) . ")";
1040 $counter++;
1045 $rhtml .= "<td><span class='text'>" .
1046 ($iter['code_type'] == 'COPAY' ? text(oeFormatMoney($iter['code'])) : text($iter['code']));
1047 if ($iter['modifier']) $rhtml .= ":" . text($iter['modifier']);
1048 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
1050 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1051 if ($iter['id'] && $iter['fee'] > 0) {
1052 $rhtml .= text(oeFormatMoney($iter['fee']));
1054 $rhtml .= "</span></td>\n";
1055 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1056 if ($iter['id']) $rhtml .= getProviderName(empty($iter['provider_id']) ? text($iter['enc_provider_id']) : text($iter['provider_id']));
1057 $rhtml .= "</span></td>\n";
1058 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1059 if($GLOBALS['display_units_in_billing'] != 0) {
1060 if ($iter['id']) $rhtml .= xlt("Units") . ":" . text($iter{"units"});
1062 $rhtml .= "</span></td>\n";
1063 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1064 if ($iter['id']) $rhtml .= text(oeFormatSDFT(strtotime($iter{"date"})));
1065 $rhtml .= "</span></td>\n";
1066 # This error message is generated if the authorized check box is not checked
1067 if ($iter['id'] && $iter['authorized'] != 1) {
1068 $rhtml .= "<td><span class=alert>".xlt("Note: This code has not been authorized.")."</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><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
1111 $rhtml2 .= "</span></td>\n";
1112 $rhtml2 .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
1113 $rhtml2 .= text(oeFormatSDFT(strtotime($date)));
1114 $rhtml2 .= "</span></td>\n";
1115 if ($iter['id'] && $iter['authorized'] != 1) {
1116 $rhtml2 .= "<td><span class=alert>".xlt("Note: This copay was entered against billing that has not been authorized. Please review status.")."</span></td>\n";
1117 }else{
1118 $rhtml2 .= "<td></td>\n";
1120 if(!$iter['id'] && $rowcnt == 1){
1121 $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";
1122 $CheckBoxBilling++;
1123 }else{
1124 $rhtml2 .= "<td></td>\n";
1128 $rhtml .= $rhtml2;
1130 $rhtml .= "</tr>\n";
1131 $last_encounter_id = $this_encounter_id;
1133 } // end foreach
1135 if ($lhtml) {
1136 while ($rcount < $lcount) {
1137 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='8'></td></tr>";
1138 ++$rcount;
1140 if (!$missing_mods_only || ($mmo_empty_mod && $mmo_num_charges > 1)) {
1141 if($DivPut=='yes')
1143 $lhtml.='</div>';
1144 $DivPut='no';
1146 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
1147 echo "<tr bgcolor='$bgcolor'><td colspan='9' height='5'></td></tr>\n";
1155 </table>
1156 </form>
1158 <script>
1159 set_button_states();
1160 <?php
1161 if ($alertmsg) {
1162 echo "alert('".addslashes($alertmsg)."');\n";
1165 $(document).ready(function() {
1166 $("#view-log-link").click( function() {
1167 top.restoreSession();
1168 dlgopen('customize_log.php', '_blank', 500, 400);
1171 $('input[type="submit"]').click( function() {
1172 top.restoreSession();
1173 $(this).attr('data-clicked', true);
1176 $('form[name="update_form"]').submit( function(e) {
1177 var clickedButton = $("input[type=submit][data-clicked='true'")[0];
1179 // clear clicked button indicator
1180 $('input[type="submit"]').attr('data-clicked', false);
1182 if ( !clickedButton || $(clickedButton).attr("data-open-popup") !== "true" ) {
1183 $(this).removeAttr("target");
1184 return top.restoreSession();
1185 } else {
1186 top.restoreSession();
1187 var w = window.open('about:blank','Popup_Window','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300,left = 312,top = 234');
1188 this.target = 'Popup_Window';
1192 $('.datepicker').datetimepicker({
1193 <?php $datetimepicker_timepicker = false; ?>
1194 <?php $datetimepicker_showseconds = false; ?>
1195 <?php $datetimepicker_formatInput = false; ?>
1196 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
1197 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
1200 </script>
1201 <input type="hidden" name="divnos" id="divnos" value="<?php echo attr($divnos) ?>"/>
1202 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1203 </body>
1204 </html>