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
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");
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");
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 ?>
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 */
98 #report_parameters_daterange {
103 #report_results table {
108 /* specifically exclude some from the screen */
110 #report_parameters_daterange {
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)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
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
=''/>
144 <div style
='float:left'>
149 <?php
xl('Provider','e'); ?
>:
153 generate_form_field(array('data_type' => 10, 'field_id' => 'provider',
154 'empty_title' => '-- All --'), $_POST['form_provider']);
158 <?php
xl('Visits From','e'); ?
>:
161 <input
class='datepicker' type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
165 <?php
xl('To','e'); ?
>:
168 <input
class='datepicker' type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
177 <td align
='left' valign
='middle' height
="100%">
178 <table style
='border-left:1px solid; width:100%; height:100%' >
181 <div style
='margin-left:15px'>
182 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
184 <?php
xl('Submit','e'); ?
>
187 <a href
='#' class='css_button' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
189 <?php
xl('Export to CSV','e'); ?
>
192 <?php
if ($_POST['form_refresh']) { ?
>
193 <a href
='#' id
='printbutton' class='css_button'>
195 <?php
xl('Print','e'); ?
>
206 </div
> <!-- end of parameters
-->
209 } // end not form_csvexport
211 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
212 if ($_POST['form_csvexport']) {
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";
229 <div id
="report_results">
230 <table id
='mymaintable'>
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
>
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' ";
263 if ($form_provider) {
264 $query .= "JOIN form_encounter AS e ON " .
265 "e.pid = p.pid AND e.provider_id = '$form_provider' ";
268 $query .= "LEFT OUTER JOIN form_encounter AS e ON " .
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);
286 while ($row = sqlFetchArray($res)) {
287 if ($row['pid'] == $prevpid) continue;
288 $prevpid = $row['pid'];
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";
317 <?php
echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?
>
320 <?php
echo htmlspecialchars( $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ) ?
>
323 <?php
echo $row['pubpid'] ?
>
326 <?php
echo $row['street'] ?
>
329 <?php
echo $row['city'] ?
>
332 <?php
echo $row['state'] ?
>
335 <?php
echo $row['postal_code'] ?
>
338 <?php
echo $row['phone_home'] ?
>
341 <?php
echo $row['phone_biz'] ?
>
348 if (!$_POST['form_csvexport']) {
351 <tr
class="report_totals">
353 <?php
xl('Total Number of Patients','e'); ?
>
355 <?php
echo $totalpts ?
>
361 </div
> <!-- end of results
-->
364 } // end if refresh or export
366 if (!$_POST['form_refresh'] && !$_POST['form_csvexport']) {
369 <?php
echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?
>
374 if (!$_POST['form_csvexport']) {