Skip to content

Commit

Permalink
Portal Quick Start refactor (openemr#7117)
Browse files Browse the repository at this point in the history
* Portal Quick Start refactor
- Pull quickstart dashboard from iFrame embed in home page twig
- fix nav topNav syntax

* refactor quickstart cardto twig

* - Move Dasboard template to render last on page
- add events to inject new cards in dashboard
- modify existing portal render event class to include new events for cards.

* - add me to authorship

* - delete obsalete quickstart page.
  • Loading branch information
sjpadgett authored Jan 5, 2024
1 parent 9e7ce34 commit f6b4fef
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 367 deletions.
126 changes: 81 additions & 45 deletions portal/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Brady Miller <[email protected]>
* @author Shiqiang Tao <[email protected]>
* @author Ben Marte <[email protected]>
* @copyright Copyright (c) 2016-2022 Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2016-2023 Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2019-2021 Brady Miller <[email protected]>
* @copyright Copyright (c) 2020 Shiqiang Tao <[email protected]>
* @copyright Copyright (c) 2021 Ben Marte <[email protected]>
Expand All @@ -27,6 +27,9 @@
use OpenEMR\Events\PatientPortal\RenderEvent;
use OpenEMR\Events\PatientPortal\AppointmentFilterEvent;
use OpenEMR\Services\LogoService;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;

if (isset($_SESSION['register']) && $_SESSION['register'] === true) {
require_once(__DIR__ . '/../src/Common/Session/SessionUtil.php');
Expand Down Expand Up @@ -78,7 +81,6 @@
$appts = fetchNextXAppts($current_date2, $pid, $apptLimit);

$appointments = array();

if ($appts) {
$stringCM = '(' . xl('Comments field entry present') . ')';
$stringR = '(' . xl('Recurring appointment') . ')';
Expand Down Expand Up @@ -118,6 +120,29 @@
}
}

$current_theme = sqlQuery("SELECT `setting_value` FROM `patient_settings` WHERE setting_patient = ? AND `setting_label` = ?", array($pid, 'portal_theme'))['setting_value'] ?? '';
function collectStyles(): array
{
global $webserver_root;
$theme_dir = "$webserver_root/public/themes";
$dh = opendir($theme_dir);
$styleArray = array();
while (false !== ($tfname = readdir($dh))) {
if (
$tfname == 'style_blue.css' ||
$tfname == 'style_pdf.css' ||
!preg_match("/^" . 'style_' . ".*\.css$/", $tfname)
) {
continue;
}
$styleDisplayName = str_replace("_", " ", substr($tfname, 6));
$styleDisplayName = ucfirst(str_replace(".css", "", $styleDisplayName));
$styleArray[$tfname] = $styleDisplayName;
}
asort($styleArray);
closedir($dh);
return $styleArray;
}
function buildNav($newcnt, $pid, $result)
{
$navItems = [
Expand All @@ -131,7 +156,7 @@ function buildNav($newcnt, $pid, $result)
[
'url' => '#quickstart-card',
'id' => 'quickstart_id',
'label' => xl('My Quick Start'),
'label' => xl('My Dashboard'),
'icon' => 'fa-tasks',
'dataToggle' => 'collapse',
],
Expand Down Expand Up @@ -159,7 +184,7 @@ function buildNav($newcnt, $pid, $result)
],*/
[
'url' => '#lists',
'label' => xl('My Dashboard'),
'label' => xl('My Health'),
'icon' => 'fa-list',
'dataToggle' => 'collapse'
],
Expand Down Expand Up @@ -288,46 +313,57 @@ function buildNav($newcnt, $pid, $result)

return $navItems;
}

// Available Themes
$styleArray = collectStyles();
// Build our navigation
$navMenu = buildNav($newcnt, $pid, $result);

// Render Home Page
$twig = (new TwigContainer('', $GLOBALS['kernel']))->getTwig();
echo $twig->render('portal/home.html.twig', [
'user' => $user,
'whereto' => $_SESSION['whereto'] ?? null ?: ($whereto ?? '#quickstart-card'),
'result' => $result,
'msgs' => $msgs,
'msgcnt' => $msgcnt,
'newcnt' => $newcnt,
'menuLogo' => $logoService->getLogo('portal/menu/primary'),
'allow_portal_appointments' => $GLOBALS['allow_portal_appointments'],
'web_root' => $GLOBALS['web_root'],
'payment_gateway' => $GLOBALS['payment_gateway'],
'gateway_mode_production' => $GLOBALS['gateway_mode_production'],
'portal_two_payments' => $GLOBALS['portal_two_payments'],
'allow_portal_chat' => $GLOBALS['allow_portal_chat'],
'portal_onsite_document_download' => $GLOBALS['portal_onsite_document_download'],
'portal_two_ledger' => $GLOBALS['portal_two_ledger'],
'images_static_relative' => $GLOBALS['images_static_relative'],
'youHave' => xl('You have'),
'navMenu' => $navMenu,
'primaryMenuLogoHeight' => $GLOBALS['portal_primary_menu_logo_height'] ?? '30',
'pagetitle' => xl('Home') . ' | ' . $GLOBALS['openemr_name'] . ' ' . xl('Portal'),
'messagesURL' => $messagesURL,
'patientID' => $pid,
'patientName' => $_SESSION['ptName'] ?? null,
'csrfUtils' => CsrfUtils::collectCsrfToken(),
'isEasyPro' => $isEasyPro,
'appointments' => $appointments,
'appts' => $appts,
'appointmentLimit' => $apptLimit,
'appointmentCount' => $count ?? null,
'displayLimitLabel' => xl('Display limit reached'),
'site_id' => $_SESSION['site_id'] ?? ($_GET['site'] ?? 'default'), // one way or another, we will have a site_id.
'portal_timeout' => $GLOBALS['portal_timeout'] ?? 1800, // timeout is in seconds
'language_defs' => $language_defs,
'eventNames' => [
'sectionRenderPost' => RenderEvent::EVENT_SECTION_RENDER_POST,
'scriptsRenderPre' => RenderEvent::EVENT_SCRIPTS_RENDER_PRE
]
]);
try {
echo $twig->render('portal/home.html.twig', [
'user' => $user,
'whereto' => $_SESSION['whereto'] ?? null ?: ($whereto ?? '#quickstart-card'),
'result' => $result,
'msgs' => $msgs,
'msgcnt' => $msgcnt,
'newcnt' => $newcnt,
'menuLogo' => $logoService->getLogo('portal/menu/primary'),
'allow_portal_appointments' => $GLOBALS['allow_portal_appointments'],
'web_root' => $GLOBALS['web_root'],
'payment_gateway' => $GLOBALS['payment_gateway'],
'gateway_mode_production' => $GLOBALS['gateway_mode_production'],
'portal_two_payments' => $GLOBALS['portal_two_payments'],
'allow_portal_chat' => $GLOBALS['allow_portal_chat'],
'portal_onsite_document_download' => $GLOBALS['portal_onsite_document_download'],
'portal_two_ledger' => $GLOBALS['portal_two_ledger'],
'images_static_relative' => $GLOBALS['images_static_relative'],
'youHave' => xl('You have'),
'navMenu' => $navMenu,
'primaryMenuLogoHeight' => $GLOBALS['portal_primary_menu_logo_height'] ?? '30',
'pagetitle' => xl('Home') . ' | ' . $GLOBALS['openemr_name'] . ' ' . xl('Portal'),
'messagesURL' => $messagesURL,
'patientID' => $pid,
'patientName' => $_SESSION['ptName'] ?? null,
'csrfUtils' => CsrfUtils::collectCsrfToken(),
'isEasyPro' => $isEasyPro,
'appointments' => $appointments,
'appts' => $appts,
'appointmentLimit' => $apptLimit,
'appointmentCount' => $count ?? null,
'displayLimitLabel' => xl('Display limit reached'),
'site_id' => $_SESSION['site_id'] ?? ($_GET['site'] ?? 'default'), // one way or another, we will have a site_id.
'portal_timeout' => $GLOBALS['portal_timeout'] ?? 1800, // timeout is in seconds
'language_defs' => $language_defs,
'current_theme' => $current_theme,
'styleArray' => $styleArray,
'eventNames' => [
'sectionRenderPost' => RenderEvent::EVENT_SECTION_RENDER_POST,
'scriptsRenderPre' => RenderEvent::EVENT_SCRIPTS_RENDER_PRE,
'dashboardInjectCard' => RenderEvent::EVENT_DASHBOARD_INJECT_CARD,
'dashboardRenderScripts' => RenderEvent::EVENT_DASHBOARD_RENDER_SCRIPTS
]
]);
} catch (LoaderError | RuntimeError | SyntaxError $e) {
OpenEMR\Common\Session\SessionUtil::portalSessionCookieDestroy();
die(text($e->getMessage()));
}
4 changes: 2 additions & 2 deletions portal/lib/appsql.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ public function portalAudit(string $type = null, string $rec = null, array $audi

public function portalLog($event = '', $patient_id = null, $comments = "", $binds = '', $success = '1', $user_notes = '', $ccda_doc_id = 0)
{
$groupname = isset($GLOBALS['groupname']) ? $GLOBALS['groupname'] : 'none';
$user = isset($_SESSION['portal_username']) ? $_SESSION['portal_username'] : $_SESSION['authUser'] ?? null;
$groupname = $GLOBALS['groupname'] ?? 'none';
$user = $_SESSION['portal_username'] ?? $_SESSION['authUser'] ?? null;
$log_from = isset($_SESSION['portal_username']) ? 'onsite-portal' : 'portal-dashboard';
if (!isset($_SESSION['portal_username']) && !isset($_SESSION['authUser'])) {
$log_from = 'portal-login';
Expand Down
12 changes: 1 addition & 11 deletions portal/patient/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,7 @@ var app = {
return str;

},

/**
* Convenience method for creating an option
*/
getOptionHtml: function(val,label,selected) {
return '<option value="' + _.escape(val) + '" ' + (selected ? 'selected="selected"' : '') +'>'
+ _.escape(label)
+ '</option>';
},

/**
/**
* A server error should contain json data, but if a fatal php error occurs it
* may contain html. the function will parse the return contents of an
* error response and return the error message
Expand Down
6 changes: 3 additions & 3 deletions portal/patient/scripts/app/onsitedocuments.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var page = {
// make the rows clickable ('rendered' is a custom event, not a standard backbone event)
this.collectionView.on('rendered', function () {
if (page.isDashboard) {
$("#topnav").hide();
$("#topNav").hide();
}
// attach click handler to the table rows for editing
$('table.collection tbody tr').click(function (e) {
Expand Down Expand Up @@ -100,7 +100,7 @@ var page = {
});
$('.template-item').unbind().on('click', function (e) {
if (!isModule) {
$("#topnav").hide();
$("#topNav").hide();
parent.document.getElementById('topNav').classList.add('collapse');
}
});
Expand Down Expand Up @@ -673,7 +673,7 @@ var page = {
page.encounterFormId = 0;
page.encounterFormName = '';
if (page.currentName !== 'Help') {
$("#topnav").hide();
$("#topNav").hide();
}
if (page.currentName === templateName && page.currentName && !page.isNewDoc) {
// update form for any submits.(downloads and prints)
Expand Down
2 changes: 1 addition & 1 deletion portal/patient/templates/OnsiteDocumentListView.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ function restoreDocumentEdits() {
</nav>
<div class="d-flex flex-row justify-content-center">
<!-- Pending documents left menu Deprecated and removed 01/13/22 -->
<div class="clearfix" id="topnav">
<div class="clearfix" id="topNav">
<div id="collectionAlert"></div>
</div>
<!-- Right editor container -->
Expand Down
Loading

0 comments on commit f6b4fef

Please sign in to comment.