4 * This report lists patients that were seen within a given date
8 * @link http://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2006-2015 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("../globals.php");
17 require_once("$srcdir/patient.inc");
19 use OpenEMR\Common\Csrf\CsrfUtils
;
20 use OpenEMR\Core\Header
;
23 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
24 CsrfUtils
::csrfNotVerified();
28 $form_from_date = (!empty($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01');
29 $form_to_date = (!empty($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : date('Y-12-31');
31 if (!empty($_POST['form_labels'])) {
32 header("Pragma: public");
34 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
35 header("Content-Type: application/force-download");
36 header("Content-Disposition: attachment; filename=labels.txt");
37 header("Content-Description: File Transfer");
44 /* specifically include & exclude from printing */
50 #report_parameters_daterange {
59 /* specifically exclude some from the screen */
61 #report_parameters_daterange {
67 <title
><?php
echo xlt('Front Office Receipts'); ?
></title
>
69 <?php Header
::setupHeader('datetime-picker'); ?
>
74 var win
= top
.printLogSetup ? top
: opener
.top
;
75 win
.printLogSetup(document
.getElementById('printbutton'));
77 $
('.datepicker').datetimepicker({
78 <?php
$datetimepicker_timepicker = false; ?
>
79 <?php
$datetimepicker_showseconds = false; ?
>
80 <?php
$datetimepicker_formatInput = true; ?
>
81 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
82 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
90 /* specifically include & exclude from printing */
96 #report_parameters_daterange {
102 /* specifically exclude some from the screen */
104 #report_parameters_daterange {
113 <body
class="body_top">
115 <!-- Required
for the popup date selectors
-->
116 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
118 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Unique Seen Patients'); ?
></span
>
120 <div id
="report_parameters_daterange">
121 <?php
echo text(oeFormatShortDate($form_from_date)) . " " . xlt("to{{Range}}") . " " . text(oeFormatShortDate($form_to_date)); ?
>
124 <form name
='theform' method
='post' action
='unique_seen_patients_report.php' id
='theform' onsubmit
='return top.restoreSession()'>
125 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
127 <div id
="report_parameters">
128 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
129 <input type
='hidden' name
='form_labels' id
='form_labels' value
=''/>
134 <div style
='float:left'>
138 <td
class='col-form-label'>
139 <?php
echo xlt('Visits From'); ?
>:
142 <input type
='text' class='datepicker form-control' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_from_date)); ?>'>
144 <td
class='col-form-label'>
145 <?php
echo xlt('To{{Range}}'); ?
>:
148 <input type
='text' class='datepicker form-control' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_to_date)); ?>'>
156 <td
class='h-100' align
='left' valign
='middle' height
="100%">
157 <table
class='w-100 h-100' style
='border-left:1px solid'>
160 <div
class="text-center">
161 <div
class="btn-group" role
="group">
162 <a href
='#' class='btn btn-secondary btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#form_labels").val(""); $("#theform").submit();'>
163 <?php
echo xlt('Submit'); ?
>
165 <?php
if (!empty($_POST['form_refresh'])) { ?
>
166 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
167 <?php
echo xlt('Print'); ?
>
169 <a href
='#' class='btn btn-secondary btn-transmit' onclick
='$("#form_labels").attr("value","true"); $("#theform").submit();'>
170 <?php
echo xlt('Labels'); ?
>
181 </div
> <!-- end of parameters
-->
183 <div id
="report_results">
184 <table
class='table'>
186 <thead
class='thead-light'>
187 <th
> <?php
echo xlt('Last Visit'); ?
> </th
>
188 <th
> <?php
echo xlt('Patient'); ?
> </th
>
189 <th align
='right'> <?php
echo xlt('Visits'); ?
> </th
>
190 <th align
='right'> <?php
echo xlt('Age'); ?
> </th
>
191 <th
> <?php
echo xlt('Sex'); ?
> </th
>
192 <th
> <?php
echo xlt('Race'); ?
> </th
>
193 <th
> <?php
echo xlt('Primary Insurance'); ?
> </th
>
194 <th
> <?php
echo xlt('Secondary Insurance'); ?
> </th
>
198 } // end not generating labels
200 if (!empty($_POST['form_refresh']) ||
!empty($_POST['form_labels'])) {
204 "p.pid, p.fname, p.mname, p.lname, p.DOB, p.sex, p.ethnoracial, " .
205 "p.street, p.city, p.state, p.postal_code, " .
206 "count(e.date) AS ecount, max(e.date) AS edate, " .
207 "i1.date AS idate1, i2.date AS idate2, " .
208 "c1.name AS cname1, c2.name AS cname2 " .
209 "FROM patient_data AS p " .
210 "JOIN form_encounter AS e ON " .
211 "e.pid = p.pid AND " .
214 "LEFT OUTER JOIN insurance_data AS i1 ON " .
215 "i1.pid = p.pid AND i1.type = 'primary' " .
216 "LEFT OUTER JOIN insurance_companies AS c1 ON " .
217 "c1.id = i1.provider " .
218 "LEFT OUTER JOIN insurance_data AS i2 ON " .
219 "i2.pid = p.pid AND i2.type = 'secondary' " .
220 "LEFT OUTER JOIN insurance_companies AS c2 ON " .
221 "c2.id = i2.provider " .
222 "GROUP BY p.lname, p.fname, p.mname, p.pid, i1.date, i2.date " .
223 "ORDER BY p.lname, p.fname, p.mname, p.pid, i1.date DESC, i2.date DESC";
224 $res = sqlStatement($query, array($form_from_date . ' 00:00:00', $form_to_date . ' 23:59:59'));
227 while ($row = sqlFetchArray($res)) {
228 if ($row['pid'] == $prevpid) {
232 $prevpid = $row['pid'];
237 $tdy = $row['edate'];
238 $ageInMonths = (substr($tdy, 0, 4) * 12) +
substr($tdy, 5, 2) -
239 (substr($dob, 0, 4) * 12) - substr($dob, 5, 2);
240 $dayDiff = substr($tdy, 8, 2) - substr($dob, 8, 2);
245 $age = intval($ageInMonths / 12);
248 if ($_POST['form_labels']) {
249 echo '"' . $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] . '","' .
250 $row['street'] . '","' . $row['city'] . '","' . $row['state'] . '","' .
251 $row['postal_code'] . '"' . "\n";
252 } else { // not labels
256 <?php
echo text(oeFormatShortDate(substr($row['edate'], 0, 10))); ?
>
259 <?php
echo text($row['lname']) . ', ' . text($row['fname']) . ' ' . text($row['mname']); ?
>
261 <td style
="text-align:center">
262 <?php
echo text($row['ecount']); ?
>
265 <?php
echo text($age); ?
>
268 <?php
echo text($row['sex']); ?
>
271 <?php
echo text($row['ethnoracial']); ?
>
274 <?php
echo text($row['cname1']); ?
>
277 <?php
echo text($row['cname2']); ?
>
285 if (!$_POST['form_labels']) {
287 <tr
class='report_totals'>
289 <?php
echo xlt('Total Number of Patients'); ?
>
291 <td style
="padding-left: 20px;">
292 <?php
echo text($totalpts); ?
>
294 <td colspan
='5'> 
;</td
>
299 } // end refresh or labels
301 if (empty($_POST['form_labels'])) {