3 * This report lists patients that were seen within a given date
6 * Copyright (C) 2006-2015 Rod Roark <rod@sunsetsystems.com>
7 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @author Rod Roark <rod@sunsetsystems.com>
22 * @author Brady Miller <brady.g.miller@gmail.com>
23 * @link http://www.open-emr.org
26 use OpenEMR\Core\Header
;
28 require_once("../globals.php");
29 require_once("$srcdir/patient.inc");
31 $form_from_date = (!empty($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01');
32 $form_to_date = (!empty($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : date('Y-12-31');
34 if ($_POST['form_labels']) {
35 header("Pragma: public");
37 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
38 header("Content-Type: application/force-download");
39 header("Content-Disposition: attachment; filename=labels.txt");
40 header("Content-Description: File Transfer");
46 <style type
="text/css">
47 /* specifically include & exclude from printing */
53 #report_parameters_daterange {
62 /* specifically exclude some from the screen */
64 #report_parameters_daterange {
70 <title
><?php
xl('Front Office Receipts', 'e'); ?
></title
>
72 <?php Header
::setupHeader('datetime-picker'); ?
>
74 <script language
="JavaScript">
76 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
78 $
(document
).ready(function() {
79 var win
= top
.printLogSetup ? top
: opener
.top
;
80 win
.printLogSetup(document
.getElementById('printbutton'));
82 $
('.datepicker').datetimepicker({
83 <?php
$datetimepicker_timepicker = false; ?
>
84 <?php
$datetimepicker_showseconds = false; ?
>
85 <?php
$datetimepicker_formatInput = true; ?
>
86 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
87 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
93 <style type
="text/css">
95 /* specifically include & exclude from printing */
101 #report_parameters_daterange {
107 /* specifically exclude some from the screen */
109 #report_parameters_daterange {
118 <body
class="body_top">
120 <!-- Required
for the popup date selectors
-->
121 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
123 <span
class='title'><?php
xl('Report', 'e'); ?
> - <?php
xl('Unique Seen Patients', 'e'); ?
></span
>
125 <div id
="report_parameters_daterange">
126 <?php
echo oeFormatShortDate($form_from_date) ." to ". oeFormatShortDate($form_to_date); ?
>
129 <form name
='theform' method
='post' action
='unique_seen_patients_report.php' id
='theform'>
131 <div id
="report_parameters">
132 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
133 <input type
='hidden' name
='form_labels' id
='form_labels' value
=''/>
138 <div style
='float:left'>
142 <td
class='control-label'>
143 <?php
xl('Visits From', 'e'); ?
>:
146 <input type
='text' class='datepicker form-control' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo oeFormatShortDate($form_from_date); ?>'>
148 <td
class='control-label'>
149 <?php
xl('To', 'e'); ?
>:
152 <input type
='text' class='datepicker form-control' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo oeFormatShortDate($form_to_date); ?>'>
160 <td align
='left' valign
='middle' height
="100%">
161 <table style
='border-left:1px solid; width:100%; height:100%' >
164 <div
class="text-center">
165 <div
class="btn-group" role
="group">
166 <a href
='#' class='btn btn-default btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#form_labels").val(""); $("#theform").submit();'>
167 <?php
echo xlt('Submit'); ?
>
169 <?php
if ($_POST['form_refresh']) { ?
>
170 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
171 <?php
echo xlt('Print'); ?
>
173 <a href
='#' class='btn btn-default btn-transmit' onclick
='$("#form_labels").attr("value","true"); $("#theform").submit();'>
174 <?php
echo xlt('Labels'); ?
>
185 </div
> <!-- end of parameters
-->
187 <div id
="report_results">
191 <th
> <?php
xl('Last Visit', 'e'); ?
> </th
>
192 <th
> <?php
xl('Patient', 'e'); ?
> </th
>
193 <th align
='right'> <?php
xl('Visits', 'e'); ?
> </th
>
194 <th align
='right'> <?php
xl('Age', 'e'); ?
> </th
>
195 <th
> <?php
xl('Sex', 'e'); ?
> </th
>
196 <th
> <?php
xl('Race', 'e'); ?
> </th
>
197 <th
> <?php
xl('Primary Insurance', 'e'); ?
> </th
>
198 <th
> <?php
xl('Secondary Insurance', 'e'); ?
> </th
>
202 } // end not generating labels
204 if ($_POST['form_refresh'] ||
$_POST['form_labels']) {
208 "p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
209 "p.street, p.city, p.state, p.postal_code, " .
210 "count(e.date) AS ecount, max(e.date) AS edate, " .
211 "i1.date AS idate1, i2.date AS idate2, " .
212 "c1.name AS cname1, c2.name AS cname2 " .
213 "FROM patient_data AS p " .
214 "JOIN form_encounter AS e ON " .
215 "e.pid = p.pid AND " .
216 "e.date >= '$form_from_date 00:00:00' AND " .
217 "e.date <= '$form_to_date 23:59:59' " .
218 "LEFT OUTER JOIN insurance_data AS i1 ON " .
219 "i1.pid = p.pid AND i1.type = 'primary' " .
220 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
221 "c1.id = i1.provider " .
222 "LEFT OUTER JOIN insurance_data AS i2 ON " .
223 "i2.pid = p.pid AND i2.type = 'secondary' " .
224 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
225 "c2.id = i2.provider " .
226 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
227 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
228 $res = sqlStatement($query);
231 while ($row = sqlFetchArray($res)) {
232 if ($row['pid'] == $prevpid) {
236 $prevpid = $row['pid'];
241 $tdy = $row['edate'];
242 $ageInMonths = (substr($tdy, 0, 4)*12) +
substr($tdy, 5, 2) -
243 (substr($dob, 0, 4)*12) - substr($dob, 5, 2);
244 $dayDiff = substr($tdy, 8, 2) - substr($dob, 8, 2);
249 $age = intval($ageInMonths/12);
252 if ($_POST['form_labels']) {
253 echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
254 $row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
255 $row['postal_code'] . '"' . "\n";
256 } else { // not labels
260 <?php
echo oeFormatShortDate(substr($row['edate'], 0, 10)) ?
>
263 <?php
echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?
>
265 <td style
="text-align:center">
266 <?php
echo $row['ecount'] ?
>
272 <?php
echo $row['sex'] ?
>
275 <?php
echo $row['ethnoracial'] ?
>
278 <?php
echo $row['cname1'] ?
>
281 <?php
echo $row['cname2'] ?
>
289 if (!$_POST['form_labels']) {
291 <tr
class='report_totals'>
293 <?php
xl('Total Number of Patients', 'e'); ?
>
295 <td style
="padding-left: 20px;">
296 <?php
echo $totalpts ?
>
298 <td colspan
='5'> 
;</td
>
303 } // end refresh or labels
305 if (!$_POST['form_labels']) {