ongoing internationalization of date widget
[openemr.git] / interface / reports / unique_seen_patients_report.php
blob8bca036e81edfbceaf5538c17fa6b5a1795c7e8a
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 use OpenEMR\Core\Header;
28 require_once("../globals.php");
29 require_once("$srcdir/patient.inc");
31 $form_from_date = (!empty($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01');
32 $form_to_date = (!empty($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-12-31');
34 if ($_POST['form_labels']) {
35 header("Pragma: public");
36 header("Expires: 0");
37 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
38 header("Content-Type: application/force-download");
39 header("Content-Disposition: attachment; filename=labels.txt");
40 header("Content-Description: File Transfer");
41 } else {
43 <html>
44 <head>
46 <style type="text/css">
47 /* specifically include & exclude from printing */
48 @media print {
49 #report_parameters {
50 visibility: hidden;
51 display: none;
53 #report_parameters_daterange {
54 visibility: visible;
55 display: inline;
57 #report_results {
58 margin-top: 30px;
62 /* specifically exclude some from the screen */
63 @media screen {
64 #report_parameters_daterange {
65 visibility: hidden;
66 display: none;
69 </style>
70 <title><?php xl('Front Office Receipts', 'e'); ?></title>
72 <?php Header::setupHeader('datetime-picker'); ?>
74 <script language="JavaScript">
76 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
78 $(document).ready(function() {
79 var win = top.printLogSetup ? top : opener.top;
80 win.printLogSetup(document.getElementById('printbutton'));
82 $('.datepicker').datetimepicker({
83 <?php $datetimepicker_timepicker = false; ?>
84 <?php $datetimepicker_showseconds = false; ?>
85 <?php $datetimepicker_formatInput = true; ?>
86 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
87 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
88 });
89 });
91 </script>
93 <style type="text/css">
95 /* specifically include & exclude from printing */
96 @media print {
97 #report_parameters {
98 visibility: hidden;
99 display: none;
101 #report_parameters_daterange {
102 visibility: visible;
103 display: inline;
107 /* specifically exclude some from the screen */
108 @media screen {
109 #report_parameters_daterange {
110 visibility: hidden;
111 display: none;
115 </style>
116 </head>
118 <body class="body_top">
120 <!-- Required for the popup date selectors -->
121 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
123 <span class='title'><?php xl('Report', 'e'); ?> - <?php xl('Unique Seen Patients', 'e'); ?></span>
125 <div id="report_parameters_daterange">
126 <?php echo oeFormatShortDate($form_from_date) ." &nbsp; to &nbsp; ". oeFormatShortDate($form_to_date); ?>
127 </div>
129 <form name='theform' method='post' action='unique_seen_patients_report.php' id='theform'>
131 <div id="report_parameters">
132 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
133 <input type='hidden' name='form_labels' id='form_labels' value=''/>
135 <table>
136 <tr>
137 <td width='410px'>
138 <div style='float:left'>
140 <table class='text'>
141 <tr>
142 <td class='control-label'>
143 <?php xl('Visits From', 'e'); ?>:
144 </td>
145 <td>
146 <input type='text' class='datepicker form-control' name='form_from_date' id="form_from_date" size='10' value='<?php echo oeFormatShortDate($form_from_date); ?>'>
147 </td>
148 <td class='control-label'>
149 <?php xl('To', 'e'); ?>:
150 </td>
151 <td>
152 <input type='text' class='datepicker form-control' name='form_to_date' id="form_to_date" size='10' value='<?php echo oeFormatShortDate($form_to_date); ?>'>
153 </td>
154 </tr>
155 </table>
157 </div>
159 </td>
160 <td align='left' valign='middle' height="100%">
161 <table style='border-left:1px solid; width:100%; height:100%' >
162 <tr>
163 <td>
164 <div class="text-center">
165 <div class="btn-group" role="group">
166 <a href='#' class='btn btn-default btn-save' onclick='$("#form_refresh").attr("value","true"); $("#form_labels").val(""); $("#theform").submit();'>
167 <?php echo xlt('Submit'); ?>
168 </a>
169 <?php if ($_POST['form_refresh']) { ?>
170 <a href='#' class='btn btn-default btn-print' id='printbutton'>
171 <?php echo xlt('Print'); ?>
172 </a>
173 <a href='#' class='btn btn-default btn-transmit' onclick='$("#form_labels").attr("value","true"); $("#theform").submit();'>
174 <?php echo xlt('Labels'); ?>
175 </a>
176 <?php } ?>
177 </div>
178 </div>
179 </td>
180 </tr>
181 </table>
182 </td>
183 </tr>
184 </table>
185 </div> <!-- end of parameters -->
187 <div id="report_results">
188 <table>
190 <thead>
191 <th> <?php xl('Last Visit', 'e'); ?> </th>
192 <th> <?php xl('Patient', 'e'); ?> </th>
193 <th align='right'> <?php xl('Visits', 'e'); ?> </th>
194 <th align='right'> <?php xl('Age', 'e'); ?> </th>
195 <th> <?php xl('Sex', 'e'); ?> </th>
196 <th> <?php xl('Race', 'e'); ?> </th>
197 <th> <?php xl('Primary Insurance', 'e'); ?> </th>
198 <th> <?php xl('Secondary Insurance', 'e'); ?> </th>
199 </thead>
200 <tbody>
201 <?php
202 } // end not generating labels
204 if ($_POST['form_refresh'] || $_POST['form_labels']) {
205 $totalpts = 0;
207 $query = "SELECT " .
208 "p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
209 "p.street, p.city, p.state, p.postal_code, " .
210 "count(e.date) AS ecount, max(e.date) AS edate, " .
211 "i1.date AS idate1, i2.date AS idate2, " .
212 "c1.name AS cname1, c2.name AS cname2 " .
213 "FROM patient_data AS p " .
214 "JOIN form_encounter AS e ON " .
215 "e.pid = p.pid AND " .
216 "e.date >= '$form_from_date 00:00:00' AND " .
217 "e.date <= '$form_to_date 23:59:59' " .
218 "LEFT OUTER JOIN insurance_data AS i1 ON " .
219 "i1.pid = p.pid AND i1.type = 'primary' " .
220 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
221 "c1.id = i1.provider " .
222 "LEFT OUTER JOIN insurance_data AS i2 ON " .
223 "i2.pid = p.pid AND i2.type = 'secondary' " .
224 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
225 "c2.id = i2.provider " .
226 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
227 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
228 $res = sqlStatement($query);
230 $prevpid = 0;
231 while ($row = sqlFetchArray($res)) {
232 if ($row['pid'] == $prevpid) {
233 continue;
236 $prevpid = $row['pid'];
238 $age = '';
239 if ($row['DOB']) {
240 $dob = $row['DOB'];
241 $tdy = $row['edate'];
242 $ageInMonths = (substr($tdy, 0, 4)*12) + substr($tdy, 5, 2) -
243 (substr($dob, 0, 4)*12) - substr($dob, 5, 2);
244 $dayDiff = substr($tdy, 8, 2) - substr($dob, 8, 2);
245 if ($dayDiff < 0) {
246 --$ageInMonths;
249 $age = intval($ageInMonths/12);
252 if ($_POST['form_labels']) {
253 echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
254 $row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
255 $row['postal_code'] . '"' . "\n";
256 } else { // not labels
258 <tr>
259 <td>
260 <?php echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?>
261 </td>
262 <td>
263 <?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
264 </td>
265 <td style="text-align:center">
266 <?php echo $row['ecount'] ?>
267 </td>
268 <td>
269 <?php echo $age ?>
270 </td>
271 <td>
272 <?php echo $row['sex'] ?>
273 </td>
274 <td>
275 <?php echo $row['ethnoracial'] ?>
276 </td>
277 <td>
278 <?php echo $row['cname1'] ?>
279 </td>
280 <td>
281 <?php echo $row['cname2'] ?>
282 </td>
283 </tr>
284 <?php
285 } // end not labels
286 ++$totalpts;
289 if (!$_POST['form_labels']) {
291 <tr class='report_totals'>
292 <td colspan='2'>
293 <?php xl('Total Number of Patients', 'e'); ?>
294 </td>
295 <td style="padding-left: 20px;">
296 <?php echo $totalpts ?>
297 </td>
298 <td colspan='5'>&nbsp;</td>
299 </tr>
301 <?php
302 } // end not labels
303 } // end refresh or labels
305 if (!$_POST['form_labels']) {
307 </tbody>
308 </table>
309 </div>
310 </form>
311 </body>
313 </html>
314 <?php
315 } // end not labels