added gacl config files to upgrade instructions
[openemr.git] / interface / reports / unique_seen_patients_report.php
blobb4891084478b6ec2152bd66f99befd401cc92976
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.
12 include_once("../globals.php");
13 include_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'));
18 if ($_POST['form_labels']) {
19 header("Pragma: public");
20 header("Expires: 0");
21 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
22 header("Content-Type: application/force-download");
23 header("Content-Disposition: attachment; filename=labels.txt");
24 header("Content-Description: File Transfer");
26 else {
28 <html>
29 <head>
30 <?php html_header_show();?>
31 <title><?php xl('Front Office Receipts','e'); ?></title>
33 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
34 <script type="text/javascript" src="../../library/textformat.js"></script>
35 <script type="text/javascript" src="../../library/dialog.js"></script>
36 <script language="JavaScript">
37 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
38 </script>
40 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
41 <style type="text/css">
43 /* specifically include & exclude from printing */
44 @media print {
45 #unipatreport_parameters {
46 visibility: hidden;
47 display: none;
49 #unipatreport_parameters_daterange {
50 visibility: visible;
51 display: inline;
55 /* specifically exclude some from the screen */
56 @media screen {
57 #unipatreport_parameters_daterange {
58 visibility: hidden;
59 display: none;
63 #unipatreport_parameters {
64 width: 100%;
65 background-color: #ddf;
67 #unipatreport_parameters table {
68 border: none;
69 border-collapse: collapse;
71 #unipatreport_parameters table td {
72 padding: 3px;
75 #unipatreport_results {
76 width: 100%;
77 margin-top: 10px;
79 #unipatreport_results table {
80 border: 1px solid black;
81 width: 98%;
82 border-collapse: collapse;
84 #unipatreport_results table thead {
85 display: table-header-group;
86 background-color: #ddd;
88 #unipatreport_results table th {
89 border-bottom: 1px solid black;
91 #unipatreport_results table td {
92 padding: 1px;
93 margin: 2px;
94 border-bottom: 1px solid #eee;
96 .unipatreport_totals td {
97 background-color: #77ff77;
98 font-weight: bold;
100 </style>
101 </head>
103 <body class="body_top">
105 <!-- Required for the popup date selectors -->
106 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
108 <center>
110 <h2><?php xl('Unique Seen Patients','e'); ?></h2>
112 <div id="unipatreport_parameters_daterange">
113 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
114 </div>
116 <div id="unipatreport_parameters">
117 <form name='theform' method='post' action='unique_seen_patients_report.php'>
118 <table>
119 <tr>
120 <td>
121 <?php xl('Visits From','e'); ?>:
122 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $from_date ?>'
123 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
124 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
125 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
126 title='<?php xl('Click here to choose a date','e'); ?>'>
127 &nbsp;<?php xl('To','e'); ?>:
128 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $to_date ?>'
129 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
130 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
131 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
132 title='<?php xl('Click here to choose a date','e'); ?>'>
133 &nbsp;
134 <input type='submit' name='form_refresh' value=<?php xl('Refresh','e'); ?>> &nbsp;
135 <input type='submit' name='form_labels' value=<?php xl('Labels','e'); ?>>
136 </td>
137 </tr>
138 </table>
139 </div> <!-- end of parameters -->
141 <div id="unipatreport_results">
142 <table>
144 <thead>
145 <th> <?php xl('Last Visit','e'); ?> </th>
146 <th> <?php xl('Patient','e'); ?> </th>
147 <th align='right'> <?php xl('Visits','e'); ?> </th>
148 <th align='right'> <?php xl('Age','e'); ?> </th>
149 <th> <?php xl('Sex','e'); ?> </th>
150 <th> <?php xl('Race','e'); ?> </th>
151 <th> <?php xl('Primary Insurance','e'); ?> </th>
152 <th> <?php xl('Secondary Insurance','e'); ?> </th>
153 </thead>
154 <tbody>
155 <?php
156 } // end not generating labels
158 if ($_POST['form_refresh'] || $_POST['form_labels']) {
159 $totalpts = 0;
161 $query = "SELECT " .
162 "p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
163 "p.street, p.city, p.state, p.postal_code, " .
164 "count(e.date) AS ecount, max(e.date) AS edate, " .
165 "i1.date AS idate1, i2.date AS idate2, " .
166 "c1.name AS cname1, c2.name AS cname2 " .
167 "FROM patient_data AS p " .
168 "JOIN form_encounter AS e ON " .
169 "e.pid = p.pid AND " .
170 "e.date >= '$from_date 00:00:00' AND " .
171 "e.date <= '$to_date 23:59:59' " .
172 "LEFT OUTER JOIN insurance_data AS i1 ON " .
173 "i1.pid = p.pid AND i1.type = 'primary' " .
174 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
175 "c1.id = i1.provider " .
176 "LEFT OUTER JOIN insurance_data AS i2 ON " .
177 "i2.pid = p.pid AND i2.type = 'secondary' " .
178 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
179 "c2.id = i2.provider " .
180 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
181 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
182 $res = sqlStatement($query);
184 $prevpid = 0;
185 while ($row = sqlFetchArray($res)) {
186 if ($row['pid'] == $prevpid) continue;
187 $prevpid = $row['pid'];
189 $age = '';
190 if ($row['DOB']) {
191 $dob = $row['DOB'];
192 $tdy = $row['edate'];
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 if ($_POST['form_labels']) {
201 echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
202 $row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
203 $row['postal_code'] . '"' . "\n";
205 else { // not labels
207 <tr>
208 <td>
209 <?php echo substr($row['edate'], 0, 10) ?>
210 </td>
211 <td>
212 <?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
213 </td>
214 <td style="text-align:center">
215 <?php echo $row['ecount'] ?>
216 </td>
217 <td>
218 <?php echo $age ?>
219 </td>
220 <td>
221 <?php echo $row['sex'] ?>
222 </td>
223 <td>
224 <?php echo $row['ethnoracial'] ?>
225 </td>
226 <td>
227 <?php echo $row['cname1'] ?>
228 </td>
229 <td>
230 <?php echo $row['cname2'] ?>
231 </td>
232 </tr>
233 <?php
234 } // end not labels
235 ++$totalpts;
238 if (!$_POST['form_labels']) {
240 <tr class='unipatreport_totals'>
241 <td colspan='2'>
242 <?php xl('Total Number of Patients','e'); ?>
243 </td>
244 <td style="padding-left: 20px;">
245 <?php echo $totalpts ?>
246 </td>
247 <td colspan='5'>&nbsp;</td>
248 </tr>
250 <?php
251 } // end not labels
252 } // end refresh or labels
254 if (!$_POST['form_labels']) {
256 </tbody>
257 </table>
258 </div>
259 </form>
260 </center>
261 </body>
263 <!-- stuff for the popup calendar -->
264 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
265 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
266 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
267 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
268 <script language="Javascript">
269 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
270 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
271 </script>
272 </html>
273 <?php
274 } // end not labels