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) O3-3818: Extend clinical forms workspace #2017

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 7 additions & 1 deletion packages/esm-patient-common-lib/src/form-entry-interop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { launchPatientWorkspace, launchStartVisitPrompt } from '@openmrs/esm-patient-common-lib';
import { formEntryWorkspace } from '@openmrs/esm-patient-forms-app/src/constants';

interface HtmlFormEntryForm {
formUuid: string;
Expand All @@ -19,6 +20,7 @@ export function launchFormEntryOrHtmlForms(
visitStartDatetime?: string,
visitStopDatetime?: string,
mutateForms?: () => void,
formEntryWorkspaceName = formEntryWorkspace,
) {
if (visitUuid) {
const htmlForm = htmlFormEntryForms.find((form) => form.formUuid === formUuid);
Expand All @@ -37,6 +39,7 @@ export function launchFormEntryOrHtmlForms(
visitStopDatetime,
htmlForm,
mutateForms,
formEntryWorkspaceName,
);
}
} else {
Expand All @@ -55,9 +58,12 @@ export function launchFormEntry(
visitStopDatetime?: string,
htmlForm?: HtmlFormEntryForm,
mutateForm?: () => void,
formEntryWorkspaceName = formEntryWorkspace,
) {
launchPatientWorkspace('patient-form-entry-workspace', {
launchPatientWorkspace(formEntryWorkspaceName || formEntryWorkspace, {
workspaceTitle: formName,
formEntryWorkspaceName,
patientUuid,
mutateForm,
formInfo: {
encounterUuid,
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-common-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export * from './time-helper';
export * from './types';
export * from './useAllowedFileExtensions';
export * from './useSystemVisitSetting';
export * from './useCheckAndPromptForVisit';
export * from './workspaces';
14 changes: 14 additions & 0 deletions packages/esm-patient-common-lib/src/useCheckAndPromptForVisit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { launchStartVisitPrompt } from './launchStartVisitPrompt';
import { useVisitOrOfflineVisit } from './offline/visit';
import { useSystemVisitSetting } from './useSystemVisitSetting';

export function useCheckAndPromptForVisit(patientUuid: string) {
const { systemVisitEnabled } = useSystemVisitSetting();
const { currentVisit } = useVisitOrOfflineVisit(patientUuid);

// Check if there's no active visit and the system requires visits, then prompt to start one
if (systemVisitEnabled && !currentVisit) {
launchStartVisitPrompt();
}
return { hasCurrentVisit: systemVisitEnabled && !!currentVisit };
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import {
interface FormEntryComponentProps extends DefaultPatientWorkspaceProps {
mutateForm: () => void;
formInfo: FormEntryProps;
formEntryWorkspaceName?: string;
}

const FormEntry: React.FC<FormEntryComponentProps> = ({
patientUuid,
formEntryWorkspaceName,
closeWorkspace,
closeWorkspaceWithSavedChanges,
promptBeforeClosing,
mutateForm,
formInfo,
}) => {
// console.log({ formEntryWorkspaceName });
const { encounterUuid, formUuid, visitStartDatetime, visitStopDatetime, visitTypeUuid, visitUuid, additionalProps } =
formInfo || {};
const { patient } = usePatient(patientUuid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useMemo } from 'react';
import { Tile } from '@carbon/react';
import { useConfig, useConnectivity, usePatient, ResponsiveWrapper } from '@openmrs/esm-framework';
import { ResponsiveWrapper, useConfig, useConnectivity, usePatient } from '@openmrs/esm-framework';
import {
type DefaultPatientWorkspaceProps,
EmptyDataIllustration,
Expand All @@ -13,20 +13,26 @@ import styles from './forms-dashboard.scss';
import { useForms } from '../hooks/use-forms';
import { useTranslation } from 'react-i18next';

const FormsDashboard: React.FC<DefaultPatientWorkspaceProps> = () => {
interface FormsDashboardProps extends DefaultPatientWorkspaceProps {
formEntryWorkspaceName?: string;
}

const FormsDashboard: React.FC<FormsDashboardProps> = ({ patientUuid, formEntryWorkspaceName }) => {
const { t } = useTranslation();
const config = useConfig<ConfigObject>();
const isOnline = useConnectivity();
const htmlFormEntryForms = config.htmlFormEntryForms;
const { patient, patientUuid } = usePatient();
const { patient, patientUuid: fetchedPatientUuid } = usePatient(patientUuid);
const { data: forms, error, mutateForms } = useForms(patientUuid, undefined, undefined, !isOnline, config.orderBy);
const { currentVisit } = useVisitOrOfflineVisit(patientUuid);

const handleFormOpen = useCallback(
(formUuid: string, encounterUuid: string, formName: string) => {
// console.log({ formUuid, patientUuid, formEntryWorkspaceName, fetchedPatientUuid });

launchFormEntryOrHtmlForms(
htmlFormEntryForms,
patientUuid,
fetchedPatientUuid,
formUuid,
currentVisit.uuid,
encounterUuid,
Expand All @@ -35,9 +41,10 @@ const FormsDashboard: React.FC<DefaultPatientWorkspaceProps> = () => {
currentVisit.startDatetime,
currentVisit.stopDatetime,
mutateForms,
formEntryWorkspaceName,
);
},
[currentVisit, htmlFormEntryForms, mutateForms, patientUuid],
[currentVisit, htmlFormEntryForms, mutateForms, fetchedPatientUuid, formEntryWorkspaceName],
);

const sections = useMemo(() => {
Expand Down
8 changes: 8 additions & 0 deletions packages/esm-patient-forms-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export function startupApp() {

// t('clinicalForm', 'Clinical form')
export const patientFormEntryWorkspace = getAsyncLifecycle(() => import('./forms/form-entry.workspace'), options);
export const patientFormEntryWorkspaceExtension = getAsyncLifecycle(
() => import('./forms/form-entry.workspace'),
options,
);

export const patientHtmlFormEntryWorkspace = getAsyncLifecycle(
() => import('./htmlformentry/html-form-entry.workspace'),
Expand All @@ -39,6 +43,10 @@ export const patientHtmlFormEntryWorkspace = getAsyncLifecycle(

// t('clinicalForms', 'Clinical forms')
export const clinicalFormsWorkspace = getAsyncLifecycle(() => import('./forms/forms-dashboard.workspace'), options);
export const clinicalFormsWorkspaceExtension = getAsyncLifecycle(
() => import('./forms/forms-dashboard.workspace'),
options,
);

export const clinicalFormActionMenu = getSyncLifecycle(clinicalFormActionMenuComponent, options);

Expand Down
10 changes: 10 additions & 0 deletions packages/esm-patient-forms-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"offline": true,
"online": true,
"order": 2
},
{
"name": "clinical-forms-workspaceExtension",
"component": "clinicalFormsWorkspaceExtension",
"slot": "ward-patient-clinical-forms-workspace-slot"
},
{
"name": "patient-form-entry-workspaceExtension",
"component": "patientFormEntryWorkspaceExtension",
"slot": "ward-patient-form-entry-workspace-slot"
}
],
"workspaces": [
Expand Down