allow marking queued claims as cleared
[openemr.git] / interface / billing / billing_report.php
blobf703da411d366ca140d769e48a3fb4039abda6e4
1 <?php
2 include_once("../globals.php");
3 include_once("../../library/acl.inc");
4 include_once("../../custom/code_types.inc.php");
6 include_once("$srcdir/patient.inc");
7 include_once("$srcdir/billrep.inc");
8 include_once(dirname(__FILE__) . "/../../library/classes/OFX.class.php");
9 include_once(dirname(__FILE__) . "/../../library/classes/X12Partner.class.php");
11 $EXPORT_INC = "$webserver_root/custom/BillingExport.php";
13 $alertmsg = '';
15 if ($_POST['mode'] == 'export') {
16 $sdate = $_POST['from_date'];
17 $edate = $_POST['to_date'];
19 $sql = "SELECT billing.*, concat(pd.fname, ' ', pd.lname) as name from billing "
20 . "join patient_data as pd on pd.pid = billing.pid where billed = '1' and "
21 . "(process_date > '" . mysql_real_escape_string($sdate)
22 . "' or DATE_FORMAT( process_date, '%Y-%m-%d' ) = '" . mysql_real_escape_string($sdate) ."') "
23 . "and (process_date < '" . mysql_real_escape_string($edate)
24 . "'or DATE_FORMAT( process_date, '%Y-%m-%d' ) = '" . mysql_real_escape_string($edate) ."') "
25 . "order by pid,encounter";
26 $db = get_db();
27 $results = $db->Execute($sql);
28 $billings = array();
29 if ($results->RecordCount() == 0) {
30 echo xl("No Bills Found to Include in OFX Export<br>");
32 else {
33 while(!$results->EOF) {
34 $billings[] = $results->fields;
35 $results->MoveNext();
37 $ofx = new OFX($billings);
38 header("Pragma: public");
39 header("Expires: 0");
40 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
41 header("Content-Disposition: attachment; filename=openemr_ofx.ofx");
42 header("Content-Type: text/xml");
43 echo $ofx->get_OFX();
44 exit;
48 if ($_POST['mode'] == 'process') {
49 if (exec("ps x | grep 'process_bills[.]php'")) {
50 $alertmsg = xl('Request ignored - claims processing is already running!');
52 else {
53 exec("cd $webserver_root/library/freeb;" .
54 "php -q process_bills.php bill > process_bills.log 2>&1 &");
55 $alertmsg = xl('Batch processing initiated; this may take a while.');
59 //global variables:
60 if (!isset($_POST["mode"])) {
61 if (!isset($_POST["from_date"])) {
62 $from_date=date("Y-m-d");
63 } else {
64 $from_date = $_POST["from_date"];
66 if (!isset($_POST["to_date"])) {
67 $to_date = date("Y-m-d");
68 } else {
69 $to_date = $_POST["to_date"];
71 if (!isset($_POST["code_type"])) {
72 $code_type="all";
73 } else {
74 $code_type = $_POST["code_type"];
76 if (!isset($_POST["unbilled"])) {
77 $unbilled = "on";
78 } else {
79 $unbilled = $_POST["unbilled"];
81 // if (!isset($_POST["authorized"])) {
82 // $my_authorized = "on";
83 // } else {
84 $my_authorized = $_POST["authorized"];
85 // }
86 } else {
87 $from_date = $_POST["from_date"];
88 $to_date = $_POST["to_date"];
89 $code_type = $_POST["code_type"];
90 $unbilled = $_POST["unbilled"];
91 $my_authorized = $_POST["authorized"];
94 $ofrom_date = $from_date;
95 $oto_date = $to_date;
96 $ocode_type = $code_type;
97 $ounbilled = $unbilled;
98 $oauthorized = $my_authorized;
102 <html>
103 <head>
104 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
105 <style>
106 .subbtn { margin-top:3px; margin-bottom:3px; margin-left:2px; margin-right:2px }
107 </style>
108 <script>
110 function select_all() {
111 for($i=0;$i < document.update_form.length;$i++) {
112 $name = document.update_form[$i].name;
113 if ($name.substring(0,7) == "claims[" && $name.substring($name.length -6) == "[bill]") {
114 document.update_form[$i].checked = true;
117 set_button_states();
120 function set_button_states() {
121 var f = document.update_form;
122 var count0 = 0; // selected and not billed or queued
123 var count1 = 0; // selected and queued
124 var count2 = 0; // selected and billed
125 for($i = 0; $i < f.length; ++$i) {
126 $name = f[$i].name;
127 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -6) == "[bill]" && f[$i].checked == true) {
128 if (f[$i].value == '0') ++count0;
129 else if (f[$i].value == '1' || f[$i].value == '5') ++count1;
130 else ++count2;
134 var can_generate = (count0 > 0 || count1 > 0 || count2 > 0);
135 var can_mark = (count1 > 0 || count0 > 0 || count2 > 0);
136 var can_bill = (count0 == 0 && count1 == 0 && count2 > 0);
138 <?php if (file_exists($EXPORT_INC)) { ?>
139 f.bn_external.disabled = !can_generate;
140 <?php } else { ?>
141 f.bn_hcfa_print.disabled = !can_generate;
142 f.bn_hcfa.disabled = !can_generate;
143 f.bn_ub92_print.disabled = !can_generate;
144 f.bn_ub92.disabled = !can_generate;
145 f.bn_x12.disabled = !can_generate;
146 f.bn_electronic_file.disabled = !can_bill;
147 f.bn_reopen.disabled = !can_bill;
148 <?php } ?>
149 f.bn_mark.disabled = !can_mark;
152 // Process a click to go to an encounter.
153 function toencounter(pid, pname, enc, datestr) {
154 <?php if ($GLOBALS['concurrent_layout']) { ?>
155 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
156 parent.left_nav.setPatient(pname,pid,'');
157 parent.left_nav.setEncounter(datestr, enc, othername);
158 parent.left_nav.setRadio(othername, 'enc');
159 parent.frames[othername].location.href =
160 '../patient_file/encounter/encounter_top.php?set_encounter='
161 + enc + '&pid=' + pid;
162 <?php } else { ?>
163 location.href = '../patient_file/encounter/patient_encounter.php?set_encounter='
164 + enc + '&pid=' + pid;
165 <?php } ?>
168 // Process a click to go to patient demographics.
169 function topatient(pid) {
170 <?php if ($GLOBALS['concurrent_layout']) { ?>
171 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
172 parent.frames[othername].location.href =
173 '../patient_file/summary/demographics_full.php?pid=' + pid;
174 <?php } else { ?>
175 location.href = '../patient_file/summary/demographics_full.php?pid=' + pid;
176 <?php } ?>
179 </script>
180 </head>
181 <body <?php echo $top_bg_line; ?> topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
183 <p style='margin-top:5px;margin-bottom:5px;margin-left:5px'>
184 <?php if ($GLOBALS['concurrent_layout']) { ?>
185 <font class='title'><?php xl('Billing Report','e') ?></font>
186 <?php } else if ($userauthorized) { ?>
187 <a href="../main/main.php" target=Main><font class=title><?php xl('Billing Report','e') ?></font><font class=more> <?php echo $tback; ?></font></a>
188 <?php } else { ?>
189 <a href="../main/onotes/office_comments.php" target=Main><font class=title><?php xl('Billing Report','e') ?></font><font class=more><?php echo $tback; ?></font></a>
190 <?php } ?>
191 </p>
193 <form name=the_form method=post action=billing_report.php>
195 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
196 <script type="text/javascript" src="../../library/dialog.js"></script>
197 <script type="text/javascript" src="../../library/textformat.js"></script>
198 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
199 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
200 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
201 <script language='JavaScript'>
202 var mypcc = '1';
203 </script>
205 <input type='hidden' name='mode' value='change'>
206 <table width='100%' border="1" cellspacing="0" cellpadding="0">
207 <tr>
209 <td nowrap>
210 &nbsp;<span class='text'><?php xl('From: ','e') ?></span>
211 <input type='text' size='10' name='from_date' id='from_date'
212 value='<?php echo $from_date; ?>'
213 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
214 title='yyyy-mm-dd last date of this event' />
215 <img src='../../interface/pic/show_calendar.gif' align='absbottom' width='24' height='22'
216 id='img_fromdate' border='0' alt='[?]' style='cursor:pointer'
217 title='Click here to choose a date'>
218 <script>
219 Calendar.setup({inputField:"from_date", ifFormat:"%Y-%m-%d", button:"img_fromdate"});
220 </script>
221 </td>
223 <td nowrap>
224 &nbsp;<span class='text'><?php xl('To: ','e') ?></span>
225 <input type='text' size='10' name='to_date' id='to_date'
226 value='<?php echo $to_date; ?>'
227 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
228 title='yyyy-mm-dd last date of this event' />
229 <img src='../../interface/pic/show_calendar.gif' align='absbottom' width='24' height='22'
230 id='img_todate' border='0' alt='[?]' style='cursor:pointer'
231 title='Click here to choose a date' />
232 <script>
233 Calendar.setup({inputField:"to_date", ifFormat:"%Y-%m-%d", button:"img_todate"});
234 </script>
235 <input type="hidden" name="code_type" value="%" />
236 </td>
238 <td nowrap>
239 <input type='checkbox' name='unbilled' <?php if ($unbilled == "on") {echo "checked";}; ?> />
240 <span class='text'><?php xl('Show Unbilled Only','e') ?></span>
241 </td>
243 <td nowrap>
244 <input type='checkbox' name='authorized' <?php if ($my_authorized == "on") {echo "checked";}; ?> />
245 <span class='text'><?php xl('Show Authorized Only','e') ?></span>
246 </td>
248 <td align='right' width='10%' nowrap>
249 &nbsp;<span class='text'><a href="javascript:document.the_form.mode.value='change';document.the_form.submit()" class=link_submit><?php xl('[Change View]','e') ?></a>
251 <a href="javascript:document.the_form.mode.value='export';document.the_form.submit()" class='link_submit'><?php xl('[Export OFX]','e') ?></a></span>&nbsp;
252 </td>
253 </tr>
255 <tr>
256 <td nowrap>
257 &nbsp;<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); ?>"
258 class='link_submit' target='new'><?php xl('[View Printable Report]','e') ?></a>
259 </td>
261 <td nowrap>
262 <?php
263 print '&nbsp;';
264 $acct_config = $GLOBALS['oer_config']['ws_accounting'];
265 if($acct_config['enabled'] == true) {
266 print '<span class=text><a href="javascript:void window.open(\'' . $acct_config['url_path'] . '\')">' . xl("[SQL-Ledger]") . '</a></span>';
267 if (acl_check('acct', 'rep')) {
268 print '<span class=text> &nbsp; <a href="javascript:void window.open(\'sl_receipts_report.php\')">' . xl('[Reports]') . '</a></span>';
270 if (acl_check('acct', 'eob')) {
271 print '<span class=text> &nbsp; <a href="javascript:void window.open(\'sl_eob_search.php\')">' . xl('[EOBs]') . '</a></span>';
275 </td>
277 <td colspan='2' nowrap>
278 &nbsp;
279 <?php if (! file_exists($EXPORT_INC)) { ?>
280 <a href="javascript:document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
281 title="Process all queued bills to create electronic data (and print if requested)"><?php xl('[Start Batch Processing]','e') ?></a>
282 &nbsp; <a href='../../library/freeb/process_bills.log' target='_blank' class='link_submit'
283 title='See messages from the last batch processing run'><?php xl('[view log]','e') ?></a>
284 <?php } ?>
285 </td>
287 <td align='right' nowrap>
288 <a href="javascript:select_all()" class="link_submit"><?php xl('[Select All]','e') ?></a>&nbsp;
289 </td>
291 </tr>
292 </table>
293 </form>
295 <form name='update_form' method='post' action='billing_process.php'>
297 <center>
299 <?php if (file_exists($EXPORT_INC)) { ?>
300 <input type="submit" class="subbtn" name="bn_external" value="Export Billing" title="<?php xl('Export to external billing system','e') ?>">
301 <input type="submit" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php xl('Mark as billed but skip billing','e') ?>">
302 <?php } else { ?>
303 <input type="submit" class="subbtn" name="bn_hcfa_print" value="Queue HCFA &amp; Print" title="<?php xl('Queue for HCFA batch processing and printing','e') ?>">
304 <input type="submit" class="subbtn" name="bn_hcfa" value="Queue HCFA" title="<?php xl('Queue for HCFA batch processing','e')?>">
305 <input type="submit" class="subbtn" name="bn_ub92_print" value="Queue UB92 &amp; Print" title="<?php xl('Queue for UB-92 batch processing and printing','e')?>">
306 <input type="submit" class="subbtn" name="bn_ub92" value="Queue UB92" title="<?php xl('Queue for UB-92 batch processing','e')?>">
307 <input type="submit" class="subbtn" name="bn_x12" value="Process X12"
308 title="<?php xl('Generate X12 claims and create batch','e')?>"
309 onclick="alert('After saving your batch, click [view log] to check for errors.')">
310 <input type="submit" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php xl('Post to accounting and mark as billed','e')?>">
311 <input type="submit" class="subbtn" name="bn_reopen" value="Re-Open" title="<?php xl('Mark as not billed','e')?>">
312 <input type="submit" class="subbtn" name="bn_electronic_file" value="Make Electronic Batch &amp; Clear" title="<?php xl('Download billing file, post to accounting and mark as billed','e')?>">
313 <?php } ?>
315 </center>
317 <input type='hidden' name='mode' value="bill" />
318 <input type='hidden' name='authorized' value="<?php echo $my_authorized; ?>" />
319 <input type='hidden' name='unbilled' value="<?php echo $unbilled; ?>" />
320 <input type='hidden' name='code_type' value="%" />
321 <input type='hidden' name='to_date' value="<?php echo $to_date; ?>" />
322 <input type='hidden' name='from_date' value="<?php echo $from_date; ?>" />
323 <?php
324 if ($my_authorized == "on" ) {
325 $my_authorized = "1";
326 } else {
327 $my_authorized = "%";
330 if ($unbilled == "on") {
331 $unbilled = "0";
332 } else {
333 $unbilled = "%";
336 <input type='hidden' name='bill_list' value="<?php
337 $list = getBillsListBetween($from_date,$to_date,$my_authorized,$unbilled,"%");
338 print $list;
339 ?>" />
340 <!-- new form for uploading -->
341 <?php
342 if (!isset($_POST["mode"])) {
343 if (!isset($_POST["from_date"])) {
344 $from_date=date("Y-m-d");
345 } else {
346 $from_date = $_POST["from_date"];
348 if (!isset($_POST["to_date"])) {
349 $to_date = date("Y-m-d");
350 } else {
351 $to_date = $_POST["to_date"];
353 if (!isset($_POST["code_type"])) {
354 $code_type="all";
355 } else {
356 $code_type = $_POST["code_type"];
358 if (!isset($_POST["unbilled"])) {
359 $unbilled = "on";
360 } else {
361 $unbilled = $_POST["unbilled"];
363 if (!isset($_POST["authorized"])) {
364 $my_authorized = "on";
365 } else {
366 $my_authorized = $_POST["authorized"];
368 } else {
369 $from_date = $_POST["from_date"];
370 $to_date = $_POST["to_date"];
371 $code_type = $_POST["code_type"];
372 $unbilled = $_POST["unbilled"];
373 $my_authorized = $_POST["authorized"];
375 if ($my_authorized == "on" ) {
376 $my_authorized = "1";
377 } else {
378 $my_authorized = "%";
381 if ($unbilled == "on") {
382 $unbilled = "0";
383 } else {
384 $unbilled = "%";
387 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
388 billCodesList($list);
393 <table border="0" cellspacing="0" cellpadding="0" width="100%">
396 if ($ret = getBillsBetween($from_date,$to_date,$my_authorized,$unbilled,"%")) {
397 $loop = 0;
398 $oldcode = "";
399 $last_encounter_id = "";
400 $lhtml = "";
401 $rhtml = "";
402 $lcount = 0;
403 $rcount = 0;
404 $bgcolor = "";
405 $skipping = FALSE;
407 foreach ($ret as $iter) {
409 // We include encounters here that have never been billed. However
410 // if it had no selected billing items but does have non-selected
411 // billing items, then it is not of interest.
412 if (!$iter['id']) {
413 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
414 "encounter = '" . $iter['enc_encounter'] . "' AND " .
415 "pid='" . $iter['enc_pid'] . "' AND " .
416 "activity = 1");
417 if ($res['count'] > 0) continue;
420 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
422 // echo "<!-- $this_encounter_id -->\n"; // debugging
424 if ($last_encounter_id != $this_encounter_id) {
425 if ($lhtml) {
426 while ($rcount < $lcount) {
427 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'>&nbsp;</td></tr>";
428 ++$rcount;
430 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
431 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n\n";
434 $lhtml = "";
435 $rhtml = "";
437 // If there are ANY unauthorized items in this encounter and this is
438 // the normal case of viewing only authorized billing, then skip the
439 // entire encounter.
441 $skipping = FALSE;
442 if ($my_authorized == '1') {
443 $res = sqlQuery("select count(*) as count from billing where " .
444 "encounter = '" . $iter['enc_encounter'] . "' and " .
445 "pid='" . $iter['enc_pid'] . "' and " .
446 "activity = 1 and authorized = 0");
447 if ($res['count'] > 0) {
448 $skipping = TRUE;
449 $last_encounter_id = $this_encounter_id;
450 continue;
454 $name = getPatientData($iter['enc_pid'], "fname, mname, lname");
456 # Check if patient has primary insurance and a subscriber exists for it.
457 # If not we will highlight their name in red.
458 # TBD: more checking here.
460 $res = sqlQuery("select count(*) as count from insurance_data where " .
461 "pid = " . $iter['enc_pid'] . " and " .
462 "type='primary' and " .
463 "subscriber_lname is not null and " .
464 "subscriber_lname != '' limit 1");
465 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
467 ++$encount;
468 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
469 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
470 $lcount = 1;
471 $rcount = 0;
472 $oldcode = "";
474 $ptname = $name['fname'] . " " . $name['lname'];
475 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
477 $lhtml .= "&nbsp;<span class=bold><font color='$namecolor'>$ptname" .
478 "</font></span><span class=small>&nbsp;(" . $iter['enc_pid'] . "-" .
479 $iter['enc_encounter'] . ")</span>";
481 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
482 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
483 ",'" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
484 ",'$raw_encounter_date')\">[To&nbsp;Encounter]</a>";
486 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
487 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
488 ")\">[To&nbsp;Demographics]</a>";
490 if ($iter['id']) {
491 $lcount += 2;
492 $lhtml .= "<br />\n";
493 $lhtml .= "&nbsp;<span class=text>Bill: ";
494 $lhtml .= "<select name='claims[" . $this_encounter_id . "][payer]' style='background-color:$bgcolor'>";
496 $query = "SELECT id.provider AS id, id.type, id.date, " .
497 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
498 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
499 "ic.id = id.provider AND " .
500 "id.pid = '" . mysql_escape_string($iter['enc_pid']) . "' AND " .
501 "id.date <= '$raw_encounter_date' " .
502 "ORDER BY id.type ASC, id.date DESC";
504 $result = sqlStatement($query);
505 $count = 0;
506 $default_x12_partner = $iter['ic_x12id'];
507 $prevtype = '';
508 while ($row = mysql_fetch_array($result)) {
509 if (strcmp($row['type'], $prevtype) == 0) continue;
510 $prevtype = $row['type'];
511 if (strlen($row['provider']) > 0) {
512 // This preserves any existing insurance company selection, which is
513 // important when EOB posting has re-queued for secondary billing.
514 $lhtml .= "<option value=\"" . $row['id'] . "\"";
515 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
516 $lhtml .= " selected";
517 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
519 $lhtml .= ">" . $row['type'] . ": " . $row['provider'] . "</option>";
521 $count++;
523 $lhtml .= "<option value='-1'>Unassigned</option>\n";
524 $lhtml .= "</select>&nbsp;&nbsp;\n";
525 $lhtml .= "<select name='claims[" . $this_encounter_id . "][partner]' style='background-color:$bgcolor'>";
526 $x = new X12Partner();
527 $partners = $x->_utility_array($x->x12_partner_factory());
528 foreach ($partners as $xid => $xname) {
529 $lhtml .= '<option label="' . $xname . '" value="' . $xid .'"';
530 if ($xid == $default_x12_partner) {
531 $lhtml .= "selected";
533 $lhtml .= '>' . $xname . '</option>';
535 $lhtml .= "</select>";
537 /****
538 $lhtml .= "<br>\n&nbsp;".xl("Encounter was coded: ") . $iter['date'];
539 if ($iter['billed'] == 1) {
540 $lhtml .= "<br>\n&nbsp;".xl("Claim was billed: ") . $iter['bill_date'];
541 ++$lcount;
543 if ($iter['bill_process'] == 1) {
544 $lhtml .= "<br>\n&nbsp;".xl("Claim is queued for processing");
545 ++$lcount;
547 if ($iter['bill_process'] == 5) {
548 $lhtml .= "<br>\n&nbsp;".xl("Claim is queued for printing and processing");
549 ++$lcount;
551 if ($iter['bill_process'] == 2) {
552 $lhtml .= "<br>\n&nbsp;".xl("Claim was processed: ") . $iter['process_date'];
553 if ($iter['process_file']) {
554 $lhtml .= '<br>' . "\n" . '&nbsp;'.xl("Claim is in file:").' <a href="get_claim_file.php?key=' . $iter['process_file'] .'">' . $iter['process_file'] . '</a> or ';
555 $lhtml .= '<a href="get_claim_file.php?action=print&key=' . $iter['process_file'] .'">Print It</a> or ';
556 $lhtml .= '<a target="_new" href="freebtest.php?format=' . $iter['target'] . '&billkey=' . $iter['enc_pid'] . '-' . $iter['enc_encounter'] . '">'.xl('Run Test').'</a>';
557 $lhtml .= '<input type="hidden" name="claims[' . $this_encounter_id . '][file]" value="' . $iter['process_file'] . '">';
558 ++$lcount;
560 ++$lcount;
562 if ($iter['bill_process'] == 3) {
563 $lhtml .= "<br>\n&nbsp;".xl("Claim was processed: ") . $iter['process_date'] . xl(" but there was an error: "). $iter['process_file'];
564 ++$lcount;
566 ****/
568 $lhtml .= "<br>\n&nbsp;" . substr($iter['date'], 0, 16) . " " .
569 xl("Encounter was coded");
571 $query = "SELECT * FROM claims WHERE " .
572 "patient_id = '" . $iter['enc_pid'] . "' AND " .
573 "encounter_id = '" . $iter['enc_encounter'] . "' " .
574 "ORDER BY version";
575 $cres = sqlStatement($query);
577 $lastcrow = false;
579 while ($crow = sqlFetchArray($cres)) {
581 $query = "SELECT id.type, ic.name " .
582 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
583 "id.pid = '" . $iter['enc_pid'] . "' AND " .
584 "id.provider = '" . $crow['payer_id'] . "' AND " .
585 "id.date <= '$raw_encounter_date' AND " .
586 "ic.id = id.provider " .
587 "ORDER BY id.type ASC, id.date DESC";
588 $irow= sqlQuery($query);
590 if ($crow['bill_process']) {
591 $lhtml .= "<br>\n&nbsp;" . substr($crow['bill_time'], 0, 16) . " " .
592 xl("Queued for") . " {$irow['type']} {$crow['target']} " .
593 xl("billing to ") . $irow['name'];
594 ++$lcount;
596 else if ($crow['status'] > 1) {
597 $lhtml .= "<br>\n&nbsp;" . substr($crow['bill_time'], 0, 16) . " " .
598 xl("Marked as cleared");
599 ++$lcount;
601 else {
602 $lhtml .= "<br>\n&nbsp;" . substr($crow['bill_time'], 0, 16) . " " .
603 xl("Re-opened");
604 ++$lcount;
607 if ($crow['process_time']) {
608 $lhtml .= "<br>\n&nbsp;" . substr($crow['process_time'], 0, 16) . " " .
609 xl("Claim was generated to file ") . $crow['process_file'];
610 ++$lcount;
613 $lastcrow = $crow;
614 } // end while ($crow = sqlFetchArray($cres))
616 if ($lastcrow && $lastcrow['status'] == 4) {
617 $lhtml .= "<br>\n&nbsp;This claim has been closed.";
618 ++$lcount;
620 if ($lastcrow && $lastcrow['status'] == 5) {
621 $lhtml .= "<br>\n&nbsp;This claim has been canceled.";
622 ++$lcount;
625 } // end if ($iter['id'])
628 if ($skipping) continue;
630 ++$rcount;
631 if ($rhtml) {
632 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
634 $rhtml .= "<td width='50'>";
635 if ($iter['id'] && $oldcode != $iter['code_type']) {
636 $rhtml .= "<span class=text>" . $iter['code_type'] . ": </span>";
638 $oldcode = $iter['code_type'];
639 $rhtml .= "</td>\n";
640 $justify = "";
641 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
642 $js = split(":",$iter['justify']);
643 $counter = 0;
644 foreach ($js as $j) {
645 if(!empty($j)) {
646 if ($counter == 0) {
647 $justify .= " (<b>$j</b>)";
649 else {
650 $justify .= " ($j)";
652 $counter++;
657 $rhtml .= "<td><span class=text>" . $iter{"code"}. "</span>" . '<span style="font-size:8pt;">' . $justify . "</span></td>\n";
658 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
659 if ($iter['id'] && $iter['fee'] > 0) {
660 $rhtml .= '$' . $iter['fee'];
662 $rhtml .= "</span></td>\n";
663 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
664 if ($iter['id']) $rhtml .= getProviderName($iter['provider_id']);
665 $rhtml .= "</span></td>\n";
666 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
667 if ($iter['id']) $rhtml .= date("Y-m-d",strtotime($iter{"date"}));
668 $rhtml .= "</span></td>\n";
669 if ($iter['id'] && $iter['authorized'] != 1) {
670 $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";
672 else {
673 $rhtml .= "<td></td>\n";
675 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
676 $rhtml .= "<td><input type='checkbox' value='" . $iter['bill_process'] . "$procstatus' name='claims[" . $this_encounter_id . "][bill]' onclick='set_button_states()'>&nbsp;</td>\n";
678 else {
679 $rhtml .= "<td></td>\n";
681 $rhtml .= "</tr>\n";
682 $last_encounter_id = $this_encounter_id;
685 if ($lhtml) {
686 while ($rcount < $lcount) {
687 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'>&nbsp;</td></tr>";
688 ++$rcount;
690 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
691 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
697 </table>
699 </form>
700 <script>
701 set_button_states();
703 <?php
704 if ($alertmsg) {
705 echo "alert('$alertmsg');\n";
709 </script>
710 </body>
711 </html>