Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / interface / reports / patient_list.php
blobbe9da6b0d1ff27af695e163c2e0e03f116ced6b6
1 <?php
2 // Copyright (C) 2006-2010 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");
16 // $from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
17 // $to_date = fixDate($_POST['form_to_date'], date('Y-12-31'));
18 $from_date = fixDate($_POST['form_from_date'], '');
19 $to_date = fixDate($_POST['form_to_date'], '');
20 if (empty($to_date) && !empty($from_date)) $to_date = date('Y-12-31');
21 if (empty($from_date) && !empty($to_date)) $from_date = date('Y-01-01');
23 <html>
24 <head>
25 <?php html_header_show();?>
26 <title><?php xl('Patient List','e'); ?></title>
27 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
28 <script type="text/javascript" src="../../library/textformat.js"></script>
29 <script type="text/javascript" src="../../library/dialog.js"></script>
30 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
32 <script language="JavaScript">
33 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
34 </script>
35 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
36 <style type="text/css">
38 /* specifically include & exclude from printing */
39 @media print {
40 #report_parameters {
41 visibility: hidden;
42 display: none;
44 #report_parameters_daterange {
45 visibility: visible;
46 display: inline;
47 margin-bottom: 10px;
49 #report_results table {
50 margin-top: 0px;
54 /* specifically exclude some from the screen */
55 @media screen {
56 #report_parameters_daterange {
57 visibility: hidden;
58 display: none;
60 #report_results {
61 width: 100%;
65 </style>
67 </head>
69 <body class="body_top">
71 <!-- Required for the popup date selectors -->
72 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
74 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Patient List','e'); ?></span>
76 <div id="report_parameters_daterange">
77 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
78 </div>
80 <form name='theform' id='theform' method='post' action='patient_list.php'>
82 <div id="report_parameters">
84 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
86 <table>
87 <tr>
88 <td width='410px'>
89 <div style='float:left'>
91 <table class='text'>
92 <tr>
93 <td class='label'>
94 <?php xl('Visits From','e'); ?>:
95 </td>
96 <td>
97 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
98 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
99 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
100 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
101 title='<?php xl('Click here to choose a date','e'); ?>'>
102 </td>
103 <td class='label'>
104 <?php xl('To','e'); ?>:
105 </td>
106 <td>
107 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
108 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
109 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
110 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
111 title='<?php xl('Click here to choose a date','e'); ?>'>
112 </td>
113 </tr>
114 </table>
116 </div>
118 </td>
119 <td align='left' valign='middle' height="100%">
120 <table style='border-left:1px solid; width:100%; height:100%' >
121 <tr>
122 <td>
123 <div style='margin-left:15px'>
124 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
125 <span>
126 <?php xl('Submit','e'); ?>
127 </span>
128 </a>
130 <?php if ($_POST['form_refresh']) { ?>
131 <a href='#' class='css_button' onclick='window.print()'>
132 <span>
133 <?php xl('Print','e'); ?>
134 </span>
135 </a>
136 <?php } ?>
137 </div>
138 </td>
139 </tr>
140 </table>
141 </td>
142 </tr>
143 </table>
144 </div> <!-- end of parameters -->
146 <?php
147 if ($_POST['form_refresh']) {
151 <div id="report_results">
152 <table>
153 <thead>
154 <th> <?php xl('Last Visit','e'); ?> </th>
155 <th> <?php xl('Patient','e'); ?> </th>
156 <th> <?php xl('ID','e'); ?> </th>
157 <th> <?php xl('Street','e'); ?> </th>
158 <th> <?php xl('City','e'); ?> </th>
159 <th> <?php xl('State','e'); ?> </th>
160 <th> <?php xl('Zip','e'); ?> </th>
161 <th> <?php xl('Home Phone','e'); ?> </th>
162 <th> <?php xl('Work Phone','e'); ?> </th>
163 </thead>
164 <tbody>
165 <?php
167 $totalpts = 0;
168 $query = "SELECT " .
169 "p.fname, p.mname, p.lname, p.street, p.city, p.state, " .
170 "p.postal_code, p.phone_home, p.phone_biz, p.pid, p.pubpid, " .
171 "count(e.date) AS ecount, max(e.date) AS edate, " .
172 "i1.date AS idate1, i2.date AS idate2, " .
173 "c1.name AS cname1, c2.name AS cname2 " .
174 "FROM patient_data AS p ";
175 if (!empty($from_date)) $query .=
176 "JOIN form_encounter AS e ON " .
177 "e.pid = p.pid AND " .
178 "e.date >= '$from_date 00:00:00' AND " .
179 "e.date <= '$to_date 23:59:59' ";
180 else $query .=
181 "LEFT OUTER JOIN form_encounter AS e ON e.pid = p.pid ";
182 $query .=
183 "LEFT OUTER JOIN insurance_data AS i1 ON " .
184 "i1.pid = p.pid AND i1.type = 'primary' " .
185 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
186 "c1.id = i1.provider " .
187 "LEFT OUTER JOIN insurance_data AS i2 ON " .
188 "i2.pid = p.pid AND i2.type = 'secondary' " .
189 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
190 "c2.id = i2.provider " .
191 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
192 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
193 $res = sqlStatement($query);
195 $prevpid = 0;
196 while ($row = sqlFetchArray($res)) {
197 if ($row['pid'] == $prevpid) continue;
198 $prevpid = $row['pid'];
200 /****/
202 $age = '';
203 if ($row['DOB']) {
204 $dob = $row['DOB'];
205 $tdy = $row['edate'] ? $row['edate'] : date('Y-m-d');
206 $ageInMonths = (substr($tdy,0,4)*12) + substr($tdy,5,2) -
207 (substr($dob,0,4)*12) - substr($dob,5,2);
208 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
209 if ($dayDiff < 0) --$ageInMonths;
210 $age = intval($ageInMonths/12);
213 <tr>
214 <td>
215 <?php echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?>
216 </td>
217 <td>
218 <?php echo htmlspecialchars( $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ) ?>
219 </td>
220 <td>
221 <?php echo $row['pubpid'] ?>
222 </td>
223 <td>
224 <?php echo $row['street'] ?>
225 </td>
226 <td>
227 <?php echo $row['city'] ?>
228 </td>
229 <td>
230 <?php echo $row['state'] ?>
231 </td>
232 <td>
233 <?php echo $row['postal_code'] ?>
234 </td>
235 <td>
236 <?php echo $row['phone_home'] ?>
237 </td>
238 <td>
239 <?php echo $row['phone_biz'] ?>
240 </td>
241 </tr>
242 <?php
243 ++$totalpts;
247 <tr class="report_totals">
248 <td colspan='9'>
249 <?php xl('Total Number of Patients','e'); ?>
251 <?php echo $totalpts ?>
252 </td>
253 </tr>
255 <?php
258 </tbody>
259 </table>
260 </div> <!-- end of results -->
261 <?php } else { ?>
262 <div class='text'>
263 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
264 </div>
265 <?php } ?>
267 </form>
268 </body>
270 <!-- stuff for the popup calendar -->
271 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
272 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
273 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
274 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
275 <script language="Javascript">
276 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
277 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
278 </script>
279 </html>