3 * Patient Flow Board (Patient Tracker) (Report Based on the appointment report)
5 * This program used to select and print the information captured in the Patient Flow Board program ,
6 * allowing the user to select and print the desired information.
9 * @link http://www.open-emr.org
10 * @author Terry Hill <terry@lilysystems.com>
11 * @author Brady Miller <brady.g.miller@gmail.com>
12 * @copyright Copyright (c) 2015 Terry Hill <terry@lillysystems.com>
13 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
18 require_once("../globals.php");
19 require_once("../../library/patient.inc");
20 require_once "$srcdir/options.inc.php";
21 require_once "$srcdir/appointments.inc.php";
22 require_once("$srcdir/patient_tracker.inc.php");
24 use OpenEMR\Core\Header
;
26 $patient = $_REQUEST['patient'];
28 if ($patient && !isset($_POST['form_from_date'])) {
29 // If a specific patient, default to 2 years ago.
31 $from_date = date("$tmp-m-d");
32 $to_date = date('Y-m-d');
34 $from_date = isset($_POST['form_from_date']) ?
DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d');
35 $to_date = isset($_POST['form_to_date']) ?
DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
38 # check box information
39 $chk_show_details = false;
40 if ($_POST['show_details']) {
41 $chk_show_details = true;
44 $chk_show_drug_screens = false;
45 if ($_POST['show_drug_screens']) {
46 $chk_show_drug_screens = true;
49 $chk_show_completed_drug_screens = false;
50 if ($_POST['show_completed_drug_screens']) {
51 $chk_show_completed_drug_screens = true;
54 # end check box information
56 $provider = $_POST['form_provider'];
57 $facility = $_POST['form_facility']; #(CHEMED) facility filter
58 $form_orderby = getComparisonOrder($_REQUEST['form_orderby']) ?
$_REQUEST['form_orderby'] : 'date';
59 if ($_POST["form_patient"]) {
60 $form_patient = isset($_POST['form_patient']) ?
$_POST['form_patient'] : '';
63 $form_pid = isset($_POST['form_pid']) ?
$_POST['form_pid'] : '';
64 if ($form_patient == '') {
72 <title
><?php
echo xlt('Patient Flow Board Report'); ?
></title
>
74 <?php Header
::setupHeader(['datetime-picker', 'report-helper']); ?
>
76 <script type
="text/javascript">
77 $
(document
).ready(function() {
78 var win
= top
.printLogSetup ? top
: opener
.top
;
79 win
.printLogSetup(document
.getElementById('printbutton'));
81 $
('.datepicker').datetimepicker({
82 <?php
$datetimepicker_timepicker = false; ?
>
83 <?php
$datetimepicker_showseconds = false; ?
>
84 <?php
$datetimepicker_formatInput = true; ?
>
85 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
86 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
90 function dosort(orderby
) {
91 var f
= document
.forms
[0];
92 f
.form_orderby
.value
= orderby
;
97 // CapMinds :: invokes find-patient popup.
98 function sel_patient() {
99 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
102 // CapMinds :: callback by the find-patient popup.
103 function setpatient(pid
, lname
, fname
, dob
) {
104 var f
= document
.theform
;
105 f
.form_patient
.value
= lname +
', ' + fname
;
106 f
.form_pid
.value
= pid
;
110 <style type
="text/css">
111 /* specifically include & exclude from printing */
117 #report_parameters_daterange {
121 #report_results table {
126 /* specifically exclude some from the screen */
128 #report_parameters_daterange {
136 <body
class="body_top">
138 <!-- Required
for the popup date selectors
-->
140 style
="position: absolute; visibility: hidden; z-index: 1000;"></div
>
141 <?php
if ($GLOBALS['drug_screen']) { #setting the title of the page based o if drug screening is enabled ?>
142 <span
class='title'><?php
echo xlt('Patient Flow Board'); ?
> - <?php
echo xlt('Drug Screen Report'); ?
></span
>
144 <span
class='title'><?php
echo xlt('Patient Flow Board Report'); ?
></span
>
148 <div id
="report_parameters_daterange"><?php
echo oeFormatShortDate($from_date) ." " . xlt('to') . " ". oeFormatShortDate($to_date); #sets date range for calendars ?>
151 <form method
='post' name
='theform' id
='theform' action
='patient_flow_board_report.php' onsubmit
='return top.restoreSession()'>
153 <div id
="report_parameters">
158 <div style
='float: left'>
162 <td
class='control-label'><?php
echo xlt('Facility'); ?
>:</td
>
163 <td
><?php
dropdown_facility($facility, 'form_facility'); ?
>
165 <td
class='control-label'><?php
echo xlt('Provider'); ?
>:</td
>
168 # Build a drop-down list of providers.
171 $query = "SELECT id, lname, fname FROM users WHERE ".
172 "authorized = 1 ORDER BY lname, fname"; #(CHEMED) facility filter
174 $ures = sqlStatement($query);
176 echo " <select name='form_provider' class='form-control'>\n";
177 echo " <option value=''>-- " . xlt('All') . " --\n";
179 while ($urow = sqlFetchArray($ures)) {
180 $provid = $urow['id'];
181 echo " <option value='" . attr($provid) . "'";
182 if ($provid == $_POST['form_provider']) {
186 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
196 <td
class='control-label'><?php
echo xlt('From'); ?
>:</td
>
197 <td
><input type
='text' name
='form_from_date' id
="form_from_date"
198 class='datepicker form-control'
199 size
='10' value
='<?php echo oeFormatShortDate($from_date) ?>'>
201 <td
class='control-label'><?php
echo xlt('To'); ?
>:</td
>
202 <td
><input type
='text' name
='form_to_date' id
="form_to_date"
203 class='datepicker form-control'
204 size
='10' value
='<?php echo oeFormatShortDate($to_date) ?>'>
209 <td
class='control-label'><?php
echo xlt('Status'); # status code drop down creation ?>:</td>
210 <td
><?php
generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'All'), $_POST['form_apptstatus']);?
></td
>
211 <td
><?php
echo xlt('Category') #category drop down creation ?>:</td>
213 <select id
="form_apptcat" name
="form_apptcat" class="form-control">
215 $categories=fetchAppointmentCategories();
216 echo "<option value='ALL'>".xlt("All")."</option>";
217 while ($cat=sqlFetchArray($categories)) {
218 echo "<option value='".attr($cat['id'])."'";
219 if ($cat['id']==$_POST['form_apptcat']) {
220 echo " selected='true' ";
223 echo ">".text(xl_appt_category($cat['category']))."</option>";
231  
; 
;<span
class='text'><?php
echo xlt('Patient'); ?
>: </span
>
234 <input type
='text' size
='20' name
='form_patient' class='form-control' style
='cursor:pointer;cursor:hand' value
='<?php echo attr($form_patient) ? attr($form_patient) : xla('Click To Select
'); ?>' onclick
='sel_patient()' title
='<?php echo xla('Click to select patient
'); ?>' />
235 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
239 <div
class="checkbox">
240 <label
><input type
="checkbox" name
="show_details" id
="show_details" <?php
echo ($chk_show_details) ?
"checked" : ""; ?
>> 
;<?php
echo xlt('Show Details'); ?
></label
>
247 <?php
if ($GLOBALS['drug_screen']) { ?
>
249 <?php
# these two selects will are for the drug screen entries the Show Selected for Drug Screens will show all
250 # that have a yes for selected. If you just check the Show Status of Drug Screens all drug screens will be displayed
251 # if both are selected then only completed drug screens will be displayed. ?>
253 <div
class="checkbox">
254 <label
><input type
="checkbox" name
="show_drug_screens" id
="show_drug_screens" <?php
echo ($chk_show_drug_screens) ?
"checked" : ""; ?
>> 
;<?php
echo xlt('Show Selected for Drug Screens'); ?
></label
>
258 <div
class="checkbox">
259 <label
><input type
="checkbox" name
="show_completed_drug_screens" id
="show_completed_drug_screens" <?php
echo ($chk_show_completed_drug_screens) ?
"checked" : ""; ?
>> 
;<?php
echo xlt('Show Status of Drug Screens'); ?
></label
>
270 <td align
='left' valign
='middle' height
="100%">
271 <table style
='border-left: 1px solid; width: 100%; height: 100%'>
274 <div
class="text-center">
275 <div
class="btn-group" role
="group">
276 <a href
='#' class='btn btn-default btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
277 <?php
echo xlt('Submit'); ?
>
279 <?php
if ($_POST['form_refresh'] ||
$_POST['form_orderby']) { ?
>
280 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
281 <?php
echo xlt('Print'); ?
>
288 <tr
> 
; 
;<?php
echo xlt('Most column headers can be clicked to change sort order') ?
></tr
>
295 <!-- end of search parameters
--> <?php
296 if ($_POST['form_refresh'] ||
$_POST['form_orderby']) {
298 <div id
="report_results">
302 <?php
if (!$chk_show_drug_screens && !$chk_show_completed_drug_screens) { # the first part of this block is for the Patient Flow Board report ?>
303 <th
><a href
="nojs.php" onclick
="return dosort('doctor')"
304 <?php
echo ($form_orderby == "doctor") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Provider'); ?
>
307 <th
><a href
="nojs.php" onclick
="return dosort('date')"
308 <?php
echo ($form_orderby == "date") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Date'); ?
></a
>
311 <th
><a href
="nojs.php" onclick
="return dosort('time')"
312 <?php
echo ($form_orderby == "time") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Time'); ?
></a
>
315 <th
><a href
="nojs.php" onclick
="return dosort('patient')"
316 <?php
echo ($form_orderby == "patient") ?
" style=\"color:#00cc00\"" : ""; ?
>> 
; 
; 
;<?php
echo xlt('Patient'); ?
></a
>
319 <th
><a href
="nojs.php" onclick
="return dosort('pubpid')"
320 <?php
echo ($form_orderby == "pubpid") ?
" style=\"color:#00cc00\"" : ""; ?
>> 
;<?php
echo xlt('ID'); ?
></a
>
323 <th
><a href
="nojs.php" onclick
="return dosort('type')"
324 <?php
echo ($form_orderby == "type") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Type'); ?
></a
>
327 <?php
if ($chk_show_details) { ?
>
328 <th
><a href
="nojs.php" onclick
="return dosort('trackerstatus')"
329 <?php
echo ($form_orderby == "trackerstatus") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Status'); ?
></a
>
332 <th
><a href
="nojs.php" onclick
="return dosort('trackerstatus')"
333 <?php
echo ($form_orderby == "trackerstatus") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Final Status'); ?
></a
>
339 if ($chk_show_details) { # not sure if Sorting by Arrive Time is useful
340 echo xlt('Start Time');
342 echo xlt('Arrive Time');
346 if ($chk_show_details) { # not sure if Sorting by Discharge Time is useful
347 echo xlt('End Time');
349 echo xlt('Discharge Time');
352 <th
><?php
echo xlt('Total Time'); # not adding Sorting by Total Time yet but can see that it might be useful ?></th>
354 <?php
} else { # this section is for the drug screen report ?>
356 <th
><a href
="nojs.php" onclick
="return dosort('doctor')"
357 <?php
echo ($form_orderby == "doctor") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Provider'); ?
>
360 <th
><a href
="nojs.php" onclick
="return dosort('date')"
361 <?php
echo ($form_orderby == "date") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Date'); ?
></a
>
364 <th
><a href
="nojs.php" onclick
="return dosort('time')"
365 <?php
echo ($form_orderby == "time") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Time'); ?
></a
>
368 <th
><a href
="nojs.php" onclick
="return dosort('patient')"
369 <?php
echo ($form_orderby == "patient") ?
" style=\"color:#00cc00\"" : ""; ?
>> 
; 
; 
; 
;<?php
echo xlt('Patient'); ?
></a
>
372 <?php
if (!$chk_show_completed_drug_screens) { ?
>
373 <th
><a href
="nojs.php" onclick
="return dosort('pubpid')"
374 <?php
echo ($form_orderby == "pubpid") ?
" style=\"color:#00cc00\"" : ""; ?
>> 
;<?php
echo xlt('ID'); ?
></a
>
377 <th
><a href
="nojs.php" onclick
="return dosort('pubpid')"
378 <?php
echo ($form_orderby == "pubpid") ?
" style=\"color:#00cc00\"" : ""; ?
>> 
;<?php
echo xlt('ID'); ?
></a
>
382 <th
><?php
echo xlt('Drug Screen'); # not sure if Sorting by Drug Screen is useful ?></th>
384 <?php
if (!$chk_show_completed_drug_screens) { ?
>
387 <th
><a href
="nojs.php" onclick
="return dosort('completed')"
388 <?php
echo ($form_orderby == "completed") ?
" style=\"color:#00cc00\"" : ""; ?
>><?php
echo xlt('Completed'); ?
></a
>
392 <th
></th
><th
></th
><th
></th
>
397 <!-- added
for better
print-ability
-->
401 #Appointment Status Checking
402 $form_apptstatus = $_POST['form_apptstatus'];
404 if (isset($_POST['form_apptcat'])) {
405 if ($form_apptcat!="ALL") {
406 $form_apptcat=intval($_POST['form_apptcat']);
410 #Without provider and facility data checking
411 $with_out_provider = null;
412 $with_out_facility = null;
414 # get the appointments also set the trackerboard flag to true (last entry in the fetchAppointments call so we get the tracker stuff)
415 $appointments = fetchAppointments($from_date, $to_date, $patient, $provider, $facility, $form_apptstatus, $with_out_provider, $with_out_facility, $form_apptcat, true);
416 # sort the appointments by the appointment time
417 $appointments = sortAppointments($appointments, $form_orderby);
418 # $j is used to count the number of patients that match the selected criteria.
420 //print_r2($appointments);
421 foreach ($appointments as $appointment) {
422 $patient_id = $appointment['pid'];
423 $tracker_id = $appointment['pt_tracker_id'];
424 $last_seq = $appointment['lastseq'];
425 $docname = $appointment['ulname'] . ', ' . $appointment['ufname'] . ' ' . $appointment['umname'];
426 # only get items with a tracker id.
427 if ($tracker_id == '') {
431 # only get the drug screens that are set to yes.
432 if ($chk_show_drug_screens ==1) {
433 if ($appointment['random_drug_test'] != '1') {
438 #if a patient id is entered just get that patient.
439 if (strlen($form_pid) !=0) {
440 if ($appointment['pid'] != $form_pid) {
449 # getting arrive time and end time from the elements file.
450 if ($tracker_id != 0) {
451 $newarrive = collect_checkin($tracker_id);
452 $newend = collect_checkout($tracker_id);
455 if ($newend != '' && $newarrive != '') {
459 $tracker_status = $appointment['status'];
460 # get the time interval for the entire visit. to display seconds add last option of true.
461 # get_Tracker_Time_Interval($newarrive, $newend, true)
462 $timecheck2 = get_Tracker_Time_Interval($newarrive, $newend);
463 # Get the tracker elements.
464 $tracker_elements = collect_Tracker_Elements($tracker_id);
465 # $j is incremented for a patient that made it for display.
469 <tr bgcolor
='<?php echo $bgcolor ?>'>
471 if (!$chk_show_drug_screens && !$chk_show_completed_drug_screens) { # the first part of this block is for the Patient Flow Board report ?>
472 <td
class="detail"> 
;<?php
echo ($docname == $lastdocname) ?
"" : $docname ?
>
475 <td
class="detail"><?php
echo text(oeFormatShortDate($appointment['pc_eventDate'])) ?
>
478 <td
class="detail"><?php
echo text(oeFormatTime($appointment['pc_startTime'])) ?
>
481 <td
class="detail"> 
;<?php
echo text($appointment['fname'] . " " . $appointment['lname']) ?
>
484 <td
class="detail"> 
;<?php
echo text($appointment['pubpid']) ?
>
487 <td
class="detail"> 
;<?php
echo text(xl_appt_category($appointment['pc_catname'])) ?
>
493 if ($chk_show_details) {
494 if ($no_visit != 1) {
495 echo xlt('Complete Visit Time');
498 if ($tracker_status != "") {
499 echo getListItemTitle('apptstat', $tracker_status);
505 <td
class="detail"> 
;<?php
echo text(substr($newarrive, 11)) ?
>
508 <td
class="detail"> 
;<?php
echo text(substr($newend, 11)) ?
>
511 <?php
if ($no_visit != 1) { ?
>
512 <td
class="detail"> 
;<?php
echo text($timecheck2) ?
></td
>
514 <td
class="detail"> 
;</td
>
517 if ($chk_show_details) { # lets show the detail lines
520 for ($x = 1; $x <= $last_seq; $x++
) {
522 <tr valign
='top' class="detail" >
523 <td colspan
="6" class="detail" align
='left'>
526 # get the verbiage for the status code
527 $track_stat = $tracker_elements[$i][status
];
528 # Get Interval alert time and status color.
529 $colorevents = (collectApptStatusSettings($track_stat));
531 $alert_color = $colorevents['color'];
532 $alert_time = $colorevents['time_alert'];
533 if (is_checkin($track_stat) ||
is_checkout($track_stat)) { #bold the check in and check out times in this block.
535 <td
class="detail"><b
>
542 echo getListItemTitle("apptstat", $track_stat);
546 if (is_checkin($track_stat) ||
is_checkout($track_stat)) { #bold the check in and check out times in this block.
548 <td
class="detail"><b
> 
;<?php
echo text(substr($tracker_elements[$i][start_datetime
], 11)); ?
></b
></td
>
551 <td
class="detail"> 
;<?php
echo text(substr($tracker_elements[$i][start_datetime
], 11)); ?
></td
>
552 <?php
# figure out the next time of the status
556 if ($k < $last_seq) {
557 # get the start time of the next status to determine the total time in this status
558 $start_tracker_time = $tracker_elements[$i][start_datetime
];
559 $next_tracker_time = $tracker_elements[$k][start_datetime
];
561 # since this is the last status the start and end are equal
562 $start_tracker_time = $tracker_elements[$i][start_datetime
];
563 $next_tracker_time = $tracker_elements[$i][start_datetime
];
566 if (is_checkin($track_stat) ||
is_checkout($track_stat)) { #bold the check in and check out times in this block. ?>
567 <td
class="detail"><b
> 
;<?php
echo text(substr($next_tracker_time, 11)) ?
></b
></td
><?php
569 <td
class="detail"> 
;<?php
echo text(substr($next_tracker_time, 11)) ?
></td
>
570 <?php
# compute the total time of the status
573 $tracker_time = get_Tracker_Time_Interval($start_tracker_time, $next_tracker_time);
574 # add code to alert if over time interval for status
575 $timecheck = round(abs(strtotime($start_tracker_time) - strtotime($next_tracker_time)) / 60, 0);
576 if ($timecheck > $alert_time && ($alert_time != '0')) {
577 if (is_checkin($track_stat) ||
is_checkout($track_stat)) { #bold the check in and check out times in this block. ?>
578 <td
class="detail" bgcolor
='<?php echo attr($alert_color) ?>'><b
> 
;<?php
echo text($tracker_time); ?
></b
></td
><?php
580 <td
class="detail" bgcolor
='<?php echo attr($alert_color) ?>'> 
;<?php
echo text($tracker_time); ?
></td
><?php
583 if (is_checkin($track_stat) ||
is_checkout($track_stat)) { #bold the check in and check out times in this block. ?>
584 <td
class="detail"><b
> 
;<?php
echo text($tracker_time); ?
></b
></td
><?php
586 <td
class="detail"> 
;<?php
echo text($tracker_time); ?
></td
><?php
598 } else { # this section is for the drug screen report ?>
600 <td
class="detail"> 
;<?php
echo ($docname == $lastdocname) ?
"" : $docname ?
>
603 <td
class="detail"><?php
echo text(oeFormatShortDate($appointment['pc_eventDate'])) ?
>
606 <td
class="detail"><?php
echo text(oeFormatTime($appointment['pc_startTime'])) ?
>
609 <td
class="detail"> 
;<?php
echo text($appointment['fname'] . " " . $appointment['lname']) ?
>
612 <td
class="detail"> 
;<?php
echo text($appointment['pubpid']) ?
></td
>
614 <td
class="detail" align
= > 
; 
; 
; 
; 
; 
;<?php
echo ($appointment['random_drug_test'] == '1') ?
xlt('Yes') : xlt('No'); ?
></td
>
616 <?php
if ($chk_show_completed_drug_screens) { ?
>
617 <td
class="detail"> 
; 
; 
; 
; 
; 
;<?php
echo ($appointment['drug_screen_completed'] == '1') ?
xlt('Yes') : xlt('No'); ?
></td
>
619 <td
class="detail"> 
; </td
>
622 <?php
# these last items are used to complete the screen ?>
623 <td
class="detail"> 
;</td
>
625 <td
class="detail"> 
;</td
>
627 <td
class="detail"> 
;</td
>
632 $lastdocname = $docname;
636 <?php
if (!$chk_show_drug_screens && !$chk_show_completed_drug_screens) { # is it Patient Flow Board or Drug screen ?>
637 <td colspan
="10" align
="left"><?php
echo xlt('Total number of Patient Flow Board entries'); ?
> 
;<?php
echo text($j);?
> 
;<?php
echo xlt('Patients'); ?
></td
>
639 <td colspan
="10" align
="left"><?php
echo xlt('Total number of Drug Screen entries'); ?
> 
;<?php
echo text($j);?
> 
;<?php
echo xlt('Patients'); ?
></td
>
645 <!-- end of search results
-->
647 <div
class='text'><?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>
649 <?php
} ?
> <input type
="hidden" name
="form_orderby"
650 value
="<?php echo attr($form_orderby) ?>" /> <input type
="hidden"
651 name
="patient" value
="<?php echo attr($patient) ?>" /> <input type
='hidden'
652 name
='form_refresh' id
='form_refresh' value
='' /></form
>