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 ($_POST['mode'] == 'export') {
29 $sql = ReturnOFXSql();
31 $results = $db->Execute($sql);
33 if ($results->RecordCount() == 0) {
34 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");
54 if ($_POST['mode'] == 'process') {
55 if (exec("ps x | grep 'process_bills[.]php'")) {
56 $alertmsg = xl('Request ignored - claims processing is already running!');
59 exec("cd $webserver_root/library/freeb;" .
60 "php -q process_bills.php bill > process_bills.log 2>&1 &");
61 $alertmsg = xl('Batch processing initiated; this may take a while.');
66 if (!isset($_POST["mode"])) {
67 $from_date = isset($_POST['from_date']) ?
$_POST['from_date'] : date('Y-m-d');
68 $to_date = isset($_POST['to_date' ]) ?
$_POST['to_date' ] : '';
69 $code_type = isset($_POST['code_type']) ?
$_POST['code_type'] : 'all';
70 $unbilled = isset($_POST['unbilled' ]) ?
$_POST['unbilled' ] : 'on';
71 $my_authorized = $_POST["authorized"];
73 $from_date = $_POST["from_date"];
74 $to_date = $_POST["to_date"];
75 $code_type = $_POST["code_type"];
76 $unbilled = $_POST["unbilled"];
77 $my_authorized = $_POST["authorized"];
80 // This tells us if only encounters that appear to be missing a "25" modifier
81 // are to be reported.
82 $missing_mods_only = !empty($_POST['missing_mods_only']);
85 $from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
86 $to_date = empty($_POST['to_date' ]) ? $from_date : $_POST['to_date'];
87 $code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
88 $unbilled = isset($_POST['unbilled' ]) ? $_POST['unbilled' ] : 'on';
89 $my_authorized = $_POST["authorized"];
92 $left_margin = isset($_POST["left_margin"]) ?
$_POST["left_margin"] : 24;
93 $top_margin = isset($_POST["top_margin"] ) ?
$_POST["top_margin" ] : 20;
95 $ofrom_date = $from_date;
97 $ocode_type = $code_type;
98 $ounbilled = $unbilled;
99 $oauthorized = $my_authorized;
104 <?php
if (function_exists(html_header_show
)) html_header_show(); ?
>
105 <link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
107 .subbtn
{ margin
-top
:3px
; margin
-bottom
:3px
; margin
-left
:2px
; margin
-right
:2px
}
111 function select_all() {
112 for($i=0;$i < document
.update_form
.length
;$i++
) {
113 $name = document
.update_form
[$i].name
;
114 if ($name.substring(0,7) == "claims[" && $name.substring($name.length
-6) == "[bill]") {
115 document
.update_form
[$i].checked
= true;
121 function set_button_states() {
122 var f
= document
.update_form
;
123 var count0
= 0; // selected and not billed or queued
124 var count1
= 0; // selected and queued
125 var count2
= 0; // selected and billed
126 for($i = 0; $i < f
.length
; ++
$i) {
128 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length
-6) == "[bill]" && f
[$i].checked
== true) {
129 if (f
[$i].value
== '0') ++count0
;
130 else if (f
[$i].value
== '1' || f
[$i].value
== '5') ++count1
;
135 var can_generate
= (count0
> 0 || count1
> 0 || count2
> 0);
136 var can_mark
= (count1
> 0 || count0
> 0 || count2
> 0);
137 var can_bill
= (count0
== 0 && count1
== 0 && count2
> 0);
139 <?php
if (file_exists($EXPORT_INC)) { ?
>
140 f
.bn_external
.disabled
= !can_generate
;
142 // f.bn_hcfa_print.disabled = !can_generate;
143 // f.bn_hcfa.disabled = !can_generate;
144 // f.bn_ub92_print.disabled = !can_generate;
145 // f.bn_ub92.disabled = !can_generate;
146 f
.bn_x12
.disabled
= !can_generate
;
147 <?php
if ($GLOBALS['support_encounter_claims']) { ?
>
148 f
.bn_x12_encounter
.disabled
= !can_generate
;
150 f
.bn_process_hcfa
.disabled
= !can_generate
;
151 f
.bn_hcfa_txt_file
.disabled
= !can_generate
;
152 // f.bn_electronic_file.disabled = !can_bill;
153 f
.bn_reopen
.disabled
= !can_bill
;
155 f
.bn_mark
.disabled
= !can_mark
;
158 // Process a click to go to an encounter.
159 function toencounter(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
.left_nav
.setEncounter(datestr
, enc
, othername
);
165 parent
.left_nav
.setRadio(othername
, 'enc');
166 parent
.frames
[othername
].location
.href
=
167 '../patient_file/encounter/encounter_top.php?set_encounter='
168 + enc +
'&pid=' + pid
;
170 location
.href
= '../patient_file/encounter/patient_encounter.php?set_encounter='
171 + enc +
'&pid=' + pid
;
174 // Process a click to go to an patient.
175 function topatient(pid
, pubpid
, pname
, enc
, datestr
, dobstr
) {
176 top
.restoreSession();
177 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
178 var othername
= (window
.name
== 'RTop') ?
'RBot' : 'RTop';
179 parent
.left_nav
.setPatient(pname
,pid
,pubpid
,'',dobstr
);
180 parent
.frames
[othername
].location
.href
=
181 '../patient_file/summary/demographics_full.php?pid=' + pid
;
183 location
.href
= '../patient_file/summary/demographics_full.php?pid=' + pid
;
187 <script language
="javascript" type
="text/javascript">
188 EncounterDateArray
=new Array;
189 CalendarCategoryArray
=new Array;
190 EncounterIdArray
=new Array;
191 function SubmitTheScreen()
192 {//Action on Update List link
193 if(!ProcessBeforeSubmitting())
195 top
.restoreSession();
196 document
.the_form
.mode
.value
='change';
197 document
.the_form
.target
='_self';
198 document
.the_form
.action
='billing_report.php';
199 document
.the_form
.submit();
202 function SubmitTheScreenPrint()
203 {//Action on View Printable Report link
204 if(!ProcessBeforeSubmitting())
206 top
.restoreSession();
207 document
.the_form
.target
='new';
208 document
.the_form
.action
='print_billing_report.php';
209 document
.the_form
.submit();
212 function SubmitTheScreenExportOFX()
213 {//Action on Export OFX link
214 if(!ProcessBeforeSubmitting())
216 top
.restoreSession();
217 document
.the_form
.mode
.value
='export';
218 document
.the_form
.target
='_self';
219 document
.the_form
.action
='billing_report.php';
220 document
.the_form
.submit();
223 function TestExpandCollapse()
224 {//Checks whether the Expand All, Collapse All labels need to be placed.If any result set is there these will be placed.
226 for(i
=1;i
<=document
.getElementById("divnos").value
;i++
)
228 var ele
= document
.getElementById("divid_"+i
);
237 if(document
.getElementById("ExpandAll"))
239 document
.getElementById("ExpandAll").innerHTML
='';
240 document
.getElementById("CollapseAll").innerHTML
='';
244 function expandcollapse(atr
){
245 if(atr
== "expand") {//Called in the Expand All, Collapse All links(All items will be expanded or collapsed)
246 for(i
=1;i
<=document
.getElementById("divnos").value
;i++
){
247 var mydivid
="divid_"+i
;var myspanid
="spanid_"+i
;
248 var ele
= document
.getElementById(mydivid
); var text
= document
.getElementById(myspanid
);
251 ele
.style
.display
= "inline";text
.innerHTML
= "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
256 for(i
=1;i
<=document
.getElementById("divnos").value
;i++
){
257 var mydivid
="divid_"+i
;var myspanid
="spanid_"+i
;
258 var ele
= document
.getElementById(mydivid
); var text
= document
.getElementById(myspanid
);
261 ele
.style
.display
= "none"; text
.innerHTML
= "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
267 function divtoggle(spanid
, divid
) {//Called in the Expand, Collapse links(This is for a single item)
268 var ele
= document
.getElementById(divid
);
271 var text
= document
.getElementById(spanid
);
272 if(ele
.style
.display
== "inline") {
273 ele
.style
.display
= "none";
274 text
.innerHTML
= "<?php echo htmlspecialchars(xl('Expand'), ENT_QUOTES); ?>";
277 ele
.style
.display
= "inline";
278 text
.innerHTML
= "<?php echo htmlspecialchars(xl('Collapse'), ENT_QUOTES); ?>";
282 function MarkAsCleared(Type
)
284 CheckBoxBillingCount
=0;
285 for (var CheckBoxBillingIndex
=0; ; CheckBoxBillingIndex++
)
287 CheckBoxBillingObject
=document
.getElementById('CheckBoxBilling'+CheckBoxBillingIndex
);
288 if(!CheckBoxBillingObject
)
290 if(CheckBoxBillingObject
.checked
)
292 ++CheckBoxBillingCount
;
297 Message
='<?php echo htmlspecialchars( xl('After saving your batch
, click
[View Log
] to check
for errors
.'), ENT_QUOTES); ?>';
301 Message
='<?php echo htmlspecialchars( xl('After saving the PDF
, click
[View Log
] to check
for errors
.'), ENT_QUOTES); ?>';
305 Message
='<?php echo htmlspecialchars( xl('After saving the TEXT
file(s
), click
[View Log
] to check
for errors
.'), ENT_QUOTES); ?>';
307 if(confirm(Message +
"\n\n\n<?php echo addslashes( xl('Total') ); ?>" +
' ' + CheckBoxBillingCount +
' ' +
"<?php echo addslashes( xl('Selected') ); ?>\n" +
308 "<?php echo addslashes( xl('Would You Like them to be Marked as Cleared.') ); ?>"))
310 document
.getElementById('HiddenMarkAsCleared').value
='yes';
314 document
.getElementById('HiddenMarkAsCleared').value
='';
318 <?php
include_once("$srcdir/../interface/reports/report.script.php"); ?
><!-- Criteria Section common javascript page
-->
319 <!-- ================================================== -->
320 <!-- =============Included
for Insurance ajax criteria
==== -->
321 <!-- ================================================== -->
322 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
323 <?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
324 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
326 #ajax_div_insurance {
329 background
-color
: #FBFDD0;
330 border
: 1px solid
#ccc;
334 <script language
="javascript" type
="text/javascript">
335 document
.onclick
=TakeActionOnHide
;
337 <!-- ================================================== -->
338 <!-- =============Included
for Insurance ajax criteria
==== -->
339 <!-- ================================================== -->
341 <body
class="body_top" onLoad
="TestExpandCollapse()">
343 <p style
='margin-top:5px;margin-bottom:5px;margin-left:5px'>
345 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
346 <font
class='title'><?php
echo xlt('Billing Manager') ?
></font
>
347 <?php
} else if ($userauthorized) { ?
>
348 <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
>
350 <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
>
355 <form name
='the_form' method
='post' action
='billing_report.php' onsubmit
='return top.restoreSession()' style
="display:inline">
357 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
358 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
359 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
360 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
361 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
362 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
363 <script language
='JavaScript'>
367 <input type
='hidden' name
='mode' value
='change'>
368 <!-- ============================================================================================================================================= -->
369 <!-- Criteria section Starts
-->
370 <!-- ============================================================================================================================================= -->
372 //The following are the search criteria per page.All the following variable which ends with 'Master' need to be filled properly.
373 //Each item is seperated by a comma(,).
374 //$ThisPageSearchCriteriaDisplayMaster ==>It is the display on screen for the set of criteria.
375 //$ThisPageSearchCriteriaKeyMaster ==>Corresponding database fields in the same order.
376 //$ThisPageSearchCriteriaDataTypeMaster ==>Corresponding data type in the same order.
377 $ThisPageSearchCriteriaDisplayRadioMaster=array();
378 $ThisPageSearchCriteriaRadioKeyMaster=array();
379 $ThisPageSearchCriteriaQueryDropDownMaster=array();
380 $ThisPageSearchCriteriaQueryDropDownMasterDefault=array();
381 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey=array();
382 $ThisPageSearchCriteriaIncludeMaster=array();
384 $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") );
385 $ThisPageSearchCriteriaKeyMaster="form_encounter.date,billing.date,claims.process_time,claims.target,patient_data.fname,".
386 "form_encounter.pid,claims.payer_id,form_encounter.encounter,insurance_data.provider,billing.id,billing.billed,".
387 "billing.authorized,form_encounter.last_level_billed,billing.x12_partner_id";
388 $ThisPageSearchCriteriaDataTypeMaster="datetime,datetime,datetime,radio,text_like,".
389 "text,include,text,radio,radio,radio,".
390 "radio_like,radio,query_drop_down";
391 //The below section is needed if there is any 'radio' or 'radio_like' type in the $ThisPageSearchCriteriaDataTypeMaster
392 //$ThisPageSearchCriteriaDisplayRadioMaster,$ThisPageSearchCriteriaRadioKeyMaster ==>For each radio data type this pair comes.
393 //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.
394 $ThisPageSearchCriteriaDisplayRadioMaster[1] = array( xl("All"),xl("eClaims"),xl("Paper") );//Display Value
395 $ThisPageSearchCriteriaRadioKeyMaster[1]="all,standard,hcfa";//Key
396 $ThisPageSearchCriteriaDisplayRadioMaster[2]= array( xl("All"),xl("Insured"),xl("Non-Insured") );//Display Value
397 $ThisPageSearchCriteriaRadioKeyMaster[2]="all,1,0";//Key
398 $ThisPageSearchCriteriaDisplayRadioMaster[3]= array( xl("All"),xl("Coded"),xl("Not Coded") );//Display Value
399 $ThisPageSearchCriteriaRadioKeyMaster[3]="all,not null,null";//Key
400 $ThisPageSearchCriteriaDisplayRadioMaster[4]= array( xl("All"),xl("Unbilled"),xl("Billed"),xl("Denied") );//Display Value
401 $ThisPageSearchCriteriaRadioKeyMaster[4]="all,0,1,7";//Key
402 $ThisPageSearchCriteriaDisplayRadioMaster[5]= array( xl("All"),xl("Authorized"),xl("Unauthorized") );
403 $ThisPageSearchCriteriaRadioKeyMaster[5]="%,1,0";
404 $ThisPageSearchCriteriaDisplayRadioMaster[6]= array( xl("All"),xl("None"),xl("Ins 1"),xl("Ins 2 or Ins 3") );
405 $ThisPageSearchCriteriaRadioKeyMaster[6]="all,0,1,2";
406 //The below section is needed if there is any 'query_drop_down' type in the $ThisPageSearchCriteriaDataTypeMaster
407 $ThisPageSearchCriteriaQueryDropDownMaster[1]="SELECT name,id FROM x12_partners;";
408 $ThisPageSearchCriteriaQueryDropDownMasterDefault[1]= xl("All");//Only one item will be here
409 $ThisPageSearchCriteriaQueryDropDownMasterDefaultKey[1]="all";//Only one item will be here
410 //The below section is needed if there is any 'include' type in the $ThisPageSearchCriteriaDataTypeMaster
411 //Function name is added here.Corresponding include files need to be included in the respective pages as done in this page.
412 //It is labled(Included for Insurance ajax criteria)(Line:-279-299).
413 $ThisPageSearchCriteriaIncludeMaster[1]="InsuranceCompanyDisplay";//This is php function defined in the file 'report.inc.php'
415 if(!isset($_REQUEST['mode']))//default case
417 $_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")."')";
418 $_REQUEST['final_this_page_criteria'][1]="billing.billed = '0'";
420 $_REQUEST['final_this_page_criteria_text'][0]=xl("Date of Service = Today");
421 $_REQUEST['final_this_page_criteria_text'][1]=xl("Billing Status = Unbilled");
423 $_REQUEST['date_master_criteria_form_encounter_date']="today";
424 $_REQUEST['master_from_date_form_encounter_date']=date("Y-m-d");
425 $_REQUEST['master_to_date_form_encounter_date']=date("Y-m-d");
427 $_REQUEST['radio_billing_billed']=0;
431 <table width
='100%' border
="0" cellspacing
="0" cellpadding
="0">
433 <td width
="25%"> 
;</td
>
435 <?php
include_once("$srcdir/../interface/reports/criteria.tab.php"); ?
>
439 // ============================================================================================================================================= -->
440 // Criteria section Ends -->
441 // ============================================================================================================================================= -->
444 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
446 <td width
="15%"> 
;</td
>
447 <td width
="85%"><span
class='text'><a onClick
="javascript:return SubmitTheScreen();" href
="#" class=link_submit
>[<?php
echo htmlspecialchars(xl('Update List'), ENT_QUOTES
) ?
>]</a
>
449 <a onClick
="javascript:return SubmitTheScreenExportOFX();" href
="#" class='link_submit'><?php
echo htmlspecialchars(xl('[Export OFX]'), ENT_QUOTES
) ?
></a
></span
> </td
>
453 <td
><a onClick
="javascript:return SubmitTheScreenPrint();" href
="#"
454 class='link_submit' ><?php
echo htmlspecialchars(xl('[View Printable Report]'), ENT_QUOTES
) ?
></a
></td
>
460 $acct_config = $GLOBALS['oer_config']['ws_accounting'];
461 if($acct_config['enabled']) {
462 if($acct_config['enabled'] !== 2) {
463 print '<span class=text><a href="javascript:void window.open(\'' . $acct_config['url_path'] . '\')">' . htmlspecialchars(xl("[SQL-Ledger]"), ENT_QUOTES
) . '</a> </span>';
465 if (acl_check('acct', 'rep')) {
466 print '<span class=text><a href="javascript:void window.open(\'sl_receipts_report.php\')" onclick="top.restoreSession()">' . htmlspecialchars(xl('[Reports]'), ENT_QUOTES
) . '</a> </span>';
468 if (acl_check('acct', 'eob')) {
469 print '<span class=text><a href="javascript:void window.open(\'sl_eob_search.php\')" onclick="top.restoreSession()">' . htmlspecialchars(xl('[EOBs]'), ENT_QUOTES
) . '</a></span>';
478 <?php
if (! file_exists($EXPORT_INC)) { ?
>
480 <a href
="javascript:top.restoreSession();document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
481 title
="Process all queued bills to create electronic data (and print if requested)"><?php
echo htmlspecialchars(xl('[Start Batch Processing]'), ENT_QUOTES
) ?
></a
>
484 <a href
='../../library/freeb/process_bills.log' target
='_blank' class='link_submit'
485 title
='<?php htmlspecialchars(xl('See messages from the last set of generated claims
'), ENT_QUOTES); ?>'><?php
echo htmlspecialchars(xl('[View Log]'), ENT_QUOTES
) ?
></a
>
491 <td
><a href
="javascript:select_all()" class="link_submit"><?php
echo htmlspecialchars(xl('[Select All]','e'), ENT_QUOTES
) ?
></a
></td
>
499 <table width
='100%' border
="0" cellspacing
="0" cellpadding
="0" >
507 <form name
='update_form' method
='post' action
='billing_process.php' onsubmit
='return top.restoreSession()' style
="display:inline">
509 <span
class='text' style
="display:inline">
510 <?php
if (file_exists($EXPORT_INC)) { ?
>
511 <input type
="submit" class="subbtn" name
="bn_external" value
="Export Billing" title
="<?php echo xla('Export to external billing system') ?>">
512 <input type
="submit" class="subbtn" name
="bn_mark" value
="Mark as Cleared" title
="<?php echo xla('Mark as billed but skip billing') ?>">
515 <input type
="submit" class="subbtn" name
="bn_hcfa_print" value
="Queue HCFA & Print" title
="<?php echo xla('Queue for HCFA batch processing and printing') ?>">
516 <input type
="submit" class="subbtn" name
="bn_hcfa" value
="Queue HCFA" title
="<?php echo xla('Queue for HCFA batch processing')?>">
517 <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')?>">
518 <input type
="submit" class="subbtn" name
="bn_ub92" value
="Queue UB92" title
="<?php echo xla('Queue for UB-92 batch processing')?>">
520 <input type
="submit" class="subbtn" name
="bn_x12" value
="<?php echo xla('Generate X12')?>"
521 title
="<?php echo xla('Generate and download X12 batch')?>"
522 onclick
="MarkAsCleared(1)">
523 <?php
if ($GLOBALS['support_encounter_claims']) { ?
>
524 <input type
="submit" class="subbtn" name
="bn_x12_encounter" value
="<?php echo xla('Generate X12 Encounter')?>"
525 title
="<?php echo xla('Generate and download X12 encounter claim batch')?>"
526 onclick
="MarkAsCleared(1)">
528 <input type
="submit" class="subbtn" style
="width:175px;" name
="bn_process_hcfa" value
="<?php echo xla('Generate CMS 1500 PDF')?>"
529 title
="<?php echo xla('Generate and download CMS 1500 paper claims')?>"
530 onclick
="MarkAsCleared(2)">
531 <input type
="submit" class="subbtn" style
="width:175px;" name
="bn_hcfa_txt_file" value
="<?php echo xla('Generate CMS 1500 TEXT')?>"
532 title
="<?php echo xla('Making batch text files for uploading to Clearing House and will mark as billed')?>"
533 onclick
="MarkAsCleared(3)">
534 <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')?>">
535 <input type
="submit" class="subbtn" name
="bn_reopen" value
="<?php echo xla('Re-Open')?>" title
="<?php echo xla('Mark as not billed')?>">
537 <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')?>">
540 <?php
echo xlt('CMS 1500 Margins'); ?
>:
541  
;<?php
echo xlt('Left'); ?
>:
542 <input type
='text' size
='2' name
='left_margin'
543 value
='<?php echo attr($left_margin); ?>'
544 title
='<?php echo xla('HCFA left margin in points
'); ?>' />
545  
;<?php
echo xlt('Top'); ?
>:
546 <input type
='text' size
='2' name
='top_margin'
547 value
='<?php echo attr($top_margin); ?>'
548 title
='<?php echo xla('HCFA top margin in points
'); ?>' />
553 <input type
='hidden' name
='HiddenMarkAsCleared' id
='HiddenMarkAsCleared' value
="" />
554 <input type
='hidden' name
='mode' value
="bill" />
555 <input type
='hidden' name
='authorized' value
="<?php echo attr($my_authorized); ?>" />
556 <input type
='hidden' name
='unbilled' value
="<?php echo attr($unbilled); ?>" />
557 <input type
='hidden' name
='code_type' value
="%" />
558 <input type
='hidden' name
='to_date' value
="<?php echo attr($to_date); ?>" />
559 <input type
='hidden' name
='from_date' value
="<?php echo attr($from_date); ?>" />
562 if ($my_authorized == "on" ) {
563 $my_authorized = "1";
565 $my_authorized = "%";
567 if ($unbilled == "on") {
572 $list = getBillsListBetween("%");
575 <input type
='hidden' name
='bill_list' value
="<?php echo attr($list); ?>" />
577 <!-- new form
for uploading
-->
580 if (!isset($_POST["mode"])) {
581 if (!isset($_POST["from_date"])) {
582 $from_date = date("Y-m-d");
584 $from_date = $_POST["from_date"];
586 if (empty($_POST["to_date"])) {
589 $to_date = $_POST["to_date"];
591 if (!isset($_POST["code_type"])) {
594 $code_type = $_POST["code_type"];
596 if (!isset($_POST["unbilled"])) {
599 $unbilled = $_POST["unbilled"];
601 if (!isset($_POST["authorized"])) {
602 $my_authorized = "on";
604 $my_authorized = $_POST["authorized"];
607 $from_date = $_POST["from_date"];
608 $to_date = $_POST["to_date"];
609 $code_type = $_POST["code_type"];
610 $unbilled = $_POST["unbilled"];
611 $my_authorized = $_POST["authorized"];
614 if ($my_authorized == "on" ) {
615 $my_authorized = "1";
617 $my_authorized = "%";
620 if ($unbilled == "on") {
626 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
627 billCodesList($list);
631 <table border
="0" cellspacing
="0" cellpadding
="0" width
="100%">
634 if ($ret = getBillsBetween("%"))
639 <tr
><td colspan
='8' align
="right" ><table width
="250" border
="0" cellspacing
="0" cellpadding
="0">
641 <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
>
642 <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
>
643 <td width
="50"> 
;</td
>
651 $last_encounter_id = "";
659 $mmo_empty_mod = false;
660 $mmo_num_charges = 0;
663 foreach ($ret as $iter) {
665 // We include encounters here that have never been billed. However
666 // if it had no selected billing items but does have non-selected
667 // billing items, then it is not of interest.
669 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
670 "encounter = ? AND " .
672 "activity = 1", array($iter['enc_encounter'],$iter['enc_pid']) );
673 if ($res['count'] > 0) continue;
676 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
678 if ($last_encounter_id != $this_encounter_id) {
680 // This dumps all HTML for the previous encounter.
683 while ($rcount < $lcount) {
684 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'></td></tr>";
687 // This test handles the case where we are only listing encounters
688 // that appear to have a missing "25" modifier.
689 if (!$missing_mods_only ||
($mmo_empty_mod && $mmo_num_charges > 1)) {
695 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
696 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n\n";
703 $mmo_empty_mod = false;
704 $mmo_num_charges = 0;
706 // If there are ANY unauthorized items in this encounter and this is
707 // the normal case of viewing only authorized billing, then skip the
711 if ($my_authorized == '1') {
712 $res = sqlQuery("select count(*) as count from billing where " .
713 "encounter = ? and " .
715 "activity = 1 and authorized = 0", array($iter['enc_encounter'],$iter['enc_pid']) );
716 if ($res['count'] > 0) {
718 $last_encounter_id = $this_encounter_id;
723 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
725 # Check if patient has primary insurance and a subscriber exists for it.
726 # If not we will highlight their name in red.
727 # TBD: more checking here.
729 $res = sqlQuery("select count(*) as count from insurance_data where " .
731 "type='primary' and " .
732 "subscriber_lname is not null and " .
733 "subscriber_lname != '' limit 1", array($iter['enc_pid']) );
734 $namecolor = ($res['count'] > 0) ?
"black" : "#ff7777";
736 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
737 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
742 $ptname = $name['fname'] . " " . $name['lname'];
743 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
745 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
746 $lhtml .= " <span class=bold><font color='$namecolor'>". text($ptname) .
747 "</font></span><span class=small> (" . text($iter['enc_pid']) . "-" .
748 text($iter['enc_encounter']) . ")</span>";
750 //Encounter details are stored to javacript as array.
751 $result4 = sqlStatement("SELECT fe.encounter,fe.date,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
752 " 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']) );
753 if(sqlNumRows($result4)>0)
755 <script language
='JavaScript'>
757 EncounterDateArray
[<?php
echo attr($iter['enc_pid']); ?
>]=new Array;
758 CalendarCategoryArray
[<?php
echo attr($iter['enc_pid']); ?
>]=new Array;
759 EncounterIdArray
[<?php
echo attr($iter['enc_pid']); ?
>]=new Array;
761 while($rowresult4 = sqlFetchArray($result4))
764 EncounterIdArray
[<?php
echo attr($iter['enc_pid']); ?
>][Count
]='<?php echo htmlspecialchars($rowresult4['encounter
'], ENT_QUOTES); ?>';
765 EncounterDateArray
[<?php
echo attr($iter['enc_pid']); ?
>][Count
]='<?php echo htmlspecialchars(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date
']))), ENT_QUOTES); ?>';
766 CalendarCategoryArray
[<?php
echo attr($iter['enc_pid']); ?
>][Count
]='<?php echo htmlspecialchars( xl_appt_category($rowresult4['pc_catname
']), ENT_QUOTES); ?>';
774 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
775 $lhtml .= " <a class=\"link_submit\" " .
776 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
777 ",'" . addslashes($name['pubpid']) .
778 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
779 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
780 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
781 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
782 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" .
783 xlt('To Enctr') . " " . text(oeFormatShortDate($raw_encounter_date)) . "]</a>";
785 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
786 $lhtml .= " <a class=\"link_submit\" " .
787 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
788 ",'" . addslashes($name['pubpid']) .
789 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
790 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
791 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
792 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
793 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" . xlt('To Dems') . "]</a>";
795 $lhtml .= " <a onclick='divtoggle(\"spanid_$divnos\",\"divid_$divnos\");' class='small' id='aid_$divnos' href=\"JavaScript:void(0);".
796 "\">(<span id=spanid_$divnos class=\"indicator\">" . htmlspecialchars( xl('Expand'), ENT_QUOTES
) . "</span>)</a>";
801 $lhtml .= "<br />\n";
802 $lhtml .= " <span class=text>Bill: ";
803 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' style='background-color:$bgcolor'>";
805 $query = "SELECT id.provider AS id, id.type, id.date, " .
806 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
807 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
808 "ic.id = id.provider AND " .
811 "ORDER BY id.type ASC, id.date DESC";
813 $result = sqlStatement($query, array($iter['enc_pid'],$raw_encounter_date) );
815 $default_x12_partner = $iter['ic_x12id'];
818 while ($row = sqlFetchArray($result)) {
819 if (strcmp($row['type'], $prevtype) == 0) continue;
820 $prevtype = $row['type'];
821 if (strlen($row['provider']) > 0) {
822 // This preserves any existing insurance company selection, which is
823 // important when EOB posting has re-queued for secondary billing.
824 $lhtml .= "<option value=\"" . attr(substr($row['type'],0,1).$row['id']) . "\"";
825 if (($count == 0 && !$iter['payer_id']) ||
$row['id'] == $iter['payer_id']) {
826 $lhtml .= " selected";
827 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
829 $lhtml .= ">" . text($row['type']) . ": " . text($row['provider']) . "</option>";
834 $lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
835 $lhtml .= "</select> \n";
836 $lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][partner]' style='background-color:$bgcolor'>";
837 $x = new X12Partner();
838 $partners = $x->_utility_array($x->x12_partner_factory());
839 foreach ($partners as $xid => $xname) {
840 $lhtml .= '<option label="' . attr($xname) . '" value="' . attr($xid) .'"';
841 if ($xid == $default_x12_partner) {
842 $lhtml .= "selected";
844 $lhtml .= '>' . text($xname) . '</option>';
846 $lhtml .= "</select>";
848 $lhtml .= "<br>\n <div id='divid_$divnos' style='display:none'>" . text(oeFormatShortDate(substr($iter['date'], 0, 10)))
849 . text(substr($iter['date'], 10, 6)) . " " . xlt("Encounter was coded");
851 $query = "SELECT * FROM claims WHERE " .
852 "patient_id = ? AND " .
853 "encounter_id = ? " .
855 $cres = sqlStatement($query, array($iter['enc_pid'],$iter['enc_encounter']) );
859 while ($crow = sqlFetchArray($cres)) {
860 $query = "SELECT id.type, ic.name " .
861 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
863 "id.provider = ? AND " .
864 "id.date <= ? AND " .
865 "ic.id = id.provider " .
866 "ORDER BY id.type ASC, id.date DESC";
868 $irow= sqlQuery($query, array($iter['enc_pid'],$crow['payer_id'],$raw_encounter_date) );
870 if ($crow['bill_process']) {
871 $lhtml .= "<br>\n " .
872 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
873 text(substr($crow['bill_time'], 10, 6)) . " " .
874 xlt("Queued for") . " " . text($irow['type']) . " " . text($crow['target']) . " " .
875 xlt("billing to ") . text($irow['name']);
878 else if ($crow['status'] < 6) {
879 if ($crow['status'] > 1) {
880 $lhtml .= "<br>\n " .
881 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
882 text(substr($crow['bill_time'], 10, 6)) . " " .
883 htmlspecialchars( xl("Marked as cleared"), ENT_QUOTES
);
887 $lhtml .= "<br>\n " .
888 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
889 text(substr($crow['bill_time'], 10, 6)) . " " .
890 htmlspecialchars( xl("Re-opened"), ENT_QUOTES
);
894 else if ($crow['status'] == 6) {
895 $lhtml .= "<br>\n " .
896 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
897 text(substr($crow['bill_time'], 10, 6)) . " " .
898 htmlspecialchars( xl("This claim has been forwarded to next level."), ENT_QUOTES
);
901 else if ($crow['status'] == 7) {
902 $lhtml .= "<br>\n " .
903 text(oeFormatShortDate(substr($crow['bill_time'], 0, 10))) .
904 text(substr($crow['bill_time'], 10, 6)) . " " .
905 htmlspecialchars( xl("This claim has been denied.Reason:-"), ENT_QUOTES
);
906 if($crow['process_file'])
908 $code_array=split(',',$crow['process_file']);
909 foreach($code_array as $code_key => $code_value)
911 $lhtml .= "<br>\n ";
912 $reason_array=split('_',$code_value);
913 if(!isset($adjustment_reasons[$reason_array[3]]))
915 $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]).']';
919 $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]]);
925 $lhtml .=htmlspecialchars( xl("Not Specified."), ENT_QUOTES
);
930 if ($crow['process_time']) {
931 $lhtml .= "<br>\n " .
932 text(oeFormatShortDate(substr($crow['process_time'], 0, 10))) .
933 text(substr($crow['process_time'], 10, 6)) . " " .
934 xlt("Claim was generated to file") . " " .
935 "<a href='get_claim_file.php?key=" . attr($crow['process_file']) .
936 "' onclick='top.restoreSession()'>" .
937 text($crow['process_file']) . "</a>";
942 } // end while ($crow = sqlFetchArray($cres))
944 if ($lastcrow && $lastcrow['status'] == 4) {
945 $lhtml .= "<br>\n " . xlt("This claim has been closed.");
949 if ($lastcrow && $lastcrow['status'] == 5) {
950 $lhtml .= "<br>\n " . xlt("This claim has been canceled.");
953 } // end if ($iter['id'])
955 } // end if ($last_encounter_id != $this_encounter_id)
957 if ($skipping) continue;
959 // Collect info related to the missing modifiers test.
960 if ($iter['fee'] > 0) {
962 $tmp = substr($iter['code'], 0, 3);
963 if (($tmp == '992' ||
$tmp == '993') && empty($iter['modifier']))
964 $mmo_empty_mod = true;
970 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
972 $rhtml .= "<td width='50'>";
973 if ($iter['id'] && $oldcode != $iter['code_type']) {
974 $rhtml .= "<span class=text>" . text($iter['code_type']) . ": </span>";
977 $oldcode = $iter['code_type'];
981 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
982 $js = split(":",$iter['justify']);
984 foreach ($js as $j) {
987 $justify .= " (<b>" . text($j) . "</b>)";
990 $justify .= " (" . text($j) . ")";
997 $rhtml .= "<td><span class='text'>" .
998 ($iter['code_type'] == 'COPAY' ?
text(oeFormatMoney($iter['code'])) : text($iter['code']));
999 if ($iter['modifier']) $rhtml .= ":" . text($iter['modifier']);
1000 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
1002 $rhtml .= '<td align="right"><span style="font-size:8pt;"> ';
1003 if ($iter['id'] && $iter['fee'] > 0) {
1004 $rhtml .= text(oeFormatMoney($iter['fee']));
1006 $rhtml .= "</span></td>\n";
1007 $rhtml .= '<td><span style="font-size:8pt;"> ';
1008 if ($iter['id']) $rhtml .= getProviderName(empty($iter['provider_id']) ?
text($iter['enc_provider_id']) : text($iter['provider_id']));
1009 $rhtml .= "</span></td>\n";
1010 $rhtml .= '<td width=100> <span style="font-size:8pt;">';
1011 if ($iter['id']) $rhtml .= text(oeFormatSDFT(strtotime($iter{"date"})));
1012 $rhtml .= "</span></td>\n";
1013 if ($iter['id'] && $iter['authorized'] != 1) {
1014 $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";
1017 $rhtml .= "<td></td>\n";
1019 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
1020 $tmpbpr = $iter['bill_process'];
1021 if ($tmpbpr == '0' && $iter['billed']) $tmpbpr = '2';
1022 $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";
1026 $rhtml .= "<td></td>\n";
1028 if($last_encounter_id != $this_encounter_id){
1031 $resMoneyGot = sqlStatement("SELECT pay_amount as PatientPay,date(post_time) as date FROM ar_activity where ".
1032 "pid = ? and encounter = ? and payer_type=0 and account_code='PCP'",
1033 array($iter['enc_pid'],$iter['enc_encounter']));
1034 //new fees screen copay gives account_code='PCP'
1035 if(sqlNumRows($resMoneyGot) > 0){
1039 //checks whether a copay exists for the encounter and if exists displays it.
1040 while($rowMoneyGot = sqlFetchArray($resMoneyGot)){
1042 $PatientPay=$rowMoneyGot['PatientPay'];
1043 $date=$rowMoneyGot['date'];
1044 if($PatientPay > 0){
1046 $rhtml2 .= "<tr bgcolor='$bgcolor'>\n";
1048 $rhtml2 .= "<td width='50'>";
1049 $rhtml2 .= "<span class='text'>".xlt('COPAY').": </span>";
1050 $rhtml2 .= "</td>\n";
1051 $rhtml2 .= "<td><span class='text'>".text(oeFormatMoney($PatientPay))."</span><span style='font-size:8pt;'> </span></td>\n";
1052 $rhtml2 .= '<td align="right"><span style="font-size:8pt;"> ';
1053 $rhtml2 .= "</span></td>\n";
1054 $rhtml2 .= '<td><span style="font-size:8pt;"> ';
1055 $rhtml2 .= "</span></td>\n";
1056 $rhtml2 .= '<td width=100> <span style="font-size:8pt;">';
1057 $rhtml2 .= text(oeFormatSDFT(strtotime($date)));
1058 $rhtml2 .= "</span></td>\n";
1059 if ($iter['id'] && $iter['authorized'] != 1) {
1060 $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";
1062 $rhtml2 .= "<td></td>\n";
1064 if(!$iter['id'] && $rowcnt == 1){
1065 $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";
1068 $rhtml2 .= "<td></td>\n";
1074 $rhtml .= "</tr>\n";
1075 $last_encounter_id = $this_encounter_id;
1080 while ($rcount < $lcount) {
1081 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'></td></tr>";
1084 if (!$missing_mods_only ||
($mmo_empty_mod && $mmo_num_charges > 1)) {
1090 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
1091 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
1103 set_button_states();
1106 echo "alert('".addslashes($alertmsg)."');\n";
1110 <input type
="hidden" name
="divnos" id
="divnos" value
="<?php echo attr($divnos) ?>"/>
1111 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />