2 require_once("{$GLOBALS['srcdir']}/sql.inc");
4 //date must be in nice format (e.g. 2002-07-11)
6 // function getBillsBy($date, $qtype = "day", $auth="%", $cols = "date,pid,code_type,code,user,authorized")
8 // if ($qtype == "all") {
9 // $res = sqlStatement("select $cols from billing order by date ASC");
11 // elseif ($qtype == "day") {
12 // $res = sqlStatement("select $cols from billing where date like '$date' order by date ASC");
14 // elseif ($qtype == "month") {
15 // $m = substr($date,5,2);
16 // $y = substr($date,0,4);
17 // $res = sqlStatement("select $cols from billing where MONTH(date) = '$m' and YEAR(date) = '$y' ORDER by date ASC");
19 // elseif ($qtype == "year") {
20 // $y = substr($date,0,4);
21 // $res = sqlStatement("select $cols from billing where YEAR(date) = '$y' ORDER by date ASC");
24 // for($iter=0; $row=sqlFetchArray($res); $iter++)
26 // $all[$iter] = $row;
32 function getBillsBetween($date, $date2, $auth="%", $unbilled, $code_type,
33 $cols = "id,date,pid,code_type,code,user,authorized,x12_partner_id")
35 $billstring = "billing.billed = '0'";
36 if ($unbilled == "0") {
37 //3 is an error condition
38 $billstring = "billing.billed = '0' or (billing.billed = '1' and billing.bill_process = '3')";
41 $billstring = "billing.billed = '1'";
44 // $sql = "select * from billing where date >= '$date' and " .
45 // "date <= '$date2 23:59:59' and authorized like '$auth' and " .
46 // "($billstring) and code_type like '$code_type' and activity = 1 " .
47 // "order by encounter, pid, code_type, code ASC";
49 // Selecting by the date in the billing table is wrong, because that is
50 // just the data entry date; instead we want to go by the encounter date
51 // which is the date in the form_encounter table.
53 $sql = "select form_encounter.date as enc_date, billing.* " .
54 "from form_encounter, billing where " .
55 "form_encounter.date >= '$date' and " .
56 "form_encounter.date <= '$date2 23:59:59' and " .
57 "billing.encounter = form_encounter.encounter and " .
58 "billing.authorized like '$auth' and " .
59 "($billstring) and " .
60 "billing.code_type like '$code_type' and " .
61 "billing.activity = 1 " .
62 "order by billing.encounter, billing.pid, billing.code_type, billing.code ASC";
64 $res = sqlStatement($sql);
66 for($iter=0; $row=sqlFetchArray($res); $iter++)
74 function getBillsListBetween($date, $date2, $auth="%", $unbilled, $code_type,
75 $cols = "billing.id, form_encounter.date, billing.pid, billing.code_type, billing.code, billing.user")
77 $billstring = "billed = '0'";
78 if ($unbilled == "0") {
79 //3 is an error condition
80 $billstring = "billed = '0' or (billed = '1' and bill_process = '3')";
83 $billstring = "billed = '1'";
86 // $sql = "select $cols from billing where date >= '$date' and date <= '$date2 23:59:59' and authorized like '$auth' and ($billstring) and code_type like '$code_type' and activity = 1 order by pid,date ASC";
88 // See above comment in getBillsBetween().
90 $sql = "select $cols " .
91 "from form_encounter, billing where " .
92 "form_encounter.date >= '$date' and " .
93 "form_encounter.date <= '$date2 23:59:59' and " .
94 "billing.encounter = form_encounter.encounter and " .
95 "billing.authorized like '$auth' and " .
96 "($billstring) and " .
97 "billing.code_type like '$code_type' and " .
98 "billing.activity = 1 " .
99 "order by billing.pid, billing.date ASC";
101 $res = sqlStatement($sql);
102 //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";
104 for($iter=0; $row=sqlFetchArray($res); $iter++)
106 $string .= $row{"id"}.",";
108 $string = substr($string,0,strlen($string)-1);
113 // function billCodesBetween($date, $date2, $auth="%", $code_type)
115 // sqlStatement("update billing set billed=1 where date >= '$date' and date <= '$date2 23:59:59' and authorized like '$auth' and code_type like '$code_type'");
118 function billCodesList($list,$skip = "()") {
123 sqlStatement("update billing set billed=1 where id in $list");
125 sqlStatement("update billing set billed=1 where id in $list and id not in $skip");
130 // function getCodeTypes () {
131 // $res = sqlStatement("select distinct code_type from billing order by code_type");
133 // for($iter=0; $row=sqlFetchArray($res); $iter++)
135 // $all[$iter] = $row;