3 require ("xmlrpc.inc");
4 require (dirname(__FILE__
) . "/../sql.inc");
5 require (dirname(__FILE__
) . "/../../includes/config.php");
7 if ($argv[1] != "bill") {
8 echo "This script can only be accessed as a CLI program.\n";
9 echo "To execute from the command line run 'php -q process_bills.php bill' .\n";
13 $db = $GLOBALS['adodb']['db'];
15 //Used for testing purposed to send the same transactions through again and again
16 //$sql = "update billing set billed = 0, bill_process = 0, bill_date = null, process_date = null, process_file = null";
17 //$results = $db->Execute($sql);
19 $sql = "SELECT * from billing WHERE bill_process = 1 or bill_process = 5 group by pid,encounter" ;
21 $results = $db->Execute($sql);
26 echo "There was an error with the database.\n";
31 if ($results->RecordCount() == 0) {
32 echo "No bills queued for processing.\n";
36 while (!$results->EOF
) {
37 $ta['key'] = $results->fields
['pid'] . "-" . $results->fields
['encounter'];
38 $ta['bill_process'] = $results->fields
['bill_process'];
39 $ta['format'] = $results->fields
['target'];
44 foreach ($billkeys as $billkey) {
45 $tmp = split("-",$billkey['key']);
46 $patient_id = $tmp[0];
48 $name = "FreeB.Bill.process";
50 $format = $billkey['format'];
53 $format = $GLOBALS['oer_config']['freeb']['default_format'];
56 if ($format == "hcfa" ||
$format == "ub92") {
62 echo "Creating job for: " . $billkey['key'] . " as $format returning $file_type.\n";
63 $args = array(new xmlrpcval($billkey['key'],XMLRPCSTRING
), new xmlrpcval($format),new xmlrpcval($file_type));
65 $f=new xmlrpcmsg($name,$args);
66 //print "<pre>" . htmlentities($f->serialize()) . "</pre>\n";
67 $c=new xmlrpc_client("/RPC2", "localhost",18081);
71 if (!$r) { die("send failed"); }
73 if (!$r->faultCode()) {
74 //print "<HR>I got this value back for $name<BR>";
75 $presult = $v->scalarval();
76 echo "Claim for PatientID: $patient_id, Encounter: $billkey[key] processed successfully. Results are in file:\n " . basename("/" . $presult) . "\n";
77 $sql = "UPDATE billing set process_date = now(), bill_process = 2, process_file = '" . basename("/" . $presult) . "' where encounter = $encounter AND pid = '" . $patient_id . "'";
78 $results = $db->Execute($sql);
80 echo "There was an error with the database.\n";
81 echo $db->ErrorMsg() . "\n";
83 elseif ($billkey['bill_process'] == 5) {
84 //the bill was generated without an error now print it
85 $fconfig = $GLOBALS['oer_config']['freeb'];
86 $fname = $fconfig['claim_file_dir'] . basename("/" . $presult);
87 $estring = $fconfig['print_command'] . " -P " . $fconfig['printer_name'] . " " . $fconfig['printer_extras'] . " " . $fname;
88 //echo $estring . "<br>";
89 $rstring = exec(escapeshellcmd($estring));
91 //echo "<PRE>" . htmlentities($r->serialize()). "</PRE>\n";
94 //print "<HR>Fault: ";
95 $presult = "Code: " . $r->faultCode() . " Reason '" .$r->faultString()."'<BR>";
96 echo "Claim for PatientID: $patient_id, Encounter: $billkey[key] failed due to: \n " . basename("/" . $presult) . "\n";
97 $sql = "UPDATE billing set process_date = now(), bill_process = 3, process_file = '" . mysql_real_escape_string(basename("/" . $presult)) . "' where encounter = $encounter AND pid = '" . $patient_id . "'";
98 $results = $db->Execute($sql);
100 echo "There was an error with the database.\n";
101 echo $db->ErrorMsg() . "\n";