To make it easy to download the latest version from online CVS browser.
[openemr.git] / interface / reports / unique_seen_patients_report.php
blob4990c0018c4cc15a87c3ca14fc6ac67fc7b882ca
1 <?
2 // Copyright (C) 2006 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 <html>
19 <head>
20 <title><? xl('Front Office Receipts','e'); ?></title>
21 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
22 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
23 <script type="text/javascript" src="../../library/calendar.js"></script>
24 <script type="text/javascript" src="../../library/textformat.js"></script>
25 <script type="text/javascript" src="../../library/dialog.js"></script>
26 <script language="JavaScript">
27 var mypcc = '<? echo $GLOBALS['phone_country_code'] ?>';
28 </script>
29 </head>
31 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
33 <!-- Required for the popup date selectors -->
34 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
36 <center>
38 <h2><? xl('Unique Seen Patients','e'); ?></h2>
40 <form name='theform' method='post' action='unique_seen_patients_report.php'>
42 <table border='0' cellpadding='3'>
44 <tr>
45 <td>
46 <? xl('Visits From','e'); ?>:
47 <input type='text' name='form_from_date' size='10' value='<? echo $from_date ?>'
48 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
49 <a href="javascript:show_calendar('theform.form_from_date')"
50 title=".xl('Click here to choose a date')."
51 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
52 &nbsp;<? xl('To','e'); ?>:
53 <input type='text' name='form_to_date' size='10' value='<? echo $to_date ?>'
54 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
55 <a href="javascript:show_calendar('theform.form_to_date')"
56 title=".xl('Click here to choose a date')."
57 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
58 &nbsp;
59 <input type='submit' name='form_refresh' value=<? xl('Refresh','e'); ?>>
60 </td>
61 </tr>
63 <tr>
64 <td height="1">
65 </td>
66 </tr>
68 </table>
70 <table border='0' cellpadding='1' cellspacing='3' width='98%'>
72 <tr bgcolor="#dddddd">
73 <td class="dehead">
74 <? xl('Last Visit','e'); ?>
75 </td>
76 <td class='dehead'>
77 <? xl('Patient','e'); ?>
78 </td>
79 <td class='dehead' align='right'>
80 <? xl('Visits','e'); ?>
81 </td>
82 <td class='dehead' align='right'>
83 <? xl('Age','e'); ?>
84 </td>
85 <td class='dehead'>
86 <? xl('Sex','e'); ?>
87 </td>
88 <td class='dehead'>
89 <? xl('Race','e'); ?>
90 </td>
91 <td class='dehead'>
92 <? xl('Primary Insurance','e'); ?>
93 </td>
94 <td class='dehead'>
95 <? xl('Secondary Insurance','e'); ?>
96 </td>
97 </tr>
99 if ($_POST['form_refresh']) {
100 $totalpts = 0;
102 $query = "SELECT " .
103 "p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
104 "count(e.date) AS ecount, max(e.date) AS edate, " .
105 "c1.name AS cname1, c2.name AS cname2 " .
106 "FROM patient_data AS p " .
107 "JOIN form_encounter AS e ON " .
108 "e.pid = p.pid AND " .
109 "e.date >= '$from_date 00:00:00' AND " .
110 "e.date <= '$to_date 23:59:59' " .
111 "LEFT OUTER JOIN insurance_data AS i1 ON " .
112 "i1.pid = p.pid AND i1.type = 'primary' " .
113 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
114 "c1.id = i1.provider " .
115 "LEFT OUTER JOIN insurance_data AS i2 ON " .
116 "i2.pid = p.pid AND i2.type = 'secondary' " .
117 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
118 "c2.id = i2.provider " .
119 "GROUP BY p.lname, p.fname, p.mname, p.pid " .
120 "ORDER BY p.lname, p.fname, p.mname, p.pid";
122 // echo "<!-- $query -->\n"; // debugging
123 $res = sqlStatement($query);
125 while ($row = sqlFetchArray($res)) {
126 $age = '';
127 if ($row['DOB']) {
128 $dob = $row['DOB'];
129 $tdy = $row['edate'];
130 $ageInMonths = (substr($tdy,0,4)*12) + substr($tdy,5,2) -
131 (substr($dob,0,4)*12) - substr($dob,5,2);
132 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
133 if ($dayDiff < 0) --$ageInMonths;
134 $age = intval($ageInMonths/12);
137 <tr>
138 <td class='detail'>
139 <?php echo substr($row['edate'], 0, 10) ?>
140 </td>
141 <td class='detail'>
142 <?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
143 </td>
144 <td class='detail' align='right'>
145 <?php echo $row['ecount'] ?>
146 </td>
147 <td class='detail' align='right'>
148 <?php echo $age ?>
149 </td>
150 <td class='detail'>
151 <?php echo $row['sex'] ?>
152 </td>
153 <td class='detail'>
154 <?php echo $row['ethnoracial'] ?>
155 </td>
156 <td class='detail'>
157 <?php echo $row['cname1'] ?>
158 </td>
159 <td class='detail'>
160 <?php echo $row['cname2'] ?>
161 </td>
162 </tr>
163 <?php
164 ++$totalpts;
168 <tr>
169 <td class='dehead' colspan='8'>
170 &nbsp;
171 </td>
172 </tr>
174 <tr>
175 <td class='dehead' colspan='3'>
176 <? xl('Total Number of Patients','e'); ?>
177 </td>
178 <td class='detail' colspan='4'>
179 <?php echo $totalpts ?>
180 </td>
181 </tr>
183 <?php
187 </table>
188 </form>
189 </center>
190 </body>
191 </html>