5 * This report shows past encounters with filtering and sorting,
6 * Added filtering to show encounters not e-signed, encounters e-signed and forms e-signed.
8 * Copyright (C) 2015 Terry Hill <terry@lillysystems.com>
9 * Copyright (C) 2007-2016 Rod Roark <rod@sunsetsystems.com>
10 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
12 * LICENSE: This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 3
15 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
24 * @author Terry Hill <terry@lilysystems.com>
25 * @author Rod Roark <rod@sunsetsystems.com>
26 * @author Brady Miller <brady.g.miller@gmail.com>
27 * @link http://www.open-emr.org
31 use OpenEMR\Core\Header
;
33 require_once("../globals.php");
34 require_once("$srcdir/forms.inc");
35 require_once("$srcdir/billing.inc");
36 require_once("$srcdir/patient.inc");
37 require_once "$srcdir/options.inc.php";
39 $alertmsg = ''; // not used yet but maybe later
41 // For each sorting option, specify the ORDER BY argument.
44 'doctor' => 'lower(u.lname), lower(u.fname), fe.date',
45 'patient' => 'lower(p.lname), lower(p.fname), fe.date',
46 'pubpid' => 'lower(p.pubpid), fe.date',
47 'time' => 'fe.date, lower(u.lname), lower(u.fname)',
48 'encounter' => 'fe.encounter, fe.date, lower(u.lname), lower(u.fname)',
51 function bucks($amount)
54 printf("%.2f", $amount);
58 function show_doc_total($lastdocname, $doc_encounters)
62 echo " <td class='detail'>$lastdocname</td>\n";
63 echo " <td class='detail' align='right'>$doc_encounters</td>\n";
68 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
69 $form_to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
70 $form_provider = $_POST['form_provider'];
71 $form_facility = $_POST['form_facility'];
72 $form_details = $_POST['form_details'] ?
true : false;
73 $form_new_patients = $_POST['form_new_patients'] ?
true : false;
74 $form_esigned = $_POST['form_esigned'] ?
true : false;
75 $form_not_esigned = $_POST['form_not_esigned'] ?
true : false;
76 $form_encounter_esigned = $_POST['form_encounter_esigned'] ?
true : false;
78 $form_orderby = $ORDERHASH[$_REQUEST['form_orderby']] ?
79 $_REQUEST['form_orderby'] : 'doctor';
80 $orderby = $ORDERHASH[$form_orderby];
86 if ($form_encounter_esigned) {
87 $esign_fields = ", es.table, es.tid ";
88 $esign_joins = "LEFT OUTER JOIN esign_signatures AS es ON es.tid = fe.encounter ";
92 $esign_fields = ", es.table, es.tid ";
93 $esign_joins = "LEFT OUTER JOIN esign_signatures AS es ON es.tid = fe.encounter ";
96 if ($form_not_esigned) {
97 $esign_fields = ", es.table, es.tid ";
98 $esign_joins = "LEFT JOIN esign_signatures AS es on es.tid = fe.encounter ";
102 "fe.encounter, fe.date, fe.reason, " .
103 "f.formdir, f.form_name, " .
104 "p.fname, p.mname, p.lname, p.pid, p.pubpid, " .
105 "u.lname AS ulname, u.fname AS ufname, u.mname AS umname " .
107 "FROM ( form_encounter AS fe, forms AS f ) " .
108 "LEFT OUTER JOIN patient_data AS p ON p.pid = fe.pid " .
109 "LEFT JOIN users AS u ON u.id = fe.provider_id " .
111 "WHERE f.pid = fe.pid AND f.encounter = fe.encounter AND f.formdir = 'newpatient' ";
113 $query .= "AND fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59' ";
115 $query .= "AND fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_from_date 23:59:59' ";
118 if ($form_provider) {
119 $query .= "AND fe.provider_id = '$form_provider' ";
122 if ($form_facility) {
123 $query .= "AND fe.facility_id = '$form_facility' ";
126 if ($form_new_patients) {
127 $query .= "AND fe.date = (SELECT MIN(fe2.date) FROM form_encounter AS fe2 WHERE fe2.pid = fe.pid) ";
130 if ($form_encounter_esigned) {
131 $query .= "AND es.tid = fe.encounter AND es.table = 'form_encounter' ";
135 $query .= "AND es.tid = fe.encounter ";
138 if ($form_not_esigned) {
139 $query .= "AND es.tid IS NULL ";
142 $query .= "ORDER BY $orderby";
144 $res = sqlStatement($query);
149 <title
><?php
echo xlt('Encounters Report'); ?
></title
>
151 <?php Header
::setupHeader(['datetime-picker', 'report-helper']); ?
>
153 <style type
="text/css">
155 /* specifically include & exclude from printing */
161 #report_parameters_daterange {
165 #report_results table {
170 /* specifically exclude some from the screen */
172 #report_parameters_daterange {
180 <script LANGUAGE
="JavaScript">
182 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
184 $
(document
).ready(function() {
185 oeFixedHeaderSetup(document
.getElementById('mymaintable'));
186 var win
= top
.printLogSetup ? top
: opener
.top
;
187 win
.printLogSetup(document
.getElementById('printbutton'));
189 $
('.datepicker').datetimepicker({
190 <?php
$datetimepicker_timepicker = false; ?
>
191 <?php
$datetimepicker_showseconds = false; ?
>
192 <?php
$datetimepicker_formatInput = false; ?
>
193 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
194 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
198 function dosort(orderby
) {
199 var f
= document
.forms
[0];
200 f
.form_orderby
.value
= orderby
;
205 function refreshme() {
206 document
.forms
[0].submit();
212 <body
class="body_top">
213 <!-- Required
for the popup date selectors
-->
214 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
216 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Encounters'); ?
></span
>
218 <div id
="report_parameters_daterange">
219 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
222 <form method
='post' name
='theform' id
='theform' action
='encounters_report.php' onsubmit
='return top.restoreSession()'>
224 <div id
="report_parameters">
228 <div style
='float:left'>
232 <td
class='control-label'>
233 <?php
echo xlt('Facility'); ?
>:
236 <?php
dropdown_facility($form_facility, 'form_facility', true); ?
>
238 <td
class='control-label'>
239 <?php
echo xlt('Provider'); ?
>:
244 // Build a drop-down list of providers.
247 $query = "SELECT id, lname, fname FROM users WHERE ".
248 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
250 $ures = sqlStatement($query);
252 echo " <select name='form_provider' class='form-control'>\n";
253 echo " <option value=''>-- " . xlt('All') . " --\n";
255 while ($urow = sqlFetchArray($ures)) {
256 $provid = $urow['id'];
257 echo " <option value='" . attr($provid) . "'";
258 if ($provid == $_POST['form_provider']) {
262 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
271 <td
class='control-label'>
272 <?php
echo xlt('From'); ?
>:
275 <input type
='text' class='datepicker form-control' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr($form_from_date) ?>'
278 <td
class='control-label'>
279 <?php
echo xlt('To'); ?
>:
282 <input type
='text' class='datepicker form-control' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr($form_to_date) ?>'
289 <div
class="checkbox">
290 <label
><input type
='checkbox' name
='form_details'<?php
if ($form_details) {
293 <?php
echo xlt('Details'); ?
></label
>
295 <div
class="checkbox">
296 <label
><input type
='checkbox' name
='form_new_patients' title
='<?php echo xla('First
-time visits only
'); ?>'<?php
if ($form_new_patients) {
299 <?php
echo xlt('New'); ?
></label
>
304 <div
class="checkbox">
305 <label
><input type
='checkbox' name
='form_esigned'<?php
if ($form_esigned) {
308 <?php
echo xlt('Forms Esigned'); ?
></label
>
310 <div
class="checkbox">
311 <label
><input type
='checkbox' name
='form_encounter_esigned'<?php
if ($form_encounter_esigned) {
314 <?php
echo xlt('Encounter Esigned'); ?
></label
>
316 <div
class="checkbox">
317 <label
><input type
='checkbox' name
='form_not_esigned'<?php
if ($form_not_esigned) {
320 <?php
echo xlt('Not Esigned'); ?
></label
>
329 <td align
='left' valign
='middle' height
="100%">
330 <table style
='border-left:1px solid; width:100%; height:100%' >
333 <div
class="text-center">
334 <div
class="btn-group" role
="group">
335 <a href
='#' class='btn btn-default btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
336 <?php
echo xlt('Submit'); ?
>
338 <?php
if ($_POST['form_refresh'] ||
$_POST['form_orderby']) { ?
>
339 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
340 <?php
echo xlt('Print'); ?
>
352 </div
> <!-- end report_parameters
-->
355 if ($_POST['form_refresh'] ||
$_POST['form_orderby']) {
357 <div id
="report_results">
358 <table id
='mymaintable'>
360 <?php
if ($form_details) { ?
>
362 <a href
="nojs.php" onclick
="return dosort('doctor')"
363 <?php
if ($form_orderby == "doctor") {
364 echo " style=\"color:#00cc00\"";
365 } ?
>><?php
echo xlt('Provider'); ?
> </a
>
368 <a href
="nojs.php" onclick
="return dosort('time')"
369 <?php
if ($form_orderby == "time") {
370 echo " style=\"color:#00cc00\"";
371 } ?
>><?php
echo xlt('Date'); ?
></a
>
374 <a href
="nojs.php" onclick
="return dosort('patient')"
375 <?php
if ($form_orderby == "patient") {
376 echo " style=\"color:#00cc00\"";
377 } ?
>><?php
echo xlt('Patient'); ?
></a
>
380 <a href
="nojs.php" onclick
="return dosort('pubpid')"
381 <?php
if ($form_orderby == "pubpid") {
382 echo " style=\"color:#00cc00\"";
383 } ?
>><?php
echo xlt('ID'); ?
></a
>
386 <?php
echo xlt('Status'); ?
>
389 <?php
echo xlt('Encounter'); ?
>
392 <a href
="nojs.php" onclick
="return dosort('encounter')"
393 <?php
if ($form_orderby == "encounter") {
394 echo " style=\"color:#00cc00\"";
395 } ?
>><?php
echo xlt('Encounter Number'); ?
></a
>
398 <?php
echo xlt('Form'); ?
>
401 <?php
echo xlt('Coding'); ?
>
404 <th
><?php
echo xlt('Provider'); ?
></td
>
405 <th
><?php
echo xlt('Encounters'); ?
></td
>
413 while ($row = sqlFetchArray($res)) {
414 $patient_id = $row['pid'];
417 if (!empty($row['ulname']) ||
!empty($row['ufname'])) {
418 $docname = $row['ulname'];
419 if (!empty($row['ufname']) ||
!empty($row['umname'])) {
420 $docname .= ', ' . $row['ufname'] . ' ' . $row['umname'];
426 // Fetch all other forms for this encounter.
428 $encarr = getFormByEncounter(
431 "formdir, user, form_name, form_id"
434 foreach ($encarr as $enc) {
435 if ($enc['formdir'] == 'newpatient') {
440 $encnames .= '<br />';
443 $encnames .= text($enc['form_name']); // need to html escape it here for output below
447 // Fetch coding and compute billing status.
451 if ($billres = getBillingByEncounter(
454 "code_type, code, code_text, billed"
456 foreach ($billres as $billrow) {
457 // $title = addslashes($billrow['code_text']);
458 if ($billrow['code_type'] != 'COPAY' && $billrow['code_type'] != 'TAX') {
459 $coded .= $billrow['code'] . ', ';
460 if ($billrow['billed']) {
468 $coded = substr($coded, 0, strlen($coded) - 2);
471 // Figure product sales into billing status.
472 $sres = sqlStatement("SELECT billed FROM drug_sales " .
473 "WHERE pid = '{$row['pid']}' AND encounter = '{$row['encounter']}'");
474 while ($srow = sqlFetchArray($sres)) {
475 if ($srow['billed']) {
482 // Compute billing status.
483 if ($billed_count && $unbilled_count) {
484 $status = xl('Mixed');
485 } else if ($billed_count) {
486 $status = xl('Closed');
487 } else if ($unbilled_count) {
488 $status = xl('Open');
490 $status = xl('Empty');
493 <tr bgcolor
='<?php echo $bgcolor ?>'>
495 <?php
echo ($docname == $lastdocname) ?
"" : text($docname) ?
> 
;
498 <?php
echo text(oeFormatShortDate(substr($row['date'], 0, 10))) ?
> 
;
501 <?php
echo text($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']); ?
> 
;
504 <?php
echo text($row['pubpid']); ?
> 
;
507 <?php
echo text($status); ?
> 
;
510 <?php
echo text($row['reason']); ?
> 
;
513 <?php
echo text($row['encounter']); ?
> 
;
516 <?php
echo $encnames; //since this variable contains html, have already html escaped it above ?>
519 <?php
echo text($coded); ?
>
524 if ($docname != $lastdocname) {
525 show_doc_total($lastdocname, $doc_encounters);
532 $lastdocname = $docname;
535 if (!$form_details) {
536 show_doc_total($lastdocname, $doc_encounters);
542 </div
> <!-- end encresults
-->
545 <?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>
549 <input type
="hidden" name
="form_orderby" value
="<?php echo attr($form_orderby) ?>" />
550 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
555 <script language
='JavaScript'>
556 <?php
if ($alertmsg) {
557 echo " alert('$alertmsg');\n";