function calendar_arrived($form_pid) { $Today = date('Y-m-d'); //Take all recurring events relevent for today. $result_event = sqlStatement("SELECT * FROM openemr_postcalendar_events WHERE pc_recurrtype='1' and pc_pid =? and pc_endDate!='0000-00-00' \n\t\tand pc_eventDate < ? and pc_endDate >= ? ", array($form_pid, $Today, $Today)); if (sqlNumRows($result_event) == 0) { $result_event = sqlStatement("SELECT * FROM openemr_postcalendar_events WHERE pc_pid =?\tand pc_eventDate = ?", array($form_pid, $Today)); if (sqlNumRows($result_event) == 0) { echo "<br><br><br>" . htmlspecialchars(xl('Sorry No Appointment is Fixed'), ENT_QUOTES) . ". " . htmlspecialchars(xl('No Encounter could be created'), ENT_QUOTES) . "."; die; } else { $enc = todaysEncounterCheck($form_pid); //create encounter $zero_enc = 0; sqlStatement("UPDATE openemr_postcalendar_events SET pc_apptstatus ='@' WHERE pc_pid =? and pc_eventDate = ?", array($form_pid, $Today)); } } else { while ($row_event = sqlFetchArray($result_event)) { $pc_eid = $row_event['pc_eid']; $pc_eventDate = $row_event['pc_eventDate']; $pc_recurrspec_array = unserialize($row_event['pc_recurrspec']); while (1) { if ($pc_eventDate == $Today) { if (!($exist_eid = check_event_exist($pc_eid))) { update_event($pc_eid); } else { sqlStatement("UPDATE openemr_postcalendar_events SET pc_apptstatus = '@' WHERE pc_eid = ?", array($exist_eid)); } $enc = todaysEncounterCheck($form_pid); //create encounter $zero_enc = 0; break; } elseif ($pc_eventDate > $Today) { echo "<br><br><br>" . htmlspecialchars(xl('Sorry No Appointment is Fixed'), ENT_QUOTES) . ". " . htmlspecialchars(xl('No Encounter could be created'), ENT_QUOTES) . "."; die; break; } $pc_eventDate_array = split('-', $pc_eventDate); //Find the next day as per the frequency definition. $pc_eventDate =& __increment($pc_eventDate_array[2], $pc_eventDate_array[1], $pc_eventDate_array[0], $pc_recurrspec_array['event_repeat_freq'], $pc_recurrspec_array['event_repeat_freq_type']); } } } return $enc; }
function updateAppointmentStatus($pid, $encdate, $newstatus) { if (empty($GLOBALS['gbl_auto_update_appt_status'])) { return; } $query = "SELECT pc_eid, pc_aid, pc_catid, pc_apptstatus, pc_eventDate, pc_startTime, " . "pc_hometext, pc_facility, pc_billing_location, pc_room " . "FROM openemr_postcalendar_events WHERE " . "pc_pid = ? AND pc_recurrtype = 0 AND pc_eventDate = ? " . "ORDER BY pc_startTime DESC, pc_eid DESC LIMIT 1"; $tmp = sqlQuery($query, array($pid, $encdate)); if (!empty($tmp['pc_eid'])) { $appt_eid = $tmp['pc_eid']; $appt_status = $tmp['pc_apptstatus']; // Some tests for illogical changes. if ($appt_status == '$') { return; } if ($newstatus == '<' && $appt_status == '>') { return; } $encounter = todaysEncounterCheck($pid, $tmp['pc_eventDate'], $tmp['pc_hometext'], $tmp['pc_facility'], $tmp['pc_billing_location'], $tmp['pc_aid'], $tmp['pc_catid'], false); manage_tracker_status($tmp['pc_eventDate'], $tmp['pc_startTime'], $appt_eid, $pid, $_SESSION["authUser"], $newstatus, $tmp['pc_room'], $encounter); } }
$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); } } echo "<html>\n<body>\n<script language='JavaScript'>\n"; echo " window.opener.pattrk.submit();\n";
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']); } } } }
function DOBandEncounter() { global $event_date, $info_msg; // Save new DOB if it's there. $patient_dob = trim($_POST['form_dob']); if ($patient_dob && $_POST['form_pid']) { sqlStatement("UPDATE patient_data SET DOB = ? WHERE " . "pid = ?", array($patient_dob, $_POST['form_pid'])); } // Auto-create a new encounter if appropriate. // if ($GLOBALS['auto_create_new_encounters'] && $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d')) { $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}"; } } }
function calendar_arrived($form_pid) { $Today = date('Y-m-d'); //Take all recurring events relevent for today. $result_event = sqlStatement("SELECT * FROM openemr_postcalendar_events WHERE pc_recurrtype != '0' and pc_pid = ? and pc_endDate != '0000-00-00'\n\t\tand pc_eventDate < ? and pc_endDate >= ? ", array($form_pid, $Today, $Today)); if (sqlNumRows($result_event) == 0) { $result_event = sqlStatement("SELECT * FROM openemr_postcalendar_events WHERE pc_pid =?\tand pc_eventDate = ?", array($form_pid, $Today)); if (sqlNumRows($result_event) == 0) { echo "<br><br><br>" . htmlspecialchars(xl('Sorry No Appointment is Fixed'), ENT_QUOTES) . ". " . htmlspecialchars(xl('No Encounter could be created'), ENT_QUOTES) . "."; die; } else { $enc = todaysEncounterCheck($form_pid); //create encounter $zero_enc = 0; sqlStatement("UPDATE openemr_postcalendar_events SET pc_apptstatus ='@' WHERE pc_pid =? and pc_eventDate = ?", array($form_pid, $Today)); } } else { while ($row_event = sqlFetchArray($result_event)) { $pc_eid = $row_event['pc_eid']; $pc_eventDate = $row_event['pc_eventDate']; $pc_recurrspec_array = unserialize($row_event['pc_recurrspec']); while (1) { if ($pc_eventDate == $Today) { if (!($exist_eid = check_event_exist($pc_eid))) { update_event($pc_eid); } else { sqlStatement("UPDATE openemr_postcalendar_events SET pc_apptstatus = '@' WHERE pc_eid = ?", array($exist_eid)); } $enc = todaysEncounterCheck($form_pid); //create encounter $zero_enc = 0; break; } elseif ($pc_eventDate > $Today) { echo "<br><br><br>" . htmlspecialchars(xl('Sorry No Appointment is Fixed'), ENT_QUOTES) . ". " . htmlspecialchars(xl('No Encounter could be created'), ENT_QUOTES) . "."; die; break; } // Added by Rod to handle repeats on nth or last given weekday of a month: if ($row_event['pc_recurrtype'] == 2) { $my_repeat_on_day = $pc_recurrspec_array['event_repeat_on_day']; $my_repeat_on_num = $pc_recurrspec_array['event_repeat_on_num']; $adate = getdate(strtotime($pc_eventDate)); $adate['mon'] += 1; if ($adate['mon'] > 12) { $adate['year'] += 1; $adate['mon'] -= 12; } if ($my_repeat_on_num < 5) { // not last $adate['mday'] = 1; $dow = jddayofweek(cal_to_jd(CAL_GREGORIAN, $adate['mon'], $adate['mday'], $adate['year'])); if ($dow > $my_repeat_on_day) { $dow -= 7; } $adate['mday'] += ($my_repeat_on_num - 1) * 7 + $my_repeat_on_day - $dow; } else { // last weekday of month $adate['mday'] = cal_days_in_month(CAL_GREGORIAN, $adate['mon'], $adate['year']); $dow = jddayofweek(cal_to_jd(CAL_GREGORIAN, $adate['mon'], $adate['mday'], $adate['year'])); if ($dow < $my_repeat_on_day) { $dow += 7; } $adate['mday'] += $my_repeat_on_day - $dow; } $pc_eventDate = date('Y-m-d', mktime(0, 0, 0, $adate['mon'], $adate['mday'], $adate['year'])); } else { // pc_recurrtype is 1 $pc_eventDate_array = split('-', $pc_eventDate); // Find the next day as per the frequency definition. $pc_eventDate =& __increment($pc_eventDate_array[2], $pc_eventDate_array[1], $pc_eventDate_array[0], $pc_recurrspec_array['event_repeat_freq'], $pc_recurrspec_array['event_repeat_freq_type']); } } } } return $enc; }