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";
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";
27 $results = $db->Execute($sql);
29 if ($results->RecordCount() == 0) {
30 echo xl("No Bills Found to Include in OFX Export<br>");
33 while(!$results->EOF
) {
34 $billings[] = $results->fields
;
37 $ofx = new OFX($billings);
38 header("Pragma: public");
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");
49 if ($_POST['mode'] == 'process') {
50 if (exec("ps x | grep 'process_bills[.]php'")) {
51 $alertmsg = xl('Request ignored - claims processing is already running!');
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.');
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"];
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"];
75 // This tells us if only encounters that appear to be missing a "25" modifier
76 // are to be reported.
77 $missing_mods_only = !empty($_POST['missing_mods_only']);
80 $from_date = isset($_POST['from_date']) ? $_POST['from_date'] : date('Y-m-d');
81 $to_date = empty($_POST['to_date' ]) ? $from_date : $_POST['to_date'];
82 $code_type = isset($_POST['code_type']) ? $_POST['code_type'] : 'all';
83 $unbilled = isset($_POST['unbilled' ]) ? $_POST['unbilled' ] : 'on';
84 $my_authorized = $_POST["authorized"];
87 $left_margin = isset($_POST["left_margin"]) ?
$_POST["left_margin"] : 24;
88 $top_margin = isset($_POST["top_margin"] ) ?
$_POST["top_margin" ] : 20;
90 $ofrom_date = $from_date;
92 $ocode_type = $code_type;
93 $ounbilled = $unbilled;
94 $oauthorized = $my_authorized;
99 <?php
if (function_exists(html_header_show
)) html_header_show(); ?
>
100 <link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
102 .subbtn
{ margin
-top
:3px
; margin
-bottom
:3px
; margin
-left
:2px
; margin
-right
:2px
}
106 function select_all() {
107 for($i=0;$i < document
.update_form
.length
;$i++
) {
108 $name = document
.update_form
[$i].name
;
109 if ($name.substring(0,7) == "claims[" && $name.substring($name.length
-6) == "[bill]") {
110 document
.update_form
[$i].checked
= true;
116 function set_button_states() {
117 var f
= document
.update_form
;
118 var count0
= 0; // selected and not billed or queued
119 var count1
= 0; // selected and queued
120 var count2
= 0; // selected and billed
121 for($i = 0; $i < f
.length
; ++
$i) {
123 if ($name.substring(0, 7) == "claims[" && $name.substring($name.length
-6) == "[bill]" && f
[$i].checked
== true) {
124 if (f
[$i].value
== '0') ++count0
;
125 else if (f
[$i].value
== '1' || f
[$i].value
== '5') ++count1
;
130 var can_generate
= (count0
> 0 || count1
> 0 || count2
> 0);
131 var can_mark
= (count1
> 0 || count0
> 0 || count2
> 0);
132 var can_bill
= (count0
== 0 && count1
== 0 && count2
> 0);
134 <?php
if (file_exists($EXPORT_INC)) { ?
>
135 f
.bn_external
.disabled
= !can_generate
;
137 // f.bn_hcfa_print.disabled = !can_generate;
138 // f.bn_hcfa.disabled = !can_generate;
139 // f.bn_ub92_print.disabled = !can_generate;
140 // f.bn_ub92.disabled = !can_generate;
141 f
.bn_x12
.disabled
= !can_generate
;
142 <?php
if ($GLOBALS['support_encounter_claims']) { ?
>
143 f
.bn_x12_encounter
.disabled
= !can_generate
;
145 f
.bn_process_hcfa
.disabled
= !can_generate
;
146 f
.bn_hcfa_txt_file
.disabled
= !can_generate
;
147 // f.bn_electronic_file.disabled = !can_bill;
148 f
.bn_reopen
.disabled
= !can_bill
;
150 f
.bn_mark
.disabled
= !can_mark
;
153 // Process a click to go to an encounter.
154 function toencounter(pid
, pubpid
, pname
, enc
, datestr
) {
155 top
.restoreSession();
156 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
157 var othername
= (window
.name
== 'RTop') ?
'RBot' : 'RTop';
158 parent
.left_nav
.setPatient(pname
,pid
,pubpid
,'');
159 parent
.left_nav
.setEncounter(datestr
, enc
, othername
);
160 parent
.left_nav
.setRadio(othername
, 'enc');
161 parent
.frames
[othername
].location
.href
=
162 '../patient_file/encounter/encounter_top.php?set_encounter='
163 + enc +
'&pid=' + pid
;
165 location
.href
= '../patient_file/encounter/patient_encounter.php?set_encounter='
166 + enc +
'&pid=' + pid
;
170 function topatient(pid
) {
171 top
.restoreSession();
172 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
173 var othername
= (window
.name
== 'RTop') ?
'RBot' : 'RTop';
174 parent
.frames
[othername
].location
.href
=
175 '../patient_file/summary/demographics_full.php?pid=' + pid
;
177 location
.href
= '../patient_file/summary/demographics_full.php?pid=' + pid
;
183 <body
class="body_top">
185 <p style
='margin-top:5px;margin-bottom:5px;margin-left:5px'>
187 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
188 <font
class='title'><?php
xl('Billing Report','e') ?
></font
>
189 <?php
} else if ($userauthorized) { ?
>
190 <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
>
192 <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
>
197 <form name
='the_form' method
='post' action
='billing_report.php' onsubmit
='return top.restoreSession()'>
199 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
200 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
201 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
202 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
203 <script type
="text/javascript" src
="../../library/dynarch_calendar_en.js"></script
>
204 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
205 <script language
='JavaScript'>
209 <input type
='hidden' name
='mode' value
='change'>
211 <table width
='100%' border
="1" cellspacing
="0" cellpadding
="0">
214  
;<span
class='text'><?php
xl('From: ','e') ?
></span
>
215 <input type
='text' size
='10' name
='from_date' id
='from_date'
216 value
='<?php echo $from_date; ?>'
217 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
218 title
=<?php
xl('yyyy-mm-dd last date of this event','e','\'','\''); ?
> />
219 <img src
='../../interface/pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
220 id
='img_fromdate' border
='0' alt
='[?]' style
='cursor:pointer'
221 title
=<?php
xl('Click here to choose a date','e','\'','\''); ?
> />
223 Calendar
.setup({inputField
:"from_date", ifFormat
:"%Y-%m-%d", button
:"img_fromdate"});
228  
;<span
class='text'><?php
xl('To: ','e') ?
></span
>
229 <input type
='text' size
='10' name
='to_date' id
='to_date'
230 value
='<?php echo $to_date; ?>'
231 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
232 title
=<?php
xl('yyyy-mm-dd last date of this event','e','\'','\''); ?
> />
233 <img src
='../../interface/pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
234 id
='img_todate' border
='0' alt
='[?]' style
='cursor:pointer'
235 title
=<?php
xl('Click here to choose a date','e','\'','\''); ?
> />
237 Calendar
.setup({inputField
:"to_date", ifFormat
:"%Y-%m-%d", button
:"img_todate"});
239 <input type
="hidden" name
="code_type" value
="%" />
243 <input type
='checkbox' name
='unbilled' <?php
if ($unbilled == "on") {echo "checked";}; ?
> />
244 <span
class='text'><?php
xl('Unbilled Only','e') ?
></span
>
246 <input type
='checkbox' name
='authorized' <?php
if ($my_authorized == "on") {echo "checked";}; ?
> />
247 <span
class='text'><?php
xl('Authorized Only','e') ?
></span
>
248 <?php
if (!empty($GLOBALS['missing_mods_option'])) { ?
>
250 <input type
='checkbox' name
='missing_mods_only' <?php
if ($missing_mods_only) echo "checked"; ?
> />
251 <span
class='text'><?php
xl('Missing Mods Only','e') ?
></span
>
255 <td align
='right' width
='10%' nowrap
>
256  
;<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
>
258 <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
> 
;
266  
;<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); ?>"
267 class='link_submit' target
='new' onclick
='top.restoreSession()'><?php
xl('[View Printable Report]','e') ?
></a
>
273 $acct_config = $GLOBALS['oer_config']['ws_accounting'];
274 if($acct_config['enabled']) {
275 if($acct_config['enabled'] !== 2) {
276 print '<span class=text><a href="javascript:void window.open(\'' . $acct_config['url_path'] . '\')">' . xl("[SQL-Ledger]") . '</a> </span>';
278 if (acl_check('acct', 'rep')) {
279 print '<span class=text><a href="javascript:void window.open(\'sl_receipts_report.php\')" onclick="top.restoreSession()">' . xl('[Reports]') . '</a> </span>';
281 if (acl_check('acct', 'eob')) {
282 print '<span class=text><a href="javascript:void window.open(\'sl_eob_search.php\')" onclick="top.restoreSession()">' . xl('[EOBs]') . '</a></span>';
288 <td
class='text' nowrap
>
290 <?php
if (! file_exists($EXPORT_INC)) { ?
>
292 <a href
="javascript:top.restoreSession();document.the_form.mode.value='process';document.the_form.submit()" class="link_submit"
293 title
="Process all queued bills to create electronic data (and print if requested)"><?php
xl('[Start Batch Processing]','e') ?
></a
>
296 <a href
='../../library/freeb/process_bills.log' target
='_blank' class='link_submit'
297 title
=<?php
xl('See messages from the last set of generated claims','e','\'','\''); ?
>><?php
xl('[View Log]','e') ?
></a
>
301 <td align
='right' nowrap
>
302 <a href
="javascript:select_all()" class="link_submit"><?php
xl('[Select All]','e') ?
></a
> 
;
310 <form name
='update_form' method
='post' action
='billing_process.php' onsubmit
='return top.restoreSession()'>
315 <?php
if (file_exists($EXPORT_INC)) { ?
>
316 <input type
="submit" class="subbtn" name
="bn_external" value
="Export Billing" title
="<?php xl('Export to external billing system','e') ?>">
317 <input type
="submit" class="subbtn" name
="bn_mark" value
="Mark as Cleared" title
="<?php xl('Mark as billed but skip billing','e') ?>">
320 <input type
="submit" class="subbtn" name
="bn_hcfa_print" value
="Queue HCFA & Print" title
="<?php xl('Queue for HCFA batch processing and printing','e') ?>">
321 <input type
="submit" class="subbtn" name
="bn_hcfa" value
="Queue HCFA" title
="<?php xl('Queue for HCFA batch processing','e')?>">
322 <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')?>">
323 <input type
="submit" class="subbtn" name
="bn_ub92" value
="Queue UB92" title
="<?php xl('Queue for UB-92 batch processing','e')?>">
325 <input type
="submit" class="subbtn" name
="bn_x12" value
="<?php xl('Generate X12','e')?>"
326 title
="<?php xl('Generate and download X12 batch','e')?>"
327 onclick
="alert('<?php xl('After saving your batch, click [View Log] to check for errors.','e'); ?>')">
328 <?php
if ($GLOBALS['support_encounter_claims']) { ?
>
329 <input type
="submit" class="subbtn" name
="bn_x12_encounter" value
="<?php xl('Generate X12 Encounter','e')?>"
330 title
="<?php xl('Generate and download X12 encounter claim batch','e')?>"
331 onclick
="alert('<?php xl('After saving your batch, click [View Log] to check for errors.','e'); ?>')">
333 <input type
="submit" class="subbtn" name
="bn_process_hcfa" value
="<?php xl('Generate CMS 1500 PDF','e')?>"
334 title
="<?php xl('Generate and download CMS 1500 paper claims','e')?>"
335 onclick
="alert('<?php xl('After saving the PDF, click [View Log] to check for errors.','e'); ?>')">
336 <input type
="submit" class="subbtn" name
="bn_hcfa_txt_file" value
="<?php xl('Generate CMS 1500 TEXT','e')?>"
337 title
="<?php xl('Making batch text files for uploading to Clearing House and will mark as billed', 'e')?>"
338 onclick
="alert('<?php xl('After saving the TEXT file(s), click [View Log] to check for errors.','e'); ?>')">
339 <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')?>">
340 <input type
="submit" class="subbtn" name
="bn_reopen" value
="<?php xl('Re-Open','e')?>" title
="<?php xl('Mark as not billed','e')?>">
342 <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')?>">
345 <?php
xl('CMS 1500 Margins','e'); ?
>:
346  
;<?php
xl('Left','e'); ?
>:
347 <input type
='text' size
='2' name
='left_margin'
348 value
='<?php echo $left_margin; ?>'
349 title
=<?php
xl('HCFA left margin in points','e','\'','\''); ?
> />
350  
;<?php
xl('Top','e'); ?
>:
351 <input type
='text' size
='2' name
='top_margin'
352 value
='<?php echo $top_margin; ?>'
353 title
=<?php
xl('HCFA top margin in points','e','\'','\''); ?
> />
359 <input type
='hidden' name
='mode' value
="bill" />
360 <input type
='hidden' name
='authorized' value
="<?php echo $my_authorized; ?>" />
361 <input type
='hidden' name
='unbilled' value
="<?php echo $unbilled; ?>" />
362 <input type
='hidden' name
='code_type' value
="%" />
363 <input type
='hidden' name
='to_date' value
="<?php echo $to_date; ?>" />
364 <input type
='hidden' name
='from_date' value
="<?php echo $from_date; ?>" />
367 if ($my_authorized == "on" ) {
368 $my_authorized = "1";
370 $my_authorized = "%";
372 if ($unbilled == "on") {
378 $list = getBillsListBetween($from_date,
379 empty($to_date) ?
$from_date : $to_date,
380 $my_authorized,$unbilled,"%");
383 <input type
='hidden' name
='bill_list' value
="<?php echo $list; ?>" />
385 <!-- new form
for uploading
-->
388 if (!isset($_POST["mode"])) {
389 if (!isset($_POST["from_date"])) {
390 $from_date = date("Y-m-d");
392 $from_date = $_POST["from_date"];
394 if (empty($_POST["to_date"])) {
397 $to_date = $_POST["to_date"];
399 if (!isset($_POST["code_type"])) {
402 $code_type = $_POST["code_type"];
404 if (!isset($_POST["unbilled"])) {
407 $unbilled = $_POST["unbilled"];
409 if (!isset($_POST["authorized"])) {
410 $my_authorized = "on";
412 $my_authorized = $_POST["authorized"];
415 $from_date = $_POST["from_date"];
416 $to_date = $_POST["to_date"];
417 $code_type = $_POST["code_type"];
418 $unbilled = $_POST["unbilled"];
419 $my_authorized = $_POST["authorized"];
422 if ($my_authorized == "on" ) {
423 $my_authorized = "1";
425 $my_authorized = "%";
428 if ($unbilled == "on") {
434 if (isset($_POST["mode"]) && $_POST["mode"] == "bill") {
435 billCodesList($list);
440 <table border
="0" cellspacing
="0" cellpadding
="0" width
="100%">
443 if ($ret = getBillsBetween($from_date,
444 empty($to_date) ?
$from_date : $to_date,
445 $my_authorized, $unbilled, "%"))
449 $last_encounter_id = "";
457 $mmo_empty_mod = false;
458 $mmo_num_charges = 0;
460 foreach ($ret as $iter) {
462 // We include encounters here that have never been billed. However
463 // if it had no selected billing items but does have non-selected
464 // billing items, then it is not of interest.
466 $res = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
467 "encounter = '" . $iter['enc_encounter'] . "' AND " .
468 "pid='" . $iter['enc_pid'] . "' AND " .
470 if ($res['count'] > 0) continue;
473 $this_encounter_id = $iter['enc_pid'] . "-" . $iter['enc_encounter'];
475 if ($last_encounter_id != $this_encounter_id) {
477 // This dumps all HTML for the previous encounter.
480 while ($rcount < $lcount) {
481 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'> </td></tr>";
484 // This test handles the case where we are only listing encounters
485 // that appear to have a missing "25" modifier.
486 if (!$missing_mods_only ||
($mmo_empty_mod && $mmo_num_charges > 1)) {
487 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
488 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n\n";
495 $mmo_empty_mod = false;
496 $mmo_num_charges = 0;
498 // If there are ANY unauthorized items in this encounter and this is
499 // the normal case of viewing only authorized billing, then skip the
503 if ($my_authorized == '1') {
504 $res = sqlQuery("select count(*) as count from billing where " .
505 "encounter = '" . $iter['enc_encounter'] . "' and " .
506 "pid='" . $iter['enc_pid'] . "' and " .
507 "activity = 1 and authorized = 0");
508 if ($res['count'] > 0) {
510 $last_encounter_id = $this_encounter_id;
515 $name = getPatientData($iter['enc_pid'], "fname, mname, lname, pubpid");
517 # Check if patient has primary insurance and a subscriber exists for it.
518 # If not we will highlight their name in red.
519 # TBD: more checking here.
521 $res = sqlQuery("select count(*) as count from insurance_data where " .
522 "pid = " . $iter['enc_pid'] . " and " .
523 "type='primary' and " .
524 "subscriber_lname is not null and " .
525 "subscriber_lname != '' limit 1");
526 $namecolor = ($res['count'] > 0) ?
"black" : "#ff7777";
528 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
529 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
534 $ptname = $name['fname'] . " " . $name['lname'];
535 $raw_encounter_date = date("Y-m-d", strtotime($iter['enc_date']));
537 // Add Encounter Date to display with "To Encounter" button 2/17/09 JCH
538 $lhtml .= " <span class=bold><font color='$namecolor'>$ptname" .
539 "</font></span><span class=small> (" . $iter['enc_pid'] . "-" .
540 $iter['enc_encounter'] . ")</span>";
542 // Not sure why the next section seems to do nothing except post "To Encounter" button 2/17/09 JCH
543 $lhtml .= " <a class=\"link_submit\" " .
544 "href=\"javascript:window.toencounter(" . $iter['enc_pid'] .
545 ",'" . addslashes($name['pubpid']) .
546 "','" . addslashes($ptname) . "'," . $iter['enc_encounter'] .
547 ",'$raw_encounter_date')\">[" . xl('To Enctr') . " $raw_encounter_date]</a>";
549 // Changed "To xxx" buttons to allow room for encounter date display 2/17/09 JCH
550 $lhtml .= " <a class=\"link_submit\" " .
551 "href=\"javascript:window.topatient(" . $iter['enc_pid'] .
552 ")\">[" . xl('To Dems') . "]</a>";
557 $lhtml .= "<br />\n";
558 $lhtml .= " <span class=text>Bill: ";
559 $lhtml .= "<select name='claims[" . $this_encounter_id . "][payer]' style='background-color:$bgcolor'>";
561 $query = "SELECT id.provider AS id, id.type, id.date, " .
562 "ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
563 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
564 "ic.id = id.provider AND " .
565 "id.pid = '" . mysql_escape_string($iter['enc_pid']) . "' AND " .
566 "id.date <= '$raw_encounter_date' " .
567 "ORDER BY id.type ASC, id.date DESC";
569 $result = sqlStatement($query);
571 $default_x12_partner = $iter['ic_x12id'];
574 while ($row = mysql_fetch_array($result)) {
575 if (strcmp($row['type'], $prevtype) == 0) continue;
576 $prevtype = $row['type'];
577 if (strlen($row['provider']) > 0) {
578 // This preserves any existing insurance company selection, which is
579 // important when EOB posting has re-queued for secondary billing.
580 $lhtml .= "<option value=\"" . strtoupper(substr($row['type'],0,1)) . $row['id'] . "\"";
581 if (($count == 0 && !$iter['payer_id']) ||
$row['id'] == $iter['payer_id']) {
582 $lhtml .= " selected";
583 if (!is_numeric($default_x12_partner)) $default_x12_partner = $row['ic_x12id'];
585 $lhtml .= ">" . $row['type'] . ": " . $row['provider'] . "</option>";
590 $lhtml .= "<option value='-1'>Unassigned</option>\n";
591 $lhtml .= "</select> \n";
592 $lhtml .= "<select name='claims[" . $this_encounter_id . "][partner]' style='background-color:$bgcolor'>";
593 $x = new X12Partner();
594 $partners = $x->_utility_array($x->x12_partner_factory());
595 foreach ($partners as $xid => $xname) {
596 $lhtml .= '<option label="' . $xname . '" value="' . $xid .'"';
597 if ($xid == $default_x12_partner) {
598 $lhtml .= "selected";
600 $lhtml .= '>' . $xname . '</option>';
602 $lhtml .= "</select>";
603 $lhtml .= "<br>\n " . substr($iter['date'], 0, 16) . " " .
604 xl("Encounter was coded");
606 $query = "SELECT * FROM claims WHERE " .
607 "patient_id = '" . $iter['enc_pid'] . "' AND " .
608 "encounter_id = '" . $iter['enc_encounter'] . "' " .
610 $cres = sqlStatement($query);
614 while ($crow = sqlFetchArray($cres)) {
615 $query = "SELECT id.type, ic.name " .
616 "FROM insurance_data AS id, insurance_companies AS ic WHERE " .
617 "id.pid = '" . $iter['enc_pid'] . "' AND " .
618 "id.provider = '" . $crow['payer_id'] . "' AND " .
619 "id.date <= '$raw_encounter_date' AND " .
620 "ic.id = id.provider " .
621 "ORDER BY id.type ASC, id.date DESC";
623 $irow= sqlQuery($query);
625 if ($crow['bill_process']) {
626 $lhtml .= "<br>\n " . substr($crow['bill_time'], 0, 16) . " " .
627 xl("Queued for") . " {$irow['type']} {$crow['target']} " .
628 xl("billing to ") . $irow['name'];
631 else if ($crow['status'] > 1) {
632 $lhtml .= "<br>\n " . substr($crow['bill_time'], 0, 16) . " " .
633 xl("Marked as cleared");
637 $lhtml .= "<br>\n " . substr($crow['bill_time'], 0, 16) . " " .
642 if ($crow['process_time']) {
643 $lhtml .= "<br>\n " . substr($crow['process_time'], 0, 16) . " " .
644 xl("Claim was generated to file ") .
645 "<a href='get_claim_file.php?key=" . $crow['process_file'] .
646 "' onclick='top.restoreSession()'>" .
647 $crow['process_file'] . "</a>";
652 } // end while ($crow = sqlFetchArray($cres))
654 if ($lastcrow && $lastcrow['status'] == 4) {
655 $lhtml .= "<br>\n This claim has been closed.";
659 if ($lastcrow && $lastcrow['status'] == 5) {
660 $lhtml .= "<br>\n This claim has been canceled.";
663 } // end if ($iter['id'])
665 } // end if ($last_encounter_id != $this_encounter_id)
667 if ($skipping) continue;
669 // Collect info related to the missing modifiers test.
670 if ($iter['fee'] > 0) {
672 $tmp = substr($iter['code'], 0, 3);
673 if (($tmp == '992' ||
$tmp == '993') && empty($iter['modifier']))
674 $mmo_empty_mod = true;
680 $rhtml .= "<tr bgcolor='$bgcolor'>\n";
682 $rhtml .= "<td width='50'>";
683 if ($iter['id'] && $oldcode != $iter['code_type']) {
684 $rhtml .= "<span class=text>" . $iter['code_type'] . ": </span>";
687 $oldcode = $iter['code_type'];
691 if ($iter['id'] && $code_types[$iter['code_type']]['just']) {
692 $js = split(":",$iter['justify']);
694 foreach ($js as $j) {
697 $justify .= " (<b>$j</b>)";
707 $rhtml .= "<td><span class='text'>" . $iter['code'];
708 if ($iter['modifier']) $rhtml .= ":" . $iter['modifier'];
709 $rhtml .= "</span><span style='font-size:8pt;'>$justify</span></td>\n";
711 $rhtml .= '<td align="right"><span style="font-size:8pt;"> ';
712 if ($iter['id'] && $iter['fee'] > 0) {
713 $rhtml .= '$' . $iter['fee'];
715 $rhtml .= "</span></td>\n";
716 $rhtml .= '<td><span style="font-size:8pt;"> ';
717 if ($iter['id']) $rhtml .= getProviderName(empty($iter['provider_id']) ?
$iter['enc_provider_id'] : $iter['provider_id']);
718 $rhtml .= "</span></td>\n";
719 $rhtml .= '<td width=100> <span style="font-size:8pt;">';
720 if ($iter['id']) $rhtml .= date("Y-m-d",strtotime($iter{"date"}));
721 $rhtml .= "</span></td>\n";
722 if ($iter['id'] && $iter['authorized'] != 1) {
723 $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";
726 $rhtml .= "<td></td>\n";
728 if ($iter['id'] && $last_encounter_id != $this_encounter_id) {
729 $tmpbpr = $iter['bill_process'];
730 if ($tmpbpr == '0' && $iter['billed']) $tmpbpr = '2';
731 $rhtml .= "<td><input type='checkbox' value='$tmpbpr' name='claims[" . $this_encounter_id . "][bill]' onclick='set_button_states()'> </td>\n";
734 $rhtml .= "<td></td>\n";
737 $last_encounter_id = $this_encounter_id;
742 while ($rcount < $lcount) {
743 $rhtml .= "<tr bgcolor='$bgcolor'><td colspan='7'> </td></tr>";
746 if (!$missing_mods_only ||
($mmo_empty_mod && $mmo_num_charges > 1)) {
747 echo "<tr bgcolor='$bgcolor'>\n<td rowspan='$rcount' valign='top'>\n$lhtml</td>$rhtml\n";
748 echo "<tr bgcolor='$bgcolor'><td colspan='8' height='5'></td></tr>\n";
763 echo "alert('$alertmsg');\n";