got rid of empty files that created and headers sent problem
[openemr.git] / interface / reports / appt_encounter_report.php
blobb4372e238fb92e78239e0614ea83a99588ec25c7
1 <?
2 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This report cross-references appointments with encounters.
10 // For a given date, show a line for each appointment with the
11 // matching encounter, and also for each encounter that has no
12 // matching appointment. This helps to catch these errors:
14 // * Appointments with no encounter
15 // * Encounters with no appointment
16 // * Codes not justified
17 // * Codes not authorized
18 // * Procedure codes without a fee
19 // * Fees assigned to diagnoses (instead of procedures)
20 // * Encounters not billed
22 include_once("../globals.php");
23 include_once("../../library/patient.inc");
24 include_once("../../custom/code_types.inc.php");
26 $alertmsg = ''; // not used yet but maybe later
28 function bucks($amount) {
29 if ($amount)
30 printf("%.2f", $amount);
33 if ($_POST['form_search']) {
34 $form_date = fixDate($_POST['form_date'], "");
36 // MySQL doesn't grok full outer joins so we do it the hard way.
38 $query = "( " .
39 "SELECT " .
40 "e.pc_startTime, " .
41 "fe.encounter, " .
42 "f.authorized, " .
43 "p.fname, p.lname, p.pid, " .
44 "u.lname AS docname " .
45 "FROM openemr_postcalendar_events AS e " .
46 "LEFT OUTER JOIN form_encounter AS fe " .
47 "ON LEFT(fe.date, 10) = e.pc_eventDate AND fe.pid = e.pc_pid " .
48 "LEFT OUTER JOIN forms AS f ON f.encounter = fe.encounter AND f.formdir = 'newpatient' " .
49 "LEFT OUTER JOIN patient_data AS p ON p.pid = e.pc_pid " .
50 "LEFT OUTER JOIN users AS u ON u.id = e.pc_aid " .
51 "WHERE e.pc_eventDate = '$form_date' AND " .
52 "( e.pc_catid = 5 OR e.pc_catid = 9 OR e.pc_catid = 10 ) " .
53 ") UNION ( " .
54 "SELECT " .
55 "e.pc_startTime, " .
56 "fe.encounter, " .
57 "f.authorized, " .
58 "p.fname, p.lname, p.pid, " .
59 "u.lname AS docname " .
60 "FROM form_encounter AS fe " .
61 "LEFT OUTER JOIN openemr_postcalendar_events AS e " .
62 "ON LEFT(fe.date, 10) = e.pc_eventDate AND fe.pid = e.pc_pid AND " .
63 "( e.pc_catid = 5 OR e.pc_catid = 9 OR e.pc_catid = 10 ) " .
64 "LEFT OUTER JOIN forms AS f ON f.encounter = fe.encounter AND f.formdir = 'newpatient' " .
65 "LEFT OUTER JOIN patient_data AS p ON p.pid = fe.pid " .
66 "LEFT OUTER JOIN users AS u ON u.username = f.user " .
67 "WHERE LEFT(fe.date, 10) = '$form_date' " .
68 ") " .
69 "ORDER BY docname, pc_startTime";
71 $res = sqlStatement($query);
74 <html>
75 <head>
76 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
77 <title>Appointments and Encounters</title>
78 </head>
80 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
81 <center>
83 <form method='post' action='appt_encounter_report.php'>
85 <table border='0' cellpadding='5' cellspacing='0' width='98%'>
87 <tr>
88 <td height="1" colspan="2">
89 </td>
90 </tr>
92 <tr bgcolor='#ddddff'>
93 <td align='left'>
94 <h2>Appointments and Encounters</h2>
95 </td>
96 <td align='right'>
97 Booking Date:
98 <input type='text' name='form_date' size='10' value='<? echo $_POST['form_date']; ?>'
99 title='Date of appointments mm/dd/yyyy'>
100 &nbsp;
101 <input type='submit' name='form_search' value='Search'>
102 </td>
103 </tr>
105 <tr>
106 <td height="1" colspan="2">
107 </td>
108 </tr>
110 </table>
112 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
114 <tr bgcolor="#dddddd">
115 <td class="dehead">
116 &nbsp;Practitioner
117 </td>
118 <td class="dehead">
119 &nbsp;Time
120 </td>
121 <td class="dehead">
122 &nbsp;Patient
123 </td>
124 <td class="dehead" align="right">
125 Chart&nbsp;
126 </td>
127 <td class="dehead" align="right">
128 Encounter&nbsp;
129 </td>
130 <td class="dehead" align="right">
131 Charge&nbsp;
132 </td>
133 <td class="dehead" align="center">
134 Billed
135 </td>
136 <td class="dehead">
137 &nbsp;Error
138 </td>
139 </tr>
141 if ($res) {
142 $lastdocname = "";
143 while ($row = sqlFetchArray($res)) {
144 $patient_id = $row['pid'];
145 $encounter = $row['encounter'];
146 $docname = $row['docname'];
148 $billed = "Y";
149 $errmsg = "";
150 $charges = 0;
152 // Scan the billing items for status and fee total.
154 $query = "SELECT code_type, authorized, billed, fee, justify " .
155 "FROM billing WHERE " .
156 "pid = '$patient_id' AND encounter = '$encounter' AND activity = 1";
157 $bres = sqlStatement($query);
159 while ($brow = sqlFetchArray($bres)) {
160 if (! $brow['billed']) $billed = "";
161 if (! $brow['authorized']) $errmsg = "Needs Auth";
162 if ($code_types[$brow['code_type']]['just']) {
163 if (! $brow['justify']) $errmsg = "Needs Justify";
165 if ($code_types[$brow['code_type']]['fee']) {
166 $charges += $brow['fee'];
167 if ($brow['fee'] == 0 ) $errmsg = "Missing Fee";
168 } else {
169 if ($brow['fee'] != 0) $errmsg = "Misplaced Fee";
172 if (! $charges) $billed = "";
174 <tr bgcolor='<? echo $bgcolor ?>'>
175 <td class="detail">
176 &nbsp;<? echo ($docname == $lastdocname) ? "" : $docname ?>
177 </td>
178 <td class="detail">
179 &nbsp;<? echo substr($row['pc_startTime'], 0, 5) ?>
180 </td>
181 <td class="detail">
182 &nbsp;<? echo $row['fname'] . " " . $row['lname'] ?>
183 </td>
184 <td class="detail" align="right">
185 <? echo $row['pid'] ?>&nbsp;
186 </td>
187 <td class="detail" align="right">
188 <? echo $row['encounter'] ?>&nbsp;
189 </td>
190 <td class="detail" align="right">
191 <? bucks($charges) ?>&nbsp;
192 </td>
193 <td class="detail" align="center">
194 <? echo $billed ?>
195 </td>
196 <td class="detail" align="left">
197 &nbsp;<? echo $errmsg ?>
198 </td>
199 </tr>
201 $lastdocname = $docname;
206 </table>
208 </form>
209 </center>
210 <script>
212 if ($alertmsg) {
213 echo " alert('$alertmsg');\n";
216 </script>
217 </body>
218 </html>