Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) UHM-8241 Create O2 pregnancy / infant dashboard extension for … #2

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/esm-commons-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
5 changes: 5 additions & 0 deletions packages/esm-commons-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
@@ -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<HTMLIFrameElement>();

const { motherChildRelationships } = useAppContext<MaternalWardViewContext>('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 (
<div className={styles.iframeWrapper} key={patientUuid}>
<iframe ref={iframeRef} src={src} onLoad={onLoad} className={styles.o2Iframe} />
</div>
);
} else {
return;
}
};

export default O2PregnancyInfantProgramDashboard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
:global(div[data-extension-id='o2-pregnancy-infant-dashboard']) {
flex: 1;
}

.iframeWrapper {
height: 100%;
width: 100%;
}

.o2Iframe {
height: 100%;
width: 100%;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionMenuButton, launchWorkspace, UserAvatarIcon } from '@openmrs/esm-framework';
import { ActionMenuButton, CalendarHeatMapIcon, launchWorkspace } from '@openmrs/esm-framework';
import React from 'react';
import { useTranslation } from 'react-i18next';
import type { WardPatientWorkspaceProps } from './types';
Expand All @@ -8,7 +8,7 @@ export default function WardPatientActionButton() {

return (
<ActionMenuButton
getIcon={(props) => <UserAvatarIcon {...props} />}
getIcon={(props) => <CalendarHeatMapIcon {...props} />}
label={t('visitSummary', 'Visit summary')}
iconDescription={t('patientVisitSummary', 'Patient visit summary')}
handler={() => launchWorkspace<WardPatientWorkspaceProps>('o2-visit-summary-workspace')}
Expand Down
19 changes: 18 additions & 1 deletion packages/esm-commons-app/src/ward-app/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import type { DefaultWorkspaceProps, Patient, Visit } from '@openmrs/esm-framework';

// a stripped down version of the same type defined in esm-ward-app
// stripped down versions of the same types defined in esm-ward-app

export type WardPatient = {
patient: Patient;
visit: Visit;
// other fields not typed
};

export interface WardPatientWorkspaceProps extends DefaultWorkspaceProps {
wardPatient: WardPatient;
}

export interface PatientAndAdmission {
patient: Patient;
// other fields not typed
}

export interface MotherChildRelationships {
motherByChildUuid: Map<string, PatientAndAdmission>;
childrenByMotherUuid: Map<string, PatientAndAdmission[]>;
isLoading: boolean;
}

export interface MaternalWardViewContext {
motherChildRelationships: MotherChildRelationships;
}