2 require_once("{$GLOBALS['srcdir']}/sql.inc");
4 //date must be in nice format (e.g. 2002-07-11)
6 function getBillsBetween($date, $date2, $auth="%", $unbilled, $code_type,
7 $cols = "id,date,pid,code_type,code,user,authorized,x12_partner_id")
9 $billstring = "billing.billed = '0'";
10 if ($unbilled == "0") {
11 //3 is an error condition
12 $billstring = "billing.billed = '0' or (billing.billed = '1' and billing.bill_process = '3')";
15 $billstring = "billing.billed = '1'";
18 // Selecting by the date in the billing table is wrong, because that is
19 // just the data entry date; instead we want to go by the encounter date
20 // which is the date in the form_encounter table.
22 $sql = "SELECT fe.date AS enc_date, fe.pid AS enc_pid, " .
23 "fe.encounter AS enc_encounter, billing.* " .
24 "FROM form_encounter AS fe " .
25 "LEFT OUTER JOIN billing ON " .
26 "billing.encounter = fe.encounter AND " .
27 "billing.pid = fe.pid AND " .
28 "billing.authorized like '$auth' AND " .
29 "( $billstring ) AND " .
30 "billing.code_type LIKE '$code_type' AND " .
31 "billing.activity = 1 " .
33 "fe.date >= '$date' AND " .
34 "fe.date <= '$date2 23:59:59' " .
35 "ORDER BY fe.encounter, fe.pid, billing.code_type, billing.code ASC";
37 $res = sqlStatement($sql);
39 for($iter=0; $row=sqlFetchArray($res); $iter++)
47 function getBillsListBetween($date, $date2, $auth="%", $unbilled, $code_type,
48 $cols = "billing.id, form_encounter.date, billing.pid, billing.code_type, billing.code, billing.user")
50 $billstring = "billed = '0'";
51 if ($unbilled == "0") {
52 //3 is an error condition
53 $billstring = "billed = '0' or (billed = '1' and bill_process = '3')";
56 $billstring = "billed = '1'";
59 // See above comment in getBillsBetween().
61 $sql = "select $cols " .
62 "from form_encounter, billing where " .
63 "form_encounter.date >= '$date' and " .
64 "form_encounter.date <= '$date2 23:59:59' and " .
65 "billing.encounter = form_encounter.encounter and " .
66 "billing.authorized like '$auth' and " .
67 "($billstring) and " .
68 "billing.code_type like '$code_type' and " .
69 "billing.activity = 1 " .
70 "order by billing.pid, billing.date ASC";
72 $res = sqlStatement($sql);
73 //print "select $cols from billing where date >= '$date' and date <= '$date2 23:59:59' and authorized like '$auth' and billed like '$unbilled' and code_type like '$code_type' order by pid,date ASC";
75 for($iter=0; $row=sqlFetchArray($res); $iter++)
77 $string .= $row{"id"}.",";
79 $string = substr($string,0,strlen($string)-1);
84 function billCodesList($list,$skip = "()") {
89 sqlStatement("update billing set billed=1 where id in $list");
91 sqlStatement("update billing set billed=1 where id in $list and id not in $skip");