3 * Patient Tracker (Patient Flow Board)
5 * This program displays the information entered in the Calendar program ,
6 * allowing the user to change status and view those changed here and in the Calendar
7 * Will allow the collection of length of time spent in each status
10 * @link http://www.open-emr.org
11 * @author Terry Hill <terry@lilysystems.com>
12 * @author Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2015 Terry Hill <terry@lillysystems.com>
14 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
19 require_once("../globals.php");
20 require_once("$srcdir/patient.inc");
21 require_once("$srcdir/options.inc.php");
22 require_once("$srcdir/patient_tracker.inc.php");
23 require_once("$srcdir/user.inc");
25 // mdsupport - user_settings prefix
26 $uspfx = substr(__FILE__
, strlen($webserver_root)) . '.';
27 $setting_new_window = prevSetting($uspfx, 'setting_new_window', 'form_new_window', ' ');
29 #define variables, future enhancement allow changing the to_date and from_date
30 #to allow picking a date to review
32 if (!is_null($_POST['form_provider'])) {
33 $provider = $_POST['form_provider'];
34 } else if ($_SESSION['userauthorized']) {
35 $provider = $_SESSION['authUserID'];
40 $facility = !is_null($_POST['form_facility']) ?
$_POST['form_facility'] : null;
41 $form_apptstatus = !is_null($_POST['form_apptstatus']) ?
$_POST['form_apptstatus'] : null;
43 if (isset($_POST['form_apptcat'])) {
44 if ($form_apptcat!="ALL") {
45 $form_apptcat=intval($_POST['form_apptcat']);
49 $form_patient_name = !is_null($_POST['form_patient_name']) ?
$_POST['form_patient_name'] : null;
50 $form_patient_id = !is_null($_POST['form_patient_id']) ?
$_POST['form_patient_id'] : null;
52 $appointments = array();
53 $from_date = date("Y-m-d");
54 $to_date = date("Y-m-d");
55 $datetime = date("Y-m-d H:i:s");
57 # go get the information and process it
58 $appointments = fetch_Patient_Tracker_Events($from_date, $to_date, $provider, $facility, $form_apptstatus, $form_apptcat, $form_patient_name, $form_patient_id);
59 $appointments = sortAppointments($appointments, 'time');
61 //grouping of the count of every status
62 $appointments_status = getApptStatus($appointments);
64 // Below are new constants for the translation pipeline
66 // xl('Reminder done')
72 // xl('Left w/o visit')
73 // xl('Ins/fin issue')
77 // xl('Canceled < 24h')
78 $lres = sqlStatement("SELECT option_id, title FROM list_options WHERE list_id = ? AND activity=1", array('apptstat'));
79 while ($lrow = sqlFetchArray($lres)) {
80 // if exists, remove the legend character
81 if ($lrow['title'][1] == ' ') {
82 $splitTitle = explode(' ', $lrow['title']);
83 array_shift($splitTitle);
84 $title = implode(' ', $splitTitle);
86 $title = $lrow['title'];
89 $statuses_list[$lrow['option_id']] = $title;
92 $chk_prov = array(); // list of providers with appointments
94 // Scan appointments for additional info
95 foreach ($appointments as $apt) {
96 $chk_prov[$apt['uprovider_id']] = $apt['ulname'] . ', ' . $apt['ufname'] . ' ' . $apt['umname'];
101 <title
><?php
echo xlt("Flow Board") ?
></title
>
102 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
103 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative'];?>/font-awesome-4-6-3/css/font-awesome.css" type
="text/css">
105 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
106 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
107 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
109 <script language
="JavaScript">
111 function refreshme() {
112 top
.restoreSession();
113 document
.pattrk
.submit();
115 // popup for patient tracker status
116 function bpopup(tkid
) {
118 dlgopen('../patient_tracker/patient_tracker_status.php?tracker_id=' + tkid
, '_blank', 500, 250);
122 // popup for calendar add edit
123 function calendarpopup(eid
,date_squash
) {
125 dlgopen('../main/calendar/add_edit_event.php?eid=' + eid +
'&date=' + date_squash
, '_blank', 775, 500);
129 // auto refresh screen pat_trkr_timer is the timer variable
130 function refreshbegin(first
){
131 <?php
if ($GLOBALS['pat_trkr_timer'] != '0') { ?
>
132 var reftime
="<?php echo attr($GLOBALS['pat_trkr_timer']); ?>";
133 var parsetime
=reftime
.split(":");
134 parsetime
=(parsetime
[0]*60)+
(parsetime
[1]*1)*1000;
138 setTimeout("refreshbegin('0')",parsetime
);
144 // used to display the patient demographic and encounter screens
145 function topatient(newpid
, enc
) {
146 if (document
.pattrk
.form_new_window
.checked
) {
147 openNewTopWindow(newpid
,enc
);
150 top
.restoreSession();
152 top
.RTop
.location
= "<?php echo $GLOBALS['webroot']; ?>/interface/patient_file/summary/demographics.php?set_pid=" + newpid +
"&set_encounterid=" + enc
;
155 top
.RTop
.location
= "<?php echo $GLOBALS['webroot']; ?>/interface/patient_file/summary/demographics.php?set_pid=" + newpid
;
160 // opens the demographic and encounter screens in a new window
161 function openNewTopWindow(newpid
,newencounterid
) {
162 document
.fnew
.patientID
.value
= newpid
;
163 document
.fnew
.encounterID
.value
= newencounterid
;
164 top
.restoreSession();
165 document
.fnew
.submit();
173 if ($GLOBALS['pat_trkr_timer'] == '0') {
174 // if the screen is not set up for auto refresh, use standard page call
175 $action_page = "patient_tracker.php";
177 // if the screen is set up for auto refresh, this will allow it to be closed by auto logoff
178 $action_page = "patient_tracker.php?skip_timeout_reset=1";
182 <span
class="title"><?php
echo xlt("Flow Board") ?
></span
>
183 <body
class="body_top" >
184 <form method
='post' name
='theform' id
='theform' action
='<?php echo $action_page; ?>' onsubmit
='return top.restoreSession()'>
185 <div id
="flow_board_parameters">
188 <td
class='label_custom'><?php
echo xlt('Provider'); ?
>:</td
>
191 # Build a drop-down list of providers.
193 $query = "SELECT id, lname, fname FROM users WHERE ".
194 "authorized = 1 ORDER BY lname, fname"; #(CHEMED) facility filter
196 $ures = sqlStatement($query);
198 echo " <select name='form_provider'>\n";
199 echo " <option value='ALL'>-- " . xlt('All') . " --\n";
201 while ($urow = sqlFetchArray($ures)) {
202 $provid = $urow['id'];
203 echo " <option value='" . attr($provid) . "'";
204 if (isset($_POST['form_provider']) && $provid == $_POST['form_provider']) {
206 } elseif (!isset($_POST['form_provider'])&& $_SESSION['userauthorized'] && $provid == $_SESSION['authUserID']) {
210 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
217 <td
class='label_custom'><?php
echo xlt('Status'); # status code drop down creation ?>:</td>
218 <td
><?php
generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'All'), $_POST['form_apptstatus']);?
></td
>
219 <td
><?php
echo xlt('Category') #category drop down creation ?>:</td>
221 <select id
="form_apptcat" name
="form_apptcat">
223 $categories=fetchAppointmentCategories();
224 echo "<option value='ALL'>".xlt("All")."</option>";
225 while ($cat=sqlFetchArray($categories)) {
226 echo "<option value='".attr($cat['id'])."'";
227 if ($cat['id']==$_POST['form_apptcat']) {
228 echo " selected='true' ";
231 echo ">".text(xl_appt_category($cat['category']))."</option>";
236 <td style
="border-left: 1px solid;" rowspan
="2">
237 <div style
='margin-left: 15px'>
238 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
239 <span
> <?php
echo xlt('Filter'); ?
> </span
> </a
>
240 <?php
if ($_POST['form_refresh'] ||
$_POST['form_orderby']) { ?
>
241 <a href
='#' class='css_button' id
='printbutton'>
242 <span
> <?php
echo xlt('Print'); ?
> </span
> </a
>
248 <td
><?php
echo xlt('Patient ID') ?
>:</td
>
250 <input type
="text" id
="patient_id" name
="form_patient_id" value
="<?php echo ($form_patient_id) ? attr($form_patient_id) : ""; ?>">
252 <td
><?php
echo xlt('Patient Name') ?
>:</td
>
254 <input type
="text" id
="patient_name" name
="form_patient_name" value
="<?php echo ($form_patient_name) ? attr($form_patient_name) : ""; ?>">
261 <form name
='pattrk' id
='pattrk' method
='post' action
='<?php echo $action_page; ?>' onsubmit
='return top.restoreSession()' enctype
='multipart/form-data'>
264 <?php
if (count($chk_prov) == 1) {?
>
265 <h2
><span style
='float: left'><?php
echo xlt('Appointments for'). ' : '. text(reset($chk_prov)) ?
></span
></h2
>
267 <div id
= 'inanewwindow' class='inanewwindow'>
268 <span style
='float: right'>
269 <a id
='setting_cog'><i
class="fa fa-cog fa-2x fa-fw"> 
;</i
></a
>
270 <?php
// Note that are unable to html escape below $setting_new_window, or else will break the code, secondary to white space issues. ?>
271 <input type
='hidden' name
='setting_new_window' id
='setting_new_window' value
='<?php echo $setting_new_window ?>' />
272 <label id
='settings'><input type
='checkbox' name
='form_new_window' id
='form_new_window' value
='1'<?php
echo $setting_new_window ?
> >
273 <?php
echo xlt('Open Patient in New Window'); ?
></input
></label
>
274 <a id
='refreshme'><i
class="fa fa-refresh fa-2x fa-fw"> 
;</i
></a
>
278 <?php
if ($GLOBALS['pat_trkr_timer'] =='0') { ?
>
279 <table border
='0' cellpadding
='5' cellspacing
='0'>
281 <td align
='center'><br
>
282 <a href
='javascript:;' class='css_button_small' align
='center' style
='color:gray' onclick
="document.getElementById('pattrk').submit();"><span
><?php
echo xlt('Refresh Screen'); ?
></span
></a
>
288 <table border
='0' cellpadding
='1' cellspacing
='2' width
='100%'>
293 $statuses_output = xlt('Total patients') . ':' . text($appointments_status['count_all']);
294 unset($appointments_status['count_all']);
295 foreach ($appointments_status as $status_symbol => $count) {
296 $statuses_output .= " | " . text(xl_list_label($statuses_list[$status_symbol])) .":" . $count;
299 echo $statuses_output;
304 <tr bgcolor
="#cccff">
305 <?php
if ($GLOBALS['ptkr_show_pid']) { ?
>
306 <td
class="dehead" align
="center">
307 <?php
echo xlt('PID'); ?
>
310 <td
class="dehead" align
="center">
311 <?php
echo xlt('Patient'); ?
>
313 <?php
if ($GLOBALS['ptkr_visit_reason']) { ?
>
314 <td
class="dehead" align
="center">
315 <?php
echo xlt('Reason'); ?
>
318 <?php
if ($GLOBALS['ptkr_show_encounter']) { ?
>
319 <td
class="dehead" align
="center">
320 <?php
echo xlt('Encounter'); ?
>
323 <td
class="dehead" align
="center">
324 <?php
echo xlt('Exam Room #'); ?
>
326 <td
class="dehead" align
="center">
327 <?php
echo xlt('Appt Time'); ?
>
329 <td
class="dehead" align
="center">
330 <?php
echo xlt('Arrive Time'); ?
>
332 <td
class="dehead" align
="center">
333 <?php
echo xlt('Status'); ?
>
335 <td
class="dehead" align
="center">
336 <?php
echo xlt('Current Status Time'); ?
>
338 <td
class="dehead" align
="center">
339 <?php
echo xlt('Visit Type'); ?
>
341 <?php
if (count($chk_prov) > 1) { ?
>
342 <td
class="dehead" align
="center">
343 <?php
echo xlt('Provider'); ?
>
346 <td
class="dehead" align
="center">
347 <?php
echo xlt('Total Time'); ?
>
349 <td
class="dehead" align
="center">
350 <?php
echo xlt('Check Out Time'); ?
>
352 <td
class="dehead" align
="center">
353 <?php
echo xlt('Updated By'); ?
>
355 <?php
if ($GLOBALS['drug_screen']) { ?
>
356 <td
class="dehead" align
="center">
357 <?php
echo xlt('Random Drug Screen'); ?
>
359 <td
class="dehead" align
="center">
360 <?php
echo xlt('Drug Screen Completed'); ?
>
366 foreach ($appointments as $appointment) {
367 # Collect appt date and set up squashed date for use below
368 $date_appt = $appointment['pc_eventDate'];
369 $date_squash = str_replace("-", "", $date_appt);
371 # Collect variables and do some processing
372 $docname = $chk_prov[$appointment['uprovider_id']];
373 if (strlen($docname)<= 3) {
377 $ptname = $appointment['lname'] . ', ' . $appointment['fname'] . ' ' . $appointment['mname'];
378 $appt_enc = $appointment['encounter'];
379 $appt_eid = (!empty($appointment['eid'])) ?
$appointment['eid'] : $appointment['pc_eid'];
380 $appt_pid = (!empty($appointment['pid'])) ?
$appointment['pid'] : $appointment['pc_pid'];
382 continue; // skip when $appt_pid = 0, since this means it is not a patient specific appt slot
385 $status = (!empty($appointment['status'])) ?
$appointment['status'] : $appointment['pc_apptstatus'];
386 $appt_room = (!empty($appointment['room'])) ?
$appointment['room'] : $appointment['pc_room'];
387 $appt_time = (!empty($appointment['appttime'])) ?
$appointment['appttime'] : $appointment['pc_startTime'];
388 $tracker_id = $appointment['id'];
390 if ($GLOBALS['ptkr_visit_reason']) {
391 $reason_visit = $appointment['pc_hometext'];
394 $newarrive = collect_checkin($tracker_id);
395 $newend = collect_checkout($tracker_id);
396 $colorevents = (collectApptStatusSettings($status));
397 $bgcolor = $colorevents['color'];
398 $statalert = $colorevents['time_alert'];
399 # process the time to allow items with a check out status to be displayed
400 if (is_checkout($status) && ($GLOBALS['checkout_roll_off'] > 0)) {
401 $to_time = strtotime($newend);
402 $from_time = strtotime($datetime);
403 $display_check_out = round(abs($from_time - $to_time) / 60, 0);
404 if ($display_check_out >= $GLOBALS['checkout_roll_off']) {
409 <tr bgcolor
='<?php echo $bgcolor ?>'>
410 <?php
if ($GLOBALS['ptkr_show_pid']) { ?
>
411 <td
class="detail" align
="center">
412 <?php
echo text($appt_pid) ?
>
415 <td
class="detail" align
="center">
416 <a href
="#" onclick
="return topatient('<?php echo attr($appt_pid);?>','<?php echo attr($appt_enc);?>')" >
417 <?php
echo text($ptname); ?
></a
>
420 <?php
if ($GLOBALS['ptkr_visit_reason']) { ?
>
421 <td
class="detail" align
="center">
422 <?php
echo text($reason_visit) ?
>
425 <?php
if ($GLOBALS['ptkr_show_encounter']) { ?
>
426 <td
class="detail" align
="center">
427 <?php
if ($appt_enc != 0) {
428 echo text($appt_enc);
432 <td
class="detail" align
="center">
433 <?php
echo getListItemTitle('patient_flow_board_rooms', $appt_room);?
>
435 <td
class="detail" align
="center">
436 <?php
echo oeFormatTime($appt_time) ?
>
438 <td
class="detail" align
="center">
439 <?php
echo ($newarrive ?
oeFormatTime($newarrive) : ' ') ?
>
441 <td
class="detail" align
="center">
442 <?php
if (empty($tracker_id)) { #for appt not yet with tracker id and for recurring appt ?>
443 <a href
="" onclick
="return calendarpopup(<?php echo attr($appt_eid).",".attr($date_squash); # calls popup for add edit calendar event?>)">
445 <a href
="" onclick
="return bpopup(<?php echo attr($tracker_id); # calls popup for patient tracker status?>)">
447 <?php
echo text(getListItemTitle("apptstat", $status)); # drop down list for appointment status?>
452 #time in current status
453 $to_time = strtotime(date("Y-m-d H:i:s"));
455 if (strtotime($newend) != '') {
456 $from_time = strtotime($newarrive);
457 $to_time = strtotime($newend);
460 $from_time = strtotime($appointment['start_datetime']);
464 $timecheck = round(abs($to_time - $from_time) / 60, 0);
465 if ($timecheck >= $statalert && ($statalert != '0')) { # Determine if the time in status limit has been reached.
466 echo "<td align='center' class='js-blink-infinite'> "; # and if so blink
468 echo "<td align='center' class='detail'> "; # and if not do not blink
471 if (($yestime == '1') && ($timecheck >=1) && (strtotime($newarrive)!= '')) {
472 echo text($timecheck . ' ' .($timecheck >=2 ?
xl('minutes'): xl('minute')));
475 #end time in current status
478 <td
class="detail" align
="center">
479 <?php
echo text(xl_appt_category($appointment['pc_title'])) ?
>
481 <?php
if (count($chk_prov) > 1) { ?
>
482 <td
class="detail" align
="center">
483 <?php
echo text($docname); ?
>
486 <td
class="detail" align
="center">
489 # total time in practice
490 if (strtotime($newend) != '') {
491 $from_time = strtotime($newarrive);
492 $to_time = strtotime($newend);
494 $from_time = strtotime($newarrive);
495 $to_time = strtotime(date("Y-m-d H:i:s"));
498 $timecheck2 = round(abs($to_time - $from_time) / 60, 0);
499 if (strtotime($newarrive) != '' && ($timecheck2 >=1)) {
500 echo text($timecheck2 . ' ' .($timecheck2 >=2 ?
xl('minutes'): xl('minute')));
503 # end total time in practice
505 <?php
echo text($appointment['pc_time']); ?
>
507 <td
class="detail" align
="center">
509 if (strtotime($newend) != '') {
510 echo oeFormatTime($newend) ;
514 <td
class="detail" align
="center">
515 <?php
echo text($appointment['user']) ?
>
517 <?php
if ($GLOBALS['drug_screen']) { ?
>
518 <?php
if (strtotime($newarrive) != '') { ?
>
519 <td
class="detail" align
="center">
520 <?php
if (text($appointment['random_drug_test']) == '1') {
529 <?php
if (strtotime($newarrive) != '' && $appointment['random_drug_test'] == '1') { ?
>
530 <td
class="detail" align
="center">
531 <?php
if (strtotime($newend) != '') { # the following block allows the check box for drug screens to be disabled once the status is check out ?>
532 <input type
=checkbox disabled
='disable' class="drug_screen_completed" id
="<?php echo htmlspecialchars($appointment['pt_tracker_id'], ENT_NOQUOTES) ?>" <?php
if ($appointment['drug_screen_completed'] == "1") {
536 <input type
=checkbox
class="drug_screen_completed" id
='<?php echo htmlspecialchars($appointment['pt_tracker_id
'], ENT_NOQUOTES) ?>' name
="drug_screen_completed" <?php
if ($appointment['drug_screen_completed'] == "1") {
551 //saving the filter for auto refresh
552 if (!is_null($_POST['form_provider'])) {
553 echo "<input type='hidden' name='form_provider' value='" . attr($_POST['form_provider']) . "'>";
556 if (!is_null($_POST['form_facility'])) {
557 echo "<input type='hidden' name='form_facility' value='" . attr($_POST['form_facility']) . "'>";
560 if (!is_null($_POST['form_apptstatus'])) {
561 echo "<input type='hidden' name='form_apptstatus' value='" . attr($_POST['form_apptstatus']) . "'>";
564 if (!is_null($_POST['form_apptcat'])) {
565 echo "<input type='hidden' name='form_apptcat' value='" . attr($_POST['form_apptcat']) . "'>";
568 if (!is_null($_POST['form_patient_id'])) {
569 echo "<input type='hidden' name='form_patient_id' value='" . attr($_POST['form_patient_id']) . "'>";
572 if (!is_null($_POST['form_patient_name'])) {
573 echo "<input type='hidden' name='form_patient_name' value='" . attr($_POST['form_patient_name']) . "'>";
580 <script type
="text/javascript">
581 $
(document
).ready(function() {
582 $
('#settings').css("display","none");
585 $
('.js-blink-infinite').each(function() {
586 // set up blinking text
588 setInterval(function() {
589 if (elem
.css('visibility') == 'hidden') {
590 elem
.css('visibility', 'visible');
592 elem
.css('visibility', 'hidden');
597 // toggle of the check box status for drug screen completed and ajax call to update the database
598 $
(".drug_screen_completed").change(function() {
599 top
.restoreSession();
601 testcomplete_toggle
="true";
603 testcomplete_toggle
="false";
605 $
.post( "../../library/ajax/drug_screen_completed.php", {
607 testcomplete
: testcomplete_toggle
612 // mdsupport - Immediately post changes to form_new_window
613 $
('#form_new_window').click(function () {
614 $
('#setting_new_window').val(this
.checked ?
' checked' : ' ');
615 $
.post( "<?php echo basename(__FILE__) ?>", {
616 data
: $
('form#pattrk').serialize(),
617 success
: function (data
) {}
621 $
('#setting_cog').click(function () {
622 $
(this
).css("display","none");
623 $
('#settings').css("display","inline");
626 $
('#refreshme').click(function () {
630 <!-- form used to open a
new top level window when a patient row is clicked
-->
631 <form name
='fnew' method
='post' target
='_blank' action
='../main/main_screen.php?auth=login&site=<?php echo attr($_SESSION['site_id
']); ?>'>
632 <input type
='hidden' name
='patientID' value
='0' />
633 <input type
='hidden' name
='encounterID' value
='0' />