Fix to clear LBF form data that is not returned by the form but is defined in its...
[openemr.git] / interface / reports / unique_seen_patients_report.php
blob3ea8eb7bc33d009e805f1191df2957222f47663e
1 <?php
2 // Copyright (C) 2006-2010 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 lists patients that were seen within a given date
10 // range.
12 require_once("../globals.php");
13 require_once("$srcdir/patient.inc");
14 require_once("$srcdir/formatting.inc.php");
16 $from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
17 $to_date = fixDate($_POST['form_to_date'], date('Y-12-31'));
19 if ($_POST['form_labels']) {
20 header("Pragma: public");
21 header("Expires: 0");
22 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
23 header("Content-Type: application/force-download");
24 header("Content-Disposition: attachment; filename=labels.txt");
25 header("Content-Description: File Transfer");
27 else {
29 <html>
30 <head>
31 <?php html_header_show();?>
32 <style type="text/css">
33 /* specifically include & exclude from printing */
34 @media print {
35 #report_parameters {
36 visibility: hidden;
37 display: none;
39 #report_parameters_daterange {
40 visibility: visible;
41 display: inline;
43 #report_results {
44 margin-top: 30px;
48 /* specifically exclude some from the screen */
49 @media screen {
50 #report_parameters_daterange {
51 visibility: hidden;
52 display: none;
55 </style>
56 <title><?php xl('Front Office Receipts','e'); ?></title>
58 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
59 <script type="text/javascript" src="../../library/textformat.js"></script>
60 <script type="text/javascript" src="../../library/dialog.js"></script>
61 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
63 <script language="JavaScript">
64 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
65 </script>
67 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
68 <style type="text/css">
70 /* specifically include & exclude from printing */
71 @media print {
72 #report_parameters {
73 visibility: hidden;
74 display: none;
76 #report_parameters_daterange {
77 visibility: visible;
78 display: inline;
82 /* specifically exclude some from the screen */
83 @media screen {
84 #report_parameters_daterange {
85 visibility: hidden;
86 display: none;
90 </style>
91 </head>
93 <body class="body_top">
95 <!-- Required for the popup date selectors -->
96 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
98 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Unique Seen Patients','e'); ?></span>
100 <div id="report_parameters_daterange">
101 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
102 </div>
104 <form name='theform' method='post' action='unique_seen_patients_report.php' id='theform'>
106 <div id="report_parameters">
107 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
108 <input type='hidden' name='form_labels' id='form_labels' value=''/>
110 <table>
111 <tr>
112 <td width='410px'>
113 <div style='float:left'>
115 <table class='text'>
116 <tr>
117 <td class='label'>
118 <?php xl('Visits From','e'); ?>:
119 </td>
120 <td>
121 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
122 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
123 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
124 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
125 title='<?php xl('Click here to choose a date','e'); ?>'>
126 </td>
127 <td class='label'>
128 <?php xl('To','e'); ?>:
129 </td>
130 <td>
131 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
132 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
133 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
134 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
135 title='<?php xl('Click here to choose a date','e'); ?>'>
136 </td>
137 </tr>
138 </table>
140 </div>
142 </td>
143 <td align='left' valign='middle' height="100%">
144 <table style='border-left:1px solid; width:100%; height:100%' >
145 <tr>
146 <td>
147 <div style='margin-left:15px'>
148 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
149 <span>
150 <?php xl('Submit','e'); ?>
151 </span>
152 </a>
154 <?php if ($_POST['form_refresh']) { ?>
155 <a href='#' class='css_button' onclick='window.print()'>
156 <span>
157 <?php xl('Print','e'); ?>
158 </span>
159 </a>
160 <a href='#' class='css_button' onclick='$("#form_labels").attr("value","true"); $("#theform").submit();'>
161 <span>
162 <?php xl('Labels','e'); ?>
163 </span>
164 </a>
165 <?php } ?>
166 </div>
167 </td>
168 </tr>
169 </table>
170 </td>
171 </tr>
172 </table>
173 </div> <!-- end of parameters -->
175 <div id="report_results">
176 <table>
178 <thead>
179 <th> <?php xl('Last Visit','e'); ?> </th>
180 <th> <?php xl('Patient','e'); ?> </th>
181 <th align='right'> <?php xl('Visits','e'); ?> </th>
182 <th align='right'> <?php xl('Age','e'); ?> </th>
183 <th> <?php xl('Sex','e'); ?> </th>
184 <th> <?php xl('Race','e'); ?> </th>
185 <th> <?php xl('Primary Insurance','e'); ?> </th>
186 <th> <?php xl('Secondary Insurance','e'); ?> </th>
187 </thead>
188 <tbody>
189 <?php
190 } // end not generating labels
192 if ($_POST['form_refresh'] || $_POST['form_labels']) {
193 $totalpts = 0;
195 $query = "SELECT " .
196 "p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
197 "p.street, p.city, p.state, p.postal_code, " .
198 "count(e.date) AS ecount, max(e.date) AS edate, " .
199 "i1.date AS idate1, i2.date AS idate2, " .
200 "c1.name AS cname1, c2.name AS cname2 " .
201 "FROM patient_data AS p " .
202 "JOIN form_encounter AS e ON " .
203 "e.pid = p.pid AND " .
204 "e.date >= '$from_date 00:00:00' AND " .
205 "e.date <= '$to_date 23:59:59' " .
206 "LEFT OUTER JOIN insurance_data AS i1 ON " .
207 "i1.pid = p.pid AND i1.type = 'primary' " .
208 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
209 "c1.id = i1.provider " .
210 "LEFT OUTER JOIN insurance_data AS i2 ON " .
211 "i2.pid = p.pid AND i2.type = 'secondary' " .
212 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
213 "c2.id = i2.provider " .
214 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
215 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
216 $res = sqlStatement($query);
218 $prevpid = 0;
219 while ($row = sqlFetchArray($res)) {
220 if ($row['pid'] == $prevpid) continue;
221 $prevpid = $row['pid'];
223 $age = '';
224 if ($row['DOB']) {
225 $dob = $row['DOB'];
226 $tdy = $row['edate'];
227 $ageInMonths = (substr($tdy,0,4)*12) + substr($tdy,5,2) -
228 (substr($dob,0,4)*12) - substr($dob,5,2);
229 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
230 if ($dayDiff < 0) --$ageInMonths;
231 $age = intval($ageInMonths/12);
234 if ($_POST['form_labels']) {
235 echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
236 $row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
237 $row['postal_code'] . '"' . "\n";
239 else { // not labels
241 <tr>
242 <td>
243 <?php echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?>
244 </td>
245 <td>
246 <?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
247 </td>
248 <td style="text-align:center">
249 <?php echo $row['ecount'] ?>
250 </td>
251 <td>
252 <?php echo $age ?>
253 </td>
254 <td>
255 <?php echo $row['sex'] ?>
256 </td>
257 <td>
258 <?php echo $row['ethnoracial'] ?>
259 </td>
260 <td>
261 <?php echo $row['cname1'] ?>
262 </td>
263 <td>
264 <?php echo $row['cname2'] ?>
265 </td>
266 </tr>
267 <?php
268 } // end not labels
269 ++$totalpts;
272 if (!$_POST['form_labels']) {
274 <tr class='report_totals'>
275 <td colspan='2'>
276 <?php xl('Total Number of Patients','e'); ?>
277 </td>
278 <td style="padding-left: 20px;">
279 <?php echo $totalpts ?>
280 </td>
281 <td colspan='5'>&nbsp;</td>
282 </tr>
284 <?php
285 } // end not labels
286 } // end refresh or labels
288 if (!$_POST['form_labels']) {
290 </tbody>
291 </table>
292 </div>
293 </form>
294 </body>
296 <!-- stuff for the popup calendar -->
297 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
298 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
299 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
300 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
301 <script language="Javascript">
302 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
303 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
304 </script>
305 </html>
306 <?php
307 } // end not labels