2 // Copyright (C) 2006-2016 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?v=<?php echo $v_js_includes; ?>"></script
>
49 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
50 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-9-1/index.js"></script
>
51 <script type
="text/javascript" src
="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script
>
53 <script language
="JavaScript">
54 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
56 $
(document
).ready(function() {
57 oeFixedHeaderSetup(document
.getElementById('mymaintable'));
58 top
.printLogSetup(document
.getElementById('printbutton'));
63 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
64 <style type
="text/css">
66 /* specifically include & exclude from printing */
72 #report_parameters_daterange {
77 #report_results table {
82 /* specifically exclude some from the screen */
84 #report_parameters_daterange {
97 <body
class="body_top">
99 <!-- Required
for the popup date selectors
-->
100 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
102 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Patient List','e'); ?
></span
>
104 <div id
="report_parameters_daterange">
105 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
108 <form name
='theform' id
='theform' method
='post' action
='patient_list.php'>
110 <div id
="report_parameters">
112 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
113 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
118 <div style
='float:left'>
123 <?php
xl('Provider','e'); ?
>:
127 generate_form_field(array('data_type' => 10, 'field_id' => 'provider',
128 'empty_title' => '-- All --'), $_POST['form_provider']);
132 <?php
xl('Visits From','e'); ?
>:
135 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
136 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
137 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
138 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
139 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
142 <?php
xl('To','e'); ?
>:
145 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
146 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
147 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
148 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
149 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
157 <td align
='left' valign
='middle' height
="100%">
158 <table style
='border-left:1px solid; width:100%; height:100%' >
161 <div style
='margin-left:15px'>
162 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
164 <?php
xl('Submit','e'); ?
>
167 <a href
='#' class='css_button' onclick
='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
169 <?php
xl('Export to CSV','e'); ?
>
172 <?php
if ($_POST['form_refresh']) { ?
>
173 <a href
='#' id
='printbutton' class='css_button'>
175 <?php
xl('Print','e'); ?
>
186 </div
> <!-- end of parameters
-->
189 } // end not form_csvexport
191 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
192 if ($_POST['form_csvexport']) {
194 echo '"' . xl('Last Visit') . '",';
195 echo '"' . xl('First') . '",';
196 echo '"' . xl('Last') . '",';
197 echo '"' . xl('Middle') . '",';
198 echo '"' . xl('ID') . '",';
199 echo '"' . xl('Street') . '",';
200 echo '"' . xl('City') . '",';
201 echo '"' . xl('State') . '",';
202 echo '"' . xl('Zip') . '",';
203 echo '"' . xl('Home Phone') . '",';
204 echo '"' . xl('Work Phone') . '"' . "\n";
209 <div id
="report_results">
210 <table id
='mymaintable'>
212 <th
> <?php
xl('Last Visit','e'); ?
> </th
>
213 <th
> <?php
xl('Patient','e'); ?
> </th
>
214 <th
> <?php
xl('ID','e'); ?
> </th
>
215 <th
> <?php
xl('Street','e'); ?
> </th
>
216 <th
> <?php
xl('City','e'); ?
> </th
>
217 <th
> <?php
xl('State','e'); ?
> </th
>
218 <th
> <?php
xl('Zip','e'); ?
> </th
>
219 <th
> <?php
xl('Home Phone','e'); ?
> </th
>
220 <th
> <?php
xl('Work Phone','e'); ?
> </th
>
227 "p.fname, p.mname, p.lname, p.street, p.city, p.state, " .
228 "p.postal_code, p.phone_home, p.phone_biz, p.pid, p.pubpid, " .
229 "count(e.date) AS ecount, max(e.date) AS edate, " .
230 "i1.date AS idate1, i2.date AS idate2, " .
231 "c1.name AS cname1, c2.name AS cname2 " .
232 "FROM patient_data AS p ";
233 if (!empty($from_date)) {
234 $query .= "JOIN form_encounter AS e ON " .
235 "e.pid = p.pid AND " .
236 "e.date >= '$from_date 00:00:00' AND " .
237 "e.date <= '$to_date 23:59:59' ";
238 if ($form_provider) {
239 $query .= "AND e.provider_id = '$form_provider' ";
243 if ($form_provider) {
244 $query .= "JOIN form_encounter AS e ON " .
245 "e.pid = p.pid AND e.provider_id = '$form_provider' ";
248 $query .= "LEFT OUTER JOIN form_encounter AS e ON " .
253 "LEFT OUTER JOIN insurance_data AS i1 ON " .
254 "i1.pid = p.pid AND i1.type = 'primary' " .
255 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
256 "c1.id = i1.provider " .
257 "LEFT OUTER JOIN insurance_data AS i2 ON " .
258 "i2.pid = p.pid AND i2.type = 'secondary' " .
259 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
260 "c2.id = i2.provider " .
261 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
262 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
263 $res = sqlStatement($query);
266 while ($row = sqlFetchArray($res)) {
267 if ($row['pid'] == $prevpid) continue;
268 $prevpid = $row['pid'];
272 $tdy = $row['edate'] ?
$row['edate'] : date('Y-m-d');
273 $ageInMonths = (substr($tdy,0,4)*12) +
substr($tdy,5,2) -
274 (substr($dob,0,4)*12) - substr($dob,5,2);
275 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
276 if ($dayDiff < 0) --$ageInMonths;
277 $age = intval($ageInMonths/12);
280 if ($_POST['form_csvexport']) {
281 echo '"' . oeFormatShortDate(substr($row['edate'], 0, 10)) . '",';
282 echo '"' . qescape($row['lname']) . '",';
283 echo '"' . qescape($row['fname']) . '",';
284 echo '"' . qescape($row['mname']) . '",';
285 echo '"' . qescape($row['pubpid']) . '",';
286 echo '"' . qescape($row['street']) . '",';
287 echo '"' . qescape($row['city']) . '",';
288 echo '"' . qescape($row['state']) . '",';
289 echo '"' . qescape($row['postal_code']) . '",';
290 echo '"' . qescape($row['phone_home']) . '",';
291 echo '"' . qescape($row['phone_biz']) . '"' . "\n";
297 <?php
echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?
>
300 <?php
echo htmlspecialchars( $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ) ?
>
303 <?php
echo $row['pubpid'] ?
>
306 <?php
echo $row['street'] ?
>
309 <?php
echo $row['city'] ?
>
312 <?php
echo $row['state'] ?
>
315 <?php
echo $row['postal_code'] ?
>
318 <?php
echo $row['phone_home'] ?
>
321 <?php
echo $row['phone_biz'] ?
>
328 if (!$_POST['form_csvexport']) {
331 <tr
class="report_totals">
333 <?php
xl('Total Number of Patients','e'); ?
>
335 <?php
echo $totalpts ?
>
341 </div
> <!-- end of results
-->
344 } // end if refresh or export
346 if (!$_POST['form_refresh'] && !$_POST['form_csvexport']) {
349 <?php
echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?
>
354 if (!$_POST['form_csvexport']) {
360 <!-- stuff
for the popup calendar
-->
361 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
362 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
363 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
364 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
365 <script language
="Javascript">
366 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
367 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});