ongoing internationalization of date widget
[openemr.git] / interface / reports / patient_list.php
blobca3f8d645bef33912b70c26b57efcaae8d83e78c
1 <?php
2 /**
3 * This report lists patients that were seen within a given date
4 * range, or all patients if no date range is entered.
6 * Copyright (C) 2006-2016 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 3
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");
30 require_once("$srcdir/options.inc.php");
32 // Prepare a string for CSV export.
33 function qescape($str)
35 $str = str_replace('\\', '\\\\', $str);
36 return str_replace('"', '\\"', $str);
39 $from_date = DateToYYYYMMDD($_POST['form_from_date']);
40 $to_date = DateToYYYYMMDD($_POST['form_to_date']);
41 if (empty($to_date) && !empty($from_date)) {
42 $to_date = date('Y-12-31');
45 if (empty($from_date) && !empty($to_date)) {
46 $from_date = date('Y-01-01');
49 $form_provider = empty($_POST['form_provider']) ? 0 : intval($_POST['form_provider']);
51 // In the case of CSV export only, a download will be forced.
52 if ($_POST['form_csvexport']) {
53 header("Pragma: public");
54 header("Expires: 0");
55 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
56 header("Content-Type: application/force-download");
57 header("Content-Disposition: attachment; filename=patient_list.csv");
58 header("Content-Description: File Transfer");
59 } else {
61 <html>
62 <head>
64 <title><?php xl('Patient List', 'e'); ?></title>
66 <?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>
67 <script language="JavaScript">
68 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
70 $(document).ready(function() {
71 oeFixedHeaderSetup(document.getElementById('mymaintable'));
72 top.printLogSetup(document.getElementById('printbutton'));
74 $('.datepicker').datetimepicker({
75 <?php $datetimepicker_timepicker = false; ?>
76 <?php $datetimepicker_showseconds = false; ?>
77 <?php $datetimepicker_formatInput = true; ?>
78 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
79 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
80 });
82 });
84 </script>
86 <style type="text/css">
88 /* specifically include & exclude from printing */
89 @media print {
90 #report_parameters {
91 visibility: hidden;
92 display: none;
94 #report_parameters_daterange {
95 visibility: visible;
96 display: inline;
97 margin-bottom: 10px;
99 #report_results table {
100 margin-top: 0px;
104 /* specifically exclude some from the screen */
105 @media screen {
106 #report_parameters_daterange {
107 visibility: hidden;
108 display: none;
110 #report_results {
111 width: 100%;
115 </style>
117 </head>
119 <body class="body_top">
121 <!-- Required for the popup date selectors -->
122 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
124 <span class='title'><?php xl('Report', 'e'); ?> - <?php xl('Patient List', 'e'); ?></span>
126 <div id="report_parameters_daterange">
127 <?php if (!(empty($to_date) && empty($from_date))) { ?>
128 <?php echo date("d F Y", strtotime($from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($to_date)); ?>
129 <?php } ?>
130 </div>
132 <form name='theform' id='theform' method='post' action='patient_list.php' onsubmit='return top.restoreSession()'>
134 <div id="report_parameters">
136 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
137 <input type='hidden' name='form_csvexport' id='form_csvexport' value=''/>
139 <table>
140 <tr>
141 <td width='60%'>
142 <div style='float:left'>
144 <table class='text'>
145 <tr>
146 <td class='control-label'>
147 <?php xl('Provider', 'e'); ?>:
148 </td>
149 <td>
150 <?php
151 generate_form_field(array('data_type' => 10, 'field_id' => 'provider',
152 'empty_title' => '-- All --'), $_POST['form_provider']);
154 </td>
155 <td class='control-label'>
156 <?php xl('Visits From', 'e'); ?>:
157 </td>
158 <td>
159 <input class='datepicker form-control' type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo oeFormatShortDate($from_date) ?>'>
160 </td>
161 <td class='control-label'>
162 <?php xl('To', 'e'); ?>:
163 </td>
164 <td>
165 <input class='datepicker form-control' type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo oeFormatShortDate($to_date) ?>'>
166 </td>
167 </tr>
168 </table>
170 </div>
172 </td>
173 <td align='left' valign='middle' height="100%">
174 <table style='border-left:1px solid; width:100%; height:100%' >
175 <tr>
176 <td>
177 <div class="text-center">
178 <div class="btn-group" role="group">
179 <a href='#' class='btn btn-default btn-save' onclick='$("#form_csvexport").val(""); $("#form_refresh").attr("value","true"); $("#theform").submit();'>
180 <?php echo xlt('Submit'); ?>
181 </a>
182 <a href='#' class='btn btn-default btn-transmit' onclick='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
183 <?php echo xlt('Export to CSV'); ?>
184 </a>
185 <?php if ($_POST['form_refresh']) { ?>
186 <a href='#' id='printbutton' class='btn btn-default btn-print'>
187 <?php xl('Print', 'e'); ?>
188 </a>
189 <?php } ?>
190 </div>
191 </div>
192 </td>
193 </tr>
194 </table>
195 </td>
196 </tr>
197 </table>
198 </div> <!-- end of parameters -->
200 <?php
201 } // end not form_csvexport
203 if ($_POST['form_refresh'] || $_POST['form_csvexport']) {
204 if ($_POST['form_csvexport']) {
205 // CSV headers:
206 echo '"' . xl('Last Visit') . '",';
207 echo '"' . xl('First') . '",';
208 echo '"' . xl('Last') . '",';
209 echo '"' . xl('Middle') . '",';
210 echo '"' . xl('ID') . '",';
211 echo '"' . xl('Street') . '",';
212 echo '"' . xl('City') . '",';
213 echo '"' . xl('State') . '",';
214 echo '"' . xl('Zip') . '",';
215 echo '"' . xl('Home Phone') . '",';
216 echo '"' . xl('Work Phone') . '"' . "\n";
217 } else {
220 <div id="report_results">
221 <table id='mymaintable'>
222 <thead>
223 <th> <?php xl('Last Visit', 'e'); ?> </th>
224 <th> <?php xl('Patient', 'e'); ?> </th>
225 <th> <?php xl('ID', 'e'); ?> </th>
226 <th> <?php xl('Street', 'e'); ?> </th>
227 <th> <?php xl('City', 'e'); ?> </th>
228 <th> <?php xl('State', 'e'); ?> </th>
229 <th> <?php xl('Zip', 'e'); ?> </th>
230 <th> <?php xl('Home Phone', 'e'); ?> </th>
231 <th> <?php xl('Work Phone', 'e'); ?> </th>
232 </thead>
233 <tbody>
234 <?php
235 } // end not export
236 $totalpts = 0;
237 $query = "SELECT " .
238 "p.fname, p.mname, p.lname, p.street, p.city, p.state, " .
239 "p.postal_code, p.phone_home, p.phone_biz, p.pid, p.pubpid, " .
240 "count(e.date) AS ecount, max(e.date) AS edate, " .
241 "i1.date AS idate1, i2.date AS idate2, " .
242 "c1.name AS cname1, c2.name AS cname2 " .
243 "FROM patient_data AS p ";
244 if (!empty($from_date)) {
245 $query .= "JOIN form_encounter AS e ON " .
246 "e.pid = p.pid AND " .
247 "e.date >= '$from_date 00:00:00' AND " .
248 "e.date <= '$to_date 23:59:59' ";
249 if ($form_provider) {
250 $query .= "AND e.provider_id = '$form_provider' ";
252 } else {
253 if ($form_provider) {
254 $query .= "JOIN form_encounter AS e ON " .
255 "e.pid = p.pid AND e.provider_id = '$form_provider' ";
256 } else {
257 $query .= "LEFT OUTER JOIN form_encounter AS e ON " .
258 "e.pid = p.pid ";
262 $query .=
263 "LEFT OUTER JOIN insurance_data AS i1 ON " .
264 "i1.pid = p.pid AND i1.type = 'primary' " .
265 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
266 "c1.id = i1.provider " .
267 "LEFT OUTER JOIN insurance_data AS i2 ON " .
268 "i2.pid = p.pid AND i2.type = 'secondary' " .
269 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
270 "c2.id = i2.provider " .
271 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
272 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
273 $res = sqlStatement($query);
275 $prevpid = 0;
276 while ($row = sqlFetchArray($res)) {
277 if ($row['pid'] == $prevpid) {
278 continue;
281 $prevpid = $row['pid'];
282 $age = '';
283 if ($row['DOB']) {
284 $dob = $row['DOB'];
285 $tdy = $row['edate'] ? $row['edate'] : date('Y-m-d');
286 $ageInMonths = (substr($tdy, 0, 4)*12) + substr($tdy, 5, 2) -
287 (substr($dob, 0, 4)*12) - substr($dob, 5, 2);
288 $dayDiff = substr($tdy, 8, 2) - substr($dob, 8, 2);
289 if ($dayDiff < 0) {
290 --$ageInMonths;
293 $age = intval($ageInMonths/12);
296 if ($_POST['form_csvexport']) {
297 echo '"' . oeFormatShortDate(substr($row['edate'], 0, 10)) . '",';
298 echo '"' . qescape($row['lname']) . '",';
299 echo '"' . qescape($row['fname']) . '",';
300 echo '"' . qescape($row['mname']) . '",';
301 echo '"' . qescape($row['pubpid']) . '",';
302 echo '"' . qescape($row['street']) . '",';
303 echo '"' . qescape($row['city']) . '",';
304 echo '"' . qescape($row['state']) . '",';
305 echo '"' . qescape($row['postal_code']) . '",';
306 echo '"' . qescape($row['phone_home']) . '",';
307 echo '"' . qescape($row['phone_biz']) . '"' . "\n";
308 } else {
310 <tr>
311 <td>
312 <?php echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?>
313 </td>
314 <td>
315 <?php echo htmlspecialchars($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']) ?>
316 </td>
317 <td>
318 <?php echo $row['pubpid'] ?>
319 </td>
320 <td>
321 <?php echo $row['street'] ?>
322 </td>
323 <td>
324 <?php echo $row['city'] ?>
325 </td>
326 <td>
327 <?php echo $row['state'] ?>
328 </td>
329 <td>
330 <?php echo $row['postal_code'] ?>
331 </td>
332 <td>
333 <?php echo $row['phone_home'] ?>
334 </td>
335 <td>
336 <?php echo $row['phone_biz'] ?>
337 </td>
338 </tr>
339 <?php
340 } // end not export
341 ++$totalpts;
342 } // end while
343 if (!$_POST['form_csvexport']) {
346 <tr class="report_totals">
347 <td colspan='9'>
348 <?php xl('Total Number of Patients', 'e'); ?>
350 <?php echo $totalpts ?>
351 </td>
352 </tr>
354 </tbody>
355 </table>
356 </div> <!-- end of results -->
357 <?php
358 } // end not export
359 } // end if refresh or export
361 if (!$_POST['form_refresh'] && !$_POST['form_csvexport']) {
363 <div class='text'>
364 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e'); ?>
365 </div>
366 <?php
369 if (!$_POST['form_csvexport']) {
372 </form>
373 </body>
375 </html>
376 <?php
377 } // end not export