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-2022 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.php");
21 require_once("$srcdir/options.inc.php");
22 require_once('lib/portal_mail.inc.php');
23 require_once(__DIR__
. '/../library/appointments.inc.php');
25 use OpenEMR\Common\Csrf\CsrfUtils
;
26 use OpenEMR\Common\Twig\TwigContainer
;
27 use OpenEMR\Events\PatientPortal\RenderEvent
;
28 use OpenEMR\Events\PatientPortal\AppointmentFilterEvent
;
29 use OpenEMR\Services\LogoService
;
31 if (isset($_SESSION['register']) && $_SESSION['register'] === true) {
32 require_once(__DIR__
. '/../src/Common/Session/SessionUtil.php');
33 OpenEMR\Common\Session\SessionUtil
::portalSessionCookieDestroy();
34 header('Location: ' . $landingpage . '&w');
38 if (!isset($_SESSION['portal_init'])) {
39 $_SESSION['portal_init'] = true;
42 $logoService = new LogoService();
45 // Get language definitions for js
46 $language = $_SESSION['language_choice'] ??
'1'; // defaults english
47 $sql = "SELECT c.constant_name, d.definition FROM lang_definitions as d
48 JOIN lang_constants AS c ON d.cons_id = c.cons_id
50 $tarns = sqlStatement($sql, $language);
51 $language_defs = array();
52 while ($row = SqlFetchArray($tarns)) {
53 $language_defs[$row['constant_name']] = $row['definition'];
56 $whereto = $_SESSION['whereto'] ??
null;
58 $user = $_SESSION['sessionUser'] ??
'portal user';
59 $result = getPatientData($pid);
61 $msgs = getPortalPatientNotes($_SESSION['portal_username']);
62 $msgcnt = count($msgs);
64 foreach ($msgs as $i) {
65 if ($i['message_status'] == 'New') {
69 if ($newcnt > 0 && $_SESSION['portal_init']) {
70 $whereto = $_SESSION['whereto'] = '#secure-msgs-card';
72 $messagesURL = $GLOBALS['web_root'] . '' . '/portal/messaging/messages.php';
74 $isEasyPro = $GLOBALS['easipro_enable'] && !empty($GLOBALS['easipro_server']) && !empty($GLOBALS['easipro_name']);
76 $current_date2 = date('Y-m-d');
78 $appts = fetchNextXAppts($current_date2, $pid, $apptLimit);
80 $appointments = array();
83 $stringCM = '(' . xl('Comments field entry present') . ')';
84 $stringR = '(' . xl('Recurring appointment') . ')';
86 foreach ($appts as $row) {
87 $status_title = getListItemTitle('apptstat', $row['pc_apptstatus']);
89 $dayname = xl(date('l', strtotime($row['pc_eventDate'])));
91 $disphour = (int)substr($row['pc_startTime'], 0, 2);
92 $dispmin = substr($row['pc_startTime'], 3, 2);
93 if ($disphour >= 12) {
100 if ($row['pc_hometext'] != '') {
101 $etitle = xl('Comments') . ': ' . $row['pc_hometext'] . "\r\n";
107 'appointmentDate' => $dayname . ', ' . $row['pc_eventDate'] . ' ' . $disphour . ':' . $dispmin . ' ' . $dispampm,
108 'appointmentType' => xl('Type') . ': ' . $row['pc_catname'],
109 'provider' => xl('Provider') . ': ' . $row['ufname'] . ' ' . $row['ulname'],
110 'status' => xl('Status') . ': ' . $status_title,
111 'mode' => (int)$row['pc_recurrtype'] > 0 ?
'recurring' : $row['pc_recurrtype'],
112 'icon_type' => (int)$row['pc_recurrtype'] > 0,
114 'pc_eid' => $row['pc_eid'],
116 $filteredEvent = $GLOBALS['kernel']->getEventDispatcher()->dispatch(new AppointmentFilterEvent($row, $formattedRecord), AppointmentFilterEvent
::EVENT_NAME
);
117 $appointments[] = $filteredEvent->getAppointment() ??
$formattedRecord;
121 function buildNav($newcnt, $pid, $result)
126 'label' => $result['fname'] . ' ' . $result['lname'],
128 'dropdownID' => 'account',
129 'messageCount' => $newcnt ??
0,
132 'url' => '#profilecard',
133 'label' => xl('My Profile'),
135 'dataToggle' => 'collapse',
139 'url' => '#secure-msgs-card',
140 'label' => xl('My Messages'),
141 'icon' => 'fa-envelope',
142 'dataToggle' => 'collapse',
143 'messageCount' => $newcnt ??
0,
146 'url' => '#documentscard',
147 'label' => xl('My Documents'),
148 'icon' => 'fa-file-medical',
149 'dataToggle' => 'collapse'
153 'label' => xl('My Dashboard'),
155 'dataToggle' => 'collapse'
158 'url' => '#openSignModal',
159 'label' => xl('My Signature'),
160 'icon' => 'fa-file-signature',
161 'dataToggle' => 'modal',
162 'dataType' => 'patient-signature'
168 'label' => xl('Reports'),
169 'icon' => 'fa-book-medical',
170 'dropdownID' => 'reports',
173 'url' => $GLOBALS['web_root'] . '' . '/ccdaservice/ccda_gateway.php?action=view&csrf_token_form=' . urlencode(CsrfUtils
::collectCsrfToken()),
174 'label' => xl('View CCD'),
176 'target_blank' => 'true',
179 'url' => $GLOBALS['web_root'] . '' . '/ccdaservice/ccda_gateway.php?action=dl&csrf_token_form=' . urlencode(CsrfUtils
::collectCsrfToken()),
180 'label' => xl('Download CCD'),
181 'icon' => 'fa-download',
186 if (($GLOBALS['portal_two_ledger'] ||
$GLOBALS['portal_two_payments'])) {
187 if (!empty($GLOBALS['portal_two_ledger'])) {
190 'label' => xl('Accountings'),
191 'icon' => 'fa-file-invoice-dollar',
192 'dropdownID' => 'accounting',
195 'url' => '#ledgercard',
196 'label' => xl('Ledger'),
197 'icon' => 'fa-folder-open',
198 'dataToggle' => 'collapse'
205 if ($GLOBALS['easipro_enable'] && !empty($GLOBALS['easipro_server']) && !empty($GLOBALS['easipro_name'])) {
208 'label' => xl('My Assessments'),
209 'icon' => 'fas fa-file-medical',
210 'dataToggle' => 'collapse',
211 'dataType' => 'cardgroup'
215 // Build sub nav items
217 if (!empty($GLOBALS['allow_portal_chat'])) {
219 'url' => '#messagescard',
220 'label' => xl('Chat'),
221 'icon' => 'fa-comment-medical',
222 'dataToggle' => 'collapse',
223 'dataType' => 'cardgroup'
227 for ($i = 0, $iMax = count($navItems); $i < $iMax; $i++
) {
228 if ($GLOBALS['allow_portal_appointments'] && $navItems[$i]['label'] === ($result['fname'] . ' ' . $result['lname'])) {
229 $navItems[$i]['children'][] = [
230 'url' => '#appointmentcard',
231 'label' => xl('My Appointments'),
232 'icon' => 'fa-calendar-check',
233 'dataToggle' => 'collapse'
237 if ($navItems[$i]['label'] === ($result['fname'] . ' ' . $result['lname'])) {
239 $navItems[$i]['children'],
241 'url' => 'javascript:changeCredentials(event)',
242 'label' => xl('Change Credentials'),
243 'icon' => 'fa-cog fa-fw',
246 'url' => 'logout.php',
247 'label' => xl('Logout'),
248 'icon' => 'fa-ban fa-fw',
253 if (!empty($GLOBALS['portal_onsite_document_download']) && $navItems[$i]['label'] === xl('Reports')) {
255 $navItems[$i]['children'],
257 'url' => '#reportcard',
258 'label' => xl('Report Content'),
259 'icon' => 'fa-folder-open',
260 'dataToggle' => 'collapse'
263 'url' => '#downloadcard',
264 'label' => xl('Download Charted Documents'),
265 'icon' => 'fa-download',
266 'dataToggle' => 'collapse'
270 if (!empty($GLOBALS['portal_two_payments']) && $navItems[$i]['label'] === xl('Accountings')) {
271 $navItems[$i]['children'][] = [
272 'url' => '#paymentcard',
273 'label' => xl('Make Payment'),
274 'icon' => 'fa-credit-card',
275 'dataToggle' => 'collapse'
283 $navMenu = buildNav($newcnt, $pid, $result);
285 $twig = (new TwigContainer('', $GLOBALS['kernel']))->getTwig();
286 echo $twig->render('portal/home.html.twig', [
288 'whereto' => $_SESSION['whereto'] ??
null ?
: ($whereto ??
'#documentscard'),
293 'menuLogo' => $logoService->getLogo('portal/menu/primary'),
294 'allow_portal_appointments' => $GLOBALS['allow_portal_appointments'],
295 'web_root' => $GLOBALS['web_root'],
296 'payment_gateway' => $GLOBALS['payment_gateway'],
297 'gateway_mode_production' => $GLOBALS['gateway_mode_production'],
298 'portal_two_payments' => $GLOBALS['portal_two_payments'],
299 'allow_portal_chat' => $GLOBALS['allow_portal_chat'],
300 'portal_onsite_document_download' => $GLOBALS['portal_onsite_document_download'],
301 'portal_two_ledger' => $GLOBALS['portal_two_ledger'],
302 'images_static_relative' => $GLOBALS['images_static_relative'],
303 'youHave' => xl('You have'),
304 'navMenu' => $navMenu,
305 'pagetitle' => xl('Home') . ' | ' . xl('OpenEMR Portal'),
306 'messagesURL' => $messagesURL,
308 'patientName' => $_SESSION['ptName'] ??
null,
309 'csrfUtils' => CsrfUtils
::collectCsrfToken(),
310 'isEasyPro' => $isEasyPro,
311 'appointments' => $appointments,
313 'appointmentLimit' => $apptLimit,
314 'appointmentCount' => $count ??
null,
315 'displayLimitLabel' => xl('Display limit reached'),
316 'site_id' => $_SESSION['site_id'] ??
($_GET['site'] ??
'default'), // one way or another, we will have a site_id.
317 'portal_timeout' => $GLOBALS['portal_timeout'] ??
1800, // timeout is in seconds
318 'language_defs' => $language_defs,
320 'sectionRenderPost' => RenderEvent
::EVENT_SECTION_RENDER_POST
,
321 'scriptsRenderPre' => RenderEvent
::EVENT_SCRIPTS_RENDER_PRE