From 82769f77462636d7bd52cdcf388778c40717eb9c Mon Sep 17 00:00:00 2001 From: Chi Bong Ho Date: Thu, 21 Nov 2024 14:11:54 -0500 Subject: [PATCH] (feat) UHM-8241 Create O2 pregnancy / infant dashboard extension for the ward app --- packages/esm-commons-app/src/index.ts | 5 ++ packages/esm-commons-app/src/routes.json | 5 ++ ...2-pregnancy-infant-dashboard.extension.tsx | 56 +++++++++++++++++++ .../o2-pregnancy-infant-dashboard.scss | 13 +++++ ...-visit-summary-action-button.extension.tsx | 4 +- .../esm-commons-app/src/ward-app/types.ts | 19 ++++++- 6 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 packages/esm-commons-app/src/ward-app/o2-pregnancy-infant-dashboard.extension.tsx create mode 100644 packages/esm-commons-app/src/ward-app/o2-pregnancy-infant-dashboard.scss diff --git a/packages/esm-commons-app/src/index.ts b/packages/esm-commons-app/src/index.ts index 3754303..0c07a3a 100644 --- a/packages/esm-commons-app/src/index.ts +++ b/packages/esm-commons-app/src/index.ts @@ -27,4 +27,9 @@ export const o2VisitSummaryWorkspace = getAsyncLifecycle( options, ); +export const o2PregnancyInfantDashboard = getAsyncLifecycle( + () => import('./ward-app/o2-pregnancy-infant-dashboard.extension'), + options, +); + export function startupApp() {} diff --git a/packages/esm-commons-app/src/routes.json b/packages/esm-commons-app/src/routes.json index 2ba3586..2d9d3f0 100644 --- a/packages/esm-commons-app/src/routes.json +++ b/packages/esm-commons-app/src/routes.json @@ -7,6 +7,11 @@ "name": "o2-visit-summary-workspace-siderail-button", "component": "o2VisitSummaryWorkspaceSideRailIcon", "slot": "action-menu-ward-patient-items-slot" + }, + { + "name": "o2-pregnancy-infant-dashboard", + "component": "o2PregnancyInfantDashboard", + "slot": "ward-patient-workspace-content-slot" } ], "workspaces": [ diff --git a/packages/esm-commons-app/src/ward-app/o2-pregnancy-infant-dashboard.extension.tsx b/packages/esm-commons-app/src/ward-app/o2-pregnancy-infant-dashboard.extension.tsx new file mode 100644 index 0000000..ef0fad8 --- /dev/null +++ b/packages/esm-commons-app/src/ward-app/o2-pregnancy-infant-dashboard.extension.tsx @@ -0,0 +1,56 @@ +import { useAppContext } from '@openmrs/esm-framework'; +import React, { useCallback, useRef } from 'react'; +import styles from './o2-pregnancy-infant-dashboard.scss'; +import { type MaternalWardViewContext } from './types'; + +/** + * Extension to display either the O2 pregnancy program or infant program dashboard, + * depending on whether patient is mother or infant. + */ +const O2PregnancyInfantProgramDashboard: React.FC<{ patientUuid: string }> = ({ patientUuid }) => { + const iframeRef = useRef(); + + const { motherChildRelationships } = useAppContext('maternal-ward-view-context') ?? {}; + const isInfant = motherChildRelationships?.motherByChildUuid?.has(patientUuid); + + const infantProgramUuid = 'dc1b588a-9b94-45e4-8346-71b7c9a24845'; + const pregnancyProgramUuid = '6a5713c2-3fd5-46e7-8f25-36a0f7871e12'; + const dashboardUuid = isInfant ? infantProgramUuid : pregnancyProgramUuid; + + // hide the headers, breadcrumbs and various sections of the dashboards + const onLoad = useCallback(() => { + const dashboard = iframeRef.current.contentDocument; + const elementsToHide = [ + 'header', + '.patient-header', + '#breadcrumbs', + '.action-section', + '.visits-section', + '.pregnancy\\.dashboard\\.ancInitialEncounters', + '.pregnancy\\.dashboard\\.ancFollowupEncounters', + '.patient-location', + '.pregnancy\\.dashboard\\.currentEnrollment', + '.infant\\.dashboard\\.newbornAssesmentEncounters', + '.infant\\.dashboard\\.newbornDailyProgressEncounters', + '.infant\\.dashboard\\.currentEnrollment', + '.program-history', + ]; + + const styleTag = dashboard.createElement('style'); + styleTag.innerHTML = elementsToHide.map((e) => `${e} {display: none !important;}`).join('\n'); + dashboard.head.appendChild(styleTag); + }, []); + + if (patientUuid) { + const src = `${window.openmrsBase}/coreapps/clinicianfacing/patient.page?patientId=${patientUuid}&dashboard=${dashboardUuid}`; + return ( +
+