Fixed quote escaping problem in view.php.
[openemr.git] / interface / billing / billing_report.php
blob856b265bfb3f8cf152099b736746530c5e26ac46
1 <?php
2 require_once("../globals.php");
3 require_once("../../library/acl.inc");
4 require_once("../../custom/code_types.inc.php");
6 require_once("$srcdir/patient.inc");
7 require_once("$srcdir/billrep.inc");
8 require_once(dirname(__FILE__) . "/../../library/classes/OFX.class.php");
9 require_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 // This is obsolete.
49 if ($_POST['mode'] == 'process') {
50 if (exec("ps x | grep 'process_bills[.]php'")) {
51 $alertmsg = xl('Request ignored - claims processing is already running!');
53 else {
54 exec("cd $webserver_root/library/freeb;" .
55 "php -q process_bills.php bill > process_bills.log 2>&1 &");
56 $alertmsg = xl('Batch processing initiated; this may take a while.');
60 //global variables:
61 if (!isset($_POST["mode"])) {
62 $from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
63 $to_date = isset($_POST['to_date' ]) ? $_POST['to_date' ] : '';
64 $code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
65 $unbilled = isset($_POST['unbilled' ]) ? $_POST['unbilled' ] : 'on';
66 $my_authorized = $_POST["authorized"];
67 } else {
68 $from_date = $_POST["from_date"];
69 $to_date = $_POST["to_date"];
70 $code_type = $_POST["code_type"];
71 $unbilled = $_POST["unbilled"];
72 $my_authorized = $_POST["authorized"];
76 $from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
77 $to_date = empty($_POST['to_date' ]) ? $from_date : $_POST['to_date'];
78 $code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
79 $unbilled = isset($_POST['unbilled' ]) ? $_POST['unbilled' ] : 'on';
80 $my_authorized = $_POST["authorized"];
83 $left_margin = isset($_POST["left_margin"]) ? $_POST["left_margin"] : 24;
84 $top_margin = isset($_POST["top_margin"] ) ? $_POST["top_margin" ] : 27;
86 $ofrom_date = $from_date;
87 $oto_date = $to_date;
88 $ocode_type = $code_type;
89 $ounbilled = $unbilled;
90 $oauthorized = $my_authorized;
93 <html>
94 <head>
95 <?php if (function_exists(html_header_show)) html_header_show(); ?>
96 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
97 <style>
98 .subbtn { margin-top:3px; margin-bottom:3px; margin-left:2px; margin-right:2px }
99 </style>
100 <script>
102 function select_all() {
103 for($i=0;$i < document.update_form.length;$i++) {
104 $name = document.update_form[$i].name;
105 if ($name.substring(0,7) == "claims[" && $name.substring($name.length -6) == "[bill]") {
106 document.update_form[$i].checked = true;
109 set_button_states();
112 function set_button_states() {
113 var f = document.update_form;
114 var count0 = 0; // selected and not billed or queued
115 var count1 = 0; // selected and queued
116 var count2 = 0; // selected and billed
117 for($i = 0; $i < f.length; ++$i) {
118 $name = f[$i].name;
119 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length -6) == "[bill]" && f[$i].checked == true) {
120 if (f[$i].value == '0') ++count0;
121 else if (f[$i].value == '1' || f[$i].value == '5') ++count1;
122 else ++count2;
126 var can_generate = (count0 > 0 || count1 > 0 || count2 > 0);
127 var can_mark = (count1 > 0 || count0 > 0 || count2 > 0);
128 var can_bill = (count0 == 0 && count1 == 0 && count2 > 0);
130 <?php if (file_exists($EXPORT_INC)) { ?>
131 f.bn_external.disabled = !can_generate;
132 <?php } else { ?>
133 // f.bn_hcfa_print.disabled = !can_generate;
134 // f.bn_hcfa.disabled = !can_generate;
135 // f.bn_ub92_print.disabled = !can_generate;
136 // f.bn_ub92.disabled = !can_generate;
137 f.bn_x12.disabled = !can_generate;
138 f.bn_process_hcfa.disabled = !can_generate;
139 // f.bn_electronic_file.disabled = !can_bill;
140 f.bn_reopen.disabled = !can_bill;
141 <?php } ?>
142 f.bn_mark.disabled = !can_mark;
145 // Process a click to go to an encounter.
146 function toencounter(pid, pubpid, pname, enc, datestr) {
147 top.restoreSession();
148 <?php if ($GLOBALS['concurrent_layout']) { ?>
149 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
150 parent.left_nav.setPatient(pname,pid,pubpid,'');
151 parent.left_nav.setEncounter(datestr, enc, othername);
152 parent.left_nav.setRadio(othername, 'enc');
153 parent.frames[othername].location.href =
154 '../patient_file/encounter/encounter_top.php?set_encounter='
155 + enc + '&pid=' + pid;
156 <?php } else { ?>
157 location.href = '../patient_file/encounter/patient_encounter.php?set_encounter='
158 + enc + '&pid=' + pid;
159 <?php } ?>
162 // Process a click to go to patient demographics.
163 // larry :: dbc insert
164 <?php if( $GLOBALS['dutchpc'] )
167 function topatient(pid) {
168 top.restoreSession();
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_dutch.php?pid=' + pid;
173 <?php } else { ?>
174 location.href = '../patient_file/summary/demographics_full_dutch.php?pid=' + pid;
175 <?php } ?>
178 <?php } else
179 { ?>
181 function topatient(pid) {
182 top.restoreSession();
183 <?php if ($GLOBALS['concurrent_layout']) { ?>
184 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
185 parent.frames[othername].location.href =
186 '../patient_file/summary/demographics_full.php?pid=' + pid;
187 <?php } else { ?>
188 location.href = '../patient_file/summary/demographics_full.php?pid=' + pid;
189 <?php } ?>
191 <?php } ?>
192 // larry :: end of dbc change
194 </script>
195 </head>
196 <body class="body_top">
198 <p style='margin-top:5px;margin-bottom:5px;margin-left:5px'>
200 <?php if ($GLOBALS['concurrent_layout']) { ?>
201 <font class='title'><?php xl('Billing Report','e') ?></font>
202 <?php } else if ($userauthorized) { ?>
203 <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>
204 <?php } else { ?>
205 <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 <?php } ?>
208 </p>
210 <form name='the_form' method='post' action='billing_report.php' onsubmit='return top.restoreSession()'>
212 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
213 <script type="text/javascript" src="../../library/dialog.js"></script>
214 <script type="text/javascript" src="../../library/textformat.js"></script>
215 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
216 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
217 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
218 <script language='JavaScript'>
219 var mypcc = '1';
220 </script>
222 <input type='hidden' name='mode' value='change'>
224 <table width='100%' border="1" cellspacing="0" cellpadding="0">
225 <tr>
226 <td nowrap>
227 &nbsp;<span class='text'><?php xl('From: ','e') ?></span>
228 <input type='text' size='10' name='from_date' id='from_date'
229 value='<?php echo $from_date; ?>'
230 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
231 title='yyyy-mm-dd last date of this event' />
232 <img src='../../interface/pic/show_calendar.gif' align='absbottom' width='24' height='22'
233 id='img_fromdate' border='0' alt='[?]' style='cursor:pointer'
234 title='Click here to choose a date'>
235 <script>
236 Calendar.setup({inputField:"from_date", ifFormat:"%Y-%m-%d", button:"img_fromdate"});
237 </script>
238 </td>
240 <td nowrap>
241 &nbsp;<span class='text'><?php xl('To: ','e') ?></span>
242 <input type='text' size='10' name='to_date' id='to_date'
243 value='<?php echo $to_date; ?>'
244 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
245 title='yyyy-mm-dd last date of this event' />
246 <img src='../../interface/pic/show_calendar.gif' align='absbottom' width='24' height='22'
247 id='img_todate' border='0' alt='[?]' style='cursor:pointer'
248 title='Click here to choose a date' />
249 <script>
250 Calendar.setup({inputField:"to_date", ifFormat:"%Y-%m-%d", button:"img_todate"});
251 </script>
252 <input type="hidden" name="code_type" value="%" />
253 </td>
255 <td nowrap>
256 <input type='checkbox' name='unbilled' <?php if ($unbilled == "on") {echo "checked";}; ?> />
257 <span class='text'><?php xl('Show Unbilled Only','e') ?></span>
258 </td>
260 <td nowrap>
261 <input type='checkbox' name='authorized' <?php if ($my_authorized == "on") {echo "checked";}; ?> />
262 <span class='text'><?php xl('Show Authorized Only','e') ?></span>
263 </td>
265 <td align='right' width='10%' nowrap>
266 &nbsp;<span class='text'><a href="javascript:top.restoreSession();document.the_form.mode.value='change';document.the_form.submit()" class=link_submit><?php xl('[Change View]','e') ?></a>
268 <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>&nbsp;
269 </td>
271 </tr>
273 <tr>
275 <td nowrap>
276 &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); ?>"
277 class='link_submit' target='new' onclick='top.restoreSession()'><?php xl('[View Printable Report]','e') ?></a>
278 </td>
280 <td nowrap>
281 <?php
282 print '&nbsp;';
283 $acct_config = $GLOBALS['oer_config']['ws_accounting'];
284 if($acct_config['enabled']) {
285 if($acct_config['enabled'] !== 2) {
286 print '<span class=text><a href="javascript:void window.open(\'' . $acct_config['url_path'] . '\')">' . xl("[SQL-Ledger]") . '</a> &nbsp; </span>';
288 if (acl_check('acct', 'rep')) {
289 print '<span class=text><a href="javascript:void window.open(\'sl_receipts_report.php\')" onclick="top.restoreSession()">' . xl('[Reports]') . '</a> &nbsp; </span>';
291 if (acl_check('acct', 'eob')) {
292 print '<span class=text><a href="javascript:void window.open(\'sl_eob_search.php\')" onclick="top.restoreSession()">' . xl('[EOBs]') . '</a></span>';
296 </td>
298 <td colspan='2' class='text' nowrap>
299 &nbsp;
300 <?php if (! file_exists($EXPORT_INC)) { ?>
301 <!--
302 <a href="javascript:top.restoreSession();document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
303 title="Process all queued bills to create electronic data (and print if requested)"><?php xl('[Start Batch Processing]','e') ?></a>
304 &nbsp;
306 <a href='../../library/freeb/process_bills.log' target='_blank' class='link_submit'
307 title='See messages from the last set of generated claims'><?php xl('[View Log]','e') ?></a>
308 <?php } ?>
309 </td>
311 <td align='right' nowrap>
312 <a href="javascript:select_all()" class="link_submit"><?php xl('[Select All]','e') ?></a>&nbsp;
313 </td>
315 </tr>
316 </table>
318 </form>
320 <form name='update_form' method='post' action='billing_process.php' onsubmit='return top.restoreSession()'>
322 <center>
324 <span class='text'>
325 <?php if (file_exists($EXPORT_INC)) { ?>
326 <input type="submit" class="subbtn" name="bn_external" value="Export Billing" title="<?php xl('Export to external billing system','e') ?>">
327 <input type="submit" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php xl('Mark as billed but skip billing','e') ?>">
328 <?php } else { ?>
329 <!--
330 <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') ?>">
331 <input type="submit" class="subbtn" name="bn_hcfa" value="Queue HCFA" title="<?php xl('Queue for HCFA batch processing','e')?>">
332 <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')?>">
333 <input type="submit" class="subbtn" name="bn_ub92" value="Queue UB92" title="<?php xl('Queue for UB-92 batch processing','e')?>">
335 <input type="submit" class="subbtn" name="bn_x12" value="Generate X12"
336 title="<?php xl('Generate and download X12 batch','e')?>"
337 onclick="alert('After saving your batch, click [View Log] to check for errors.')">
338 <input type="submit" class="subbtn" name="bn_process_hcfa" value="Generate HCFA"
339 title="<?php xl('Generate and download HCFA 1500 paper claims','e')?>"
340 onclick="alert('After saving the PDF, click [View Log] to check for errors.')">
341 <input type="submit" class="subbtn" name="bn_mark" value="Mark as Cleared" title="<?php xl('Post to accounting and mark as billed','e')?>">
342 <input type="submit" class="subbtn" name="bn_reopen" value="Re-Open" title="<?php xl('Mark as not billed','e')?>">
343 <!--
344 <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')?>">
346 &nbsp;&nbsp;&nbsp;
347 HCFA Margins:
348 &nbsp;Left:
349 <input type='text' size='2' name='left_margin'
350 value='<?php echo $left_margin; ?>'
351 title='HCFA left margin in points' />
352 &nbsp;Top:
353 <input type='text' size='2' name='top_margin'
354 value='<?php echo $top_margin; ?>'
355 title='HCFA top margin in points' />
356 </span>
357 <?php } ?>
359 </center>
361 <input type='hidden' name='mode' value="bill" />
362 <input type='hidden' name='authorized' value="<?php echo $my_authorized; ?>" />
363 <input type='hidden' name='unbilled' value="<?php echo $unbilled; ?>" />
364 <input type='hidden' name='code_type' value="%" />
365 <input type='hidden' name='to_date' value="<?php echo $to_date; ?>" />
366 <input type='hidden' name='from_date' value="<?php echo $from_date; ?>" />
368 <?php
369 if ($my_authorized == "on" ) {
370 $my_authorized = "1";
371 } else {
372 $my_authorized = "%";
374 if ($unbilled == "on") {
375 $unbilled = "0";
376 } else {
377 $unbilled = "%";
380 $list = getBillsListBetween($from_date,
381 empty($to_date) ? $from_date : $to_date,
382 $my_authorized,$unbilled,"%");
385 <input type='hidden' name='bill_list' value="<?php echo $list; ?>" />
387 <!-- new form for uploading -->
389 <?php
390 if (!isset($_POST["mode"])) {
391 if (!isset($_POST["from_date"])) {
392 $from_date = date("Y-m-d");
393 } else {
394 $from_date = $_POST["from_date"];
396 if (empty($_POST["to_date"])) {
397 $to_date = '';
398 } else {
399 $to_date = $_POST["to_date"];
401 if (!isset($_POST["code_type"])) {
402 $code_type="all";
403 } else {
404 $code_type = $_POST["code_type"];
406 if (!isset($_POST["unbilled"])) {
407 $unbilled = "on";
408 } else {
409 $unbilled = $_POST["unbilled"];
411 if (!isset($_POST["authorized"])) {
412 $my_authorized = "on";
413 } else {
414 $my_authorized = $_POST["authorized"];
416 } else {
417 $from_date = $_POST["from_date"];
418 $to_date = $_POST["to_date"];
419 $code_type = $_POST["code_type"];
420 $unbilled = $_POST["unbilled"];
421 $my_authorized = $_POST["authorized"];
424 if ($my_authorized == "on" ) {
425 $my_authorized = "1";
426 } else {
427 $my_authorized = "%";
430 if ($unbilled == "on") {
431 $unbilled = "0";
432 } else {
433 $unbilled = "%";
436 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
437 billCodesList($list);
442 <table border="0" cellspacing="0" cellpadding="0" width="100%">
444 <?php
445 if ($ret = getBillsBetween($from_date,
446 empty($to_date) ? $from_date : $to_date,
447 $my_authorized, $unbilled, "%"))
449 $loop = 0;
450 $oldcode = "";
451 $last_encounter_id = "";
452 $lhtml = "";
453 $rhtml = "";
454 $lcount = 0;
455 $rcount = 0;
456 $bgcolor = "";
457 $skipping = FALSE;
459 foreach ($ret as $iter) {
461 // We include encounters here that have never been billed. However
462 // if it had no selected billing items but does have non-selected
463 // billing items, then it is not of interest.
464 if (!$iter['id']) {
465 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
466 "encounter = '" . $iter['enc_encounter'] . "' AND " .
467 "pid='" . $iter['enc_pid'] . "' AND " .
468 "activity = 1");
469 if ($res['count'] > 0) continue;
472 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
474 if ($last_encounter_id != $this_encounter_id) {
475 if ($lhtml) {
476 while ($rcount < $lcount) {
477 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'>&nbsp;</td></tr>";
478 ++$rcount;
480 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
481 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n\n";
484 $lhtml = "";
485 $rhtml = "";
487 // If there are ANY unauthorized items in this encounter and this is
488 // the normal case of viewing only authorized billing, then skip the
489 // entire encounter.
491 $skipping = FALSE;
492 if ($my_authorized == '1') {
493 $res = sqlQuery("select count(*) as count from billing where " .
494 "encounter = '" . $iter['enc_encounter'] . "' and " .
495 "pid='" . $iter['enc_pid'] . "' and " .
496 "activity = 1 and authorized = 0");
497 if ($res['count'] > 0) {
498 $skipping = TRUE;
499 $last_encounter_id = $this_encounter_id;
500 continue;
504 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid");
506 # Check if patient has primary insurance and a subscriber exists for it.
507 # If not we will highlight their name in red.
508 # TBD: more checking here.
510 $res = sqlQuery("select count(*) as count from insurance_data where " .
511 "pid = " . $iter['enc_pid'] . " and " .
512 "type='primary' and " .
513 "subscriber_lname is not null and " .
514 "subscriber_lname != '' limit 1");
515 $namecolor = ($res['count'] > 0) ? "black" : "#ff7777";
517 ++$encount;
518 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
519 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
520 $lcount = 1;
521 $rcount = 0;
522 $oldcode = "";
524 $ptname = $name['fname'] . " " . $name['lname'];
525 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
527 $lhtml .= "&nbsp;<span class=bold><font color='$namecolor'>$ptname" .
528 "</font></span><span class=small>&nbsp;(" . $iter['enc_pid'] . "-" .
529 $iter['enc_encounter'] . ")</span>";
531 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
532 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
533 ",'" . addslashes($name['pubpid']) .
534 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
535 ",'$raw_encounter_date')\">[To&nbsp;Encounter]</a>";
537 $lhtml .= "&nbsp;&nbsp;&nbsp;<a class=\"link_submit\" " .
538 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
539 ")\">[To&nbsp;Demographics]</a>";
541 if ($iter['id']) {
543 $lcount += 2;
544 $lhtml .= "<br />\n";
545 $lhtml .= "&nbsp;<span class=text>Bill: ";
546 $lhtml .= "<select name='claims[" . $this_encounter_id . "][payer]' style='background-color:$bgcolor'>";
548 $query = "SELECT id.provider AS id, id.type, id.date, " .
549 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
550 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
551 "ic.id = id.provider AND " .
552 "id.pid = '" . mysql_escape_string($iter['enc_pid']) . "' AND " .
553 "id.date <= '$raw_encounter_date' " .
554 "ORDER BY id.type ASC, id.date DESC";
556 $result = sqlStatement($query);
557 $count = 0;
558 $default_x12_partner = $iter['ic_x12id'];
559 $prevtype = '';
561 while ($row = mysql_fetch_array($result)) {
562 if (strcmp($row['type'], $prevtype) == 0) continue;
563 $prevtype = $row['type'];
564 if (strlen($row['provider']) > 0) {
565 // This preserves any existing insurance company selection, which is
566 // important when EOB posting has re-queued for secondary billing.
567 $lhtml .= "<option value=\"" . strtoupper(substr($row['type'],0,1)) . $row['id'] . "\"";
568 if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
569 $lhtml .= " selected";
570 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
572 $lhtml .= ">" . $row['type'] . ": " . $row['provider'] . "</option>";
574 $count++;
577 $lhtml .= "<option value='-1'>Unassigned</option>\n";
578 $lhtml .= "</select>&nbsp;&nbsp;\n";
579 $lhtml .= "<select name='claims[" . $this_encounter_id . "][partner]' style='background-color:$bgcolor'>";
580 $x = new X12Partner();
581 $partners = $x->_utility_array($x->x12_partner_factory());
582 foreach ($partners as $xid => $xname) {
583 $lhtml .= '<option label="' . $xname . '" value="' . $xid .'"';
584 if ($xid == $default_x12_partner) {
585 $lhtml .= "selected";
587 $lhtml .= '>' . $xname . '</option>';
589 $lhtml .= "</select>";
590 $lhtml .= "<br>\n&nbsp;" . substr($iter['date'], 0, 16) . " " .
591 xl("Encounter was coded");
593 $query = "SELECT * FROM claims WHERE " .
594 "patient_id = '" . $iter['enc_pid'] . "' AND " .
595 "encounter_id = '" . $iter['enc_encounter'] . "' " .
596 "ORDER BY version";
597 $cres = sqlStatement($query);
599 $lastcrow = false;
601 while ($crow = sqlFetchArray($cres)) {
602 $query = "SELECT id.type, ic.name " .
603 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
604 "id.pid = '" . $iter['enc_pid'] . "' AND " .
605 "id.provider = '" . $crow['payer_id'] . "' AND " .
606 "id.date <= '$raw_encounter_date' AND " .
607 "ic.id = id.provider " .
608 "ORDER BY id.type ASC, id.date DESC";
610 $irow= sqlQuery($query);
612 if ($crow['bill_process']) {
613 $lhtml .= "<br>\n&nbsp;" . substr($crow['bill_time'], 0, 16) . " " .
614 xl("Queued for") . " {$irow['type']} {$crow['target']} " .
615 xl("billing to ") . $irow['name'];
616 ++$lcount;
618 else if ($crow['status'] > 1) {
619 $lhtml .= "<br>\n&nbsp;" . substr($crow['bill_time'], 0, 16) . " " .
620 xl("Marked as cleared");
621 ++$lcount;
623 else {
624 $lhtml .= "<br>\n&nbsp;" . substr($crow['bill_time'], 0, 16) . " " .
625 xl("Re-opened");
626 ++$lcount;
629 if ($crow['process_time']) {
630 $lhtml .= "<br>\n&nbsp;" . substr($crow['process_time'], 0, 16) . " " .
631 xl("Claim was generated to file ") .
632 "<a href='get_claim_file.php?key=" . $crow['process_file'] .
633 "' onclick='top.restoreSession()'>" .
634 $crow['process_file'] . "</a>";
635 ++$lcount;
638 $lastcrow = $crow;
639 } // end while ($crow = sqlFetchArray($cres))
641 if ($lastcrow && $lastcrow['status'] == 4) {
642 $lhtml .= "<br>\n&nbsp;This claim has been closed.";
643 ++$lcount;
646 if ($lastcrow && $lastcrow['status'] == 5) {
647 $lhtml .= "<br>\n&nbsp;This claim has been canceled.";
648 ++$lcount;
650 } // end if ($iter['id'])
652 } // end if ($last_encounter_id != $this_encounter_id)
654 if ($skipping) continue;
656 ++$rcount;
658 if ($rhtml) {
659 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
661 $rhtml .= "<td width='50'>";
662 if ($iter['id'] && $oldcode != $iter['code_type']) {
663 $rhtml .= "<span class=text>" . $iter['code_type'] . ": </span>";
666 $oldcode = $iter['code_type'];
667 $rhtml .= "</td>\n";
668 $justify = "";
670 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
671 $js = split(":",$iter['justify']);
672 $counter = 0;
673 foreach ($js as $j) {
674 if(!empty($j)) {
675 if ($counter == 0) {
676 $justify .= " (<b>$j</b>)";
678 else {
679 $justify .= " ($j)";
681 $counter++;
686 $rhtml .= "<td><span class=text>" . $iter{"code"}. "</span>" . '<span style="font-size:8pt;">' . $justify . "</span></td>\n";
687 $rhtml .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
688 if ($iter['id'] && $iter['fee'] > 0) {
689 $rhtml .= '$' . $iter['fee'];
691 $rhtml .= "</span></td>\n";
692 $rhtml .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
693 if ($iter['id']) $rhtml .= getProviderName($iter['provider_id']);
694 $rhtml .= "</span></td>\n";
695 $rhtml .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
696 if ($iter['id']) $rhtml .= date("Y-m-d",strtotime($iter{"date"}));
697 $rhtml .= "</span></td>\n";
698 if ($iter['id'] && $iter['authorized'] != 1) {
699 $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";
701 else {
702 $rhtml .= "<td></td>\n";
704 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
705 $tmpbpr = $iter['bill_process'];
706 if ($tmpbpr == '0' && $iter['billed']) $tmpbpr = '2';
707 $rhtml .= "<td><input type='checkbox' value='$tmpbpr' name='claims[" . $this_encounter_id . "][bill]' onclick='set_button_states()'>&nbsp;</td>\n";
709 else {
710 $rhtml .= "<td></td>\n";
712 $rhtml .= "</tr>\n";
713 $last_encounter_id = $this_encounter_id;
715 } // end foreach
717 if ($lhtml) {
718 while ($rcount < $lcount) {
719 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'>&nbsp;</td></tr>";
720 ++$rcount;
722 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
723 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
730 </table>
731 </form>
733 <script>
734 set_button_states();
735 <?php
736 if ($alertmsg) {
737 echo "alert('$alertmsg');\n";
740 </script>
742 </body>
743 </html>