function manage_tracker_status($apptdate,$appttime,$eid,$pid,$user,$status='',$room='',$enc_id='') { #First ensure the eid is not a recurrent appointment. If it is, then do not do anything and return false. $pc_appt = sqlQuery("SELECT `pc_recurrtype` FROM `openemr_postcalendar_events` WHERE `pc_eid` = ?", array($eid)); if ($pc_appt['pc_recurrtype'] != 0) { return false; } $datetime = date("Y-m-d H:i:s"); if (is_null($room)) { $room = ''; } #Check to see if there is an entry in the patient_tracker table. $tracker = sqlQuery("SELECT id, apptdate, appttime, eid, pid, original_user, encounter, lastseq,". "patient_tracker_element.room AS lastroom,patient_tracker_element.status AS laststatus ". "from `patient_tracker`". "LEFT JOIN patient_tracker_element " . "ON patient_tracker.id = patient_tracker_element.pt_tracker_id " . "AND patient_tracker.lastseq = patient_tracker_element.seq " . "WHERE `apptdate` = ? AND `appttime` = ? " . "AND `eid` = ? AND `pid` = ?", array($apptdate,$appttime,$eid,$pid)); if (empty($tracker)) { #Add a new tracker. $tracker_id = sqlInsert("INSERT INTO `patient_tracker` " . "(`date`, `apptdate`, `appttime`, `eid`, `pid`, `original_user`, `encounter`, `lastseq`) " . "VALUES (?,?,?,?,?,?,?,'1')", array($datetime,$apptdate,$appttime,$eid,$pid,$user,$enc_id)); #If there is a status or a room, then add a tracker item. if (!empty($status) || !empty($room)) { sqlInsert("INSERT INTO `patient_tracker_element` " . "(`pt_tracker_id`, `start_datetime`, `user`, `status`, `room`, `seq`) " . "VALUES (?,?,?,?,?,'1')", array($tracker_id,$datetime,$user,$status,$room)); } } else { #Tracker already exists. $tracker_id = $tracker['id']; if (($status != $tracker['laststatus']) || ($room != $tracker['lastroom'])) { #Status or room has changed, so need to update tracker. #Update lastseq in tracker. sqlStatement("UPDATE `patient_tracker` SET `lastseq` = ? WHERE `id` = ?", array(($tracker['lastseq']+1),$tracker_id)); #Add a tracker item. sqlInsert("INSERT INTO `patient_tracker_element` " . "(`pt_tracker_id`, `start_datetime`, `user`, `status`, `room`, `seq`) " . "VALUES (?,?,?,?,?,?)", array($tracker_id,$datetime,$user,$status,$room,($tracker['lastseq']+1))); } if (!empty($enc_id)) { #enc_id (encounter number) is not blank, so update this in tracker. sqlStatement("UPDATE `patient_tracker` SET `encounter` = ? WHERE `id` = ?", array($enc_id,$tracker_id)); } } #Ensure the entry in calendar appt entry has been updated. $pc_appt = sqlQuery("SELECT `pc_apptstatus`, `pc_room` FROM `openemr_postcalendar_events` WHERE `pc_eid` = ?", array($eid)); if ($status != $pc_appt['pc_apptstatus']) { sqlStatement("UPDATE `openemr_postcalendar_events` SET `pc_apptstatus` = ? WHERE `pc_eid` = ?", array($status,$eid)); } if ($room != $pc_appt['pc_room']) { sqlStatement("UPDATE `openemr_postcalendar_events` SET `pc_room` = ? WHERE `pc_eid` = ?", array($room,$eid)); } if( $GLOBALS['drug_screen'] && !empty($status) && is_checkin($status)) { $yearly_limit = $GLOBALS['maximum_drug_test_yearly']; $percentage = $GLOBALS['drug_testing_percentage']; random_drug_test($tracker_id,$percentage,$yearly_limit); } # Returning the tracker id that has been managed return $tracker_id; }
"AND patient_tracker.lastseq = patient_tracker_element.seq " . "WHERE patient_tracker.id =?",array($_GET['tracker_id'])); $tkpid = $trow['pid']; $appttime = $trow['appttime']; $apptdate = $trow['apptdate']; $pceid = $trow['eid']; $theroom = ''; if ($_POST['statustype'] !='') { $status = $_POST['statustype']; if (strlen($_POST['roomnum']) != 0) { $theroom = $_POST['roomnum']; } # Gather information and send to manage tracker status. if ($GLOBALS['auto_create_new_encounters'] && $apptdate == date('Y-m-d') && (is_checkin($status) == '1') && !is_tracker_encounter_exist($apptdate,$appttime,$tkpid,$pceid)) { # Gather information for encounter fields $genenc = sqlQuery("select pc_catid as category, pc_hometext as reason, pc_aid as provider, pc_facility as facility, pc_billing_location as billing_facility " . "from openemr_postcalendar_events where pc_eid =? " , array($pceid)); $encounter = todaysEncounterCheck($tkpid, $apptdate, $genenc['reason'], $genenc['facility'], $genenc['billing_facility'], $genenc['provider'], $genenc['category'],false); # Capture the appt status and room number for patient tracker. This will map the encounter to it also. if (!empty($pceid)) { manage_tracker_status($apptdate,$appttime,$pceid,$tkpid,$_SESSION["authUser"],$status,$theroom,$encounter); } } else { # Capture the appt status and room number for patient tracker. if (!empty($pceid)) { manage_tracker_status($apptdate,$appttime,$pceid,$tkpid,$_SESSION["authUser"],$status,$theroom);
} else { ?> <td class="detail" bgcolor='<?php echo attr($alert_color); ?> '> <?php echo text($tracker_time); ?> </td> <?php } ?> <?php } else { if (is_checkin($track_stat) || is_checkout($track_stat)) { #bold the check in and check out times in this block. ?> <td class="detail"><b> <?php echo text($tracker_time); ?> </b></td> <?php } else { ?> <td class="detail"> <?php echo text($tracker_time); ?> </td> <?php }
function DOBandEncounter() { global $event_date, $info_msg; // Save new DOB if it's there. $patient_dob = trim($_POST['form_dob']); $tmph = $_POST['form_hour'] + 0; $tmpm = $_POST['form_minute'] + 0; if ($_POST['form_ampm'] == '2' && $tmph < 12) { $tmph += 12; } $appttime = "{$tmph}:{$tmpm}:00"; if ($patient_dob && $_POST['form_pid']) { sqlStatement("UPDATE patient_data SET DOB = ? WHERE " . "pid = ?", array($patient_dob, $_POST['form_pid'])); } // Manage tracker status. // And auto-create a new encounter if appropriate. if (!empty($_POST['form_pid'])) { if ($GLOBALS['auto_create_new_encounters'] && $event_date == date('Y-m-d') && is_checkin($_POST['form_apptstatus']) == '1' && !is_tracker_encounter_exist($event_date, $appttime, $_POST['form_pid'], $_GET['eid'])) { $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false); if ($encounter) { $info_msg .= xl("New encounter created with id"); $info_msg .= " {$encounter}"; } # Capture the appt status and room number for patient tracker. This will map the encounter to it also. if (isset($GLOBALS['temporary-eid-for-manage-tracker']) || !empty($_GET['eid'])) { // Note that the temporary-eid-for-manage-tracker is used to capture the eid for new appointments and when separate a recurring // appointment. It is set in the InsertEvent() function. Note that in the case of spearating a recurrent appointment, the get eid // parameter is actually erroneous(is eid of the recurrent appt and not the new separated appt), so need to use the // temporary-eid-for-manage-tracker global instead. $temp_eid = isset($GLOBALS['temporary-eid-for-manage-tracker']) ? $GLOBALS['temporary-eid-for-manage-tracker'] : $_GET['eid']; manage_tracker_status($event_date, $appttime, $temp_eid, $_POST['form_pid'], $_SESSION["authUser"], $_POST['form_apptstatus'], $_POST['form_room'], $encounter); } } else { # Capture the appt status and room number for patient tracker. if (!empty($_GET['eid'])) { manage_tracker_status($event_date, $appttime, $_GET['eid'], $_POST['form_pid'], $_SESSION["authUser"], $_POST['form_apptstatus'], $_POST['form_room']); } } } }
<td class="detail"><b> <?php echo text(substr($next_tracker_time,11)) ?></b></td> <?php } else { ?> <td class="detail"> <?php echo text(substr($next_tracker_time,11)) ?></td> <?php # compute the total time of the status } $tracker_time = get_Tracker_Time_Interval($start_tracker_time, $next_tracker_time); # add code to alert if over time interval for status $timecheck = round(abs( strtotime($start_tracker_time) - strtotime($next_tracker_time)) / 60,0); if($timecheck > $alert_time && ($alert_time != '0')) { if (is_checkin($track_stat) || is_checkout($track_stat)) { #bold the check in and check out times in this block. ?> <td class="detail" bgcolor='<?php echo attr($alert_color) ?>'><b> <?php echo text($tracker_time); ?></b></td> <?php } else { ?> <td class="detail" bgcolor='<?php echo attr($alert_color) ?>'> <?php echo text($tracker_time); ?></td> <?php } ?> <?php } else { if (is_checkin($track_stat) || is_checkout($track_stat)) { #bold the check in and check out times in this block. ?> <td class="detail"><b> <?php echo text($tracker_time); ?></b></td> <?php } else { ?> <td class="detail"> <?php echo text($tracker_time); ?></td> <?php } } $i++; } } ?> </td> </tr> <?php } else { # this section is for the drug screen report ?>