6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once(dirname(__FILE__). "/../interface/globals.php");
15 use OpenEMR\Common\Logging\EventAuditLogger;
17 // Function called to set the global session variable for patient id (pid) number.
18 function setpid($new_pid)
20 global $pid, $encounter;
22 // Escape $new_pid by forcing it to an integer to protect from sql injection
23 $new_pid_int = intval($new_pid);
24 // If the $new_pid was not an integer, then send an error to error log
25 if (!is_numeric($new_pid)) {
26 error_log("Critical OpenEMR Error: Attempt to set pid to following non-integer value was denied: " . errorLogEscape($new_pid), 0);
27 error_log("Requested pid " . errorLogEscape($new_pid), 0);
28 error_log("Returned pid " . errorLogEscape($new_pid_int), 0);
31 // Be careful not to clear the encounter unless the pid is really changing.
32 if (!isset($_SESSION['pid']) || $pid != $new_pid_int || $pid != $_SESSION['pid']) {
33 $_SESSION['encounter'] = $encounter = 0;
36 // unset therapy_group session when set session for patient
37 if ($_SESSION['pid'] != 0 && isset($_SESSION['therapy_group'])) {
38 unset($_SESSION['therapy_group']);
42 // Set pid to the escaped pid
43 $_SESSION['pid'] = $new_pid_int;
46 EventAuditLogger::instance()->newEvent("view", $_SESSION["authUser"], $_SESSION["authProvider"], 1, '', $pid);