Openemr fix 4723 module install script uses OpenEMR sql upgrade service (#4724)
[openemr.git] / portal / home.php
blob5f3b28abe46eb6fa8163fadc86ad6683f56e0c4c
1 <?php
3 /**
4 * Patient Portal Home
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @author Shiqiang Tao <StrongTSQ@gmail.com>
11 * @author Ben Marte <benmarte@gmail.com>
12 * @copyright Copyright (c) 2016-2021 Jerry Padgett <sjpadgett@gmail.com>
13 * @copyright Copyright (c) 2019-2021 Brady Miller <brady.g.miller@gmail.com>
14 * @copyright Copyright (c) 2020 Shiqiang Tao <StrongTSQ@gmail.com>
15 * @copyright Copyright (c) 2021 Ben Marte <benmarte@gmail.com>
16 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
19 require_once('verify_session.php');
20 require_once("$srcdir/patient.inc");
21 require_once("$srcdir/options.inc.php");
22 require_once('lib/portal_mail.inc');
23 require_once(__DIR__ . '/../library/appointments.inc.php');
25 use OpenEMR\Common\Csrf\CsrfUtils;
26 use OpenEMR\Common\Twig\TwigContainer;
28 if (isset($_SESSION['register']) && $_SESSION['register'] === true) {
29 require_once(__DIR__ . '/../src/Common/Session/SessionUtil.php');
30 OpenEMR\Common\Session\SessionUtil::portalSessionCookieDestroy();
31 header('Location: ' . $landingpage . '&w');
32 exit();
35 if (!isset($_SESSION['portal_init'])) {
36 $_SESSION['portal_init'] = true;
39 $whereto = $_SESSION['whereto'] ?? null;
41 $user = $_SESSION['sessionUser'] ?? 'portal user';
42 $result = getPatientData($pid);
44 $msgs = getPortalPatientNotes($_SESSION['portal_username']);
45 $msgcnt = count($msgs);
46 $newcnt = 0;
47 foreach ($msgs as $i) {
48 if ($i['message_status'] == 'New') {
49 $newcnt += 1;
52 if ($newcnt > 0 && $_SESSION['portal_init']) {
53 $whereto = $_SESSION['whereto'] = '#secure-msgs-card';
55 $messagesURL = $GLOBALS['web_root'] . '' . '/portal/messaging/messages.php';
57 $isEasyPro = $GLOBALS['easipro_enable'] && !empty($GLOBALS['easipro_server']) && !empty($GLOBALS['easipro_name']);
59 $current_date2 = date('Y-m-d');
60 $apptLimit = 30;
61 $appts = fetchNextXAppts($current_date2, $pid, $apptLimit);
63 $appointments = array();
65 if ($appts) {
66 $stringCM = '(' . xl('Comments field entry present') . ')';
67 $stringR = '(' . xl('Recurring appointment') . ')';
68 $count = 0;
69 foreach ($appts as $row) {
70 $status_title = getListItemTitle('apptstat', $row['pc_apptstatus']);
71 $count++;
72 $dayname = xl(date('l', strtotime($row['pc_eventDate'])));
73 $dispampm = 'am';
74 $disphour = substr($row['pc_startTime'], 0, 2) + 0;
75 $dispmin = substr($row['pc_startTime'], 3, 2);
76 if ($disphour >= 12) {
77 $dispampm = 'pm';
78 if ($disphour > 12) {
79 $disphour -= 12;
83 if ($row['pc_hometext'] != '') {
84 $etitle = xl('Comments') . ': ' . $row['pc_hometext'] . "\r\n";
85 } else {
86 $etitle = '';
89 $appointments[] = [
90 'appointmentDate' => $dayname . ', ' . $row['pc_eventDate'] . ' ' . $disphour . ':' . $dispmin . ' ' . $dispampm,
91 'appointmentType' => xl('Type') . ': ' . $row['pc_catname'],
92 'provider' => xl('Provider') . ': ' . $row['ufname'] . ' ' . $row['ulname'],
93 'status' => xl('Status') . ': ' . $status_title,
94 'mode' => (int)$row['pc_recurrtype'] > 0 ? 'recurring' : $row['pc_recurrtype'],
95 'icon_type' => (int)$row['pc_recurrtype'] > 0,
96 'etitle' => $etitle,
97 'pc_eid' => $row['pc_eid'],
102 function buildNav($newcnt, $pid, $result)
104 $navItems = [
106 'url' => '#',
107 'label' => $result['fname'] . ' ' . $result['lname'],
108 'icon' => 'fa-user',
109 'dropdownID' => 'account',
110 'messageCount' => $newcnt ?? 0,
111 'children' => [
113 'url' => '#profilecard',
114 'label' => xl('My Profile'),
115 'icon' => 'fa-user',
116 'dataToggle' => 'collapse',
120 'url' => '#secure-msgs-card',
121 'label' => xl('My Messages'),
122 'icon' => 'fa-envelope',
123 'dataToggle' => 'collapse',
124 'messageCount' => $newcnt ?? 0,
127 'url' => '#documentscard',
128 'label' => xl('My Documents'),
129 'icon' => 'fa-file-medical',
130 'dataToggle' => 'collapse'
133 'url' => '#lists',
134 'label' => xl('My Dashboard'),
135 'icon' => 'fa-list',
136 'dataToggle' => 'collapse'
139 'url' => '#openSignModal',
140 'label' => xl('My Signature'),
141 'icon' => 'fa-file-signature',
142 'dataToggle' => 'modal',
143 'dataType' => 'patient-signature'
148 'url' => '#',
149 'label' => xl('Reports'),
150 'icon' => 'fa-book-medical',
151 'dropdownID' => 'reports',
152 'children' => [
154 'url' => $GLOBALS['web_root'] . '' . '/ccdaservice/ccda_gateway.php?action=startandrun&csrf_token_form=' . urlencode(CsrfUtils::collectCsrfToken()),
155 'label' => xl('View CCD'),
156 'icon' => 'fa-envelope',
161 if (($GLOBALS['portal_two_ledger'] || $GLOBALS['portal_two_payments'])) {
162 if (!empty($GLOBALS['portal_two_ledger'])) {
163 $navItems[] = [
164 'url' => '#',
165 'label' => xl('Accountings'),
166 'icon' => 'fa-file-invoice-dollar',
167 'dropdownID' => 'accounting',
168 'children' => [
170 'url' => '#ledgercard',
171 'label' => xl('Ledger'),
172 'icon' => 'fa-folder-open',
173 'dataToggle' => 'collapse'
180 // Build sub nav items
182 if (!empty($GLOBALS['allow_portal_chat'])) {
183 $navItems[] = [
184 'url' => '#messagescard',
185 'label' => xl('Chat'),
186 'icon' => 'fa-comment-medical',
187 'dataToggle' => 'collapse',
188 'dataType' => 'cardgroup'
192 for ($i = 0, $iMax = count($navItems); $i < $iMax; $i++) {
193 if ($GLOBALS['allow_portal_appointments'] && $navItems[$i]['label'] === ($result['fname'] . ' ' . $result['lname'])) {
194 $navItems[$i]['children'][] = [
195 'url' => '#appointmentcard',
196 'label' => xl('My Appointments'),
197 'icon' => 'fa-calendar-check',
198 'dataToggle' => 'collapse'
202 if ($navItems[$i]['label'] === ($result['fname'] . ' ' . $result['lname'])) {
203 array_push(
204 $navItems[$i]['children'],
206 'url' => 'javascript:changeCredentials(event)',
207 'label' => xl('Change Credentials'),
208 'icon' => 'fa-cog fa-fw',
211 'url' => 'logout.php',
212 'label' => xl('Logout'),
213 'icon' => 'fa-ban fa-fw',
218 if (!empty($GLOBALS['portal_onsite_document_download']) && $navItems[$i]['label'] === xl('Reports')) {
219 array_push(
220 $navItems[$i]['children'],
222 'url' => '#reportcard',
223 'label' => xl('Report Content'),
224 'icon' => 'fa-folder-open',
225 'dataToggle' => 'collapse'
228 'url' => '#downloadcard',
229 'label' => xl('Download Lab Documents'),
230 'icon' => 'fa-download',
231 'dataToggle' => 'collapse'
235 if (!empty($GLOBALS['portal_two_payments']) && $navItems[$i]['label'] === xl('Accountings')) {
236 $navItems[$i]['children'][] = [
237 'url' => '#paymentcard',
238 'label' => xl('Make Payment'),
239 'icon' => 'fa-credit-card',
240 'dataToggle' => 'collapse'
245 return $navItems;
248 $navMenu = buildNav($newcnt, $pid, $result);
250 echo (new TwigContainer(''))->getTwig()->render('portal/home.html.twig', [
251 'user' => $user,
252 'whereto' => $_SESSION['whereto'] ?: ($whereto ?? '#documentscard'),
253 'result' => $result,
254 'msgs' => $msgs,
255 'msgcnt' => $msgcnt,
256 'newcnt' => $newcnt,
257 'allow_portal_appointments' => $GLOBALS['allow_portal_appointments'],
258 'web_root' => $GLOBALS['web_root'],
259 'payment_gateway' => $GLOBALS['payment_gateway'],
260 'gateway_mode_production' => $GLOBALS['gateway_mode_production'],
261 'portal_two_payments' => $GLOBALS['portal_two_payments'],
262 'allow_portal_chat' => $GLOBALS['allow_portal_chat'],
263 'portal_onsite_document_download' => $GLOBALS['portal_onsite_document_download'],
264 'portal_two_ledger' => $GLOBALS['portal_two_ledger'],
265 'images_static_relative' => $GLOBALS['images_static_relative'],
266 'youHave' => xl('You have'),
267 'navMenu' => $navMenu,
268 'pagetitle' => xl('Home') . ' | ' . xl('OpenEMR Portal'),
269 'messagesURL' => $messagesURL,
270 'patientID' => $pid,
271 'patientName' => $_SESSION['ptName'],
272 'csrfUtils' => CsrfUtils::collectCsrfToken(),
273 'isEasyPro' => $isEasyPro,
274 'appointments' => $appointments,
275 'appts' => $appts,
276 'appointmentLimit' => $apptLimit,
277 'appointmentCount' => $count,
278 'displayLimitLabel' => xl('Display limit reached'),