Merge pull request #1169 from matrix-israel/AE/fixRegressionConditions
[openemr.git] / library / appointment_status.inc.php
blob81b34aa319f0820501307bfe24106c2f9d1febfa
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)
20 if (empty($GLOBALS['gbl_auto_update_appt_status'])) {
21 return;
24 $query = "SELECT pc_eid, pc_aid, pc_catid, pc_apptstatus, pc_eventDate, pc_startTime, " .
25 "pc_hometext, pc_facility, pc_billing_location, pc_room " .
26 "FROM openemr_postcalendar_events WHERE " .
27 "pc_pid = ? AND pc_recurrtype = 0 AND pc_eventDate = ? " .
28 "ORDER BY pc_startTime DESC, pc_eid DESC LIMIT 1";
29 $tmp = sqlQuery($query, array($pid, $encdate));
30 if (!empty($tmp['pc_eid'])) {
31 $appt_eid = $tmp['pc_eid'];
32 $appt_status = $tmp['pc_apptstatus'];
33 // Some tests for illogical changes.
34 if ($appt_status == '$') {
35 return;
38 if ($newstatus == '<' && $appt_status == '>') {
39 return;
42 $encounter = todaysEncounterCheck(
43 $pid,
44 $tmp['pc_eventDate'],
45 $tmp['pc_hometext'],
46 $tmp['pc_facility'],
47 $tmp['pc_billing_location'],
48 $tmp['pc_aid'],
49 $tmp['pc_catid'],
50 false
52 manage_tracker_status(
53 $tmp['pc_eventDate'],
54 $tmp['pc_startTime'],
55 $appt_eid,
56 $pid,
57 $_SESSION["authUser"],
58 $newstatus,
59 $tmp['pc_room'],
60 $encounter