Fix for issue #291
[openemr.git] / library / appointment_status.inc.php
blobca84d85b8c863c5bfbb204b03f15765dfd096af2
1 <?php
2 // Copyright (C) 2011, 2016 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This is called to update the appointment status for a specified patient
10 // with an encounter on the specified date. It does nothing unless the
11 // feature to auto-update appointment statuses is enabled.
13 // See sample code in: interface/patient_tracker/patient_tracker_status.php
14 // This updates the patient tracker board as well as the appointment.
16 require_once(dirname(__FILE__) . '/patient_tracker.inc.php');
18 function updateAppointmentStatus($pid, $encdate, $newstatus) {
19 if (empty($GLOBALS['gbl_auto_update_appt_status'])) return;
20 $query = "SELECT pc_eid, pc_aid, pc_catid, pc_apptstatus, pc_eventDate, pc_startTime, " .
21 "pc_hometext, pc_facility, pc_billing_location, pc_room " .
22 "FROM openemr_postcalendar_events WHERE " .
23 "pc_pid = ? AND pc_recurrtype = 0 AND pc_eventDate = ? " .
24 "ORDER BY pc_startTime DESC, pc_eid DESC LIMIT 1";
25 $tmp = sqlQuery($query, array($pid, $encdate));
26 if (!empty($tmp['pc_eid'])) {
27 $appt_eid = $tmp['pc_eid'];
28 $appt_status = $tmp['pc_apptstatus'];
29 // Some tests for illogical changes.
30 if ($appt_status == '$') return;
31 if ($newstatus == '<' && $appt_status == '>') return;
32 $encounter = todaysEncounterCheck($pid, $tmp['pc_eventDate'], $tmp['pc_hometext'], $tmp['pc_facility'],
33 $tmp['pc_billing_location'], $tmp['pc_aid'], $tmp['pc_catid'],false);
34 manage_tracker_status($tmp['pc_eventDate'], $tmp['pc_startTime'], $appt_eid, $pid,
35 $_SESSION["authUser"], $newstatus, $tmp['pc_room'], $encounter);