Skip to content

Commit

Permalink
(Upgrade): Update the esm-patient-common-lib version. (#1846)
Browse files Browse the repository at this point in the history
* update the esm-patient-common-lib version

* update yarn.lock

* remove unused import

* some tweaks
  • Loading branch information
hadijahkyampeire authored May 16, 2024
1 parent 908f3db commit c50c7a3
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 193 deletions.
4 changes: 2 additions & 2 deletions packages/esm-commons-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"yup": "^0.29.1"
},
"peerDependencies": {
"@openmrs/esm-framework": "5.x",
"@openmrs/esm-patient-common-lib": "6.x",
"@openmrs/esm-framework": "*",
"@openmrs/esm-patient-common-lib": "*",
"dayjs": "1.x",
"react": "18.x",
"react-i18next": "11.x",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import localizedFormat from 'dayjs/plugin/localizedFormat';
import relativeTime from 'dayjs/plugin/relativeTime';
import { AddPatientToListOverflowMenuItem } from '../modals/add-patient-to-list-modal.component';
import { fetchPatientLastEncounter } from '../../api/api';
import { changeWorkspaceContext } from '@openmrs/esm-patient-common-lib';
import { launchForm } from '../../utils/ohri-forms-commons';
import { navigate } from '@openmrs/esm-framework';
import { navigate, WorkspaceWindow } from '@openmrs/esm-framework';

interface PatientMetaConfig {
location: { name: string };
Expand Down Expand Up @@ -62,14 +61,16 @@ export const LaunchableFormMenuItem = ({
{isLoading ? (
<InlineLoading style={{ margin: '0 auto', width: '16px' }} />
) : (
<OverflowMenuItem
itemText={actionText}
onClick={() => {
changeWorkspaceContext(patientUuid);
launchForm(form, encounterUuid ? 'edit' : 'enter', moduleName, form.name, encounterUuid, null, null);
navigate({ to: patientUrl });
}}
/>
<>
<OverflowMenuItem
itemText={actionText}
onClick={() => {
launchForm(form, encounterUuid ? 'edit' : 'enter', moduleName, form.name, encounterUuid, null, null);
navigate({ to: patientUrl });
}}
/>
<WorkspaceWindow contextKey={`patient/${patientUuid}`} />
</>
)}
</>
);
Expand Down Expand Up @@ -132,7 +133,7 @@ export const ViewTptSummaryMenuItem = ({ patientUuid, ViewTptSummary, encounterT
} else {
setIsLoading(false);
}
}, []);
}, [ViewTptSummary.editLatestEncounter, encounterType, patientUuid, encounterUuid, viewTptSummaryActionText]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const EncounterList: React.FC<EncounterListProps> = ({
const [pageSize, setPageSize] = useState(10);
const [isLoadingForms, setIsLoadingForms] = useState(true);
const { isDead } = usePatientDeathStatus(patientUuid);
const formNames = useMemo(() => formList.map((form) => form.name), []);
const formNames = useMemo(() => formList.map((form) => form.name), [formList]);
const { formsJson, isLoading: isLoadingFormsJson } = useFormsJson(formNames);
const { encounters, isLoading, onFormSave } = useEncounterRows(patientUuid, encounterType, filter);
const { moduleName, workspaceWindowSize, displayText, hideFormLauncher } = launchOptions;
Expand Down Expand Up @@ -96,39 +96,39 @@ export const EncounterList: React.FC<EncounterListProps> = ({
[forms, t],
);

const handleDeleteEncounter = useCallback((encounterUuid, encounterTypeName) => {
const close = showModal('delete-encounter-modal', {
close: () => close(),
encounterTypeName: encounterTypeName || '',
onConfirmation: () => {
const abortController = new AbortController();
deleteEncounter(encounterUuid, abortController)
.then(() => {
mutate(
(key) =>
typeof key === "string" && key.startsWith("/ws/rest/v1/encounter"),
undefined,
{ revalidate: true }
);
showSnackbar({
isLowContrast: true,
title: t('encounterDeleted', 'Encounter deleted'),
subtitle: `Encounter ${t('successfullyDeleted', 'successfully deleted')}`,
kind: 'success',
});
})
.catch(() => {
showSnackbar({
isLowContrast: false,
title: t('error', 'Error'),
subtitle: `Encounter ${t('failedDeleting', "couldn't be deleted")}`,
kind: 'error',
const handleDeleteEncounter = useCallback(
(encounterUuid, encounterTypeName) => {
const close = showModal('delete-encounter-modal', {
close: () => close(),
encounterTypeName: encounterTypeName || '',
onConfirmation: () => {
const abortController = new AbortController();
deleteEncounter(encounterUuid, abortController)
.then(() => {
mutate((key) => typeof key === 'string' && key.startsWith('/ws/rest/v1/encounter'), undefined, {
revalidate: true,
});
showSnackbar({
isLowContrast: true,
title: t('encounterDeleted', 'Encounter deleted'),
subtitle: `Encounter ${t('successfullyDeleted', 'successfully deleted')}`,
kind: 'success',
});
})
.catch(() => {
showSnackbar({
isLowContrast: false,
title: t('error', 'Error'),
subtitle: `Encounter ${t('failedDeleting', "couldn't be deleted")}`,
kind: 'error',
});
});
});
close();
},
});
}, [])
close();
},
});
},
[t],
);

useEffect(() => {
if (!isLoadingFormsJson) {
Expand Down Expand Up @@ -223,15 +223,15 @@ export const EncounterList: React.FC<EncounterListProps> = ({
// If custom config is available, generate actions accordingly; otherwise, fallback to the default actions.
const actions = tableRow.actions?.length ? tableRow.actions : defaultActions;
tableRow['actions'] = (
<OverflowMenu flipped className={styles.flippedOverflowMenu} data-testid='actions-id'>
<OverflowMenu flipped className={styles.flippedOverflowMenu} data-testid="actions-id">
{actions.map((actionItem, index) => (
<OverflowMenuItem
index={index}
itemText={actionItem.label}
onClick={(e) => {
e.preventDefault();
actionItem.mode == 'delete' ?
handleDeleteEncounter(encounter.uuid, encounter.encounterType.name)
actionItem.mode == 'delete'
? handleDeleteEncounter(encounter.uuid, encounter.encounterType.name)
: launchEncounterForm(
forms.find((form) => form.name == actionItem?.form?.name),
moduleName,
Expand All @@ -242,7 +242,7 @@ export const EncounterList: React.FC<EncounterListProps> = ({
actionItem.intent,
workspaceWindowSize,
patientUuid,
);
);
}}
/>
))}
Expand All @@ -252,7 +252,7 @@ export const EncounterList: React.FC<EncounterListProps> = ({
});
setPaginatedRows(rows);
},
[columns, defaultActions, forms, moduleName, workspaceWindowSize, patientUuid, onFormSave],
[columns, defaultActions, forms, moduleName, workspaceWindowSize, patientUuid, onFormSave, handleDeleteEncounter],
);

useEffect(() => {
Expand All @@ -265,7 +265,7 @@ export const EncounterList: React.FC<EncounterListProps> = ({
if (forms.length == 1 && !forms[0]['availableIntents']?.length) {
// we only have one form with no intents
// just return the "Add" button
return (
return (
<Button
kind="ghost"
renderIcon={Add}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ export function deleteEncounter(encounterUuid: string, abortController: AbortCon
},
signal: abortController.signal,
});
}
}
12 changes: 12 additions & 0 deletions packages/esm-commons-lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { FormEngine } from '@openmrs/openmrs-form-engine-lib';
import { getSyncLifecycle } from '@openmrs/esm-framework';

export * from './constants';
export * from './api/api';
export * from './api/types';
Expand Down Expand Up @@ -49,3 +52,12 @@ export * from './components/expandable-list-widget/expandable-list.component';
export * from './components/extension-conditional-renderer/patient-based-extension-renderer';
export * from './components/patient-table/patient-table.component';
export * from './hooks/useLastEncounter';

// Workspace registration moved to the index.ts and routes.json
const options = {
featureName: 'ohri-forms-workspace-item',
moduleName: "@ohri/openmrs-esm-ohri-commons-lib",
};

// t('ohriForms', "OHRI Forms")
export const ohriFormsWorkspace = getSyncLifecycle(FormEngine, options);
9 changes: 9 additions & 0 deletions packages/esm-commons-lib/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,14 @@
"pages": [
],
"extensions": [
],
"workspaces": [
{
"name": "ohri-forms-workspace-item",
"title": "ohriForms",
"component": "ohriFormsWorkspace",
"type": "form",
"canHide": true
}
]
}
26 changes: 9 additions & 17 deletions packages/esm-commons-lib/src/workspace/ohri-workspace-utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getSyncLifecycle } from '@openmrs/esm-framework';
import { BehaviorSubject } from 'rxjs';
import { closeWorkspace, launchPatientWorkspace, registerWorkspace } from '@openmrs/esm-patient-common-lib';
import { FormEngine, SessionMode } from '@openmrs/openmrs-form-engine-lib';
export interface WorkspaceContextProps {
import { closeWorkspace } from '@openmrs/esm-framework';
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib';
import { SessionMode } from '@openmrs/openmrs-form-engine-lib';

export interface WorkspaceContextProps {
title: string;
encounterUuid?: string;
state?: any;
Expand All @@ -18,26 +19,17 @@ let counter = 0;

export const launchOHRIWorkSpace = (props: WorkspaceContextProps) => {
const workspaceName = props.workspaceName || 'ohri-forms-' + counter++;

const close = () => {
return closeWorkspace(workspaceName, { ignoreChanges: true });
};

const onFormSubmit = () => {
props.state?.updateParent?.();
close();
};
registerWorkspace({
name: workspaceName,
title: props.title,
preferredWindowSize: <any>props.screenSize,
load: getSyncLifecycle(FormEngine, {
featureName: 'ohri-forms-workspace-item',
moduleName: props.moduleName,
}),
canMaximize: true,
canHide: true,
width: 'wider',
});



launchPatientWorkspace(workspaceName, {
...props.state,
mode: props.mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { launchFormWithCustomTitle } from '@ohri/openmrs-esm-ohri-commons-lib';
import { getForm, applyFormIntent } from '@openmrs/openmrs-form-engine-lib';
import styles from './tabs/patient-list.scss';
import { OverflowMenu, OverflowMenuItem } from '@carbon/react';
import { changeWorkspaceContext, closeAllWorkspaces, resetWorkspaceStore } from '@openmrs/esm-patient-common-lib';
import { navigate } from '@openmrs/esm-framework';
import { navigate, WorkspaceWindow } from '@openmrs/esm-framework';
import { useTranslation } from 'react-i18next';
import { moduleName } from '../../../index';

Expand Down Expand Up @@ -42,17 +41,19 @@ export const LabresultsFormViewer: React.FC<LabresultsFormViewerProps> = ({
return (
<>
{encounterUuid ? (
<OverflowMenu flipped className={styles.flippedOverflowMenu}>
<OverflowMenuItem
itemText={t('viewResult', 'View Result')}
onClick={(e) => {
e.preventDefault();
changeWorkspaceContext(patientUuid);
launchEncounterForm(applyFormIntent('*', getForm(form.package, form.name)), '*', 'view', encounterUuid);
navigate({ to: patientUrl });
}}
/>
</OverflowMenu>
<>
<OverflowMenu flipped className={styles.flippedOverflowMenu}>
<OverflowMenuItem
itemText={t('viewResult', 'View Result')}
onClick={(e) => {
e.preventDefault();
launchEncounterForm(applyFormIntent('*', getForm(form.package, form.name)), '*', 'view', encounterUuid);
navigate({ to: patientUrl });
}}
/>
</OverflowMenu>
<WorkspaceWindow contextKey={`patient/${patientUuid}`} />
</>
) : (
<></>
)}
Expand Down
Loading

0 comments on commit c50c7a3

Please sign in to comment.