2 // Copyright (C) 2006-2012 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This report lists patients that were seen within a given date
10 // range, or all patients if no date range is entered.
12 require_once("../globals.php");
13 require_once("$srcdir/patient.inc");
14 require_once("$srcdir/formatting.inc.php");
15 require_once("$srcdir/options.inc.php");
17 // Prepare a string for CSV export.
18 function qescape($str) {
19 $str = str_replace('\\', '\\\\', $str);
20 return str_replace('"', '\\"', $str);
23 // $from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
24 // $to_date = fixDate($_POST['form_to_date'], date('Y-12-31'));
25 $from_date = fixDate($_POST['form_from_date'], '');
26 $to_date = fixDate($_POST['form_to_date'], '');
27 if (empty($to_date) && !empty($from_date)) $to_date = date('Y-12-31');
28 if (empty($from_date) && !empty($to_date)) $from_date = date('Y-01-01');
30 $form_provider = empty($_POST['form_provider']) ?
0 : intval($_POST['form_provider']);
32 // In the case of CSV export only, a download will be forced.
33 if ($_POST['form_csvexport']) {
34 header("Pragma: public");
36 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
37 header("Content-Type: application/force-download");
38 header("Content-Disposition: attachment; filename=patient_list.csv");
39 header("Content-Description: File Transfer");
45 <?php
html_header_show();?
>
46 <title
><?php
xl('Patient List','e'); ?
></title
>
47 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
48 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
49 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
50 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
52 <script language
="JavaScript">
53 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
55 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
56 <style type
="text/css">
58 /* specifically include & exclude from printing */
64 #report_parameters_daterange {
69 #report_results table {
74 /* specifically exclude some from the screen */
76 #report_parameters_daterange {
89 <body
class="body_top">
91 <!-- Required
for the popup date selectors
-->
92 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
94 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Patient List','e'); ?
></span
>
96 <div id
="report_parameters_daterange">
97 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
100 <form name
='theform' id
='theform' method
='post' action
='patient_list.php'>
102 <div id
="report_parameters">
104 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
105 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
110 <div style
='float:left'>
115 <?php
xl('Provider','e'); ?
>:
119 generate_form_field(array('data_type' => 10, 'field_id' => 'provider',
120 'empty_title' => '-- All --'), $form_provider);
124 <?php
xl('Visits From','e'); ?
>:
127 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
128 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
129 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
130 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
131 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
134 <?php
xl('To','e'); ?
>:
137 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
138 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
139 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
140 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
141 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
149 <td align
='left' valign
='middle' height
="100%">
150 <table style
='border-left:1px solid; width:100%; height:100%' >
153 <div style
='margin-left:15px'>
154 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
156 <?php
xl('Submit','e'); ?
>
159 <a href
='#' class='css_button' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
161 <?php
xl('Export to CSV','e'); ?
>
164 <?php
if ($_POST['form_refresh']) { ?
>
165 <a href
='#' class='css_button' onclick
='window.print()'>
167 <?php
xl('Print','e'); ?
>
178 </div
> <!-- end of parameters
-->
181 } // end not form_csvexport
183 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
184 if ($_POST['form_csvexport']) {
186 echo '"' . xl('Last Visit') . '",';
187 echo '"' . xl('First') . '",';
188 echo '"' . xl('Last') . '",';
189 echo '"' . xl('Middle') . '",';
190 echo '"' . xl('ID') . '",';
191 echo '"' . xl('Street') . '",';
192 echo '"' . xl('City') . '",';
193 echo '"' . xl('State') . '",';
194 echo '"' . xl('Zip') . '",';
195 echo '"' . xl('Home Phone') . '",';
196 echo '"' . xl('Work Phone') . '"' . "\n";
201 <div id
="report_results">
204 <th
> <?php
xl('Last Visit','e'); ?
> </th
>
205 <th
> <?php
xl('Patient','e'); ?
> </th
>
206 <th
> <?php
xl('ID','e'); ?
> </th
>
207 <th
> <?php
xl('Street','e'); ?
> </th
>
208 <th
> <?php
xl('City','e'); ?
> </th
>
209 <th
> <?php
xl('State','e'); ?
> </th
>
210 <th
> <?php
xl('Zip','e'); ?
> </th
>
211 <th
> <?php
xl('Home Phone','e'); ?
> </th
>
212 <th
> <?php
xl('Work Phone','e'); ?
> </th
>
219 "p.fname, p.mname, p.lname, p.street, p.city, p.state, " .
220 "p.postal_code, p.phone_home, p.phone_biz, p.pid, p.pubpid, " .
221 "count(e.date) AS ecount, max(e.date) AS edate, " .
222 "i1.date AS idate1, i2.date AS idate2, " .
223 "c1.name AS cname1, c2.name AS cname2 " .
224 "FROM patient_data AS p ";
225 if (!empty($from_date)) {
226 $query .= "JOIN form_encounter AS e ON " .
227 "e.pid = p.pid AND " .
228 "e.date >= '$from_date 00:00:00' AND " .
229 "e.date <= '$to_date 23:59:59' ";
230 if ($form_provider) {
231 $query .= "AND e.provider_id = '$form_provider' ";
235 if ($form_provider) {
236 $query .= "JOIN form_encounter AS e ON " .
237 "e.pid = p.pid AND e.provider_id = '$form_provider' ";
240 $query .= "LEFT OUTER JOIN form_encounter AS e ON " .
245 "LEFT OUTER JOIN insurance_data AS i1 ON " .
246 "i1.pid = p.pid AND i1.type = 'primary' " .
247 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
248 "c1.id = i1.provider " .
249 "LEFT OUTER JOIN insurance_data AS i2 ON " .
250 "i2.pid = p.pid AND i2.type = 'secondary' " .
251 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
252 "c2.id = i2.provider " .
253 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
254 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
255 $res = sqlStatement($query);
258 while ($row = sqlFetchArray($res)) {
259 if ($row['pid'] == $prevpid) continue;
260 $prevpid = $row['pid'];
264 $tdy = $row['edate'] ?
$row['edate'] : date('Y-m-d');
265 $ageInMonths = (substr($tdy,0,4)*12) +
substr($tdy,5,2) -
266 (substr($dob,0,4)*12) - substr($dob,5,2);
267 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
268 if ($dayDiff < 0) --$ageInMonths;
269 $age = intval($ageInMonths/12);
272 if ($_POST['form_csvexport']) {
273 echo '"' . oeFormatShortDate(substr($row['edate'], 0, 10)) . '",';
274 echo '"' . qescape($row['lname']) . '",';
275 echo '"' . qescape($row['fname']) . '",';
276 echo '"' . qescape($row['mname']) . '",';
277 echo '"' . qescape($row['pubpid']) . '",';
278 echo '"' . qescape($row['street']) . '",';
279 echo '"' . qescape($row['city']) . '",';
280 echo '"' . qescape($row['state']) . '",';
281 echo '"' . qescape($row['postal_code']) . '",';
282 echo '"' . qescape($row['phone_home']) . '",';
283 echo '"' . qescape($row['phone_biz']) . '"' . "\n";
289 <?php
echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?
>
292 <?php
echo htmlspecialchars( $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ) ?
>
295 <?php
echo $row['pubpid'] ?
>
298 <?php
echo $row['street'] ?
>
301 <?php
echo $row['city'] ?
>
304 <?php
echo $row['state'] ?
>
307 <?php
echo $row['postal_code'] ?
>
310 <?php
echo $row['phone_home'] ?
>
313 <?php
echo $row['phone_biz'] ?
>
320 if (!$_POST['form_csvexport']) {
323 <tr
class="report_totals">
325 <?php
xl('Total Number of Patients','e'); ?
>
327 <?php
echo $totalpts ?
>
333 </div
> <!-- end of results
-->
336 } // end if refresh or export
338 if (!$_POST['form_refresh'] && !$_POST['form_csvexport']) {
341 <?php
echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?
>
346 if (!$_POST['form_csvexport']) {
352 <!-- stuff
for the popup calendar
-->
353 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
354 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
355 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
356 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
357 <script language
="Javascript">
358 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
359 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});