forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unique_seen_patients_report.php
315 lines (279 loc) · 8.84 KB
/
unique_seen_patients_report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
// Copyright (C) 2006-2015 Rod Roark <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This report lists patients that were seen within a given date
// range.
require_once("../globals.php");
require_once("$srcdir/patient.inc");
require_once("$srcdir/formatting.inc.php");
$from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
$to_date = fixDate($_POST['form_to_date'], date('Y-12-31'));
if ($_POST['form_labels']) {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=labels.txt");
header("Content-Description: File Transfer");
}
else {
?>
<html>
<head>
<?php html_header_show();?>
<style type="text/css">
/* specifically include & exclude from printing */
@media print {
#report_parameters {
visibility: hidden;
display: none;
}
#report_parameters_daterange {
visibility: visible;
display: inline;
}
#report_results {
margin-top: 30px;
}
}
/* specifically exclude some from the screen */
@media screen {
#report_parameters_daterange {
visibility: hidden;
display: none;
}
}
</style>
<title><?php xl('Front Office Receipts','e'); ?></title>
<script type="text/javascript" src="../../library/overlib_mini.js"></script>
<script type="text/javascript" src="../../library/textformat.js"></script>
<script type="text/javascript" src="../../library/dialog.js"></script>
<script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
<script language="JavaScript">
var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
$(document).ready(function() {
var win = top.printLogSetup ? top : opener.top;
win.printLogSetup(document.getElementById('printbutton'));
});
</script>
<link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
<style type="text/css">
/* specifically include & exclude from printing */
@media print {
#report_parameters {
visibility: hidden;
display: none;
}
#report_parameters_daterange {
visibility: visible;
display: inline;
}
}
/* specifically exclude some from the screen */
@media screen {
#report_parameters_daterange {
visibility: hidden;
display: none;
}
}
</style>
</head>
<body class="body_top">
<!-- Required for the popup date selectors -->
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<span class='title'><?php xl('Report','e'); ?> - <?php xl('Unique Seen Patients','e'); ?></span>
<div id="report_parameters_daterange">
<?php echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?>
</div>
<form name='theform' method='post' action='unique_seen_patients_report.php' id='theform'>
<div id="report_parameters">
<input type='hidden' name='form_refresh' id='form_refresh' value=''/>
<input type='hidden' name='form_labels' id='form_labels' value=''/>
<table>
<tr>
<td width='410px'>
<div style='float:left'>
<table class='text'>
<tr>
<td class='label'>
<?php xl('Visits From','e'); ?>:
</td>
<td>
<input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
<img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
title='<?php xl('Click here to choose a date','e'); ?>'>
</td>
<td class='label'>
<?php xl('To','e'); ?>:
</td>
<td>
<input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
<img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
title='<?php xl('Click here to choose a date','e'); ?>'>
</td>
</tr>
</table>
</div>
</td>
<td align='left' valign='middle' height="100%">
<table style='border-left:1px solid; width:100%; height:100%' >
<tr>
<td>
<div style='margin-left:15px'>
<a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
<span>
<?php xl('Submit','e'); ?>
</span>
</a>
<?php if ($_POST['form_refresh']) { ?>
<a href='#' class='css_button' id='printbutton'>
<span>
<?php xl('Print','e'); ?>
</span>
</a>
<a href='#' class='css_button' onclick='$("#form_labels").attr("value","true"); $("#theform").submit();'>
<span>
<?php xl('Labels','e'); ?>
</span>
</a>
<?php } ?>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div> <!-- end of parameters -->
<div id="report_results">
<table>
<thead>
<th> <?php xl('Last Visit','e'); ?> </th>
<th> <?php xl('Patient','e'); ?> </th>
<th align='right'> <?php xl('Visits','e'); ?> </th>
<th align='right'> <?php xl('Age','e'); ?> </th>
<th> <?php xl('Sex','e'); ?> </th>
<th> <?php xl('Race','e'); ?> </th>
<th> <?php xl('Primary Insurance','e'); ?> </th>
<th> <?php xl('Secondary Insurance','e'); ?> </th>
</thead>
<tbody>
<?php
} // end not generating labels
if ($_POST['form_refresh'] || $_POST['form_labels']) {
$totalpts = 0;
$query = "SELECT " .
"p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
"p.street, p.city, p.state, p.postal_code, " .
"count(e.date) AS ecount, max(e.date) AS edate, " .
"i1.date AS idate1, i2.date AS idate2, " .
"c1.name AS cname1, c2.name AS cname2 " .
"FROM patient_data AS p " .
"JOIN form_encounter AS e ON " .
"e.pid = p.pid AND " .
"e.date >= '$from_date 00:00:00' AND " .
"e.date <= '$to_date 23:59:59' " .
"LEFT OUTER JOIN insurance_data AS i1 ON " .
"i1.pid = p.pid AND i1.type = 'primary' " .
"LEFT OUTER JOIN insurance_companies AS c1 ON " .
"c1.id = i1.provider " .
"LEFT OUTER JOIN insurance_data AS i2 ON " .
"i2.pid = p.pid AND i2.type = 'secondary' " .
"LEFT OUTER JOIN insurance_companies AS c2 ON " .
"c2.id = i2.provider " .
"GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
"ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
$res = sqlStatement($query);
$prevpid = 0;
while ($row = sqlFetchArray($res)) {
if ($row['pid'] == $prevpid) continue;
$prevpid = $row['pid'];
$age = '';
if ($row['DOB']) {
$dob = $row['DOB'];
$tdy = $row['edate'];
$ageInMonths = (substr($tdy,0,4)*12) + substr($tdy,5,2) -
(substr($dob,0,4)*12) - substr($dob,5,2);
$dayDiff = substr($tdy,8,2) - substr($dob,8,2);
if ($dayDiff < 0) --$ageInMonths;
$age = intval($ageInMonths/12);
}
if ($_POST['form_labels']) {
echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
$row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
$row['postal_code'] . '"' . "\n";
}
else { // not labels
?>
<tr>
<td>
<?php echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?>
</td>
<td>
<?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
</td>
<td style="text-align:center">
<?php echo $row['ecount'] ?>
</td>
<td>
<?php echo $age ?>
</td>
<td>
<?php echo $row['sex'] ?>
</td>
<td>
<?php echo $row['ethnoracial'] ?>
</td>
<td>
<?php echo $row['cname1'] ?>
</td>
<td>
<?php echo $row['cname2'] ?>
</td>
</tr>
<?php
} // end not labels
++$totalpts;
}
if (!$_POST['form_labels']) {
?>
<tr class='report_totals'>
<td colspan='2'>
<?php xl('Total Number of Patients','e'); ?>
</td>
<td style="padding-left: 20px;">
<?php echo $totalpts ?>
</td>
<td colspan='5'> </td>
</tr>
<?php
} // end not labels
} // end refresh or labels
if (!$_POST['form_labels']) {
?>
</tbody>
</table>
</div>
</form>
</body>
<!-- stuff for the popup calendar -->
<style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
<script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
<?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
<script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
<script language="Javascript">
Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
</script>
</html>
<?php
} // end not labels
?>