Removes frames from login gui and condense login gui into a single file.
[openemr.git] / interface / reports / unique_seen_patients_report.php
blobb84f0861db268ca316ed59ddef31d1a10778c00a
1 <?php
2 // Copyright (C) 2006-2015 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">
65 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
67 $(document).ready(function() {
68 var win = top.printLogSetup ? top : opener.top;
69 win.printLogSetup(document.getElementById('printbutton'));
70 });
72 </script>
74 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
75 <style type="text/css">
77 /* specifically include & exclude from printing */
78 @media print {
79 #report_parameters {
80 visibility: hidden;
81 display: none;
83 #report_parameters_daterange {
84 visibility: visible;
85 display: inline;
89 /* specifically exclude some from the screen */
90 @media screen {
91 #report_parameters_daterange {
92 visibility: hidden;
93 display: none;
97 </style>
98 </head>
100 <body class="body_top">
102 <!-- Required for the popup date selectors -->
103 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
105 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Unique Seen Patients','e'); ?></span>
107 <div id="report_parameters_daterange">
108 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
109 </div>
111 <form name='theform' method='post' action='unique_seen_patients_report.php' id='theform'>
113 <div id="report_parameters">
114 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
115 <input type='hidden' name='form_labels' id='form_labels' value=''/>
117 <table>
118 <tr>
119 <td width='410px'>
120 <div style='float:left'>
122 <table class='text'>
123 <tr>
124 <td class='label'>
125 <?php xl('Visits From','e'); ?>:
126 </td>
127 <td>
128 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
129 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
130 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
131 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
132 title='<?php xl('Click here to choose a date','e'); ?>'>
133 </td>
134 <td class='label'>
135 <?php xl('To','e'); ?>:
136 </td>
137 <td>
138 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
139 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
140 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
141 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
142 title='<?php xl('Click here to choose a date','e'); ?>'>
143 </td>
144 </tr>
145 </table>
147 </div>
149 </td>
150 <td align='left' valign='middle' height="100%">
151 <table style='border-left:1px solid; width:100%; height:100%' >
152 <tr>
153 <td>
154 <div style='margin-left:15px'>
155 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
156 <span>
157 <?php xl('Submit','e'); ?>
158 </span>
159 </a>
161 <?php if ($_POST['form_refresh']) { ?>
162 <a href='#' class='css_button' id='printbutton'>
163 <span>
164 <?php xl('Print','e'); ?>
165 </span>
166 </a>
167 <a href='#' class='css_button' onclick='$("#form_labels").attr("value","true"); $("#theform").submit();'>
168 <span>
169 <?php xl('Labels','e'); ?>
170 </span>
171 </a>
172 <?php } ?>
173 </div>
174 </td>
175 </tr>
176 </table>
177 </td>
178 </tr>
179 </table>
180 </div> <!-- end of parameters -->
182 <div id="report_results">
183 <table>
185 <thead>
186 <th> <?php xl('Last Visit','e'); ?> </th>
187 <th> <?php xl('Patient','e'); ?> </th>
188 <th align='right'> <?php xl('Visits','e'); ?> </th>
189 <th align='right'> <?php xl('Age','e'); ?> </th>
190 <th> <?php xl('Sex','e'); ?> </th>
191 <th> <?php xl('Race','e'); ?> </th>
192 <th> <?php xl('Primary Insurance','e'); ?> </th>
193 <th> <?php xl('Secondary Insurance','e'); ?> </th>
194 </thead>
195 <tbody>
196 <?php
197 } // end not generating labels
199 if ($_POST['form_refresh'] || $_POST['form_labels']) {
200 $totalpts = 0;
202 $query = "SELECT " .
203 "p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
204 "p.street, p.city, p.state, p.postal_code, " .
205 "count(e.date) AS ecount, max(e.date) AS edate, " .
206 "i1.date AS idate1, i2.date AS idate2, " .
207 "c1.name AS cname1, c2.name AS cname2 " .
208 "FROM patient_data AS p " .
209 "JOIN form_encounter AS e ON " .
210 "e.pid = p.pid AND " .
211 "e.date >= '$from_date 00:00:00' AND " .
212 "e.date <= '$to_date 23:59:59' " .
213 "LEFT OUTER JOIN insurance_data AS i1 ON " .
214 "i1.pid = p.pid AND i1.type = 'primary' " .
215 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
216 "c1.id = i1.provider " .
217 "LEFT OUTER JOIN insurance_data AS i2 ON " .
218 "i2.pid = p.pid AND i2.type = 'secondary' " .
219 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
220 "c2.id = i2.provider " .
221 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
222 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
223 $res = sqlStatement($query);
225 $prevpid = 0;
226 while ($row = sqlFetchArray($res)) {
227 if ($row['pid'] == $prevpid) continue;
228 $prevpid = $row['pid'];
230 $age = '';
231 if ($row['DOB']) {
232 $dob = $row['DOB'];
233 $tdy = $row['edate'];
234 $ageInMonths = (substr($tdy,0,4)*12) + substr($tdy,5,2) -
235 (substr($dob,0,4)*12) - substr($dob,5,2);
236 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
237 if ($dayDiff < 0) --$ageInMonths;
238 $age = intval($ageInMonths/12);
241 if ($_POST['form_labels']) {
242 echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
243 $row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
244 $row['postal_code'] . '"' . "\n";
246 else { // not labels
248 <tr>
249 <td>
250 <?php echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?>
251 </td>
252 <td>
253 <?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
254 </td>
255 <td style="text-align:center">
256 <?php echo $row['ecount'] ?>
257 </td>
258 <td>
259 <?php echo $age ?>
260 </td>
261 <td>
262 <?php echo $row['sex'] ?>
263 </td>
264 <td>
265 <?php echo $row['ethnoracial'] ?>
266 </td>
267 <td>
268 <?php echo $row['cname1'] ?>
269 </td>
270 <td>
271 <?php echo $row['cname2'] ?>
272 </td>
273 </tr>
274 <?php
275 } // end not labels
276 ++$totalpts;
279 if (!$_POST['form_labels']) {
281 <tr class='report_totals'>
282 <td colspan='2'>
283 <?php xl('Total Number of Patients','e'); ?>
284 </td>
285 <td style="padding-left: 20px;">
286 <?php echo $totalpts ?>
287 </td>
288 <td colspan='5'>&nbsp;</td>
289 </tr>
291 <?php
292 } // end not labels
293 } // end refresh or labels
295 if (!$_POST['form_labels']) {
297 </tbody>
298 </table>
299 </div>
300 </form>
301 </body>
303 <!-- stuff for the popup calendar -->
304 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
305 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
306 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
307 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
308 <script language="Javascript">
309 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
310 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
311 </script>
312 </html>
313 <?php
314 } // end not labels