full tab fixes to stop scroll of tab and not show bottom border of active tab (#407)
[openemr.git] / interface / reports / patient_list.php
blobc9cd8e0f898ef82f8abc94d1bd6f8ff180f0f768
1 <?php
2 // Copyright (C) 2006-2016 Rod Roark <rod@sunsetsystems.com>
3 //
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");
35 header("Expires: 0");
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");
41 else {
43 <html>
44 <head>
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'));
59 });
61 </script>
63 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
64 <style type="text/css">
66 /* specifically include & exclude from printing */
67 @media print {
68 #report_parameters {
69 visibility: hidden;
70 display: none;
72 #report_parameters_daterange {
73 visibility: visible;
74 display: inline;
75 margin-bottom: 10px;
77 #report_results table {
78 margin-top: 0px;
82 /* specifically exclude some from the screen */
83 @media screen {
84 #report_parameters_daterange {
85 visibility: hidden;
86 display: none;
88 #report_results {
89 width: 100%;
93 </style>
95 </head>
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)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
106 </div>
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=''/>
115 <table>
116 <tr>
117 <td width='60%'>
118 <div style='float:left'>
120 <table class='text'>
121 <tr>
122 <td class='label'>
123 <?php xl('Provider','e'); ?>:
124 </td>
125 <td>
126 <?php
127 generate_form_field(array('data_type' => 10, 'field_id' => 'provider',
128 'empty_title' => '-- All --'), $_POST['form_provider']);
130 </td>
131 <td class='label'>
132 <?php xl('Visits From','e'); ?>:
133 </td>
134 <td>
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'); ?>'>
140 </td>
141 <td class='label'>
142 <?php xl('To','e'); ?>:
143 </td>
144 <td>
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'); ?>'>
150 </td>
151 </tr>
152 </table>
154 </div>
156 </td>
157 <td align='left' valign='middle' height="100%">
158 <table style='border-left:1px solid; width:100%; height:100%' >
159 <tr>
160 <td>
161 <div style='margin-left:15px'>
162 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
163 <span>
164 <?php xl('Submit','e'); ?>
165 </span>
166 </a>
167 <a href='#' class='css_button' onclick='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
168 <span>
169 <?php xl('Export to CSV','e'); ?>
170 </span>
171 </a>
172 <?php if ($_POST['form_refresh']) { ?>
173 <a href='#' id='printbutton' class='css_button'>
174 <span>
175 <?php xl('Print','e'); ?>
176 </span>
177 </a>
178 <?php } ?>
179 </div>
180 </td>
181 </tr>
182 </table>
183 </td>
184 </tr>
185 </table>
186 </div> <!-- end of parameters -->
188 <?php
189 } // end not form_csvexport
191 if ($_POST['form_refresh'] || $_POST['form_csvexport']) {
192 if ($_POST['form_csvexport']) {
193 // CSV headers:
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";
206 else {
209 <div id="report_results">
210 <table id='mymaintable'>
211 <thead>
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>
221 </thead>
222 <tbody>
223 <?php
224 } // end not export
225 $totalpts = 0;
226 $query = "SELECT " .
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' ";
242 else {
243 if ($form_provider) {
244 $query .= "JOIN form_encounter AS e ON " .
245 "e.pid = p.pid AND e.provider_id = '$form_provider' ";
247 else {
248 $query .= "LEFT OUTER JOIN form_encounter AS e ON " .
249 "e.pid = p.pid ";
252 $query .=
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);
265 $prevpid = 0;
266 while ($row = sqlFetchArray($res)) {
267 if ($row['pid'] == $prevpid) continue;
268 $prevpid = $row['pid'];
269 $age = '';
270 if ($row['DOB']) {
271 $dob = $row['DOB'];
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";
293 else {
295 <tr>
296 <td>
297 <?php echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?>
298 </td>
299 <td>
300 <?php echo htmlspecialchars( $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ) ?>
301 </td>
302 <td>
303 <?php echo $row['pubpid'] ?>
304 </td>
305 <td>
306 <?php echo $row['street'] ?>
307 </td>
308 <td>
309 <?php echo $row['city'] ?>
310 </td>
311 <td>
312 <?php echo $row['state'] ?>
313 </td>
314 <td>
315 <?php echo $row['postal_code'] ?>
316 </td>
317 <td>
318 <?php echo $row['phone_home'] ?>
319 </td>
320 <td>
321 <?php echo $row['phone_biz'] ?>
322 </td>
323 </tr>
324 <?php
325 } // end not export
326 ++$totalpts;
327 } // end while
328 if (!$_POST['form_csvexport']) {
331 <tr class="report_totals">
332 <td colspan='9'>
333 <?php xl('Total Number of Patients','e'); ?>
335 <?php echo $totalpts ?>
336 </td>
337 </tr>
339 </tbody>
340 </table>
341 </div> <!-- end of results -->
342 <?php
343 } // end not export
344 } // end if refresh or export
346 if (!$_POST['form_refresh'] && !$_POST['form_csvexport']) {
348 <div class='text'>
349 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
350 </div>
351 <?php
354 if (!$_POST['form_csvexport']) {
357 </form>
358 </body>
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"});
368 </script>
369 </html>
370 <?php
371 } // end not export