2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 require_once("../globals.php");
8 require_once("../../library/acl.inc");
9 require_once("../../custom/code_types.inc.php");
10 require_once("$srcdir/patient.inc");
11 require_once("$srcdir/billrep.inc");
12 require_once(dirname(__FILE__
) . "/../../library/classes/OFX.class.php");
13 require_once(dirname(__FILE__
) . "/../../library/classes/X12Partner.class.php");
14 require_once("$srcdir/formatting.inc.php");
16 $EXPORT_INC = "$webserver_root/custom/BillingExport.php";
20 if ($_POST['mode'] == 'export') {
21 $sdate = $_POST['from_date'];
22 $edate = $_POST['to_date'];
24 $sql = "SELECT billing.*, concat(pd.fname, ' ', pd.lname) as name from billing "
25 . "join patient_data as pd on pd.pid = billing.pid where billed = '1' and "
26 . "(process_date > '" . mysql_real_escape_string($sdate)
27 . "' or DATE_FORMAT( process_date, '%Y-%m-%d' ) = '" . mysql_real_escape_string($sdate) ."') "
28 . "and (process_date < '" . mysql_real_escape_string($edate)
29 . "'or DATE_FORMAT( process_date, '%Y-%m-%d' ) = '" . mysql_real_escape_string($edate) ."') "
30 . "order by pid,encounter";
32 $results = $db->Execute($sql);
34 if ($results->RecordCount() == 0) {
35 echo xl("No Bills Found to Include in OFX Export<br>");
38 while(!$results->EOF
) {
39 $billings[] = $results->fields
;
42 $ofx = new OFX($billings);
43 header("Pragma: public");
45 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
46 header("Content-Disposition: attachment; filename=openemr_ofx.ofx");
47 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
;
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 EncounterDateArray
=new Array;
188 CalendarCategoryArray
=new Array;
189 EncounterIdArray
=new Array;
192 <body
class="body_top">
194 <p style
='margin-top:5px;margin-bottom:5px;margin-left:5px'>
196 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
197 <font
class='title'><?php
xl('Billing Report','e') ?
></font
>
198 <?php
} else if ($userauthorized) { ?
>
199 <a href
="../main/main.php" target
='Main' onclick
='top.restoreSession()'><font
class=title
><?php
xl('Billing Report','e') ?
></font
><font
class=more
> <?php
echo $tback; ?
></font
></a
>
201 <a href
="../main/onotes/office_comments.php" target
='Main' onclick
='top.restoreSession()'><font
class=title
><?php
xl('Billing Report','e') ?
></font
><font
class=more
><?php
echo $tback; ?
></font
></a
>
206 <form name
='the_form' method
='post' action
='billing_report.php' onsubmit
='return top.restoreSession()'>
208 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
209 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
210 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
211 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
212 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
213 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
214 <script language
='JavaScript'>
218 <input type
='hidden' name
='mode' value
='change'>
220 <table width
='100%' border
="1" cellspacing
="0" cellpadding
="0">
223  
;<span
class='text'><?php
xl('From: ','e') ?
></span
>
224 <input type
='text' size
='10' name
='from_date' id
='from_date'
225 value
='<?php echo $from_date; ?>'
226 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
227 title
=<?php
xl('yyyy-mm-dd last date of this event','e','\'','\''); ?
> />
228 <img src
='../../interface/pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
229 id
='img_fromdate' border
='0' alt
='[?]' style
='cursor:pointer'
230 title
=<?php
xl('Click here to choose a date','e','\'','\''); ?
> />
232 Calendar
.setup({inputField
:"from_date", ifFormat
:"%Y-%m-%d", button
:"img_fromdate"});
237  
;<span
class='text'><?php
xl('To: ','e') ?
></span
>
238 <input type
='text' size
='10' name
='to_date' id
='to_date'
239 value
='<?php echo $to_date; ?>'
240 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
241 title
=<?php
xl('yyyy-mm-dd last date of this event','e','\'','\''); ?
> />
242 <img src
='../../interface/pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
243 id
='img_todate' border
='0' alt
='[?]' style
='cursor:pointer'
244 title
=<?php
xl('Click here to choose a date','e','\'','\''); ?
> />
246 Calendar
.setup({inputField
:"to_date", ifFormat
:"%Y-%m-%d", button
:"img_todate"});
248 <input type
="hidden" name
="code_type" value
="%" />
252 <input type
='checkbox' name
='unbilled' <?php
if ($unbilled == "on") {echo "checked";}; ?
> />
253 <span
class='text'><?php
xl('Unbilled Only','e') ?
></span
>
255 <input type
='checkbox' name
='authorized' <?php
if ($my_authorized == "on") {echo "checked";}; ?
> />
256 <span
class='text'><?php
xl('Authorized Only','e') ?
></span
>
257 <?php
if (!empty($GLOBALS['missing_mods_option'])) { ?
>
259 <input type
='checkbox' name
='missing_mods_only' <?php
if ($missing_mods_only) echo "checked"; ?
> />
260 <span
class='text'><?php
xl('Missing Mods Only','e') ?
></span
>
264 <td align
='right' width
='10%' nowrap
>
265  
;<span
class='text'><a href
="javascript:top.restoreSession();document.the_form.mode.value='change';document.the_form.submit()" class=link_submit
>[<?php
xl('Update List','e') ?
>]</a
>
267 <a href
="javascript:top.restoreSession();document.the_form.mode.value='export';document.the_form.submit()" class='link_submit'><?php
xl('[Export OFX]','e') ?
></a
></span
> 
;
275  
;<a href
="print_billing_report.php?<?php print "from_date
=".urlencode($ofrom_date)."&to_date
=".urlencode($oto_date)."&code_type
=".urlencode($ocode_type)."&unbilled
=".urlencode($ounbilled)."&authorized
=".urlencode($oauthorized); ?>"
276 class='link_submit' target
='new' onclick
='top.restoreSession()'><?php
xl('[View Printable Report]','e') ?
></a
>
282 $acct_config = $GLOBALS['oer_config']['ws_accounting'];
283 if($acct_config['enabled']) {
284 if($acct_config['enabled'] !== 2) {
285 print '<span class=text><a href="javascript:void window.open(\'' . $acct_config['url_path'] . '\')">' . xl("[SQL-Ledger]") . '</a> </span>';
287 if (acl_check('acct', 'rep')) {
288 print '<span class=text><a href="javascript:void window.open(\'sl_receipts_report.php\')" onclick="top.restoreSession()">' . xl('[Reports]') . '</a> </span>';
290 if (acl_check('acct', 'eob')) {
291 print '<span class=text><a href="javascript:void window.open(\'sl_eob_search.php\')" onclick="top.restoreSession()">' . xl('[EOBs]') . '</a></span>';
297 <td
class='text' nowrap
>
299 <?php
if (! file_exists($EXPORT_INC)) { ?
>
301 <a href
="javascript:top.restoreSession();document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
302 title
="Process all queued bills to create electronic data (and print if requested)"><?php
xl('[Start Batch Processing]','e') ?
></a
>
305 <a href
='../../library/freeb/process_bills.log' target
='_blank' class='link_submit'
306 title
=<?php
xl('See messages from the last set of generated claims','e','\'','\''); ?
>><?php
xl('[View Log]','e') ?
></a
>
310 <td align
='right' nowrap
>
311 <a href
="javascript:select_all()" class="link_submit"><?php
xl('[Select All]','e') ?
></a
> 
;
319 <form name
='update_form' method
='post' action
='billing_process.php' onsubmit
='return top.restoreSession()'>
324 <?php
if (file_exists($EXPORT_INC)) { ?
>
325 <input type
="submit" class="subbtn" name
="bn_external" value
="Export Billing" title
="<?php xl('Export to external billing system','e') ?>">
326 <input type
="submit" class="subbtn" name
="bn_mark" value
="Mark as Cleared" title
="<?php xl('Mark as billed but skip billing','e') ?>">
329 <input type
="submit" class="subbtn" name
="bn_hcfa_print" value
="Queue HCFA & Print" title
="<?php xl('Queue for HCFA batch processing and printing','e') ?>">
330 <input type
="submit" class="subbtn" name
="bn_hcfa" value
="Queue HCFA" title
="<?php xl('Queue for HCFA batch processing','e')?>">
331 <input type
="submit" class="subbtn" name
="bn_ub92_print" value
="Queue UB92 & Print" title
="<?php xl('Queue for UB-92 batch processing and printing','e')?>">
332 <input type
="submit" class="subbtn" name
="bn_ub92" value
="Queue UB92" title
="<?php xl('Queue for UB-92 batch processing','e')?>">
334 <input type
="submit" class="subbtn" name
="bn_x12" value
="<?php xl('Generate X12','e')?>"
335 title
="<?php xl('Generate and download X12 batch','e')?>"
336 onclick
="alert('<?php xl('After saving your batch, click [View Log] to check for errors.','e'); ?>')">
337 <?php
if ($GLOBALS['support_encounter_claims']) { ?
>
338 <input type
="submit" class="subbtn" name
="bn_x12_encounter" value
="<?php xl('Generate X12 Encounter','e')?>"
339 title
="<?php xl('Generate and download X12 encounter claim batch','e')?>"
340 onclick
="alert('<?php xl('After saving your batch, click [View Log] to check for errors.','e'); ?>')">
342 <input type
="submit" class="subbtn" name
="bn_process_hcfa" value
="<?php xl('Generate CMS 1500 PDF','e')?>"
343 title
="<?php xl('Generate and download CMS 1500 paper claims','e')?>"
344 onclick
="alert('<?php xl('After saving the PDF, click [View Log] to check for errors.','e'); ?>')">
345 <input type
="submit" class="subbtn" name
="bn_hcfa_txt_file" value
="<?php xl('Generate CMS 1500 TEXT','e')?>"
346 title
="<?php xl('Making batch text files for uploading to Clearing House and will mark as billed', 'e')?>"
347 onclick
="alert('<?php xl('After saving the TEXT file(s), click [View Log] to check for errors.','e'); ?>')">
348 <input type
="submit" class="subbtn" name
="bn_mark" value
="<?php xl('Mark as Cleared','e')?>" title
="<?php xl('Post to accounting and mark as billed','e')?>">
349 <input type
="submit" class="subbtn" name
="bn_reopen" value
="<?php xl('Re-Open','e')?>" title
="<?php xl('Mark as not billed','e')?>">
351 <input type
="submit" class="subbtn" name
="bn_electronic_file" value
="Make Electronic Batch & Clear" title
="<?php xl('Download billing file, post to accounting and mark as billed','e')?>">
354 <?php
xl('CMS 1500 Margins','e'); ?
>:
355  
;<?php
xl('Left','e'); ?
>:
356 <input type
='text' size
='2' name
='left_margin'
357 value
='<?php echo $left_margin; ?>'
358 title
=<?php
xl('HCFA left margin in points','e','\'','\''); ?
> />
359  
;<?php
xl('Top','e'); ?
>:
360 <input type
='text' size
='2' name
='top_margin'
361 value
='<?php echo $top_margin; ?>'
362 title
=<?php
xl('HCFA top margin in points','e','\'','\''); ?
> />
368 <input type
='hidden' name
='mode' value
="bill" />
369 <input type
='hidden' name
='authorized' value
="<?php echo $my_authorized; ?>" />
370 <input type
='hidden' name
='unbilled' value
="<?php echo $unbilled; ?>" />
371 <input type
='hidden' name
='code_type' value
="%" />
372 <input type
='hidden' name
='to_date' value
="<?php echo $to_date; ?>" />
373 <input type
='hidden' name
='from_date' value
="<?php echo $from_date; ?>" />
376 if ($my_authorized == "on" ) {
377 $my_authorized = "1";
379 $my_authorized = "%";
381 if ($unbilled == "on") {
387 $list = getBillsListBetween($from_date,
388 empty($to_date) ?
$from_date : $to_date,
389 $my_authorized,$unbilled,"%");
392 <input type
='hidden' name
='bill_list' value
="<?php echo $list; ?>" />
394 <!-- new form
for uploading
-->
397 if (!isset($_POST["mode"])) {
398 if (!isset($_POST["from_date"])) {
399 $from_date = date("Y-m-d");
401 $from_date = $_POST["from_date"];
403 if (empty($_POST["to_date"])) {
406 $to_date = $_POST["to_date"];
408 if (!isset($_POST["code_type"])) {
411 $code_type = $_POST["code_type"];
413 if (!isset($_POST["unbilled"])) {
416 $unbilled = $_POST["unbilled"];
418 if (!isset($_POST["authorized"])) {
419 $my_authorized = "on";
421 $my_authorized = $_POST["authorized"];
424 $from_date = $_POST["from_date"];
425 $to_date = $_POST["to_date"];
426 $code_type = $_POST["code_type"];
427 $unbilled = $_POST["unbilled"];
428 $my_authorized = $_POST["authorized"];
431 if ($my_authorized == "on" ) {
432 $my_authorized = "1";
434 $my_authorized = "%";
437 if ($unbilled == "on") {
443 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
444 billCodesList($list);
449 <table border
="0" cellspacing
="0" cellpadding
="0" width
="100%">
452 if ($ret = getBillsBetween($from_date,
453 empty($to_date) ?
$from_date : $to_date,
454 $my_authorized, $unbilled, "%"))
458 $last_encounter_id = "";
466 $mmo_empty_mod = false;
467 $mmo_num_charges = 0;
469 foreach ($ret as $iter) {
471 // We include encounters here that have never been billed. However
472 // if it had no selected billing items but does have non-selected
473 // billing items, then it is not of interest.
475 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
476 "encounter = '" . $iter['enc_encounter'] . "' AND " .
477 "pid='" . $iter['enc_pid'] . "' AND " .
479 if ($res['count'] > 0) continue;
482 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
484 if ($last_encounter_id != $this_encounter_id) {
486 // This dumps all HTML for the previous encounter.
489 while ($rcount < $lcount) {
490 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'> </td></tr>";
493 // This test handles the case where we are only listing encounters
494 // that appear to have a missing "25" modifier.
495 if (!$missing_mods_only ||
($mmo_empty_mod && $mmo_num_charges > 1)) {
496 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
497 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n\n";
504 $mmo_empty_mod = false;
505 $mmo_num_charges = 0;
507 // If there are ANY unauthorized items in this encounter and this is
508 // the normal case of viewing only authorized billing, then skip the
512 if ($my_authorized == '1') {
513 $res = sqlQuery("select count(*) as count from billing where " .
514 "encounter = '" . $iter['enc_encounter'] . "' and " .
515 "pid='" . $iter['enc_pid'] . "' and " .
516 "activity = 1 and authorized = 0");
517 if ($res['count'] > 0) {
519 $last_encounter_id = $this_encounter_id;
524 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
526 # Check if patient has primary insurance and a subscriber exists for it.
527 # If not we will highlight their name in red.
528 # TBD: more checking here.
530 $res = sqlQuery("select count(*) as count from insurance_data where " .
531 "pid = " . $iter['enc_pid'] . " and " .
532 "type='primary' and " .
533 "subscriber_lname is not null and " .
534 "subscriber_lname != '' limit 1");
535 $namecolor = ($res['count'] > 0) ?
"black" : "#ff7777";
537 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
538 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
543 $ptname = $name['fname'] . " " . $name['lname'];
544 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
546 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
547 $lhtml .= " <span class=bold><font color='$namecolor'>$ptname" .
548 "</font></span><span class=small> (" . $iter['enc_pid'] . "-" .
549 $iter['enc_encounter'] . ")</span>";
551 //Encounter details are stored to javacript as array.
552 $result4 = sqlStatement("SELECT fe.encounter,fe.date,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
553 " left join openemr_postcalendar_categories on fe.pc_catid=openemr_postcalendar_categories.pc_catid WHERE fe.pid = '".$iter['enc_pid']."' order by fe.date desc");
554 if(sqlNumRows($result4)>0)
556 <script language
='JavaScript'>
558 EncounterDateArray
[<?php
echo $iter['enc_pid']; ?
>]=new Array;
559 CalendarCategoryArray
[<?php
echo $iter['enc_pid']; ?
>]=new Array;
560 EncounterIdArray
[<?php
echo $iter['enc_pid']; ?
>]=new Array;
562 while($rowresult4 = sqlFetchArray($result4))
565 EncounterIdArray
[<?php
echo $iter['enc_pid']; ?
>][Count
]='<?php echo htmlspecialchars($rowresult4['encounter
'], ENT_QUOTES); ?>';
566 EncounterDateArray
[<?php
echo $iter['enc_pid']; ?
>][Count
]='<?php echo htmlspecialchars(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date
']))), ENT_QUOTES); ?>';
567 CalendarCategoryArray
[<?php
echo $iter['enc_pid']; ?
>][Count
]='<?php echo htmlspecialchars( xl_appt_category($rowresult4['pc_catname
']), ENT_QUOTES); ?>';
575 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
576 $lhtml .= " <a class=\"link_submit\" " .
577 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
578 ",'" . addslashes($name['pubpid']) .
579 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
580 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
581 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
582 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
583 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" .
584 xl('To Enctr') . " " . oeFormatShortDate($raw_encounter_date) . "]</a>";
586 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
587 $lhtml .= " <a class=\"link_submit\" " .
588 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
589 ",'" . addslashes($name['pubpid']) .
590 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
591 ",'" . oeFormatShortDate($raw_encounter_date) . "',' " .
592 xl('DOB') . ": " . oeFormatShortDate($name['DOB_YMD']) . " " . xl('Age') . ": " . getPatientAge($name['DOB_YMD']) . "');
593 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray[" . $iter['enc_pid'] . "],EncounterDateArray[" . $iter['enc_pid'] .
594 "], CalendarCategoryArray[" . $iter['enc_pid'] . "])\">[" . xl('To Dems') . "]</a>";
599 $lhtml .= "<br />\n";
600 $lhtml .= " <span class=text>Bill: ";
601 $lhtml .= "<select name='claims[" . $this_encounter_id . "][payer]' style='background-color:$bgcolor'>";
603 $query = "SELECT id.provider AS id, id.type, id.date, " .
604 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
605 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
606 "ic.id = id.provider AND " .
607 "id.pid = '" . mysql_escape_string($iter['enc_pid']) . "' AND " .
608 "id.date <= '$raw_encounter_date' " .
609 "ORDER BY id.type ASC, id.date DESC";
611 $result = sqlStatement($query);
613 $default_x12_partner = $iter['ic_x12id'];
616 while ($row = mysql_fetch_array($result)) {
617 if (strcmp($row['type'], $prevtype) == 0) continue;
618 $prevtype = $row['type'];
619 if (strlen($row['provider']) > 0) {
620 // This preserves any existing insurance company selection, which is
621 // important when EOB posting has re-queued for secondary billing.
622 $lhtml .= "<option value=\"" . strtoupper(substr($row['type'],0,1)) . $row['id'] . "\"";
623 if (($count == 0 && !$iter['payer_id']) ||
$row['id'] == $iter['payer_id']) {
624 $lhtml .= " selected";
625 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
627 $lhtml .= ">" . $row['type'] . ": " . $row['provider'] . "</option>";
632 $lhtml .= "<option value='-1'>Unassigned</option>\n";
633 $lhtml .= "</select> \n";
634 $lhtml .= "<select name='claims[" . $this_encounter_id . "][partner]' style='background-color:$bgcolor'>";
635 $x = new X12Partner();
636 $partners = $x->_utility_array($x->x12_partner_factory());
637 foreach ($partners as $xid => $xname) {
638 $lhtml .= '<option label="' . $xname . '" value="' . $xid .'"';
639 if ($xid == $default_x12_partner) {
640 $lhtml .= "selected";
642 $lhtml .= '>' . $xname . '</option>';
644 $lhtml .= "</select>";
645 $lhtml .= "<br>\n " . oeFormatShortDate(substr($iter['date'], 0, 10))
646 . substr($iter['date'], 10, 6) . " " . xl("Encounter was coded");
648 $query = "SELECT * FROM claims WHERE " .
649 "patient_id = '" . $iter['enc_pid'] . "' AND " .
650 "encounter_id = '" . $iter['enc_encounter'] . "' " .
652 $cres = sqlStatement($query);
656 while ($crow = sqlFetchArray($cres)) {
657 $query = "SELECT id.type, ic.name " .
658 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
659 "id.pid = '" . $iter['enc_pid'] . "' AND " .
660 "id.provider = '" . $crow['payer_id'] . "' AND " .
661 "id.date <= '$raw_encounter_date' AND " .
662 "ic.id = id.provider " .
663 "ORDER BY id.type ASC, id.date DESC";
665 $irow= sqlQuery($query);
667 if ($crow['bill_process']) {
668 $lhtml .= "<br>\n " .
669 oeFormatShortDate(substr($crow['bill_time'], 0, 10)) .
670 substr($crow['bill_time'], 10, 6) . " " .
671 xl("Queued for") . " {$irow['type']} {$crow['target']} " .
672 xl("billing to ") . $irow['name'];
675 else if ($crow['status'] > 1) {
676 $lhtml .= "<br>\n " .
677 oeFormatShortDate(substr($crow['bill_time'], 0, 10)) .
678 substr($crow['bill_time'], 10, 6) . " " .
679 xl("Marked as cleared");
683 $lhtml .= "<br>\n " .
684 oeFormatShortDate(substr($crow['bill_time'], 0, 10)) .
685 substr($crow['bill_time'], 10, 6) . " " .
690 if ($crow['process_time']) {
691 $lhtml .= "<br>\n " .
692 oeFormatShortDate(substr($crow['process_time'], 0, 10)) .
693 substr($crow['process_time'], 10, 6) . " " .
694 xl("Claim was generated to file ") .
695 "<a href='get_claim_file.php?key=" . $crow['process_file'] .
696 "' onclick='top.restoreSession()'>" .
697 $crow['process_file'] . "</a>";
702 } // end while ($crow = sqlFetchArray($cres))
704 if ($lastcrow && $lastcrow['status'] == 4) {
705 $lhtml .= "<br>\n This claim has been closed.";
709 if ($lastcrow && $lastcrow['status'] == 5) {
710 $lhtml .= "<br>\n This claim has been canceled.";
713 } // end if ($iter['id'])
715 } // end if ($last_encounter_id != $this_encounter_id)
717 if ($skipping) continue;
719 // Collect info related to the missing modifiers test.
720 if ($iter['fee'] > 0) {
722 $tmp = substr($iter['code'], 0, 3);
723 if (($tmp == '992' ||
$tmp == '993') && empty($iter['modifier']))
724 $mmo_empty_mod = true;
730 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
732 $rhtml .= "<td width='50'>";
733 if ($iter['id'] && $oldcode != $iter['code_type']) {
734 $rhtml .= "<span class=text>" . $iter['code_type'] . ": </span>";
737 $oldcode = $iter['code_type'];
741 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
742 $js = split(":",$iter['justify']);
744 foreach ($js as $j) {
747 $justify .= " (<b>$j</b>)";
757 $rhtml .= "<td><span class='text'>" .
758 ($iter['code_type'] == 'COPAY' ?
oeFormatMoney($iter['code']) : $iter['code']);
759 if ($iter['modifier']) $rhtml .= ":" . $iter['modifier'];
760 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
762 $rhtml .= '<td align="right"><span style="font-size:8pt;"> ';
763 if ($iter['id'] && $iter['fee'] > 0) {
764 $rhtml .= oeFormatMoney($iter['fee']);
766 $rhtml .= "</span></td>\n";
767 $rhtml .= '<td><span style="font-size:8pt;"> ';
768 if ($iter['id']) $rhtml .= getProviderName(empty($iter['provider_id']) ?
$iter['enc_provider_id'] : $iter['provider_id']);
769 $rhtml .= "</span></td>\n";
770 $rhtml .= '<td width=100> <span style="font-size:8pt;">';
771 if ($iter['id']) $rhtml .= oeFormatSDFT(strtotime($iter{"date"}));
772 $rhtml .= "</span></td>\n";
773 if ($iter['id'] && $iter['authorized'] != 1) {
774 $rhtml .= "<td><span class=alert>".xl("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";
777 $rhtml .= "<td></td>\n";
779 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
780 $tmpbpr = $iter['bill_process'];
781 if ($tmpbpr == '0' && $iter['billed']) $tmpbpr = '2';
782 $rhtml .= "<td><input type='checkbox' value='$tmpbpr' name='claims[" . $this_encounter_id . "][bill]' onclick='set_button_states()'> </td>\n";
785 $rhtml .= "<td></td>\n";
788 $last_encounter_id = $this_encounter_id;
793 while ($rcount < $lcount) {
794 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'> </td></tr>";
797 if (!$missing_mods_only ||
($mmo_empty_mod && $mmo_num_charges > 1)) {
798 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
799 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
814 echo "alert('$alertmsg');\n";