set default margins to 5
[openemr.git] / interface / reports / patient_list.php
blob0ab54c830f9e09c5a2da2acdf88697f44eb66464
1 <?php
2 // Copyright (C) 2006-2008 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");
15 // $from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
16 // $to_date = fixDate($_POST['form_to_date'], date('Y-12-31'));
17 $from_date = fixDate($_POST['form_from_date'], '');
18 $to_date = fixDate($_POST['form_to_date'], '');
19 if (empty($to_date) && !empty($from_date)) $to_date = date('Y-12-31');
20 if (empty($from_date) && !empty($to_date)) $from_date = date('Y-01-01');
22 <html>
23 <head>
24 <?php html_header_show();?>
25 <title><?php xl('Patient List','e'); ?></title>
26 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
27 <script type="text/javascript" src="../../library/textformat.js"></script>
28 <script type="text/javascript" src="../../library/dialog.js"></script>
29 <script language="JavaScript">
30 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
31 </script>
32 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
33 <style type="text/css">
35 /* specifically include & exclude from printing */
36 @media print {
37 #patlstreport_parameters {
38 visibility: hidden;
39 display: none;
41 #patlstreport_parameters_daterange {
42 visibility: visible;
43 display: inline;
47 /* specifically exclude some from the screen */
48 @media screen {
49 #patlstreport_parameters_daterange {
50 visibility: hidden;
51 display: none;
55 #patlstreport_parameters {
56 width: 100%;
57 background-color: #ddf;
59 #patlstreport_parameters table {
60 border: none;
61 border-collapse: collapse;
63 #patlstreport_parameters table td {
64 padding: 3px;
67 #patlstreport_results {
68 width: 100%;
69 margin-top: 10px;
71 #patlstreport_results table {
72 border: 1px solid black;
73 width: 98%;
74 border-collapse: collapse;
76 #patlstreport_results table thead {
77 display: table-header-group;
78 background-color: #ddd;
80 #patlstreport_results table th {
81 border-bottom: 1px solid black;
83 #patlstreport_results table td {
84 padding: 1px;
85 margin: 2px;
86 border-bottom: 1px solid #eee;
88 .patlstreport_totals td {
89 background-color: #77ff77;
90 font-weight: bold;
92 </style>
94 </head>
96 <body class="body_top">
98 <!-- Required for the popup date selectors -->
99 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
101 <center>
103 <h2><?php xl('Patient List','e'); ?></h2>
105 <div id="patlstreport_parameters_daterange">
106 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
107 </div>
109 <div id="patlstreport_parameters">
111 <form name='theform' method='post' action='patient_list.php'>
113 <table>
114 <tr>
115 <td>
116 <?php xl('Visits From','e'); ?>:
117 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $from_date ?>'
118 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
119 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
120 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
121 title='<?php xl('Click here to choose a date','e'); ?>'>
122 &nbsp;<?php xl('To','e'); ?>:
123 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $to_date ?>'
124 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
125 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
126 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
127 title='<?php xl('Click here to choose a date','e'); ?>'>
128 &nbsp;
129 <input type='submit' name='form_refresh' value=<?php xl('Refresh','e'); ?>>
130 &nbsp;
131 <input type='button' value='<?php xl('Print','e'); ?>' onclick='window.print()' />
132 </td>
133 </tr>
134 </table>
135 </div> <!-- end of parameters -->
137 <div id="patlstreport_results">
138 <table>
139 <thead>
140 <th> <?php xl('Last Visit','e'); ?> </th>
141 <th> <?php xl('Patient','e'); ?> </th>
142 <th> <?php xl('ID','e'); ?> </th>
143 <th> <?php xl('Street','e'); ?> </th>
144 <th> <?php xl('City','e'); ?> </th>
145 <th> <?php xl('State','e'); ?> </th>
146 <th> <?php xl('Zip','e'); ?> </th>
147 <th> <?php xl('Home Phone','e'); ?> </th>
148 <th> <?php xl('Work Phone','e'); ?> </th>
149 </thead>
150 <tbody>
151 <?php
152 if ($_POST['form_refresh']) {
153 $totalpts = 0;
155 $query = "SELECT " .
156 "p.fname, p.mname, p.lname, p.street, p.city, p.state, " .
157 "p.postal_code, p.phone_home, p.phone_biz, p.pid, p.pubpid, " .
158 "count(e.date) AS ecount, max(e.date) AS edate, " .
159 "i1.date AS idate1, i2.date AS idate2, " .
160 "c1.name AS cname1, c2.name AS cname2 " .
161 "FROM patient_data AS p ";
162 if (!empty($from_date)) $query .=
163 "JOIN form_encounter AS e ON " .
164 "e.pid = p.pid AND " .
165 "e.date >= '$from_date 00:00:00' AND " .
166 "e.date <= '$to_date 23:59:59' ";
167 else $query .=
168 "LEFT OUTER JOIN form_encounter AS e ON e.pid = p.pid ";
169 $query .=
170 "LEFT OUTER JOIN insurance_data AS i1 ON " .
171 "i1.pid = p.pid AND i1.type = 'primary' " .
172 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
173 "c1.id = i1.provider " .
174 "LEFT OUTER JOIN insurance_data AS i2 ON " .
175 "i2.pid = p.pid AND i2.type = 'secondary' " .
176 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
177 "c2.id = i2.provider " .
178 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
179 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
180 $res = sqlStatement($query);
182 $prevpid = 0;
183 while ($row = sqlFetchArray($res)) {
184 if ($row['pid'] == $prevpid) continue;
185 $prevpid = $row['pid'];
187 /****/
189 $age = '';
190 if ($row['DOB']) {
191 $dob = $row['DOB'];
192 $tdy = $row['edate'] ? $row['edate'] : date('Y-m-d');
193 $ageInMonths = (substr($tdy,0,4)*12) + substr($tdy,5,2) -
194 (substr($dob,0,4)*12) - substr($dob,5,2);
195 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
196 if ($dayDiff < 0) --$ageInMonths;
197 $age = intval($ageInMonths/12);
200 <tr>
201 <td>
202 <?php echo substr($row['edate'], 0, 10) ?>
203 </td>
204 <td>
205 <?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
206 </td>
207 <td>
208 <?php echo $row['pubpid'] ?>
209 </td>
210 <td>
211 <?php echo $row['street'] ?>
212 </td>
213 <td>
214 <?php echo $row['city'] ?>
215 </td>
216 <td>
217 <?php echo $row['state'] ?>
218 </td>
219 <td>
220 <?php echo $row['postal_code'] ?>
221 </td>
222 <td>
223 <?php echo $row['phone_home'] ?>
224 </td>
225 <td>
226 <?php echo $row['phone_biz'] ?>
227 </td>
228 </tr>
229 <?php
230 ++$totalpts;
234 <tr class="patlstreport_totals">
235 <td colspan='8'>
236 <?php xl('Total Number of Patients','e'); ?>
238 <?php echo $totalpts ?>
239 </td>
240 </tr>
242 <?php
245 </tbody>
246 </table>
247 </div> <!-- end of results -->
248 </form>
249 </center>
250 </body>
252 <!-- stuff for the popup calendar -->
253 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
254 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
255 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
256 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
257 <script language="Javascript">
258 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
259 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
260 </script>
261 </html>