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'];
35 else if ($_SESSION['userauthorized']) {
36 $provider = $_SESSION['authUserID'];
41 $facility = !is_null($_POST['form_facility']) ?
$_POST['form_facility'] : null;
42 $form_apptstatus = !is_null($_POST['form_apptstatus']) ?
$_POST['form_apptstatus'] : null;
44 if(isset($_POST['form_apptcat']))
46 if($form_apptcat!="ALL")
48 $form_apptcat=intval($_POST['form_apptcat']);
51 $form_patient_name = !is_null($_POST['form_patient_name']) ?
$_POST['form_patient_name'] : null;
52 $form_patient_id = !is_null($_POST['form_patient_id']) ?
$_POST['form_patient_id'] : null;
54 $appointments = array();
55 $from_date = date("Y-m-d");
56 $to_date = date("Y-m-d");
57 $datetime = date("Y-m-d H:i:s");
59 # go get the information and process it
60 $appointments = fetch_Patient_Tracker_Events($from_date, $to_date, $provider, $facility, $form_apptstatus, $form_apptcat, $form_patient_name, $form_patient_id);
61 $appointments = sortAppointments( $appointments, 'time' );
63 //grouping of the count of every status
64 $appointments_status = getApptStatus($appointments);
66 // Below are new constants for the translation pipeline
68 // xl('Reminder done')
74 // xl('Left w/o visit')
75 // xl('Ins/fin issue')
79 // xl('Canceled < 24h')
80 $lres = sqlStatement("SELECT option_id, title FROM list_options WHERE list_id = ? AND activity=1", array('apptstat'));
81 while ( $lrow = sqlFetchArray ( $lres ) ) {
82 // if exists, remove the legend character
83 if($lrow['title'][1] == ' '){
84 $splitTitle = explode(' ', $lrow['title']);
85 array_shift($splitTitle);
86 $title = implode(' ', $splitTitle);
88 $title = $lrow['title'];
91 $statuses_list[$lrow['option_id']] = $title;
94 $chk_prov = array(); // list of providers with appointments
96 // Scan appointments for additional info
97 foreach ( $appointments as $apt ) {
98 $chk_prov[$apt['uprovider_id']] = $apt['ulname'] . ', ' . $apt['ufname'] . ' ' . $apt['umname'];
103 <title
><?php
echo xlt("Flow Board") ?
></title
>
104 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
105 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative'];?>/font-awesome-4-6-3/css/font-awesome.css" type
="text/css">
107 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
108 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
109 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
111 <script language
="JavaScript">
113 function refreshme() {
114 top
.restoreSession();
115 document
.pattrk
.submit();
117 // popup for patient tracker status
118 function bpopup(tkid
) {
120 dlgopen('../patient_tracker/patient_tracker_status.php?tracker_id=' + tkid
, '_blank', 500, 250);
124 // popup for calendar add edit
125 function calendarpopup(eid
,date_squash
) {
127 dlgopen('../main/calendar/add_edit_event.php?eid=' + eid +
'&date=' + date_squash
, '_blank', 775, 500);
131 // auto refresh screen pat_trkr_timer is the timer variable
132 function refreshbegin(first
){
133 <?php
if ($GLOBALS['pat_trkr_timer'] != '0') { ?
>
134 var reftime
="<?php echo attr($GLOBALS['pat_trkr_timer']); ?>";
135 var parsetime
=reftime
.split(":");
136 parsetime
=(parsetime
[0]*60)+
(parsetime
[1]*1)*1000;
140 setTimeout("refreshbegin('0')",parsetime
);
146 // used to display the patient demographic and encounter screens
147 function topatient(newpid
, enc
) {
148 if (document
.pattrk
.form_new_window
.checked
) {
149 openNewTopWindow(newpid
,enc
);
152 top
.restoreSession();
154 top
.RTop
.location
= "<?php echo $GLOBALS['webroot']; ?>/interface/patient_file/summary/demographics.php?set_pid=" + newpid +
"&set_encounterid=" + enc
;
157 top
.RTop
.location
= "<?php echo $GLOBALS['webroot']; ?>/interface/patient_file/summary/demographics.php?set_pid=" + newpid
;
162 // opens the demographic and encounter screens in a new window
163 function openNewTopWindow(newpid
,newencounterid
) {
164 document
.fnew
.patientID
.value
= newpid
;
165 document
.fnew
.encounterID
.value
= newencounterid
;
166 top
.restoreSession();
167 document
.fnew
.submit();
175 if ($GLOBALS['pat_trkr_timer'] == '0') {
176 // if the screen is not set up for auto refresh, use standard page call
177 $action_page = "patient_tracker.php";
180 // if the screen is set up for auto refresh, this will allow it to be closed by auto logoff
181 $action_page = "patient_tracker.php?skip_timeout_reset=1";
185 <span
class="title"><?php
echo xlt("Flow Board") ?
></span
>
186 <body
class="body_top" >
187 <form method
='post' name
='theform' id
='theform' action
='<?php echo $action_page; ?>' onsubmit
='return top.restoreSession()'>
188 <div id
="flow_board_parameters">
191 <td
class='label_custom'><?php
echo xlt('Provider'); ?
>:</td
>
194 # Build a drop-down list of providers.
196 $query = "SELECT id, lname, fname FROM users WHERE ".
197 "authorized = 1 ORDER BY lname, fname"; #(CHEMED) facility filter
199 $ures = sqlStatement($query);
201 echo " <select name='form_provider'>\n";
202 echo " <option value='ALL'>-- " . xlt('All') . " --\n";
204 while ($urow = sqlFetchArray($ures)) {
205 $provid = $urow['id'];
206 echo " <option value='" . attr($provid) . "'";
207 if (isset($_POST['form_provider']) && $provid == $_POST['form_provider']){
209 } elseif(!isset($_POST['form_provider'])&& $_SESSION['userauthorized'] && $provid == $_SESSION['authUserID']){
212 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
219 <td
class='label_custom'><?php
echo xlt('Status'); # status code drop down creation ?>:</td>
220 <td
><?php
generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'All'),$_POST['form_apptstatus']);?
></td
>
221 <td
><?php
echo xlt('Category') #category drop down creation ?>:</td>
223 <select id
="form_apptcat" name
="form_apptcat">
225 $categories=fetchAppointmentCategories();
226 echo "<option value='ALL'>".xlt("All")."</option>";
227 while($cat=sqlFetchArray($categories))
229 echo "<option value='".attr($cat['id'])."'";
230 if($cat['id']==$_POST['form_apptcat'])
232 echo " selected='true' ";
234 echo ">".text(xl_appt_category($cat['category']))."</option>";
239 <td style
="border-left: 1px solid;" rowspan
="2">
240 <div style
='margin-left: 15px'>
241 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
242 <span
> <?php
echo xlt('Filter'); ?
> </span
> </a
>
243 <?php
if ($_POST['form_refresh'] ||
$_POST['form_orderby'] ) { ?
>
244 <a href
='#' class='css_button' id
='printbutton'>
245 <span
> <?php
echo xlt('Print'); ?
> </span
> </a
>
251 <td
><?php
echo xlt('Patient ID') ?
>:</td
>
253 <input type
="text" id
="patient_id" name
="form_patient_id" value
="<?php echo ($form_patient_id) ? attr($form_patient_id) : ""; ?>">
255 <td
><?php
echo xlt('Patient Name') ?
>:</td
>
257 <input type
="text" id
="patient_name" name
="form_patient_name" value
="<?php echo ($form_patient_name) ? attr($form_patient_name) : ""; ?>">
264 <form name
='pattrk' id
='pattrk' method
='post' action
='<?php echo $action_page; ?>' onsubmit
='return top.restoreSession()' enctype
='multipart/form-data'>
267 <?php
if (count($chk_prov) == 1) {?
>
268 <h2
><span style
='float: left'><?php
echo xlt('Appointments for'). ' : '. text(reset($chk_prov)) ?
></span
></h2
>
270 <div id
= 'inanewwindow' class='inanewwindow'>
271 <span style
='float: right'>
272 <a id
='setting_cog'><i
class="fa fa-cog fa-2x fa-fw"> 
;</i
></a
>
273 <?php
// Note that are unable to html escape below $setting_new_window, or else will break the code, secondary to white space issues. ?>
274 <input type
='hidden' name
='setting_new_window' id
='setting_new_window' value
='<?php echo $setting_new_window ?>' />
275 <label id
='settings'><input type
='checkbox' name
='form_new_window' id
='form_new_window' value
='1'<?php
echo $setting_new_window ?
> >
276 <?php
echo xlt('Open Patient in New Window'); ?
></input
></label
>
277 <a id
='refreshme'><i
class="fa fa-refresh fa-2x fa-fw"> 
;</i
></a
>
281 <?php
if ($GLOBALS['pat_trkr_timer'] =='0') { ?
>
282 <table border
='0' cellpadding
='5' cellspacing
='0'>
284 <td align
='center'><br
>
285 <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
>
291 <table border
='0' cellpadding
='1' cellspacing
='2' width
='100%'>
296 $statuses_output = xlt('Total patients') . ':' . text($appointments_status['count_all']);
297 unset($appointments_status['count_all']);
298 foreach($appointments_status as $status_symbol => $count){
299 $statuses_output .= " | " . text(xl_list_label($statuses_list[$status_symbol])) .":" . $count;
301 echo $statuses_output;
306 <tr bgcolor
="#cccff">
307 <?php
if ($GLOBALS['ptkr_show_pid']) { ?
>
308 <td
class="dehead" align
="center">
309 <?php
echo xlt('PID'); ?
>
312 <td
class="dehead" align
="center">
313 <?php
echo xlt('Patient'); ?
>
315 <?php
if ($GLOBALS['ptkr_visit_reason']) { ?
>
316 <td
class="dehead" align
="center">
317 <?php
echo xlt('Reason'); ?
>
320 <?php
if ($GLOBALS['ptkr_show_encounter']) { ?
>
321 <td
class="dehead" align
="center">
322 <?php
echo xlt('Encounter'); ?
>
325 <td
class="dehead" align
="center">
326 <?php
echo xlt('Exam Room #'); ?
>
328 <td
class="dehead" align
="center">
329 <?php
echo xlt('Appt Time'); ?
>
331 <td
class="dehead" align
="center">
332 <?php
echo xlt('Arrive Time'); ?
>
334 <td
class="dehead" align
="center">
335 <?php
echo xlt('Status'); ?
>
337 <td
class="dehead" align
="center">
338 <?php
echo xlt('Current Status Time'); ?
>
340 <td
class="dehead" align
="center">
341 <?php
echo xlt('Visit Type'); ?
>
343 <?php
if (count($chk_prov) > 1) { ?
>
344 <td
class="dehead" align
="center">
345 <?php
echo xlt('Provider'); ?
>
348 <td
class="dehead" align
="center">
349 <?php
echo xlt('Total Time'); ?
>
351 <td
class="dehead" align
="center">
352 <?php
echo xlt('Check Out Time'); ?
>
354 <td
class="dehead" align
="center">
355 <?php
echo xlt('Updated By'); ?
>
357 <?php
if ($GLOBALS['drug_screen']) { ?
>
358 <td
class="dehead" align
="center">
359 <?php
echo xlt('Random Drug Screen'); ?
>
361 <td
class="dehead" align
="center">
362 <?php
echo xlt('Drug Screen Completed'); ?
>
368 foreach ( $appointments as $appointment ) {
370 # Collect appt date and set up squashed date for use below
371 $date_appt = $appointment['pc_eventDate'];
372 $date_squash = str_replace("-","",$date_appt);
374 # Collect variables and do some processing
375 $docname = $chk_prov[$appointment['uprovider_id']];
376 if (strlen($docname)<= 3 ) continue;
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'];
381 if ($appt_pid ==0 ) continue; // skip when $appt_pid = 0, since this means it is not a patient specific appt slot
382 $status = (!empty($appointment['status'])) ?
$appointment['status'] : $appointment['pc_apptstatus'];
383 $appt_room = (!empty($appointment['room'])) ?
$appointment['room'] : $appointment['pc_room'];
384 $appt_time = (!empty($appointment['appttime'])) ?
$appointment['appttime'] : $appointment['pc_startTime'];
385 $tracker_id = $appointment['id'];
387 if ($GLOBALS['ptkr_visit_reason']) {
388 $reason_visit = $appointment['pc_hometext'];
390 $newarrive = collect_checkin($tracker_id);
391 $newend = collect_checkout($tracker_id);
392 $colorevents = (collectApptStatusSettings($status));
393 $bgcolor = $colorevents['color'];
394 $statalert = $colorevents['time_alert'];
395 # process the time to allow items with a check out status to be displayed
396 if ( is_checkout($status) && ($GLOBALS['checkout_roll_off'] > 0) ) {
397 $to_time = strtotime($newend);
398 $from_time = strtotime($datetime);
399 $display_check_out = round(abs($from_time - $to_time) / 60,0);
400 if ( $display_check_out >= $GLOBALS['checkout_roll_off'] ) continue;
403 <tr bgcolor
='<?php echo $bgcolor ?>'>
404 <?php
if ($GLOBALS['ptkr_show_pid']) { ?
>
405 <td
class="detail" align
="center">
406 <?php
echo text($appt_pid) ?
>
409 <td
class="detail" align
="center">
410 <a href
="#" onclick
="return topatient('<?php echo attr($appt_pid);?>','<?php echo attr($appt_enc);?>')" >
411 <?php
echo text($ptname); ?
></a
>
414 <?php
if ($GLOBALS['ptkr_visit_reason']) { ?
>
415 <td
class="detail" align
="center">
416 <?php
echo text($reason_visit) ?
>
419 <?php
if ($GLOBALS['ptkr_show_encounter']) { ?
>
420 <td
class="detail" align
="center">
421 <?php
if($appt_enc != 0) echo text($appt_enc); ?
></a
>
424 <td
class="detail" align
="center">
425 <?php
echo getListItemTitle('patient_flow_board_rooms', $appt_room);?
>
427 <td
class="detail" align
="center">
428 <?php
echo oeFormatTime($appt_time) ?
>
430 <td
class="detail" align
="center">
431 <?php
echo ($newarrive ?
oeFormatTime($newarrive) : ' ') ?
>
433 <td
class="detail" align
="center">
434 <?php
if (empty($tracker_id)) { #for appt not yet with tracker id and for recurring appt ?>
435 <a href
="" onclick
="return calendarpopup(<?php echo attr($appt_eid).",".attr($date_squash); # calls popup for add edit calendar event?>)">
437 <a href
="" onclick
="return bpopup(<?php echo attr($tracker_id); # calls popup for patient tracker status?>)">
439 <?php
echo text(getListItemTitle("apptstat",$status)); # drop down list for appointment status?>
444 #time in current status
445 $to_time = strtotime(date("Y-m-d H:i:s"));
447 if (strtotime($newend) != '') {
448 $from_time = strtotime($newarrive);
449 $to_time = strtotime($newend);
454 $from_time = strtotime($appointment['start_datetime']);
458 $timecheck = round(abs($to_time - $from_time) / 60,0);
459 if ($timecheck >= $statalert && ($statalert != '0')) { # Determine if the time in status limit has been reached.
460 echo "<td align='center' class='js-blink-infinite'> "; # and if so blink
464 echo "<td align='center' class='detail'> "; # and if not do not blink
466 if (($yestime == '1') && ($timecheck >=1) && (strtotime($newarrive)!= '')) {
467 echo text($timecheck . ' ' .($timecheck >=2 ?
xl('minutes'): xl('minute')));
469 #end time in current status
472 <td
class="detail" align
="center">
473 <?php
echo text(xl_appt_category($appointment['pc_title'])) ?
>
475 <?php
if (count($chk_prov) > 1) { ?
>
476 <td
class="detail" align
="center">
477 <?php
echo text($docname); ?
>
480 <td
class="detail" align
="center">
483 # total time in practice
484 if (strtotime($newend) != '') {
485 $from_time = strtotime($newarrive);
486 $to_time = strtotime($newend);
490 $from_time = strtotime($newarrive);
491 $to_time = strtotime(date("Y-m-d H:i:s"));
493 $timecheck2 = round(abs($to_time - $from_time) / 60,0);
494 if (strtotime($newarrive) != '' && ($timecheck2 >=1)) {
495 echo text($timecheck2 . ' ' .($timecheck2 >=2 ?
xl('minutes'): xl('minute')));
497 # end total time in practice
499 <?php
echo text($appointment['pc_time']); ?
>
501 <td
class="detail" align
="center">
503 if (strtotime($newend) != '') {
504 echo oeFormatTime($newend) ;
508 <td
class="detail" align
="center">
509 <?php
echo text($appointment['user']) ?
>
511 <?php
if ($GLOBALS['drug_screen']) { ?
>
512 <?php
if (strtotime($newarrive) != '') { ?
>
513 <td
class="detail" align
="center">
514 <?php
if (text($appointment['random_drug_test']) == '1') { echo xl('Yes'); } else { echo xl('No'); }?
>
516 <?php
} else { echo " <td>"; }?
>
517 <?php
if (strtotime($newarrive) != '' && $appointment['random_drug_test'] == '1') { ?
>
518 <td
class="detail" align
="center">
519 <?php
if (strtotime($newend) != '') { # the following block allows the check box for drug screens to be disabled once the status is check out ?>
520 <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") echo "checked";?
>>
522 <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") echo "checked";?
>>
525 <?php
} else { echo " <td>"; }?
>
533 //saving the filter for auto refresh
534 if (!is_null($_POST['form_provider'])) {
535 echo "<input type='hidden' name='form_provider' value='" . attr($_POST['form_provider']) . "'>";
537 if (!is_null($_POST['form_facility'])) {
538 echo "<input type='hidden' name='form_facility' value='" . attr($_POST['form_facility']) . "'>";
540 if (!is_null($_POST['form_apptstatus'])) {
541 echo "<input type='hidden' name='form_apptstatus' value='" . attr($_POST['form_apptstatus']) . "'>";
543 if (!is_null($_POST['form_apptcat'])) {
544 echo "<input type='hidden' name='form_apptcat' value='" . attr($_POST['form_apptcat']) . "'>";
546 if (!is_null($_POST['form_patient_id'])) {
547 echo "<input type='hidden' name='form_patient_id' value='" . attr($_POST['form_patient_id']) . "'>";
549 if (!is_null($_POST['form_patient_name'])) {
550 echo "<input type='hidden' name='form_patient_name' value='" . attr($_POST['form_patient_name']) . "'>";
557 <script type
="text/javascript">
558 $
(document
).ready(function() {
559 $
('#settings').css("display","none");
562 $
('.js-blink-infinite').each(function() {
563 // set up blinking text
565 setInterval(function() {
566 if (elem
.css('visibility') == 'hidden') {
567 elem
.css('visibility', 'visible');
569 elem
.css('visibility', 'hidden');
574 // toggle of the check box status for drug screen completed and ajax call to update the database
575 $
(".drug_screen_completed").change(function() {
576 top
.restoreSession();
578 testcomplete_toggle
="true";
580 testcomplete_toggle
="false";
582 $
.post( "../../library/ajax/drug_screen_completed.php", {
584 testcomplete
: testcomplete_toggle
589 // mdsupport - Immediately post changes to form_new_window
590 $
('#form_new_window').click(function () {
591 $
('#setting_new_window').val(this
.checked ?
' checked' : ' ');
592 $
.post( "<?php echo basename(__FILE__) ?>", {
593 data
: $
('form#pattrk').serialize(),
594 success
: function (data
) {}
598 $
('#setting_cog').click(function () {
599 $
(this
).css("display","none");
600 $
('#settings').css("display","inline");
603 $
('#refreshme').click(function () {
607 <!-- form used to open a
new top level window when a patient row is clicked
-->
608 <form name
='fnew' method
='post' target
='_blank' action
='../main/main_screen.php?auth=login&site=<?php echo attr($_SESSION['site_id
']); ?>'>
609 <input type
='hidden' name
='patientID' value
='0' />
610 <input type
='hidden' name
='encounterID' value
='0' />