new datepicker in encounter
[openemr.git] / interface / reports / patient_list.php
blobcbc25fcf2314a6a0be8178bcbe6c4f17a1b7a3fd
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
27 require_once("../globals.php");
28 require_once("$srcdir/patient.inc");
29 require_once("$srcdir/formatting.inc.php");
30 require_once("$srcdir/options.inc.php");
32 // Prepare a string for CSV export.
33 function qescape($str) {
34 $str = str_replace('\\', '\\\\', $str);
35 return str_replace('"', '\\"', $str);
38 // $from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
39 // $to_date = fixDate($_POST['form_to_date'], date('Y-12-31'));
40 $from_date = fixDate($_POST['form_from_date'], '');
41 $to_date = fixDate($_POST['form_to_date'], '');
42 if (empty($to_date) && !empty($from_date)) $to_date = date('Y-12-31');
43 if (empty($from_date) && !empty($to_date)) $from_date = date('Y-01-01');
45 $form_provider = empty($_POST['form_provider']) ? 0 : intval($_POST['form_provider']);
47 // In the case of CSV export only, a download will be forced.
48 if ($_POST['form_csvexport']) {
49 header("Pragma: public");
50 header("Expires: 0");
51 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
52 header("Content-Type: application/force-download");
53 header("Content-Disposition: attachment; filename=patient_list.csv");
54 header("Content-Description: File Transfer");
56 else {
58 <html>
59 <head>
60 <?php html_header_show();?>
61 <title><?php xl('Patient List','e'); ?></title>
62 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
63 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
64 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
65 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
66 <script type="text/javascript" src="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script>
67 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
69 <script language="JavaScript">
70 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
72 $(document).ready(function() {
73 oeFixedHeaderSetup(document.getElementById('mymaintable'));
74 top.printLogSetup(document.getElementById('printbutton'));
76 $('.datepicker').datetimepicker({
77 <?php $datetimepicker_timepicker = false; ?>
78 <?php $datetimepicker_formatInput = false; ?>
79 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
80 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
81 });
83 });
85 </script>
87 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
88 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
90 <style type="text/css">
92 /* specifically include & exclude from printing */
93 @media print {
94 #report_parameters {
95 visibility: hidden;
96 display: none;
98 #report_parameters_daterange {
99 visibility: visible;
100 display: inline;
101 margin-bottom: 10px;
103 #report_results table {
104 margin-top: 0px;
108 /* specifically exclude some from the screen */
109 @media screen {
110 #report_parameters_daterange {
111 visibility: hidden;
112 display: none;
114 #report_results {
115 width: 100%;
119 </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('Patient List','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' id='theform' method='post' action='patient_list.php'>
136 <div id="report_parameters">
138 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
139 <input type='hidden' name='form_csvexport' id='form_csvexport' value=''/>
141 <table>
142 <tr>
143 <td width='60%'>
144 <div style='float:left'>
146 <table class='text'>
147 <tr>
148 <td class='label'>
149 <?php xl('Provider','e'); ?>:
150 </td>
151 <td>
152 <?php
153 generate_form_field(array('data_type' => 10, 'field_id' => 'provider',
154 'empty_title' => '-- All --'), $_POST['form_provider']);
156 </td>
157 <td class='label'>
158 <?php xl('Visits From','e'); ?>:
159 </td>
160 <td>
161 <input class='datepicker' type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
162 title='yyyy-mm-dd'>
163 </td>
164 <td class='label'>
165 <?php xl('To','e'); ?>:
166 </td>
167 <td>
168 <input class='datepicker' type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
169 title='yyyy-mm-dd'>
170 </td>
171 </tr>
172 </table>
174 </div>
176 </td>
177 <td align='left' valign='middle' height="100%">
178 <table style='border-left:1px solid; width:100%; height:100%' >
179 <tr>
180 <td>
181 <div style='margin-left:15px'>
182 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
183 <span>
184 <?php xl('Submit','e'); ?>
185 </span>
186 </a>
187 <a href='#' class='css_button' onclick='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
188 <span>
189 <?php xl('Export to CSV','e'); ?>
190 </span>
191 </a>
192 <?php if ($_POST['form_refresh']) { ?>
193 <a href='#' id='printbutton' class='css_button'>
194 <span>
195 <?php xl('Print','e'); ?>
196 </span>
197 </a>
198 <?php } ?>
199 </div>
200 </td>
201 </tr>
202 </table>
203 </td>
204 </tr>
205 </table>
206 </div> <!-- end of parameters -->
208 <?php
209 } // end not form_csvexport
211 if ($_POST['form_refresh'] || $_POST['form_csvexport']) {
212 if ($_POST['form_csvexport']) {
213 // CSV headers:
214 echo '"' . xl('Last Visit') . '",';
215 echo '"' . xl('First') . '",';
216 echo '"' . xl('Last') . '",';
217 echo '"' . xl('Middle') . '",';
218 echo '"' . xl('ID') . '",';
219 echo '"' . xl('Street') . '",';
220 echo '"' . xl('City') . '",';
221 echo '"' . xl('State') . '",';
222 echo '"' . xl('Zip') . '",';
223 echo '"' . xl('Home Phone') . '",';
224 echo '"' . xl('Work Phone') . '"' . "\n";
226 else {
229 <div id="report_results">
230 <table id='mymaintable'>
231 <thead>
232 <th> <?php xl('Last Visit','e'); ?> </th>
233 <th> <?php xl('Patient','e'); ?> </th>
234 <th> <?php xl('ID','e'); ?> </th>
235 <th> <?php xl('Street','e'); ?> </th>
236 <th> <?php xl('City','e'); ?> </th>
237 <th> <?php xl('State','e'); ?> </th>
238 <th> <?php xl('Zip','e'); ?> </th>
239 <th> <?php xl('Home Phone','e'); ?> </th>
240 <th> <?php xl('Work Phone','e'); ?> </th>
241 </thead>
242 <tbody>
243 <?php
244 } // end not export
245 $totalpts = 0;
246 $query = "SELECT " .
247 "p.fname, p.mname, p.lname, p.street, p.city, p.state, " .
248 "p.postal_code, p.phone_home, p.phone_biz, p.pid, p.pubpid, " .
249 "count(e.date) AS ecount, max(e.date) AS edate, " .
250 "i1.date AS idate1, i2.date AS idate2, " .
251 "c1.name AS cname1, c2.name AS cname2 " .
252 "FROM patient_data AS p ";
253 if (!empty($from_date)) {
254 $query .= "JOIN form_encounter AS e ON " .
255 "e.pid = p.pid AND " .
256 "e.date >= '$from_date 00:00:00' AND " .
257 "e.date <= '$to_date 23:59:59' ";
258 if ($form_provider) {
259 $query .= "AND e.provider_id = '$form_provider' ";
262 else {
263 if ($form_provider) {
264 $query .= "JOIN form_encounter AS e ON " .
265 "e.pid = p.pid AND e.provider_id = '$form_provider' ";
267 else {
268 $query .= "LEFT OUTER JOIN form_encounter AS e ON " .
269 "e.pid = p.pid ";
272 $query .=
273 "LEFT OUTER JOIN insurance_data AS i1 ON " .
274 "i1.pid = p.pid AND i1.type = 'primary' " .
275 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
276 "c1.id = i1.provider " .
277 "LEFT OUTER JOIN insurance_data AS i2 ON " .
278 "i2.pid = p.pid AND i2.type = 'secondary' " .
279 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
280 "c2.id = i2.provider " .
281 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
282 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
283 $res = sqlStatement($query);
285 $prevpid = 0;
286 while ($row = sqlFetchArray($res)) {
287 if ($row['pid'] == $prevpid) continue;
288 $prevpid = $row['pid'];
289 $age = '';
290 if ($row['DOB']) {
291 $dob = $row['DOB'];
292 $tdy = $row['edate'] ? $row['edate'] : date('Y-m-d');
293 $ageInMonths = (substr($tdy,0,4)*12) + substr($tdy,5,2) -
294 (substr($dob,0,4)*12) - substr($dob,5,2);
295 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
296 if ($dayDiff < 0) --$ageInMonths;
297 $age = intval($ageInMonths/12);
300 if ($_POST['form_csvexport']) {
301 echo '"' . oeFormatShortDate(substr($row['edate'], 0, 10)) . '",';
302 echo '"' . qescape($row['lname']) . '",';
303 echo '"' . qescape($row['fname']) . '",';
304 echo '"' . qescape($row['mname']) . '",';
305 echo '"' . qescape($row['pubpid']) . '",';
306 echo '"' . qescape($row['street']) . '",';
307 echo '"' . qescape($row['city']) . '",';
308 echo '"' . qescape($row['state']) . '",';
309 echo '"' . qescape($row['postal_code']) . '",';
310 echo '"' . qescape($row['phone_home']) . '",';
311 echo '"' . qescape($row['phone_biz']) . '"' . "\n";
313 else {
315 <tr>
316 <td>
317 <?php echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?>
318 </td>
319 <td>
320 <?php echo htmlspecialchars( $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ) ?>
321 </td>
322 <td>
323 <?php echo $row['pubpid'] ?>
324 </td>
325 <td>
326 <?php echo $row['street'] ?>
327 </td>
328 <td>
329 <?php echo $row['city'] ?>
330 </td>
331 <td>
332 <?php echo $row['state'] ?>
333 </td>
334 <td>
335 <?php echo $row['postal_code'] ?>
336 </td>
337 <td>
338 <?php echo $row['phone_home'] ?>
339 </td>
340 <td>
341 <?php echo $row['phone_biz'] ?>
342 </td>
343 </tr>
344 <?php
345 } // end not export
346 ++$totalpts;
347 } // end while
348 if (!$_POST['form_csvexport']) {
351 <tr class="report_totals">
352 <td colspan='9'>
353 <?php xl('Total Number of Patients','e'); ?>
355 <?php echo $totalpts ?>
356 </td>
357 </tr>
359 </tbody>
360 </table>
361 </div> <!-- end of results -->
362 <?php
363 } // end not export
364 } // end if refresh or export
366 if (!$_POST['form_refresh'] && !$_POST['form_csvexport']) {
368 <div class='text'>
369 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
370 </div>
371 <?php
374 if (!$_POST['form_csvexport']) {
377 </form>
378 </body>
380 </html>
381 <?php
382 } // end not export