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.
9 $fake_register_globals=false;
10 $sanitize_all_escapes=true;
12 require_once("../globals.php");
13 require_once("../../library/acl.inc");
14 require_once("../../custom/code_types.inc.php");
15 require_once("$srcdir/patient.inc");
16 include_once("$srcdir/../interface/reports/report.inc.php");//Criteria Section common php page
17 require_once("$srcdir/billrep.inc");
18 require_once(dirname(__FILE__
) . "/../../library/classes/OFX.class.php");
19 require_once(dirname(__FILE__
) . "/../../library/classes/X12Partner.class.php");
20 require_once("$srcdir/formatting.inc.php");
21 require_once("$srcdir/options.inc.php");
22 require_once("adjustment_reason_codes.php");
24 $EXPORT_INC = "$webserver_root/custom/BillingExport.php";
28 if (isset($_POST['mode']) {
29 if ($_POST['mode'] == 'export') {
30 $sql = ReturnOFXSql();
32 $results = $db->Execute($sql);
34 if ($results->RecordCount() == 0) {
35 echo xlt("No Bills Found to Include in OFX Export")."<br>";
37 while(!$results->EOF
) {
38 $billings[] = $results->fields
;
41 $ofx = new OFX($billings);
42 header("Pragma: public");
44 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
45 header("Content-Disposition: attachment; filename=openemr_ofx.ofx");
46 header("Content-Type: text/xml");
53 if ($_POST['mode'] == 'process') {
54 if (exec("ps x | grep 'process_bills[.]php'")) {
55 $alertmsg = xl('Request ignored - claims processing is already running!');
57 exec("cd $webserver_root/library/freeb;" .
58 "php -q process_bills.php bill > process_bills.log 2>&1 &");
59 $alertmsg = xl('Batch processing initiated; this may take a while.');
65 $from_date = isset($_POST['from_date']) ?
$_POST['from_date'] : date('Y-m-d');
66 $to_date = isset($_POST['to_date' ]) ?
$_POST['to_date' ] : '';
67 $code_type = isset($_POST['code_type']) ?
$_POST['code_type'] : 'all';
68 $unbilled = isset($_POST['unbilled' ]) ?
$_POST['unbilled' ] : 'on';
69 $my_authorized = isset($_POST["authorized"]) ?
$_POST["authorized"] : '');
72 // This tells us if only encounters that appear to be missing a "25" modifier
73 // are to be reported.
74 $missing_mods_only = (isset($_POST['missing_mods_only']) && !empty($_POST['missing_mods_only']));
76 $left_margin = isset($_POST["left_margin"]) ?
$_POST["left_margin"] : 24;
77 $top_margin = isset($_POST["top_margin"] ) ?
$_POST["top_margin" ] : 20;
79 $ofrom_date = $from_date;
81 $ocode_type = $code_type;
82 $ounbilled = $unbilled;
83 $oauthorized = $my_authorized;
88 <?php
if (function_exists('html_header_show')) html_header_show(); ?
>
89 <link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
91 .subbtn
{ margin
-top
:3px
; margin
-bottom
:3px
; margin
-left
:2px
; margin
-right
:2px
}
95 function select_all() {
96 for($i=0;$i < document
.update_form
.length
;$i++
) {
97 $name = document
.update_form
[$i].name
;
98 if ($name.substring(0,7) == "claims[" && $name.substring($name.length
-6) == "[bill]") {
99 document
.update_form
[$i].checked
= true;
105 function set_button_states() {
106 var f
= document
.update_form
;
107 var count0
= 0; // selected and not billed or queued
108 var count1
= 0; // selected and queued
109 var count2
= 0; // selected and billed
110 for($i = 0; $i < f
.length
; ++
$i) {
112 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length
-6) == "[bill]" && f
[$i].checked
== true) {
113 if (f
[$i].value
== '0') ++count0
;
114 else if (f
[$i].value
== '1' || f
[$i].value
== '5') ++count1
;
119 var can_generate
= (count0
> 0 || count1
> 0 || count2
> 0);
120 var can_mark
= (count1
> 0 || count0
> 0 || count2
> 0);
121 var can_bill
= (count0
== 0 && count1
== 0 && count2
> 0);
123 <?php
if (file_exists($EXPORT_INC)) { ?
>
124 f
.bn_external
.disabled
= !can_generate
;
126 // f.bn_hcfa_print.disabled = !can_generate;
127 // f.bn_hcfa.disabled = !can_generate;
128 // f.bn_ub92_print.disabled = !can_generate;
129 // f.bn_ub92.disabled = !can_generate;
130 f
.bn_x12
.disabled
= !can_generate
;
131 <?php
if ($GLOBALS['support_encounter_claims']) { ?
>
132 f
.bn_x12_encounter
.disabled
= !can_generate
;
134 f
.bn_process_hcfa
.disabled
= !can_generate
;
135 f
.bn_hcfa_txt_file
.disabled
= !can_generate
;
136 // f.bn_electronic_file.disabled = !can_bill;
137 f
.bn_reopen
.disabled
= !can_bill
;
139 f
.bn_mark
.disabled
= !can_mark
;
142 // Process a click to go to an encounter.
143 function toencounter(pid
, pubpid
, pname
, enc
, datestr
, dobstr
) {
144 top
.restoreSession();
145 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
146 var othername
= (window
.name
== 'RTop') ?
'RBot' : 'RTop';
147 parent
.left_nav
.setPatient(pname
,pid
,pubpid
,'',dobstr
);
148 parent
.left_nav
.setEncounter(datestr
, enc
, othername
);
149 parent
.left_nav
.setRadio(othername
, 'enc');
150 parent
.frames
[othername
].location
.href
=
151 '../patient_file/encounter/encounter_top.php?set_encounter='
152 + enc +
'&pid=' + pid
;
154 location
.href
= '../patient_file/encounter/patient_encounter.php?set_encounter='
155 + enc +
'&pid=' + pid
;
158 // Process a click to go to an patient.
159 function topatient(pid
, pubpid
, pname
, enc
, datestr
, dobstr
) {
160 top
.restoreSession();
161 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
162 var othername
= (window
.name
== 'RTop') ?
'RBot' : 'RTop';
163 parent
.left_nav
.setPatient(pname
,pid
,pubpid
,'',dobstr
);
164 parent
.frames
[othername
].location
.href
=
165 '../patient_file/summary/demographics_full.php?pid=' + pid
;
167 location
.href
= '../patient_file/summary/demographics_full.php?pid=' + pid
;
171 <script language
="javascript" type
="text/javascript">
172 EncounterDateArray
=new Array;
173 CalendarCategoryArray
=new Array;
174 EncounterIdArray
=new Array;
175 function SubmitTheScreen()
176 {//Action on Update List link
177 if(!ProcessBeforeSubmitting())
179 top
.restoreSession();
180 document
.the_form
.mode
.value
='change';
181 document
.the_form
.target
='_self';
182 document
.the_form
.action
='billing_report.php';
183 document
.the_form
.submit();
186 function SubmitTheScreenPrint()
187 {//Action on View Printable Report link
188 if(!ProcessBeforeSubmitting())
190 top
.restoreSession();
191 document
.the_form
.target
='new';
192 document
.the_form
.action
='print_billing_report.php';
193 document
.the_form
.submit();
196 function SubmitTheScreenExportOFX()
197 {//Action on Export OFX link
198 if(!ProcessBeforeSubmitting())
200 top
.restoreSession();
201 document
.the_form
.mode
.value
='export';
202 document
.the_form
.target
='_self';
203 document
.the_form
.action
='billing_report.php';
204 document
.the_form
.submit();
207 function TestExpandCollapse()
208 {//Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
210 for(i
=1;i
<=document
.getElementById("divnos").value
;i++
)
212 var ele
= document
.getElementById("divid_"+i
);
221 if(document
.getElementById("ExpandAll"))
223 document
.getElementById("ExpandAll").innerHTML
='';
224 document
.getElementById("CollapseAll").innerHTML
='';
228 function expandcollapse(atr
){
229 if(atr
== "expand") {//Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
230 for(i
=1;i
<=document
.getElementById("divnos").value
;i++
){
231 var mydivid
="divid_"+i
;var myspanid
="spanid_"+i
;
232 var ele
= document
.getElementById(mydivid
); var text
= document
.getElementById(myspanid
);
235 ele
.style
.display
= "inline";text
.innerHTML
= "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
240 for(i
=1;i
<=document
.getElementById("divnos").value
;i++
){
241 var mydivid
="divid_"+i
;var myspanid
="spanid_"+i
;
242 var ele
= document
.getElementById(mydivid
); var text
= document
.getElementById(myspanid
);
245 ele
.style
.display
= "none"; text
.innerHTML
= "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
251 function divtoggle(spanid
, divid
) {//Called in the Expand, Collapse links(This is for a single item)
252 var ele
= document
.getElementById(divid
);
255 var text
= document
.getElementById(spanid
);
256 if(ele
.style
.display
== "inline") {
257 ele
.style
.display
= "none";
258 text
.innerHTML
= "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
261 ele
.style
.display
= "inline";
262 text
.innerHTML
= "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
266 function MarkAsCleared(Type
)
268 CheckBoxBillingCount
=0;
269 for (var CheckBoxBillingIndex
=0; ; CheckBoxBillingIndex++
)
271 CheckBoxBillingObject
=document
.getElementById('CheckBoxBilling'+CheckBoxBillingIndex
);
272 if(!CheckBoxBillingObject
)
274 if(CheckBoxBillingObject
.checked
)
276 ++CheckBoxBillingCount
;
281 Message
='<?php echo htmlspecialchars( xl('After saving your batch
, click
[View Log
] to check
for errors
.'), ENT_QUOTES); ?>';
285 Message
='<?php echo htmlspecialchars( xl('After saving the PDF
, click
[View Log
] to check
for errors
.'), ENT_QUOTES); ?>';
289 Message
='<?php echo htmlspecialchars( xl('After saving the TEXT
file(s
), click
[View Log
] to check
for errors
.'), ENT_QUOTES); ?>';
291 if(confirm(Message +
"\n\n\n<?php echo addslashes( xl('Total') ); ?>" +
' ' + CheckBoxBillingCount +
' ' +
"<?php echo addslashes( xl('Selected') ); ?>\n" +
292 "<?php echo addslashes( xl('Would You Like them to be Marked as Cleared.') ); ?>"))
294 document
.getElementById('HiddenMarkAsCleared').value
='yes';
298 document
.getElementById('HiddenMarkAsCleared').value
='';
302 <?php
include_once("$srcdir/../interface/reports/report.script.php"); ?
><!-- Criteria Section common javascript page
-->
303 <!-- ================================================== -->
304 <!-- =============Included
for Insurance ajax criteria
==== -->
305 <!-- ================================================== -->
306 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
307 <?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
308 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
310 #ajax_div_insurance {
313 background
-color
: #FBFDD0;
314 border
: 1px solid
#ccc;
318 <script language
="javascript" type
="text/javascript">
319 document
.onclick
=TakeActionOnHide
;
321 <!-- ================================================== -->
322 <!-- =============Included
for Insurance ajax criteria
==== -->
323 <!-- ================================================== -->
325 <body
class="body_top" onLoad
="TestExpandCollapse()">
327 <p style
='margin-top:5px;margin-bottom:5px;margin-left:5px'>
329 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
330 <font
class='title'><?php
echo xlt('Billing Manager') ?
></font
>
331 <?php
} else if ($userauthorized) { ?
>
332 <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
>
334 <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
>
339 <form name
='the_form' method
='post' action
='billing_report.php' onsubmit
='return top.restoreSession()' style
="display:inline">
341 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
342 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
343 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
344 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
345 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
346 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
347 <script language
='JavaScript'>
351 <input type
='hidden' name
='mode' value
='change'>
352 <!-- ============================================================================================================================================= -->
353 <!-- Criteria section Starts
-->
354 <!-- ============================================================================================================================================= -->
356 //The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
357 //Each item is seperated by a comma(,).
358 //$ThisPageSearchCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
359 //$ThisPageSearchCriteriaKeyMaster ==>Corresponding database fields in the same order.
360 //$ThisPageSearchCriteriaDataTypeMaster ==>Corresponding data type in the same order.
361 $ThisPageSearchCriteriaDisplayRadioMaster=array();
362 $ThisPageSearchCriteriaRadioKeyMaster=array();
363 $ThisPageSearchCriteriaQueryDropDownMaster=array();
364 $ThisPageSearchCriteriaQueryDropDownMasterDefault=array();
365 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey=array();
366 $ThisPageSearchCriteriaIncludeMaster=array();
368 $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") );
369 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
370 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
371 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id";
372 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
373 "text,include,text,radio,radio,radio,".
374 "radio_like,radio,query_drop_down";
375 //The below section is needed if there is any 'radio' or 'radio_like' type in the $ThisPageSearchCriteriaDataTypeMaster
376 //$ThisPageSearchCriteriaDisplayRadioMaster,$ThisPageSearchCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
377 //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.
378 $ThisPageSearchCriteriaDisplayRadioMaster[1] = array( xl("All"),xl("eClaims"),xl("Paper") );//Display Value
379 $ThisPageSearchCriteriaRadioKeyMaster[1]="all,standard,hcfa";//Key
380 $ThisPageSearchCriteriaDisplayRadioMaster[2]= array( xl("All"),xl("Insured"),xl("Non-Insured") );//Display Value
381 $ThisPageSearchCriteriaRadioKeyMaster[2]="all,1,0";//Key
382 $ThisPageSearchCriteriaDisplayRadioMaster[3]= array( xl("All"),xl("Coded"),xl("Not Coded") );//Display Value
383 $ThisPageSearchCriteriaRadioKeyMaster[3]="all,not null,null";//Key
384 $ThisPageSearchCriteriaDisplayRadioMaster[4]= array( xl("All"),xl("Unbilled"),xl("Billed"),xl("Denied") );//Display Value
385 $ThisPageSearchCriteriaRadioKeyMaster[4]="all,0,1,7";//Key
386 $ThisPageSearchCriteriaDisplayRadioMaster[5]= array( xl("All"),xl("Authorized"),xl("Unauthorized") );
387 $ThisPageSearchCriteriaRadioKeyMaster[5]="%,1,0";
388 $ThisPageSearchCriteriaDisplayRadioMaster[6]= array( xl("All"),xl("None"),xl("Ins 1"),xl("Ins 2 or Ins 3") );
389 $ThisPageSearchCriteriaRadioKeyMaster[6]="all,0,1,2";
390 //The below section is needed if there is any 'query_drop_down' type in the $ThisPageSearchCriteriaDataTypeMaster
391 $ThisPageSearchCriteriaQueryDropDownMaster[1]="SELECT name,id FROM x12_partners;";
392 $ThisPageSearchCriteriaQueryDropDownMasterDefault[1]= xl("All");//Only one item will be here
393 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey[1]="all";//Only one item will be here
394 //The below section is needed if there is any 'include' type in the $ThisPageSearchCriteriaDataTypeMaster
395 //Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
396 //It is labled(Included for Insurance ajax criteria)(Line:-279-299).
397 $ThisPageSearchCriteriaIncludeMaster[1]="InsuranceCompanyDisplay";//This is php function defined in the file 'report.inc.php'
399 if(!isset($_REQUEST['mode']))//default case
401 $_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")."')";
402 $_REQUEST['final_this_page_criteria'][1]="billing.billed = '0'";
404 $_REQUEST['final_this_page_criteria_text'][0]=xl("Date of Service = Today");
405 $_REQUEST['final_this_page_criteria_text'][1]=xl("Billing Status = Unbilled");
407 $_REQUEST['date_master_criteria_form_encounter_date']="today";
408 $_REQUEST['master_from_date_form_encounter_date']=date("Y-m-d");
409 $_REQUEST['master_to_date_form_encounter_date']=date("Y-m-d");
411 $_REQUEST['radio_billing_billed']=0;
415 <table width
='100%' border
="0" cellspacing
="0" cellpadding
="0">
417 <td width
="25%"> 
;</td
>
419 <?php
include_once("$srcdir/../interface/reports/criteria.tab.php"); ?
>
423 // ============================================================================================================================================= -->
424 // Criteria section Ends -->
425 // ============================================================================================================================================= -->
428 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
430 <td width
="15%"> 
;</td
>
431 <td width
="85%"><span
class='text'><a onClick
="javascript:return SubmitTheScreen();" href
="#" class=link_submit
>[<?php
echo htmlspecialchars(xl('Update List'), ENT_QUOTES
) ?
>]</a
>
433 <a onClick
="javascript:return SubmitTheScreenExportOFX();" href
="#" class='link_submit'><?php
echo htmlspecialchars(xl('[Export OFX]'), ENT_QUOTES
) ?
></a
></span
> </td
>
437 <td
><a onClick
="javascript:return SubmitTheScreenPrint();" href
="#"
438 class='link_submit' ><?php
echo htmlspecialchars(xl('[View Printable Report]'), ENT_QUOTES
) ?
></a
></td
>
444 $acct_config = $GLOBALS['oer_config']['ws_accounting'];
445 if($acct_config['enabled']) {
446 if($acct_config['enabled'] !== 2) {
447 print '<span class=text><a href="javascript:void window.open(\'' . $acct_config['url_path'] . '\')">' . htmlspecialchars(xl("[SQL-Ledger]"), ENT_QUOTES
) . '</a> </span>';
449 if (acl_check('acct', 'rep')) {
450 print '<span class=text><a href="javascript:void window.open(\'sl_receipts_report.php\')" onclick="top.restoreSession()">' . htmlspecialchars(xl('[Reports]'), ENT_QUOTES
) . '</a> </span>';
452 if (acl_check('acct', 'eob')) {
453 print '<span class=text><a href="javascript:void window.open(\'sl_eob_search.php\')" onclick="top.restoreSession()">' . htmlspecialchars(xl('[EOBs]'), ENT_QUOTES
) . '</a></span>';
462 <?php
if (! file_exists($EXPORT_INC)) { ?
>
464 <a href
="javascript:top.restoreSession();document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
465 title
="Process all queued bills to create electronic data (and print if requested)"><?php
echo htmlspecialchars(xl('[Start Batch Processing]'), ENT_QUOTES
) ?
></a
>
468 <a href
='../../library/freeb/process_bills.log' target
='_blank' class='link_submit'
469 title
='<?php htmlspecialchars(xl('See messages from the last set of generated claims
'), ENT_QUOTES); ?>'><?php
echo htmlspecialchars(xl('[View Log]'), ENT_QUOTES
) ?
></a
>
475 <td
><a href
="javascript:select_all()" class="link_submit"><?php
echo htmlspecialchars(xl('[Select All]','e'), ENT_QUOTES
) ?
></a
></td
>
483 <table width
='100%' border
="0" cellspacing
="0" cellpadding
="0" >
491 <form name
='update_form' method
='post' action
='billing_process.php' onsubmit
='return top.restoreSession()' style
="display:inline">
493 <span
class='text' style
="display:inline">
494 <?php
if (file_exists($EXPORT_INC)) { ?
>
495 <input type
="submit" class="subbtn" name
="bn_external" value
="Export Billing" title
="<?php echo xla('Export to external billing system') ?>">
496 <input type
="submit" class="subbtn" name
="bn_mark" value
="Mark as Cleared" title
="<?php echo xla('Mark as billed but skip billing') ?>">
499 <input type
="submit" class="subbtn" name
="bn_hcfa_print" value
="Queue HCFA & Print" title
="<?php echo xla('Queue for HCFA batch processing and printing') ?>">
500 <input type
="submit" class="subbtn" name
="bn_hcfa" value
="Queue HCFA" title
="<?php echo xla('Queue for HCFA batch processing')?>">
501 <input type
="submit" class="subbtn" name
="bn_ub92_print" value
="Queue UB92 & Print" title
="<?php echo xla('Queue for UB-92 batch processing and printing')?>">
502 <input type
="submit" class="subbtn" name
="bn_ub92" value
="Queue UB92" title
="<?php echo xla('Queue for UB-92 batch processing')?>">
504 <input type
="submit" class="subbtn" name
="bn_x12" value
="<?php echo xla('Generate X12')?>"
505 title
="<?php echo xla('Generate and download X12 batch')?>"
506 onclick
="MarkAsCleared(1)">
507 <?php
if ($GLOBALS['support_encounter_claims']) { ?
>
508 <input type
="submit" class="subbtn" name
="bn_x12_encounter" value
="<?php echo xla('Generate X12 Encounter')?>"
509 title
="<?php echo xla('Generate and download X12 encounter claim batch')?>"
510 onclick
="MarkAsCleared(1)">
512 <input type
="submit" class="subbtn" style
="width:175px;" name
="bn_process_hcfa" value
="<?php echo xla('Generate CMS 1500 PDF')?>"
513 title
="<?php echo xla('Generate and download CMS 1500 paper claims')?>"
514 onclick
="MarkAsCleared(2)">
515 <input type
="submit" class="subbtn" style
="width:175px;" name
="bn_hcfa_txt_file" value
="<?php echo xla('Generate CMS 1500 TEXT')?>"
516 title
="<?php echo xla('Making batch text files for uploading to Clearing House and will mark as billed')?>"
517 onclick
="MarkAsCleared(3)">
518 <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')?>">
519 <input type
="submit" class="subbtn" name
="bn_reopen" value
="<?php echo xla('Re-Open')?>" title
="<?php echo xla('Mark as not billed')?>">
521 <input type
="submit" class="subbtn" name
="bn_electronic_file" value
="Make Electronic Batch & Clear" title
="<?php echo xla('Download billing file, post to accounting and mark as billed')?>">
524 <?php
echo xlt('CMS 1500 Margins'); ?
>:
525  
;<?php
echo xlt('Left'); ?
>:
526 <input type
='text' size
='2' name
='left_margin'
527 value
='<?php echo attr($left_margin); ?>'
528 title
='<?php echo xla('HCFA left margin in points
'); ?>' />
529  
;<?php
echo xlt('Top'); ?
>:
530 <input type
='text' size
='2' name
='top_margin'
531 value
='<?php echo attr($top_margin); ?>'
532 title
='<?php echo xla('HCFA top margin in points
'); ?>' />
537 <input type
='hidden' name
='HiddenMarkAsCleared' id
='HiddenMarkAsCleared' value
="" />
538 <input type
='hidden' name
='mode' value
="bill" />
539 <input type
='hidden' name
='authorized' value
="<?php echo attr($my_authorized); ?>" />
540 <input type
='hidden' name
='unbilled' value
="<?php echo attr($unbilled); ?>" />
541 <input type
='hidden' name
='code_type' value
="%" />
542 <input type
='hidden' name
='to_date' value
="<?php echo attr($to_date); ?>" />
543 <input type
='hidden' name
='from_date' value
="<?php echo attr($from_date); ?>" />
546 if ($my_authorized == "on" ) {
547 $my_authorized = "1";
549 $my_authorized = "%";
551 if ($unbilled == "on") {
556 $list = getBillsListBetween("%");
559 <input type
='hidden' name
='bill_list' value
="<?php echo attr($list); ?>" />
561 <!-- new form
for uploading
-->
564 if (!isset($_POST["mode"])) {
565 if (!isset($_POST["from_date"])) {
566 $from_date = date("Y-m-d");
568 $from_date = $_POST["from_date"];
570 if (empty($_POST["to_date"])) {
573 $to_date = $_POST["to_date"];
575 if (!isset($_POST["code_type"])) {
578 $code_type = $_POST["code_type"];
580 if (!isset($_POST["unbilled"])) {
583 $unbilled = $_POST["unbilled"];
585 if (!isset($_POST["authorized"])) {
586 $my_authorized = "on";
588 $my_authorized = $_POST["authorized"];
591 $from_date = $_POST["from_date"];
592 $to_date = $_POST["to_date"];
593 $code_type = $_POST["code_type"];
594 $unbilled = $_POST["unbilled"];
595 $my_authorized = $_POST["authorized"];
598 if ($my_authorized == "on" ) {
599 $my_authorized = "1";
601 $my_authorized = "%";
604 if ($unbilled == "on") {
610 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
611 billCodesList($list);
615 <table border
="0" cellspacing
="0" cellpadding
="0" width
="100%">
619 if ($ret = getBillsBetween("%"))
624 <tr
><td colspan
='8' align
="right" ><table width
="250" border
="0" cellspacing
="0" cellpadding
="0">
626 <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
>
627 <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
>
628 <td width
="50"> 
;</td
>
636 $last_encounter_id = "";
644 $mmo_empty_mod = false;
645 $mmo_num_charges = 0;
647 foreach ($ret as $iter) {
649 // We include encounters here that have never been billed. However
650 // if it had no selected billing items but does have non-selected
651 // billing items, then it is not of interest.
653 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
654 "encounter = ? AND " .
656 "activity = 1", array($iter['enc_encounter'],$iter['enc_pid']) );
657 if ($res['count'] > 0) continue;
660 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
662 if ($last_encounter_id != $this_encounter_id) {
664 // This dumps all HTML for the previous encounter.
667 while ($rcount < $lcount) {
668 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'></td></tr>";
671 // This test handles the case where we are only listing encounters
672 // that appear to have a missing "25" modifier.
673 if (!$missing_mods_only ||
($mmo_empty_mod && $mmo_num_charges > 1)) {
679 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
680 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n\n";
687 $mmo_empty_mod = false;
688 $mmo_num_charges = 0;
690 // If there are ANY unauthorized items in this encounter and this is
691 // the normal case of viewing only authorized billing, then skip the
695 if ($my_authorized == '1') {
696 $res = sqlQuery("select count(*) as count from billing where " .
697 "encounter = ? and " .
699 "activity = 1 and authorized = 0", array($iter['enc_encounter'],$iter['enc_pid']) );
700 if ($res['count'] > 0) {
702 $last_encounter_id = $this_encounter_id;
707 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
709 # Check if patient has primary insurance and a subscriber exists for it.
710 # If not we will highlight their name in red.
711 # TBD: more checking here.
713 $res = sqlQuery("select count(*) as count from insurance_data where " .
715 "type='primary' and " .
716 "subscriber_lname is not null and " .
717 "subscriber_lname != '' limit 1", array($iter['enc_pid']) );
718 $namecolor = ($res['count'] > 0) ?
"black" : "#ff7777";
720 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
721 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
726 $ptname = $name['fname'] . " " . $name['lname'];
727 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
729 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
730 $lhtml .= " <span class=bold><font color='$namecolor'>". text($ptname) .
731 "</font></span><span class=small> (" . text($iter['enc_pid']) . "-" .
732 text($iter['enc_encounter']) . ")</span>";
734 //Encounter details are stored to javacript as array.
735 $result4 = sqlStatement("SELECT fe.encounter,fe.date,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
736 " 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']) );
737 if(sqlNumRows($result4)>0)
739 <script language
='JavaScript'>
741 EncounterDateArray
[<?php
echo attr($iter['enc_pid']); ?
>]=new Array;
742 CalendarCategoryArray
[<?php
echo attr($iter['enc_pid']); ?
>]=new Array;
743 EncounterIdArray
[<?php
echo attr($iter['enc_pid']); ?
>]=new Array;
745 while($rowresult4 = sqlFetchArray($result4))
748 EncounterIdArray
[<?php
echo attr($iter['enc_pid']); ?
>][Count
]='<?php echo htmlspecialchars($rowresult4['encounter
'], ENT_QUOTES); ?>';
749 EncounterDateArray
[<?php
echo attr($iter['enc_pid']); ?
>][Count
]='<?php echo htmlspecialchars(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date
']))), ENT_QUOTES); ?>';
750 CalendarCategoryArray
[<?php
echo attr($iter['enc_pid']); ?
>][Count
]='<?php echo htmlspecialchars( xl_appt_category($rowresult4['pc_catname
']), ENT_QUOTES); ?>';
758 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
759 $lhtml .= " <a class=\"link_submit\" " .
760 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
761 ",'" . addslashes($name['pubpid']) .
762 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
763 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
764 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
765 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
766 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" .
767 xlt('To Enctr') . " " . text(oeFormatShortDate($raw_encounter_date)) . "]</a>";
769 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
770 $lhtml .= " <a class=\"link_submit\" " .
771 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
772 ",'" . addslashes($name['pubpid']) .
773 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
774 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
775 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
776 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
777 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" . xlt('To Dems') . "]</a>";
779 $lhtml .= " <a onclick='divtoggle(\"spanid_$divnos\",\"divid_$divnos\");' class='small' id='aid_$divnos' href=\"JavaScript:void(0);".
780 "\">(<span id=spanid_$divnos class=\"indicator\">" . htmlspecialchars( xl('Expand'), ENT_QUOTES
) . "</span>)</a>";
785 $lhtml .= "<br />\n";
786 $lhtml .= " <span class=text>Bill: ";
787 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' style='background-color:$bgcolor'>";
789 $query = "SELECT id.provider AS id, id.type, id.date, " .
790 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
791 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
792 "ic.id = id.provider AND " .
795 "ORDER BY id.type ASC, id.date DESC";
797 $result = sqlStatement($query, array($iter['enc_pid'],$raw_encounter_date) );
799 $default_x12_partner = $iter['ic_x12id'];
802 while ($row = sqlFetchArray($result)) {
803 if (strcmp($row['type'], $prevtype) == 0) continue;
804 $prevtype = $row['type'];
805 if (strlen($row['provider']) > 0) {
806 // This preserves any existing insurance company selection, which is
807 // important when EOB posting has re-queued for secondary billing.
808 $lhtml .= "<option value=\"" . attr(substr($row['type'],0,1).$row['id']) . "\"";
809 if (($count == 0 && !$iter['payer_id']) ||
$row['id'] == $iter['payer_id']) {
810 $lhtml .= " selected";
811 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
813 $lhtml .= ">" . text($row['type']) . ": " . text($row['provider']) . "</option>";
818 $lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
819 $lhtml .= "</select> \n";
820 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][partner]' style='background-color:$bgcolor'>";
821 $x = new X12Partner();
822 $partners = $x->_utility_array($x->x12_partner_factory());
823 foreach ($partners as $xid => $xname) {
824 $lhtml .= '<option label="' . attr($xname) . '" value="' . attr($xid) .'"';
825 if ($xid == $default_x12_partner) {
826 $lhtml .= "selected";
828 $lhtml .= '>' . text($xname) . '</option>';
830 $lhtml .= "</select>";
832 $lhtml .= "<br>\n <div id='divid_$divnos' style='display:none'>" . text(oeFormatShortDate(substr($iter['date'], 0, 10)))
833 . text(substr($iter['date'], 10, 6)) . " " . xlt("Encounter was coded");
835 $query = "SELECT * FROM claims WHERE " .
836 "patient_id = ? AND " .
837 "encounter_id = ? " .
839 $cres = sqlStatement($query, array($iter['enc_pid'],$iter['enc_encounter']) );
843 while ($crow = sqlFetchArray($cres)) {
844 $query = "SELECT id.type, ic.name " .
845 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
847 "id.provider = ? AND " .
848 "id.date <= ? AND " .
849 "ic.id = id.provider " .
850 "ORDER BY id.type ASC, id.date DESC";
852 $irow= sqlQuery($query, array($iter['enc_pid'],$crow['payer_id'],$raw_encounter_date) );
854 if ($crow['bill_process']) {
855 $lhtml .= "<br>\n " .
856 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
857 text(substr($crow['bill_time'], 10, 6)) . " " .
858 xlt("Queued for") . " " . text($irow['type']) . " " . text($crow['target']) . " " .
859 xlt("billing to ") . text($irow['name']);
862 else if ($crow['status'] < 6) {
863 if ($crow['status'] > 1) {
864 $lhtml .= "<br>\n " .
865 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
866 text(substr($crow['bill_time'], 10, 6)) . " " .
867 htmlspecialchars( xl("Marked as cleared"), ENT_QUOTES
);
871 $lhtml .= "<br>\n " .
872 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
873 text(substr($crow['bill_time'], 10, 6)) . " " .
874 htmlspecialchars( xl("Re-opened"), ENT_QUOTES
);
878 else if ($crow['status'] == 6) {
879 $lhtml .= "<br>\n " .
880 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
881 text(substr($crow['bill_time'], 10, 6)) . " " .
882 htmlspecialchars( xl("This claim has been forwarded to next level."), ENT_QUOTES
);
885 else if ($crow['status'] == 7) {
886 $lhtml .= "<br>\n " .
887 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
888 text(substr($crow['bill_time'], 10, 6)) . " " .
889 htmlspecialchars( xl("This claim has been denied.Reason:-"), ENT_QUOTES
);
890 if($crow['process_file'])
892 $code_array=split(',',$crow['process_file']);
893 foreach($code_array as $code_key => $code_value)
895 $lhtml .= "<br>\n ";
896 $reason_array=split('_',$code_value);
897 if(!isset($adjustment_reasons[$reason_array[3]]))
899 $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]).']';
903 $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]]);
909 $lhtml .=htmlspecialchars( xl("Not Specified."), ENT_QUOTES
);
914 if ($crow['process_time']) {
915 $lhtml .= "<br>\n " .
916 text(oeFormatShortDate(substr($crow['process_time'], 0, 10))) .
917 text(substr($crow['process_time'], 10, 6)) . " " .
918 xlt("Claim was generated to file") . " " .
919 "<a href='get_claim_file.php?key=" . attr($crow['process_file']) .
920 "' onclick='top.restoreSession()'>" .
921 text($crow['process_file']) . "</a>";
926 } // end while ($crow = sqlFetchArray($cres))
928 if ($lastcrow && $lastcrow['status'] == 4) {
929 $lhtml .= "<br>\n " . xlt("This claim has been closed.");
933 if ($lastcrow && $lastcrow['status'] == 5) {
934 $lhtml .= "<br>\n " . xlt("This claim has been canceled.");
937 } // end if ($iter['id'])
939 } // end if ($last_encounter_id != $this_encounter_id)
941 if ($skipping) continue;
943 // Collect info related to the missing modifiers test.
944 if ($iter['fee'] > 0) {
946 $tmp = substr($iter['code'], 0, 3);
947 if (($tmp == '992' ||
$tmp == '993') && empty($iter['modifier']))
948 $mmo_empty_mod = true;
954 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
956 $rhtml .= "<td width='50'>";
957 if ($iter['id'] && $oldcode != $iter['code_type']) {
958 $rhtml .= "<span class=text>" . text($iter['code_type']) . ": </span>";
961 $oldcode = $iter['code_type'];
965 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
966 $js = split(":",$iter['justify']);
968 foreach ($js as $j) {
971 $justify .= " (<b>" . text($j) . "</b>)";
974 $justify .= " (" . text($j) . ")";
981 $rhtml .= "<td><span class='text'>" .
982 ($iter['code_type'] == 'COPAY' ?
text(oeFormatMoney($iter['code'])) : text($iter['code']));
983 if ($iter['modifier']) $rhtml .= ":" . text($iter['modifier']);
984 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
986 $rhtml .= '<td align="right"><span style="font-size:8pt;"> ';
987 if ($iter['id'] && $iter['fee'] > 0) {
988 $rhtml .= text(oeFormatMoney($iter['fee']));
990 $rhtml .= "</span></td>\n";
991 $rhtml .= '<td><span style="font-size:8pt;"> ';
992 if ($iter['id']) $rhtml .= getProviderName(empty($iter['provider_id']) ?
text($iter['enc_provider_id']) : text($iter['provider_id']));
993 $rhtml .= "</span></td>\n";
994 $rhtml .= '<td width=100> <span style="font-size:8pt;">';
995 if ($iter['id']) $rhtml .= text(oeFormatSDFT(strtotime($iter{"date"})));
996 $rhtml .= "</span></td>\n";
997 if ($iter['id'] && $iter['authorized'] != 1) {
998 $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";
1001 $rhtml .= "<td></td>\n";
1003 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
1004 $tmpbpr = $iter['bill_process'];
1005 if ($tmpbpr == '0' && $iter['billed']) $tmpbpr = '2';
1006 $rhtml .= "<td><input type='checkbox' value='" . attr($tmpbpr) . "' name='claims[" . attr($this_encounter_id) . "][bill]' onclick='set_button_states()' id='CheckBoxBilling" . attr($CheckBoxBilling*1) . "'> </td>\n";
1010 $rhtml .= "<td></td>\n";
1012 if($last_encounter_id != $this_encounter_id){
1015 $resMoneyGot = sqlStatement("SELECT pay_amount as PatientPay,date(post_time) as date FROM ar_activity where ".
1016 "pid = ? and encounter = ? and payer_type=0 and account_code='PCP'",
1017 array($iter['enc_pid'],$iter['enc_encounter']));
1018 //new fees screen copay gives account_code='PCP'
1019 if(sqlNumRows($resMoneyGot) > 0){
1023 //checks whether a copay exists for the encounter and if exists displays it.
1024 while($rowMoneyGot = sqlFetchArray($resMoneyGot)){
1026 $PatientPay=$rowMoneyGot['PatientPay'];
1027 $date=$rowMoneyGot['date'];
1028 if($PatientPay > 0){
1030 $rhtml2 .= "<tr bgcolor='$bgcolor'>\n";
1032 $rhtml2 .= "<td width='50'>";
1033 $rhtml2 .= "<span class='text'>".xlt('COPAY').": </span>";
1034 $rhtml2 .= "</td>\n";
1035 $rhtml2 .= "<td><span class='text'>".text(oeFormatMoney($PatientPay))."</span><span style='font-size:8pt;'> </span></td>\n";
1036 $rhtml2 .= '<td align="right"><span style="font-size:8pt;"> ';
1037 $rhtml2 .= "</span></td>\n";
1038 $rhtml2 .= '<td><span style="font-size:8pt;"> ';
1039 $rhtml2 .= "</span></td>\n";
1040 $rhtml2 .= '<td width=100> <span style="font-size:8pt;">';
1041 $rhtml2 .= text(oeFormatSDFT(strtotime($date)));
1042 $rhtml2 .= "</span></td>\n";
1043 if ($iter['id'] && $iter['authorized'] != 1) {
1044 $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";
1046 $rhtml2 .= "<td></td>\n";
1048 if(!$iter['id'] && $rowcnt == 1){
1049 $rhtml2 .= "<td><input type='checkbox' value='0' name='claims[" . attr($this_encounter_id) . "][bill]' onclick='set_button_states()' id='CheckBoxBilling" . attr($CheckBoxBilling*1) . "'> </td>\n";
1052 $rhtml2 .= "<td></td>\n";
1058 $rhtml .= "</tr>\n";
1059 $last_encounter_id = $this_encounter_id;
1064 while ($rcount < $lcount) {
1065 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'></td></tr>";
1068 if (!$missing_mods_only ||
($mmo_empty_mod && $mmo_num_charges > 1)) {
1074 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
1075 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
1087 set_button_states();
1090 echo "alert('".addslashes($alertmsg)."');\n";
1094 <input type
="hidden" name
="divnos" id
="divnos" value
="<?php echo attr($divnos) ?>"/>
1095 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />