removal of overlib_mini.js and calendar.js (#640)
[openemr.git] / interface / reports / unique_seen_patients_report.php
blobf534837fd941b59ed071fbafc65432879699dff8
1 <?php
2 /**
3 * This report lists patients that were seen within a given date
4 * range.
6 * Copyright (C) 2006-2015 Rod Roark <rod@sunsetsystems.com>
7 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @package OpenEMR
21 * @author Rod Roark <rod@sunsetsystems.com>
22 * @author Brady Miller <brady.g.miller@gmail.com>
23 * @link http://www.open-emr.org
26 require_once("../globals.php");
27 require_once("$srcdir/patient.inc");
29 $from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
30 $to_date = fixDate($_POST['form_to_date'], date('Y-12-31'));
32 if ($_POST['form_labels']) {
33 header("Pragma: public");
34 header("Expires: 0");
35 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
36 header("Content-Type: application/force-download");
37 header("Content-Disposition: attachment; filename=labels.txt");
38 header("Content-Description: File Transfer");
40 else {
42 <html>
43 <head>
44 <?php html_header_show();?>
45 <style type="text/css">
46 /* specifically include & exclude from printing */
47 @media print {
48 #report_parameters {
49 visibility: hidden;
50 display: none;
52 #report_parameters_daterange {
53 visibility: visible;
54 display: inline;
56 #report_results {
57 margin-top: 30px;
61 /* specifically exclude some from the screen */
62 @media screen {
63 #report_parameters_daterange {
64 visibility: hidden;
65 display: none;
68 </style>
69 <title><?php xl('Front Office Receipts','e'); ?></title>
71 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
72 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
73 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
74 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
76 <script language="JavaScript">
78 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
80 $(document).ready(function() {
81 var win = top.printLogSetup ? top : opener.top;
82 win.printLogSetup(document.getElementById('printbutton'));
84 $('.datepicker').datetimepicker({
85 <?php $datetimepicker_timepicker = false; ?>
86 <?php $datetimepicker_showseconds = false; ?>
87 <?php $datetimepicker_formatInput = false; ?>
88 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
89 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
90 });
91 });
93 </script>
95 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
96 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
98 <style type="text/css">
100 /* specifically include & exclude from printing */
101 @media print {
102 #report_parameters {
103 visibility: hidden;
104 display: none;
106 #report_parameters_daterange {
107 visibility: visible;
108 display: inline;
112 /* specifically exclude some from the screen */
113 @media screen {
114 #report_parameters_daterange {
115 visibility: hidden;
116 display: none;
120 </style>
121 </head>
123 <body class="body_top">
125 <!-- Required for the popup date selectors -->
126 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
128 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Unique Seen Patients','e'); ?></span>
130 <div id="report_parameters_daterange">
131 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
132 </div>
134 <form name='theform' method='post' action='unique_seen_patients_report.php' id='theform'>
136 <div id="report_parameters">
137 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
138 <input type='hidden' name='form_labels' id='form_labels' value=''/>
140 <table>
141 <tr>
142 <td width='410px'>
143 <div style='float:left'>
145 <table class='text'>
146 <tr>
147 <td class='label_custom'>
148 <?php xl('Visits From','e'); ?>:
149 </td>
150 <td>
151 <input type='text' class='datepicker' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
152 title='yyyy-mm-dd'>
153 </td>
154 <td class='label_custom'>
155 <?php xl('To','e'); ?>:
156 </td>
157 <td>
158 <input type='text' class='datepicker' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
159 title='yyyy-mm-dd'>
160 </td>
161 </tr>
162 </table>
164 </div>
166 </td>
167 <td align='left' valign='middle' height="100%">
168 <table style='border-left:1px solid; width:100%; height:100%' >
169 <tr>
170 <td>
171 <div style='margin-left:15px'>
172 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
173 <span>
174 <?php xl('Submit','e'); ?>
175 </span>
176 </a>
178 <?php if ($_POST['form_refresh']) { ?>
179 <a href='#' class='css_button' id='printbutton'>
180 <span>
181 <?php xl('Print','e'); ?>
182 </span>
183 </a>
184 <a href='#' class='css_button' onclick='$("#form_labels").attr("value","true"); $("#theform").submit();'>
185 <span>
186 <?php xl('Labels','e'); ?>
187 </span>
188 </a>
189 <?php } ?>
190 </div>
191 </td>
192 </tr>
193 </table>
194 </td>
195 </tr>
196 </table>
197 </div> <!-- end of parameters -->
199 <div id="report_results">
200 <table>
202 <thead>
203 <th> <?php xl('Last Visit','e'); ?> </th>
204 <th> <?php xl('Patient','e'); ?> </th>
205 <th align='right'> <?php xl('Visits','e'); ?> </th>
206 <th align='right'> <?php xl('Age','e'); ?> </th>
207 <th> <?php xl('Sex','e'); ?> </th>
208 <th> <?php xl('Race','e'); ?> </th>
209 <th> <?php xl('Primary Insurance','e'); ?> </th>
210 <th> <?php xl('Secondary Insurance','e'); ?> </th>
211 </thead>
212 <tbody>
213 <?php
214 } // end not generating labels
216 if ($_POST['form_refresh'] || $_POST['form_labels']) {
217 $totalpts = 0;
219 $query = "SELECT " .
220 "p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
221 "p.street, p.city, p.state, p.postal_code, " .
222 "count(e.date) AS ecount, max(e.date) AS edate, " .
223 "i1.date AS idate1, i2.date AS idate2, " .
224 "c1.name AS cname1, c2.name AS cname2 " .
225 "FROM patient_data AS p " .
226 "JOIN form_encounter AS e ON " .
227 "e.pid = p.pid AND " .
228 "e.date >= '$from_date 00:00:00' AND " .
229 "e.date <= '$to_date 23:59:59' " .
230 "LEFT OUTER JOIN insurance_data AS i1 ON " .
231 "i1.pid = p.pid AND i1.type = 'primary' " .
232 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
233 "c1.id = i1.provider " .
234 "LEFT OUTER JOIN insurance_data AS i2 ON " .
235 "i2.pid = p.pid AND i2.type = 'secondary' " .
236 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
237 "c2.id = i2.provider " .
238 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
239 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
240 $res = sqlStatement($query);
242 $prevpid = 0;
243 while ($row = sqlFetchArray($res)) {
244 if ($row['pid'] == $prevpid) continue;
245 $prevpid = $row['pid'];
247 $age = '';
248 if ($row['DOB']) {
249 $dob = $row['DOB'];
250 $tdy = $row['edate'];
251 $ageInMonths = (substr($tdy,0,4)*12) + substr($tdy,5,2) -
252 (substr($dob,0,4)*12) - substr($dob,5,2);
253 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
254 if ($dayDiff < 0) --$ageInMonths;
255 $age = intval($ageInMonths/12);
258 if ($_POST['form_labels']) {
259 echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
260 $row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
261 $row['postal_code'] . '"' . "\n";
263 else { // not labels
265 <tr>
266 <td>
267 <?php echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?>
268 </td>
269 <td>
270 <?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
271 </td>
272 <td style="text-align:center">
273 <?php echo $row['ecount'] ?>
274 </td>
275 <td>
276 <?php echo $age ?>
277 </td>
278 <td>
279 <?php echo $row['sex'] ?>
280 </td>
281 <td>
282 <?php echo $row['ethnoracial'] ?>
283 </td>
284 <td>
285 <?php echo $row['cname1'] ?>
286 </td>
287 <td>
288 <?php echo $row['cname2'] ?>
289 </td>
290 </tr>
291 <?php
292 } // end not labels
293 ++$totalpts;
296 if (!$_POST['form_labels']) {
298 <tr class='report_totals'>
299 <td colspan='2'>
300 <?php xl('Total Number of Patients','e'); ?>
301 </td>
302 <td style="padding-left: 20px;">
303 <?php echo $totalpts ?>
304 </td>
305 <td colspan='5'>&nbsp;</td>
306 </tr>
308 <?php
309 } // end not labels
310 } // end refresh or labels
312 if (!$_POST['form_labels']) {
314 </tbody>
315 </table>
316 </div>
317 </form>
318 </body>
320 </html>
321 <?php
322 } // end not labels