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>;.
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");
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");
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 ?>
86 <style type
="text/css">
88 /* specifically include & exclude from printing */
94 #report_parameters_daterange {
99 #report_results table {
104 /* specifically exclude some from the screen */
106 #report_parameters_daterange {
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)) ." to ". date("d F Y", strtotime($to_date)); ?
>
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
=''/>
142 <div style
='float:left'>
146 <td
class='control-label'>
147 <?php
xl('Provider', 'e'); ?
>:
151 generate_form_field(array('data_type' => 10, 'field_id' => 'provider',
152 'empty_title' => '-- All --'), $_POST['form_provider']);
155 <td
class='control-label'>
156 <?php
xl('Visits From', 'e'); ?
>:
159 <input
class='datepicker form-control' type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo oeFormatShortDate($from_date) ?>'>
161 <td
class='control-label'>
162 <?php
xl('To', 'e'); ?
>:
165 <input
class='datepicker form-control' type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo oeFormatShortDate($to_date) ?>'>
173 <td align
='left' valign
='middle' height
="100%">
174 <table style
='border-left:1px solid; width:100%; height:100%' >
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'); ?
>
182 <a href
='#' class='btn btn-default btn-transmit' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
183 <?php
echo xlt('Export to CSV'); ?
>
185 <?php
if ($_POST['form_refresh']) { ?
>
186 <a href
='#' id
='printbutton' class='btn btn-default btn-print'>
187 <?php
xl('Print', 'e'); ?
>
198 </div
> <!-- end of parameters
-->
201 } // end not form_csvexport
203 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
204 if ($_POST['form_csvexport']) {
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";
220 <div id
="report_results">
221 <table id
='mymaintable'>
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
>
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' ";
253 if ($form_provider) {
254 $query .= "JOIN form_encounter AS e ON " .
255 "e.pid = p.pid AND e.provider_id = '$form_provider' ";
257 $query .= "LEFT OUTER JOIN form_encounter AS e ON " .
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);
276 while ($row = sqlFetchArray($res)) {
277 if ($row['pid'] == $prevpid) {
281 $prevpid = $row['pid'];
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);
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";
312 <?php
echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?
>
315 <?php
echo htmlspecialchars($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']) ?
>
318 <?php
echo $row['pubpid'] ?
>
321 <?php
echo $row['street'] ?
>
324 <?php
echo $row['city'] ?
>
327 <?php
echo $row['state'] ?
>
330 <?php
echo $row['postal_code'] ?
>
333 <?php
echo $row['phone_home'] ?
>
336 <?php
echo $row['phone_biz'] ?
>
343 if (!$_POST['form_csvexport']) {
346 <tr
class="report_totals">
348 <?php
xl('Total Number of Patients', 'e'); ?
>
350 <?php
echo $totalpts ?
>
356 </div
> <!-- end of results
-->
359 } // end if refresh or export
361 if (!$_POST['form_refresh'] && !$_POST['form_csvexport']) {
364 <?php
echo xl('Please input search criteria above, and click Submit to view results.', 'e'); ?
>
369 if (!$_POST['form_csvexport']) {