fix: Update patient_tracker.php (#6595)
[openemr.git] / library / ajax / dated_reminders_counter.php
blobfb1a47a9262cd0f5f272a07165f3243b2f8bb447
1 <?php
3 /**
4 * Returns a count of due messages for current user.
5 * In 2021, added the timeout mechanism to this script.
7 * @package OpenEMR
8 * @link https://www.open-emr.org
9 * @author Craig Bezuidenhout <https://www.tajemo.co.za/>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @author Jerry Padgett <sjpadgett@gmail.com>
12 * @copyright Copyright (c) 2012 tajemo.co.za <https://www.tajemo.co.za/>
13 * @copyright Copyright (c) 2018-2021 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once(__DIR__ . "/../../interface/globals.php");
18 require_once("$srcdir/dated_reminder_functions.php");
19 require_once("$srcdir/pnotes.inc.php");
21 use OpenEMR\Common\Csrf\CsrfUtils;
22 use OpenEMR\Common\Session\SessionTracker;
24 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
25 CsrfUtils::csrfNotVerified();
28 // ensure timeout has not happened
29 if (SessionTracker::isSessionExpired()) {
30 echo json_encode(['timeoutMessage' => 'timeout']);
31 exit;
33 // keep this below above time out check.
34 OpenEMR\Common\Session\SessionUtil::setSession('keepAliveTime', time());
36 $total_counts = array();
37 $other_count = array();
38 // if portal is enabled get various alerts
39 if (!empty($_POST['isPortal'])) {
40 $total_counts = GetPortalAlertCounts();
43 if (!empty($_POST['isServicesOther'])) {
44 $other_count = GetServiceOtherCounts();
45 $total_counts = array_merge($total_counts, $other_count);
47 //Collect number of due reminders
48 $dueReminders = GetDueReminderCount(5, strtotime(date('Y/m/d')));
49 //Collect number of active messages
50 $activeMessages = getPnotesByUser("1", "no", $_SESSION['authUser'], true);
51 // Below for Message Button count display.
52 $totalNumber = $dueReminders + $activeMessages;
53 $total_counts['reminderText'] = ($totalNumber > 0 ? text((int)$totalNumber) : '');
55 echo json_encode($total_counts);