2 // Copyright (C) 2006-2010 Rod Roark <rod@sunsetsystems.com>
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
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'));
19 if ($_POST['form_labels']) {
20 header("Pragma: public");
22 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
23 header("Content-Type: application/force-download");
24 header("Content-Disposition: attachment; filename=labels.txt");
25 header("Content-Description: File Transfer");
31 <?php
html_header_show();?
>
32 <style type
="text/css">
33 /* specifically include & exclude from printing */
39 #report_parameters_daterange {
48 /* specifically exclude some from the screen */
50 #report_parameters_daterange {
56 <title
><?php
xl('Front Office Receipts','e'); ?
></title
>
58 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
59 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
60 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
61 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
63 <script language
="JavaScript">
64 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
67 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
68 <style type
="text/css">
70 /* specifically include & exclude from printing */
76 #report_parameters_daterange {
82 /* specifically exclude some from the screen */
84 #report_parameters_daterange {
93 <body
class="body_top">
95 <!-- Required
for the popup date selectors
-->
96 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
98 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Unique Seen Patients','e'); ?
></span
>
100 <div id
="report_parameters_daterange">
101 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
104 <form name
='theform' method
='post' action
='unique_seen_patients_report.php' id
='theform'>
106 <div id
="report_parameters">
107 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
108 <input type
='hidden' name
='form_labels' id
='form_labels' value
=''/>
113 <div style
='float:left'>
118 <?php
xl('Visits From','e'); ?
>:
121 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
122 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
123 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
124 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
125 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
128 <?php
xl('To','e'); ?
>:
131 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
132 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
133 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
134 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
135 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
143 <td align
='left' valign
='middle' height
="100%">
144 <table style
='border-left:1px solid; width:100%; height:100%' >
147 <div style
='margin-left:15px'>
148 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
150 <?php
xl('Submit','e'); ?
>
154 <?php
if ($_POST['form_refresh']) { ?
>
155 <a href
='#' class='css_button' onclick
='window.print()'>
157 <?php
xl('Print','e'); ?
>
160 <a href
='#' class='css_button' onclick
='$("#form_labels").attr("value","true"); $("#theform").submit();'>
162 <?php
xl('Labels','e'); ?
>
173 </div
> <!-- end of parameters
-->
175 <div id
="report_results">
179 <th
> <?php
xl('Last Visit','e'); ?
> </th
>
180 <th
> <?php
xl('Patient','e'); ?
> </th
>
181 <th align
='right'> <?php
xl('Visits','e'); ?
> </th
>
182 <th align
='right'> <?php
xl('Age','e'); ?
> </th
>
183 <th
> <?php
xl('Sex','e'); ?
> </th
>
184 <th
> <?php
xl('Race','e'); ?
> </th
>
185 <th
> <?php
xl('Primary Insurance','e'); ?
> </th
>
186 <th
> <?php
xl('Secondary Insurance','e'); ?
> </th
>
190 } // end not generating labels
192 if ($_POST['form_refresh'] ||
$_POST['form_labels']) {
196 "p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
197 "p.street, p.city, p.state, p.postal_code, " .
198 "count(e.date) AS ecount, max(e.date) AS edate, " .
199 "i1.date AS idate1, i2.date AS idate2, " .
200 "c1.name AS cname1, c2.name AS cname2 " .
201 "FROM patient_data AS p " .
202 "JOIN form_encounter AS e ON " .
203 "e.pid = p.pid AND " .
204 "e.date >= '$from_date 00:00:00' AND " .
205 "e.date <= '$to_date 23:59:59' " .
206 "LEFT OUTER JOIN insurance_data AS i1 ON " .
207 "i1.pid = p.pid AND i1.type = 'primary' " .
208 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
209 "c1.id = i1.provider " .
210 "LEFT OUTER JOIN insurance_data AS i2 ON " .
211 "i2.pid = p.pid AND i2.type = 'secondary' " .
212 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
213 "c2.id = i2.provider " .
214 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
215 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
216 $res = sqlStatement($query);
219 while ($row = sqlFetchArray($res)) {
220 if ($row['pid'] == $prevpid) continue;
221 $prevpid = $row['pid'];
226 $tdy = $row['edate'];
227 $ageInMonths = (substr($tdy,0,4)*12) +
substr($tdy,5,2) -
228 (substr($dob,0,4)*12) - substr($dob,5,2);
229 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
230 if ($dayDiff < 0) --$ageInMonths;
231 $age = intval($ageInMonths/12);
234 if ($_POST['form_labels']) {
235 echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
236 $row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
237 $row['postal_code'] . '"' . "\n";
243 <?php
echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?
>
246 <?php
echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?
>
248 <td style
="text-align:center">
249 <?php
echo $row['ecount'] ?
>
255 <?php
echo $row['sex'] ?
>
258 <?php
echo $row['ethnoracial'] ?
>
261 <?php
echo $row['cname1'] ?
>
264 <?php
echo $row['cname2'] ?
>
272 if (!$_POST['form_labels']) {
274 <tr
class='report_totals'>
276 <?php
xl('Total Number of Patients','e'); ?
>
278 <td style
="padding-left: 20px;">
279 <?php
echo $totalpts ?
>
281 <td colspan
='5'> 
;</td
>
286 } // end refresh or labels
288 if (!$_POST['form_labels']) {
296 <!-- stuff
for the popup calendar
-->
297 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
298 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
299 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
300 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
301 <script language
="Javascript">
302 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
303 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});