major improvements for keeping a history of claims, and to save and use prior insuran...
[openemr.git] / interface / billing / billing_report.php
blob46f5a583fac3263fb1fe94de726b65bf60eefc6e
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;
123 var count1 = 0;
124 var count2 = 0;
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 <?php } ?>
148 f.bn_mark.disabled = !can_mark;
151 // Process a click to go to an encounter.
152 function toencounter(pid, pname, enc, datestr) {
153 <?php if ($GLOBALS['concurrent_layout']) { ?>
154 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
155 parent.left_nav.setPatient(pname,pid,'');
156 parent.left_nav.setEncounter(datestr, enc, othername);
157 parent.left_nav.setRadio(othername, 'enc');
158 parent.frames[othername].location.href =
159 '../patient_file/encounter/encounter_top.php?set_encounter='
160 + enc + '&pid=' + pid;
161 <?php } else { ?>
162 location.href = '../patient_file/encounter/patient_encounter.php?set_encounter='
163 + enc + '&pid=' + pid;
164 <?php } ?>
167 // Process a click to go to patient demographics.
168 function topatient(pid) {
169 <?php if ($GLOBALS['concurrent_layout']) { ?>
170 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
171 parent.frames[othername].location.href =
172 '../patient_file/summary/demographics_full.php?pid=' + pid;
173 <?php } else { ?>
174 location.href = '../patient_file/summary/demographics_full.php?pid=' + pid;
175 <?php } ?>
178 </script>
179 </head>
180 <body <?php echo $top_bg_line; ?> topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
182 <p style='margin-top:5px;margin-bottom:5px;margin-left:5px'>
183 <?php if ($GLOBALS['concurrent_layout']) { ?>
184 <font class='title'><?php xl('Billing Report','e') ?></font>
185 <?php } else if ($userauthorized) { ?>
186 <a href="../main/main.php" target=Main><font class=title><?php xl('Billing Report','e') ?></font><font class=more> <?php echo $tback; ?></font></a>
187 <?php } else { ?>
188 <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>
189 <?php } ?>
190 </p>
192 <form name=the_form method=post action=billing_report.php>
194 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
195 <script type="text/javascript" src="../../library/dialog.js"></script>
196 <script type="text/javascript" src="../../library/textformat.js"></script>
197 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
198 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
199 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
200 <script language='JavaScript'>
201 var mypcc = '1';
202 </script>
204 <input type='hidden' name='mode' value='change'>
205 <table width='100%' border="1" cellspacing="0" cellpadding="0">
206 <tr>
208 <td nowrap>
209 &nbsp;<span class='text'><?php xl('From: ','e') ?></span>
210 <input type='text' size='10' name='from_date' id='from_date'
211 value='<?php echo $from_date; ?>'
212 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
213 title='yyyy-mm-dd last date of this event' />
214 <img src='../../interface/pic/show_calendar.gif' align='absbottom' width='24' height='22'
215 id='img_fromdate' border='0' alt='[?]' style='cursor:pointer'
216 title='Click here to choose a date'>
217 <script>
218 Calendar.setup({inputField:"from_date", ifFormat:"%Y-%m-%d", button:"img_fromdate"});
219 </script>
220 </td>
222 <td nowrap>
223 &nbsp;<span class='text'><?php xl('To: ','e') ?></span>
224 <input type='text' size='10' name='to_date' id='to_date'
225 value='<?php echo $to_date; ?>'
226 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
227 title='yyyy-mm-dd last date of this event' />
228 <img src='../../interface/pic/show_calendar.gif' align='absbottom' width='24' height='22'
229 id='img_todate' border='0' alt='[?]' style='cursor:pointer'
230 title='Click here to choose a date' />
231 <script>
232 Calendar.setup({inputField:"to_date", ifFormat:"%Y-%m-%d", button:"img_todate"});
233 </script>
234 <input type="hidden" name="code_type" value="%" />
235 </td>
237 <td nowrap>
238 <input type='checkbox' name='unbilled' <?php if ($unbilled == "on") {echo "checked";}; ?> />
239 <span class='text'><?php xl('Show Unbilled Only','e') ?></span>
240 </td>
242 <td nowrap>
243 <input type='checkbox' name='authorized' <?php if ($my_authorized == "on") {echo "checked";}; ?> />
244 <span class='text'><?php xl('Show Authorized Only','e') ?></span>
245 </td>
247 <td align='right' width='10%' nowrap>
248 &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>
250 <a href="javascript:document.the_form.mode.value='export';document.the_form.submit()" class='link_submit'><?php xl('[Export OFX]','e') ?></a></span>&nbsp;
251 </td>
252 </tr>
254 <tr>
255 <td nowrap>
256 &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); ?>"
257 class='link_submit' target='new'><?php xl('[View Printable Report]','e') ?></a>
258 </td>
260 <td nowrap>
261 <?php
262 print '&nbsp;';
263 $acct_config = $GLOBALS['oer_config']['ws_accounting'];
264 if($acct_config['enabled'] == true) {
265 print '<span class=text><a href="javascript:void window.open(\'' . $acct_config['url_path'] . '\')">' . xl("[SQL-Ledger]") . '</a></span>';
266 if (acl_check('acct', 'rep')) {
267 print '<span class=text> &nbsp; <a href="javascript:void window.open(\'sl_receipts_report.php\')">' . xl('[Reports]') . '</a></span>';
269 if (acl_check('acct', 'eob')) {
270 print '<span class=text> &nbsp; <a href="javascript:void window.open(\'sl_eob_search.php\')">' . xl('[EOBs]') . '</a></span>';
274 </td>
276 <td colspan='2' nowrap>
277 &nbsp;
278 <?php if (! file_exists($EXPORT_INC)) { ?>
279 <a href="javascript:document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
280 title="Process all queued bills to create electronic data (and print if requested)"><?php xl('[Start Batch Processing]','e') ?></a>
281 &nbsp; <a href='../../library/freeb/process_bills.log' target='_blank' class='link_submit'
282 title='See messages from the last batch processing run'><?php xl('[view log]','e') ?></a>
283 <?php } ?>
284 </td>
286 <td align='right' nowrap>
287 <a href="javascript:select_all()" class="link_submit"><?php xl('[Select All]','e') ?></a>&nbsp;
288 </td>
290 </tr>
291 </table>
292 </form>
294 <form name='update_form' method='post' action='billing_process.php'>
296 <center>
298 <?php if (file_exists($EXPORT_INC)) { ?>
299 <input type="submit" class="subbtn" name="bn_external" value="Export Billing" title="<?php xl('Export to external billing system','e') ?>">
300 <input type="submit" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php xl('Mark as billed but skip billing','e') ?>">
301 <?php } else { ?>
302 <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') ?>">
303 <input type="submit" class="subbtn" name="bn_hcfa" value="Queue HCFA" title="<?php xl('Queue for HCFA batch processing','e')?>">
304 <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')?>">
305 <input type="submit" class="subbtn" name="bn_ub92" value="Queue UB92" title="<?php xl('Queue for UB-92 batch processing','e')?>">
306 <input type="submit" class="subbtn" name="bn_x12" value="Process X12"
307 title="<?php xl('Generate X12 claims and create batch','e')?>"
308 onclick="alert('After saving your batch, click [view log] to check for errors.')">
309 <input type="submit" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php xl('Post to accounting and mark as billed','e')?>">
310 <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')?>">
311 <?php } ?>
313 </center>
315 <input type='hidden' name='mode' value="bill" />
316 <input type='hidden' name='authorized' value="<?php echo $my_authorized; ?>" />
317 <input type='hidden' name='unbilled' value="<?php echo $unbilled; ?>" />
318 <input type='hidden' name='code_type' value="%" />
319 <input type='hidden' name='to_date' value="<?php echo $to_date; ?>" />
320 <input type='hidden' name='from_date' value="<?php echo $from_date; ?>" />
321 <?php
322 if ($my_authorized == "on" ) {
323 $my_authorized = "1";
324 } else {
325 $my_authorized = "%";
328 if ($unbilled == "on") {
329 $unbilled = "0";
330 } else {
331 $unbilled = "%";
334 <input type='hidden' name='bill_list' value="<?php
335 $list = getBillsListBetween($from_date,$to_date,$my_authorized,$unbilled,"%");
336 print $list;
337 ?>" />
338 <!-- new form for uploading -->
339 <?php
340 if (!isset($_POST["mode"])) {
341 if (!isset($_POST["from_date"])) {
342 $from_date=date("Y-m-d");
343 } else {
344 $from_date = $_POST["from_date"];
346 if (!isset($_POST["to_date"])) {
347 $to_date = date("Y-m-d");
348 } else {
349 $to_date = $_POST["to_date"];
351 if (!isset($_POST["code_type"])) {
352 $code_type="all";
353 } else {
354 $code_type = $_POST["code_type"];
356 if (!isset($_POST["unbilled"])) {
357 $unbilled = "on";
358 } else {
359 $unbilled = $_POST["unbilled"];
361 if (!isset($_POST["authorized"])) {
362 $my_authorized = "on";
363 } else {
364 $my_authorized = $_POST["authorized"];
366 } else {
367 $from_date = $_POST["from_date"];
368 $to_date = $_POST["to_date"];
369 $code_type = $_POST["code_type"];
370 $unbilled = $_POST["unbilled"];
371 $my_authorized = $_POST["authorized"];
373 if ($my_authorized == "on" ) {
374 $my_authorized = "1";
375 } else {
376 $my_authorized = "%";
379 if ($unbilled == "on") {
380 $unbilled = "0";
381 } else {
382 $unbilled = "%";
385 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
386 billCodesList($list);
391 <table border="0" cellspacing="0" cellpadding="0" width="100%">
394 if ($ret = getBillsBetween($from_date,$to_date,$my_authorized,$unbilled,"%")) {
395 $loop = 0;
396 $oldcode = "";
397 $last_encounter_id = "";
398 $lhtml = "";
399 $rhtml = "";
400 $lcount = 0;
401 $rcount = 0;
402 $bgcolor = "";
403 $skipping = FALSE;
405 foreach ($ret as $iter) {
407 // We include encounters here that have never been billed. However
408 // if it had no selected billing items but does have non-selected
409 // billing items, then it is not of interest.
410 if (!$iter['id']) {
411 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
412 "encounter = '" . $iter['enc_encounter'] . "' AND " .
413 "pid='" . $iter['enc_pid'] . "' AND " .
414 "activity = 1");
415 if ($res['count'] > 0) continue;
418 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
420 // echo "<!-- $this_encounter_id -->\n"; // debugging
422 if ($last_encounter_id != $this_encounter_id) {
423 if ($lhtml) {
424 while ($rcount < $lcount) {
425 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'>&nbsp;</td></tr>";
426 ++$rcount;
428 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
429 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n\n";
432 $lhtml = "";
433 $rhtml = "";
435 // If there are ANY unauthorized items in this encounter and this is
436 // the normal case of viewing only authorized billing, then skip the
437 // entire encounter.
439 $skipping = FALSE;
440 if ($my_authorized == '1') {
441 $res = sqlQuery("select count(*) as count from billing where " .
442 "encounter = '" . $iter['enc_encounter'] . "' and " .
443 "pid='" . $iter['enc_pid'] . "' and " .
444 "activity = 1 and authorized = 0");
445 if ($res['count'] > 0) {
446 $skipping = TRUE;
447 $last_encounter_id = $this_encounter_id;
448 continue;
452 $name = getPatientData($iter['enc_pid'], "fname, mname, lname");
454 # Check if patient has primary insurance and a subscriber exists for it.
455 # If not we will highlight their name in red.
456 # TBD: more checking here.
458 $res = sqlQuery("select count(*) as count from insurance_data where " .
459 "pid = " . $iter['enc_pid'] . " and " .
460 "type='primary' and " .
461 "subscriber_lname is not null and " .
462 "subscriber_lname != '' limit 1");
463 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
465 ++$encount;
466 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
467 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
468 $lcount = 1;
469 $rcount = 0;
470 $oldcode = "";
472 $ptname = $name['fname'] . " " . $name['lname'];
473 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
475 $lhtml .= "&nbsp;<span class=bold><font color='$namecolor'>$ptname" .
476 "</font></span><span class=small>&nbsp;(" . $iter['enc_pid'] . "-" .
477 $iter['enc_encounter'] . ")</span>";
479 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
480 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
481 ",'" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
482 ",'$raw_encounter_date')\">[To&nbsp;Encounter]</a>";
484 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
485 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
486 ")\">[To&nbsp;Demographics]</a>";
488 if ($iter['id']) {
489 $lcount += 2;
490 $lhtml .= "<br />\n";
491 $lhtml .= "&nbsp;<span class=text>Bill: ";
492 $lhtml .= "<select name='claims[" . $this_encounter_id . "][payer]' style='background-color:$bgcolor'>";
494 $query = "SELECT id.provider AS id, id.type, id.date, " .
495 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
496 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
497 "ic.id = id.provider AND " .
498 "id.pid = '" . mysql_escape_string($iter['enc_pid']) . "' AND " .
499 "id.date <= '$raw_encounter_date' " .
500 "ORDER BY id.type ASC, id.date DESC";
502 $result = sqlStatement($query);
503 $count = 0;
504 $default_x12_partner = $iter['ic_x12id'];
505 $prevtype = '';
506 while ($row = mysql_fetch_array($result)) {
507 if (strcmp($row['type'], $prevtype) == 0) continue;
508 $prevtype = $row['type'];
509 if (strlen($row['provider']) > 0) {
510 // This preserves any existing insurance company selection, which is
511 // important when EOB posting has re-queued for secondary billing.
512 $lhtml .= "<option value=\"" . $row['id'] . "\"";
513 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
514 $lhtml .= " selected";
515 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
517 $lhtml .= ">" . $row['type'] . ": " . $row['provider'] . "</option>";
519 $count++;
521 $lhtml .= "<option value='-1'>Unassigned</option>\n";
522 $lhtml .= "</select>&nbsp;&nbsp;\n";
523 $lhtml .= "<select name='claims[" . $this_encounter_id . "][partner]' style='background-color:$bgcolor'>";
524 $x = new X12Partner();
525 $partners = $x->_utility_array($x->x12_partner_factory());
526 foreach ($partners as $xid => $xname) {
527 $lhtml .= '<option label="' . $xname . '" value="' . $xid .'"';
528 if ($xid == $default_x12_partner) {
529 $lhtml .= "selected";
531 $lhtml .= '>' . $xname . '</option>';
533 $lhtml .= "</select>";
535 /****
536 $lhtml .= "<br>\n&nbsp;".xl("Encounter was coded: ") . $iter['date'];
537 if ($iter['billed'] == 1) {
538 $lhtml .= "<br>\n&nbsp;".xl("Claim was billed: ") . $iter['bill_date'];
539 ++$lcount;
541 if ($iter['bill_process'] == 1) {
542 $lhtml .= "<br>\n&nbsp;".xl("Claim is queued for processing");
543 ++$lcount;
545 if ($iter['bill_process'] == 5) {
546 $lhtml .= "<br>\n&nbsp;".xl("Claim is queued for printing and processing");
547 ++$lcount;
549 if ($iter['bill_process'] == 2) {
550 $lhtml .= "<br>\n&nbsp;".xl("Claim was processed: ") . $iter['process_date'];
551 if ($iter['process_file']) {
552 $lhtml .= '<br>' . "\n" . '&nbsp;'.xl("Claim is in file:").' <a href="get_claim_file.php?key=' . $iter['process_file'] .'">' . $iter['process_file'] . '</a> or ';
553 $lhtml .= '<a href="get_claim_file.php?action=print&key=' . $iter['process_file'] .'">Print It</a> or ';
554 $lhtml .= '<a target="_new" href="freebtest.php?format=' . $iter['target'] . '&billkey=' . $iter['enc_pid'] . '-' . $iter['enc_encounter'] . '">'.xl('Run Test').'</a>';
555 $lhtml .= '<input type="hidden" name="claims[' . $this_encounter_id . '][file]" value="' . $iter['process_file'] . '">';
556 ++$lcount;
558 ++$lcount;
560 if ($iter['bill_process'] == 3) {
561 $lhtml .= "<br>\n&nbsp;".xl("Claim was processed: ") . $iter['process_date'] . xl(" but there was an error: "). $iter['process_file'];
562 ++$lcount;
564 ****/
566 $lhtml .= "<br>\n&nbsp;" . substr($iter['date'], 0, 16) . " " .
567 xl("Encounter was coded");
569 $query = "SELECT * FROM claims WHERE " .
570 "patient_id = '" . $iter['enc_pid'] . "' AND " .
571 "encounter_id = '" . $iter['enc_encounter'] . "' " .
572 "ORDER BY version";
573 $cres = sqlStatement($query);
575 $lastcrow = false;
577 while ($crow = sqlFetchArray($cres)) {
579 $query = "SELECT id.type, ic.name " .
580 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
581 "id.pid = '" . $iter['enc_pid'] . "' AND " .
582 "id.provider = '" . $crow['payer_id'] . "' AND " .
583 "id.date <= '$raw_encounter_date' AND " .
584 "ic.id = id.provider " .
585 "ORDER BY id.type ASC, id.date DESC";
586 $irow= sqlQuery($query);
588 if ($crow['bill_process']) {
589 $lhtml .= "<br>\n&nbsp;" . substr($crow['bill_time'], 0, 16) . " " .
590 xl("Queued for") . " {$irow['type']} {$crow['target']} " .
591 xl("billing to ") . $irow['name'];
592 ++$lcount;
594 else {
595 $lhtml .= "<br>\n&nbsp;" . substr($crow['bill_time'], 0, 16) . " " .
596 xl("Marked as cleared");
597 ++$lcount;
600 if ($crow['process_time']) {
601 $lhtml .= "<br>\n&nbsp;" . substr($crow['process_time'], 0, 16) . " " .
602 xl("Claim was generated to file ") . $crow['process_file'];
603 ++$lcount;
606 $lastcrow = $crow;
607 } // end while ($crow = sqlFetchArray($cres))
609 if ($lastcrow && $lastcrow['status'] == 4) {
610 $lhtml .= "<br>\n&nbsp;This claim has been closed.";
611 ++$lcount;
613 if ($lastcrow && $lastcrow['status'] == 5) {
614 $lhtml .= "<br>\n&nbsp;This claim has been canceled.";
615 ++$lcount;
618 } // end if ($iter['id'])
621 if ($skipping) continue;
623 ++$rcount;
624 if ($rhtml) {
625 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
627 $rhtml .= "<td width='50'>";
628 if ($iter['id'] && $oldcode != $iter['code_type']) {
629 $rhtml .= "<span class=text>" . $iter['code_type'] . ": </span>";
631 $oldcode = $iter['code_type'];
632 $rhtml .= "</td>\n";
633 $justify = "";
634 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
635 $js = split(":",$iter['justify']);
636 $counter = 0;
637 foreach ($js as $j) {
638 if(!empty($j)) {
639 if ($counter == 0) {
640 $justify .= " (<b>$j</b>)";
642 else {
643 $justify .= " ($j)";
645 $counter++;
650 $rhtml .= "<td><span class=text>" . $iter{"code"}. "</span>" . '<span style="font-size:8pt;">' . $justify . "</span></td>\n";
651 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
652 if ($iter['id'] && $iter['fee'] > 0) {
653 $rhtml .= '$' . $iter['fee'];
655 $rhtml .= "</span></td>\n";
656 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
657 if ($iter['id']) $rhtml .= getProviderName($iter['provider_id']);
658 $rhtml .= "</span></td>\n";
659 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
660 if ($iter['id']) $rhtml .= date("Y-m-d",strtotime($iter{"date"}));
661 $rhtml .= "</span></td>\n";
662 if ($iter['id'] && $iter['authorized'] != 1) {
663 $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";
665 else {
666 $rhtml .= "<td></td>\n";
668 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
669 $rhtml .= "<td><input type='checkbox' value='" . $iter['bill_process'] . "$procstatus' name='claims[" . $this_encounter_id . "][bill]' onclick='set_button_states()'>&nbsp;</td>\n";
671 else {
672 $rhtml .= "<td></td>\n";
674 $rhtml .= "</tr>\n";
675 $last_encounter_id = $this_encounter_id;
678 if ($lhtml) {
679 while ($rcount < $lcount) {
680 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'>&nbsp;</td></tr>";
681 ++$rcount;
683 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
684 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
690 </table>
692 </form>
693 <script>
694 set_button_states();
696 <?php
697 if ($alertmsg) {
698 echo "alert('$alertmsg');\n";
702 </script>
703 </body>
704 </html>