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");
16 // Prepare a string for CSV export.
17 function qescape($str) {
18 $str = str_replace('\\', '\\\\', $str);
19 return str_replace('"', '\\"', $str);
22 // $from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
23 // $to_date = fixDate($_POST['form_to_date'], date('Y-12-31'));
24 $from_date = fixDate($_POST['form_from_date'], '');
25 $to_date = fixDate($_POST['form_to_date'], '');
26 if (empty($to_date) && !empty($from_date)) $to_date = date('Y-12-31');
27 if (empty($from_date) && !empty($to_date)) $from_date = date('Y-01-01');
29 // In the case of CSV export only, a download will be forced.
30 if ($_POST['form_csvexport']) {
31 header("Pragma: public");
33 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
34 header("Content-Type: application/force-download");
35 header("Content-Disposition: attachment; filename=patient_list.csv");
36 header("Content-Description: File Transfer");
42 <?php
html_header_show();?
>
43 <title
><?php
xl('Patient List','e'); ?
></title
>
44 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
45 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
46 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
47 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
49 <script language
="JavaScript">
50 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
52 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
53 <style type
="text/css">
55 /* specifically include & exclude from printing */
61 #report_parameters_daterange {
66 #report_results table {
71 /* specifically exclude some from the screen */
73 #report_parameters_daterange {
86 <body
class="body_top">
88 <!-- Required
for the popup date selectors
-->
89 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
91 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Patient List','e'); ?
></span
>
93 <div id
="report_parameters_daterange">
94 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
97 <form name
='theform' id
='theform' method
='post' action
='patient_list.php'>
99 <div id
="report_parameters">
101 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
102 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
107 <div style
='float:left'>
112 <?php
xl('Visits From','e'); ?
>:
115 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
116 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
117 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
118 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
119 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
122 <?php
xl('To','e'); ?
>:
125 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
126 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
127 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
128 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
129 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
137 <td align
='left' valign
='middle' height
="100%">
138 <table style
='border-left:1px solid; width:100%; height:100%' >
141 <div style
='margin-left:15px'>
142 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
144 <?php
xl('Submit','e'); ?
>
147 <a href
='#' class='css_button' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
149 <?php
xl('Export to CSV','e'); ?
>
152 <?php
if ($_POST['form_refresh']) { ?
>
153 <a href
='#' class='css_button' onclick
='window.print()'>
155 <?php
xl('Print','e'); ?
>
166 </div
> <!-- end of parameters
-->
169 } // end not form_csvexport
171 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
172 if ($_POST['form_csvexport']) {
174 echo '"' . xl('Last Visit') . '",';
175 echo '"' . xl('First') . '",';
176 echo '"' . xl('Last') . '",';
177 echo '"' . xl('Middle') . '",';
178 echo '"' . xl('ID') . '",';
179 echo '"' . xl('Street') . '",';
180 echo '"' . xl('City') . '",';
181 echo '"' . xl('State') . '",';
182 echo '"' . xl('Zip') . '",';
183 echo '"' . xl('Home Phone') . '",';
184 echo '"' . xl('Work Phone') . '"' . "\n";
189 <div id
="report_results">
192 <th
> <?php
xl('Last Visit','e'); ?
> </th
>
193 <th
> <?php
xl('Patient','e'); ?
> </th
>
194 <th
> <?php
xl('ID','e'); ?
> </th
>
195 <th
> <?php
xl('Street','e'); ?
> </th
>
196 <th
> <?php
xl('City','e'); ?
> </th
>
197 <th
> <?php
xl('State','e'); ?
> </th
>
198 <th
> <?php
xl('Zip','e'); ?
> </th
>
199 <th
> <?php
xl('Home Phone','e'); ?
> </th
>
200 <th
> <?php
xl('Work Phone','e'); ?
> </th
>
207 "p.fname, p.mname, p.lname, p.street, p.city, p.state, " .
208 "p.postal_code, p.phone_home, p.phone_biz, p.pid, p.pubpid, " .
209 "count(e.date) AS ecount, max(e.date) AS edate, " .
210 "i1.date AS idate1, i2.date AS idate2, " .
211 "c1.name AS cname1, c2.name AS cname2 " .
212 "FROM patient_data AS p ";
213 if (!empty($from_date)) $query .=
214 "JOIN form_encounter AS e ON " .
215 "e.pid = p.pid AND " .
216 "e.date >= '$from_date 00:00:00' AND " .
217 "e.date <= '$to_date 23:59:59' ";
219 "LEFT OUTER JOIN form_encounter AS e ON e.pid = p.pid ";
221 "LEFT OUTER JOIN insurance_data AS i1 ON " .
222 "i1.pid = p.pid AND i1.type = 'primary' " .
223 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
224 "c1.id = i1.provider " .
225 "LEFT OUTER JOIN insurance_data AS i2 ON " .
226 "i2.pid = p.pid AND i2.type = 'secondary' " .
227 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
228 "c2.id = i2.provider " .
229 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
230 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
231 $res = sqlStatement($query);
234 while ($row = sqlFetchArray($res)) {
235 if ($row['pid'] == $prevpid) continue;
236 $prevpid = $row['pid'];
243 $tdy = $row['edate'] ?
$row['edate'] : date('Y-m-d');
244 $ageInMonths = (substr($tdy,0,4)*12) +
substr($tdy,5,2) -
245 (substr($dob,0,4)*12) - substr($dob,5,2);
246 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
247 if ($dayDiff < 0) --$ageInMonths;
248 $age = intval($ageInMonths/12);
251 if ($_POST['form_csvexport']) {
252 echo '"' . oeFormatShortDate(substr($row['edate'], 0, 10)) . '",';
253 echo '"' . qescape($row['lname']) . '",';
254 echo '"' . qescape($row['fname']) . '",';
255 echo '"' . qescape($row['mname']) . '",';
256 echo '"' . qescape($row['pubpid']) . '",';
257 echo '"' . qescape($row['street']) . '",';
258 echo '"' . qescape($row['city']) . '",';
259 echo '"' . qescape($row['state']) . '",';
260 echo '"' . qescape($row['postal_code']) . '",';
261 echo '"' . qescape($row['phone_home']) . '",';
262 echo '"' . qescape($row['phone_biz']) . '"' . "\n";
268 <?php
echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?
>
271 <?php
echo htmlspecialchars( $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ) ?
>
274 <?php
echo $row['pubpid'] ?
>
277 <?php
echo $row['street'] ?
>
280 <?php
echo $row['city'] ?
>
283 <?php
echo $row['state'] ?
>
286 <?php
echo $row['postal_code'] ?
>
289 <?php
echo $row['phone_home'] ?
>
292 <?php
echo $row['phone_biz'] ?
>
299 if (!$_POST['form_csvexport']) {
302 <tr
class="report_totals">
304 <?php
xl('Total Number of Patients','e'); ?
>
306 <?php
echo $totalpts ?
>
312 </div
> <!-- end of results
-->
315 } // end if refresh or export
317 if (!$_POST['form_refresh'] && !$_POST['form_csvexport']) {
320 <?php
echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?
>
325 if (!$_POST['form_csvexport']) {
331 <!-- stuff
for the popup calendar
-->
332 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
333 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
334 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
335 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
336 <script language
="Javascript">
337 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
338 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});