2 // Copyright (C) 2006-2015 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">
65 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
67 $
(document
).ready(function() {
68 var win
= top
.printLogSetup ? top
: opener
.top
;
69 win
.printLogSetup(document
.getElementById('printbutton'));
74 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
75 <style type
="text/css">
77 /* specifically include & exclude from printing */
83 #report_parameters_daterange {
89 /* specifically exclude some from the screen */
91 #report_parameters_daterange {
100 <body
class="body_top">
102 <!-- Required
for the popup date selectors
-->
103 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
105 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Unique Seen Patients','e'); ?
></span
>
107 <div id
="report_parameters_daterange">
108 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
111 <form name
='theform' method
='post' action
='unique_seen_patients_report.php' id
='theform'>
113 <div id
="report_parameters">
114 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
115 <input type
='hidden' name
='form_labels' id
='form_labels' value
=''/>
120 <div style
='float:left'>
125 <?php
xl('Visits From','e'); ?
>:
128 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_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_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
132 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
135 <?php
xl('To','e'); ?
>:
138 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
139 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
140 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
141 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
142 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
150 <td align
='left' valign
='middle' height
="100%">
151 <table style
='border-left:1px solid; width:100%; height:100%' >
154 <div style
='margin-left:15px'>
155 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
157 <?php
xl('Submit','e'); ?
>
161 <?php
if ($_POST['form_refresh']) { ?
>
162 <a href
='#' class='css_button' id
='printbutton'>
164 <?php
xl('Print','e'); ?
>
167 <a href
='#' class='css_button' onclick
='$("#form_labels").attr("value","true"); $("#theform").submit();'>
169 <?php
xl('Labels','e'); ?
>
180 </div
> <!-- end of parameters
-->
182 <div id
="report_results">
186 <th
> <?php
xl('Last Visit','e'); ?
> </th
>
187 <th
> <?php
xl('Patient','e'); ?
> </th
>
188 <th align
='right'> <?php
xl('Visits','e'); ?
> </th
>
189 <th align
='right'> <?php
xl('Age','e'); ?
> </th
>
190 <th
> <?php
xl('Sex','e'); ?
> </th
>
191 <th
> <?php
xl('Race','e'); ?
> </th
>
192 <th
> <?php
xl('Primary Insurance','e'); ?
> </th
>
193 <th
> <?php
xl('Secondary Insurance','e'); ?
> </th
>
197 } // end not generating labels
199 if ($_POST['form_refresh'] ||
$_POST['form_labels']) {
203 "p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
204 "p.street, p.city, p.state, p.postal_code, " .
205 "count(e.date) AS ecount, max(e.date) AS edate, " .
206 "i1.date AS idate1, i2.date AS idate2, " .
207 "c1.name AS cname1, c2.name AS cname2 " .
208 "FROM patient_data AS p " .
209 "JOIN form_encounter AS e ON " .
210 "e.pid = p.pid AND " .
211 "e.date >= '$from_date 00:00:00' AND " .
212 "e.date <= '$to_date 23:59:59' " .
213 "LEFT OUTER JOIN insurance_data AS i1 ON " .
214 "i1.pid = p.pid AND i1.type = 'primary' " .
215 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
216 "c1.id = i1.provider " .
217 "LEFT OUTER JOIN insurance_data AS i2 ON " .
218 "i2.pid = p.pid AND i2.type = 'secondary' " .
219 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
220 "c2.id = i2.provider " .
221 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
222 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
223 $res = sqlStatement($query);
226 while ($row = sqlFetchArray($res)) {
227 if ($row['pid'] == $prevpid) continue;
228 $prevpid = $row['pid'];
233 $tdy = $row['edate'];
234 $ageInMonths = (substr($tdy,0,4)*12) +
substr($tdy,5,2) -
235 (substr($dob,0,4)*12) - substr($dob,5,2);
236 $dayDiff = substr($tdy,8,2) - substr($dob,8,2);
237 if ($dayDiff < 0) --$ageInMonths;
238 $age = intval($ageInMonths/12);
241 if ($_POST['form_labels']) {
242 echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
243 $row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
244 $row['postal_code'] . '"' . "\n";
250 <?php
echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?
>
253 <?php
echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?
>
255 <td style
="text-align:center">
256 <?php
echo $row['ecount'] ?
>
262 <?php
echo $row['sex'] ?
>
265 <?php
echo $row['ethnoracial'] ?
>
268 <?php
echo $row['cname1'] ?
>
271 <?php
echo $row['cname2'] ?
>
279 if (!$_POST['form_labels']) {
281 <tr
class='report_totals'>
283 <?php
xl('Total Number of Patients','e'); ?
>
285 <td style
="padding-left: 20px;">
286 <?php
echo $totalpts ?
>
288 <td colspan
='5'> 
;</td
>
293 } // end refresh or labels
295 if (!$_POST['form_labels']) {
303 <!-- stuff
for the popup calendar
-->
304 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
305 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
306 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
307 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
308 <script language
="Javascript">
309 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
310 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});