2 include_once("../globals.php");
4 include_once("$srcdir/patient.inc");
5 include_once("$srcdir/billrep.inc");
6 include_once(dirname(__FILE__
) . "/../../library/classes/WSClaim.class.php");
8 $fconfig = $GLOBALS['oer_config']['freeb'];
11 if (isset($_POST['bn_electronic_file']) && !empty($_POST['claims'])) {
13 if (empty($_POST['claims'])) {
14 $bill_info[] = "No claims were selected for inclusion.";
19 foreach ($_POST['claims'] as $claim) {
20 if (isset($claim['bill'])) {
21 if (substr($claim['file'],strlen($claim['file']) -4) == '.pdf') {
22 $fname = substr($claim['file'],0,-4);
25 $fname = $claim['file'];
27 $fname = preg_replace("[/]","",$fname);
28 $fname = preg_replace("[\.\.]","",$fname);
29 $fname = preg_replace("[\\\\]","",$fname);
30 $fname = $fconfig['claim_file_dir'] . $fname;
31 if (file_exists($fname)) {
32 //less than 500 is almost definitely an error
33 if (filesize($fname) > 500) {
34 $bill_info[] = "Added: " . $fname . "\n";
36 $ta["data"] = file_get_contents($fname);
37 $ta["size"] = filesize($fname);
41 $bill_info[] = "May have an error:" . $fname . "\n";
45 $bill_info[] = "Not found:" . $fname . "\n";
51 $db = $GLOBALS['adodb']['db'];
53 foreach ($_POST['claims'] as $claimid => $claim) {
54 if (isset($claim['bill'])) {
55 $tmpvars = split("-",$claimid);
57 $encounter = $tmpvars[1];
58 if (!empty($encounter) && !empty($pid)) {
59 $sql = "UPDATE billing set billed = 1 where encounter = '" . $encounter .
60 "' and pid = '" . $pid . "' and activity != 0";
61 $result = $db->execute($sql);
64 $bill_info[] = "Marking claim $claimid had a db error:" . $db->ErrorMsg() . "\n";
67 //send claim to the web services code to sync to external system if enabled
68 //remeber that in openemr it is only the encounter and patient id that make a group of
69 //billing line items unique so they can be grouped or associated as 1 claim
70 $ws = new WSClaim($pid, $encounter);
75 header("Pragma: public");
77 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
78 header("Content-Type: application/force-download");
79 header("Content-Disposition: attachment; filename=". date("Y-m-d") . "-billing_batch.txt");
80 header("Content-Description: File Transfer");
85 foreach ($efile as $file) {
86 $data .= $file['data'];
87 $size +
= $file['size'];
90 header("Content-Length: " . $size);
102 function process_form($ar) {
105 $db = $GLOBALS['adodb']['db'];
107 if (empty($ar['claims'])) {
108 $ar['claims'] = array();
110 foreach ($ar['claims'] as $claimid => $claim_array) {
112 $ta = split("-",$claimid);
113 $patient_id = $ta[0];
115 $payer = $claim_array['payer'];
117 if (isset($claim_array['bill'])) {
118 $sql = "SELECT x.processing_format from x12_partners as x where x.id =" . $db->qstr($claim_array['partner']);
119 $result = $db->Execute($sql);
121 if ($result && !$result->EOF
) {
122 $target = $result->fields
['processing_format'];
125 $sql = "UPDATE billing set bill_date = NOW(), ";
127 if (isset($ar['bn_hcfa_print'])) {
128 $sql .= " bill_process = 5, target = 'hcfa', ";
129 } else if (isset($ar['bn_hcfa'])) {
130 $sql .= " bill_process = 1, target = 'hcfa', ";
131 } else if (isset($ar['bn_ub92_print'])) {
132 $sql .= " bill_process = 5, target = 'ub92', ";
133 } else if (isset($ar['bn_ub92'])) {
134 $sql .= " bill_process = 1, target = 'ub92', ";
135 } else if (isset($ar['bn_x12'])) {
136 $sql .= " bill_process = 1, target = '" . $target . "', x12_partner_id = '" . mysql_real_escape_string($claim_array['partner']) . "', ";
137 } else if (isset($ar['bn_mark'])) {
138 $sql .= " billed = 1, ";
142 $sql .= " payer_id = '$payer' where encounter = " . $encounter . " and pid = " . $patient_id;
145 $result = $db->Execute($sql);
148 $bill_info[] = "Claim $claimid could not be queued due to error:" . $db->ErrorMsg() . "\n";
151 // wtf is mark_as_billed? nothing sets it! -- Rod
152 // if($ar['mark_as_billed'] == 1) {
154 $bill_info[] = "Claim $claimid was marked as billed only.\n";
157 $bill_info[] = "Claim $claimid was queued successfully.\n";
161 //send claim to the web services code to sync to external system if enabled
162 //remeber that in openemr it is only the encounter and patient id that make a group of
163 //billing line items unique so they can be grouped or associated as 1 claim
165 $ws = new WSClaim($patient_id,$encounter);
178 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
181 <body
<?
echo $top_bg_line;?
> topmargin
=0 rightmargin
=0 leftmargin
=2 bottommargin
=0 marginwidth
=2 marginheight
=0>
182 <br
><p
><h3
>Billing queue results
:</h3
><a href
="billing_report.php">back
</a
><ul
>
184 foreach ($bill_info as $infoline) {
185 echo nl2br($infoline);