From f8234a89e292fb48048a71a51546520b7583b2c1 Mon Sep 17 00:00:00 2001 From: Hero Date: Wed, 13 Dec 2023 16:09:11 +0200 Subject: [PATCH 01/14] OHRI-1857 : Users should only be able to edit the latest MNCH visit/encounter --- .../encounter-list.component.tsx | 13 ++++++----- .../src/components/encounter-list/helpers.ts | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index ab3050434..dc14ca27c 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -8,7 +8,7 @@ import { OTable } from '../data-table/o-table.component'; import { Button, Link, OverflowMenu, OverflowMenuItem, Pagination, DataTableSkeleton } from '@carbon/react'; import { Add } from '@carbon/react/icons'; import { OHRIFormSchema } from '@openmrs/openmrs-form-engine-lib'; -import { launchEncounterForm } from './helpers'; +import { launchEncounterForm, findEncounterLatestDateIndex } from './helpers'; import { useEncounterRows } from '../../hooks/useEncounterRows'; import { OpenmrsEncounter } from '../../api/types'; import { useFormsJson } from '../../hooks/useFormsJson'; @@ -67,7 +67,7 @@ export const EncounterList: React.FC = ({ onFormSave, } = useEncounterRows(patientUuid, encounterType, filter); const { moduleName, workspaceWindowSize, displayText, hideFormLauncher } = launchOptions; - + const defaultActions = useMemo( () => [ { @@ -124,16 +124,16 @@ export const EncounterList: React.FC = ({ const constructPaginatedTableRows = useCallback( (encounters: OpenmrsEncounter[], currentPage: number, pageSize: number) => { - const startIndex = (currentPage - 1) * pageSize; + const startIndex = (currentPage - 1) * pageSize; const paginatedEncounters = []; for (let i = startIndex; i < startIndex + pageSize; i++) { if (i < encounters.length) { paginatedEncounters.push(encounters[i]); } } - const rows = paginatedEncounters.map((encounter) => { + const rows = paginatedEncounters.map((encounter, encounterIndex: number) => { const tableRow: { id: string; actions: any } = { id: encounter.uuid, actions: null }; - // inject launch actions + // inject launch actions encounter['launchFormActions'] = { editEncounter: () => launchEncounterForm( @@ -198,6 +198,7 @@ export const EncounterList: React.FC = ({ workspaceWindowSize, ); }} + disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} /> ))} @@ -212,7 +213,7 @@ export const EncounterList: React.FC = ({ useEffect(() => { if (encounters?.length) { constructPaginatedTableRows(encounters, currentPage, pageSize); - } + } }, [encounters, pageSize, constructPaginatedTableRows, currentPage]); const formLauncher = useMemo(() => { diff --git a/packages/esm-commons-lib/src/components/encounter-list/helpers.ts b/packages/esm-commons-lib/src/components/encounter-list/helpers.ts index 04730dd31..6b993cf9d 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/helpers.ts +++ b/packages/esm-commons-lib/src/components/encounter-list/helpers.ts @@ -1,6 +1,7 @@ import { OHRIFormSchema, SessionMode } from '@openmrs/openmrs-form-engine-lib'; import { launchForm } from '../../utils/ohri-forms-commons'; import { capitalize } from 'lodash-es'; +import { OpenmrsEncounter } from '../../api/types'; type LaunchAction = 'add' | 'view' | 'edit'; @@ -26,3 +27,25 @@ export function launchEncounterForm( workspaceWindowSize, ); } + +export const findEncounterLatestDateIndex = (encounters: OpenmrsEncounter[]) => { + + if (!encounters || !encounters.length) { + return; + } + + let latestDateIndex: number = 0; + + for (let i = 1; i < encounters?.length; i++) { + + const currentDate = new Date(encounters[i].encounterDatetime); + const latestDate = new Date(encounters[latestDateIndex].encounterDatetime); + + if (currentDate > latestDate) { + latestDateIndex = i; + } + } + + return latestDateIndex; + +} From 1f401739c5ccb66508a1ca6b5e4a080d536233dd Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 18 Dec 2023 06:52:20 +0200 Subject: [PATCH 02/14] changed from checking the actionItem index to label --- .../components/encounter-list/encounter-list.component.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index dc14ca27c..ae4fa274c 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -124,6 +124,7 @@ export const EncounterList: React.FC = ({ const constructPaginatedTableRows = useCallback( (encounters: OpenmrsEncounter[], currentPage: number, pageSize: number) => { + console.log('counters', encounters); const startIndex = (currentPage - 1) * pageSize; const paginatedEncounters = []; for (let i = startIndex; i < startIndex + pageSize; i++) { @@ -180,7 +181,7 @@ export const EncounterList: React.FC = ({ }); // If custom config is available, generate actions accordingly; otherwise, fallback to the default actions. const actions = tableRow.actions?.length ? tableRow.actions : defaultActions; - tableRow['actions'] = ( + tableRow['actions'] = ( {actions.map((actionItem, index) => ( = ({ workspaceWindowSize, ); }} - disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} + disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex} /> ))} From f5f5bc270c5aeb7584acce4476cf1ac030ad2e50 Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 18 Dec 2023 07:59:30 +0200 Subject: [PATCH 03/14] removed logs --- .../src/components/encounter-list/encounter-list.component.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index ae4fa274c..ccfaf1379 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -124,7 +124,6 @@ export const EncounterList: React.FC = ({ const constructPaginatedTableRows = useCallback( (encounters: OpenmrsEncounter[], currentPage: number, pageSize: number) => { - console.log('counters', encounters); const startIndex = (currentPage - 1) * pageSize; const paginatedEncounters = []; for (let i = startIndex; i < startIndex + pageSize; i++) { From 3fcebdf45eefeb73b3b10b32390cd7c52e34a180 Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 18 Dec 2023 09:29:04 +0200 Subject: [PATCH 04/14] added an optional prop on the encounter list component to disable edit --- .../components/encounter-list/encounter-list.component.tsx | 4 +++- .../child-health/tabs/infant-postnatal-care.component.tsx | 1 + .../views/maternal-health/tabs/antenatal-care.component.tsx | 1 + .../views/maternal-health/tabs/labour-delivery.component.tsx | 1 + .../views/maternal-health/tabs/postnatal-care.component.tsx | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index ccfaf1379..73472fc3c 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -40,6 +40,7 @@ export interface EncounterListProps { workspaceWindowSize?: 'minimized' | 'maximized'; }; filter?: (encounter: any) => boolean; + disableEdit?: boolean; } export const EncounterList: React.FC = ({ @@ -51,6 +52,7 @@ export const EncounterList: React.FC = ({ formList, filter, launchOptions, + disableEdit, }) => { const { t } = useTranslation(); const [paginatedRows, setPaginatedRows] = useState([]); @@ -198,7 +200,7 @@ export const EncounterList: React.FC = ({ workspaceWindowSize, ); }} - disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex} + disabled={actionItem.label == 'Edit form' && disableEdit == true && findEncounterLatestDateIndex(encounters) != encounterIndex} /> ))} diff --git a/packages/esm-ohri-pmtct-app/src/views/child-health/tabs/infant-postnatal-care.component.tsx b/packages/esm-ohri-pmtct-app/src/views/child-health/tabs/infant-postnatal-care.component.tsx index 4c4f7b9a4..00e245717 100644 --- a/packages/esm-ohri-pmtct-app/src/views/child-health/tabs/infant-postnatal-care.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/child-health/tabs/infant-postnatal-care.component.tsx @@ -114,6 +114,7 @@ const InfantPostnatalList: React.FC = ({ patientUuid } displayText: t('add', 'Add'), moduleName: moduleName, }} + disableEdit={true} /> ); }; diff --git a/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/antenatal-care.component.tsx b/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/antenatal-care.component.tsx index b0287a1dd..37988761c 100644 --- a/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/antenatal-care.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/antenatal-care.component.tsx @@ -108,6 +108,7 @@ const AntenatalCareList: React.FC = ({ patientUuid }) => displayText: t('add', 'Add'), moduleName: moduleName, }} + disableEdit={true} /> ); }; diff --git a/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/labour-delivery.component.tsx b/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/labour-delivery.component.tsx index f72328d62..0a5d49757 100644 --- a/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/labour-delivery.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/labour-delivery.component.tsx @@ -94,6 +94,7 @@ const LabourDeliveryList: React.FC = ({ patientUuid }) displayText: t('add', 'Add'), moduleName: moduleName, }} + disableEdit={true} /> ); }; diff --git a/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/postnatal-care.component.tsx b/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/postnatal-care.component.tsx index 23d01277b..1438fbc2d 100644 --- a/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/postnatal-care.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/maternal-health/tabs/postnatal-care.component.tsx @@ -94,6 +94,7 @@ const PostnatalCareList: React.FC = ({ patientUuid }) => displayText: t('add', 'Add'), moduleName: moduleName, }} + disableEdit={true} /> ); }; From 4eb3b10bbce8dcba10c1a3d496e3f739584867d9 Mon Sep 17 00:00:00 2001 From: Hero Date: Tue, 19 Dec 2023 08:10:46 +0200 Subject: [PATCH 05/14] fixed lint --- .../encounter-list/encounter-list.component.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index 73472fc3c..7045c3e2f 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -69,7 +69,7 @@ export const EncounterList: React.FC = ({ onFormSave, } = useEncounterRows(patientUuid, encounterType, filter); const { moduleName, workspaceWindowSize, displayText, hideFormLauncher } = launchOptions; - + const defaultActions = useMemo( () => [ { @@ -126,7 +126,7 @@ export const EncounterList: React.FC = ({ const constructPaginatedTableRows = useCallback( (encounters: OpenmrsEncounter[], currentPage: number, pageSize: number) => { - const startIndex = (currentPage - 1) * pageSize; + const startIndex = (currentPage - 1) * pageSize; const paginatedEncounters = []; for (let i = startIndex; i < startIndex + pageSize; i++) { if (i < encounters.length) { @@ -135,7 +135,7 @@ export const EncounterList: React.FC = ({ } const rows = paginatedEncounters.map((encounter, encounterIndex: number) => { const tableRow: { id: string; actions: any } = { id: encounter.uuid, actions: null }; - // inject launch actions + // inject launch actions encounter['launchFormActions'] = { editEncounter: () => launchEncounterForm( @@ -182,7 +182,7 @@ export const EncounterList: React.FC = ({ }); // If custom config is available, generate actions accordingly; otherwise, fallback to the default actions. const actions = tableRow.actions?.length ? tableRow.actions : defaultActions; - tableRow['actions'] = ( + tableRow['actions'] = ( {actions.map((actionItem, index) => ( = ({ workspaceWindowSize, ); }} - disabled={actionItem.label == 'Edit form' && disableEdit == true && findEncounterLatestDateIndex(encounters) != encounterIndex} + disabled={ + actionItem.label == 'Edit form' && + disableEdit == true && + findEncounterLatestDateIndex(encounters) != encounterIndex + } /> ))} @@ -215,7 +219,7 @@ export const EncounterList: React.FC = ({ useEffect(() => { if (encounters?.length) { constructPaginatedTableRows(encounters, currentPage, pageSize); - } + } }, [encounters, pageSize, constructPaginatedTableRows, currentPage]); const formLauncher = useMemo(() => { From ad8e7f7999517571f683b243535e2912d7c0ef03 Mon Sep 17 00:00:00 2001 From: Hero Date: Wed, 13 Dec 2023 16:09:11 +0200 Subject: [PATCH 06/14] OHRI-1857 : Users should only be able to edit the latest MNCH visit/encounter --- .../src/components/encounter-list/encounter-list.component.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index 7045c3e2f..06f53c0f0 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -205,6 +205,7 @@ export const EncounterList: React.FC = ({ disableEdit == true && findEncounterLatestDateIndex(encounters) != encounterIndex } + // disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} /> ))} From 898946aa918928916b110f1872cf7cf55557e70c Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 18 Dec 2023 06:52:20 +0200 Subject: [PATCH 07/14] changed from checking the actionItem index to label --- .../src/components/encounter-list/encounter-list.component.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index 06f53c0f0..55116f884 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -127,6 +127,7 @@ export const EncounterList: React.FC = ({ const constructPaginatedTableRows = useCallback( (encounters: OpenmrsEncounter[], currentPage: number, pageSize: number) => { const startIndex = (currentPage - 1) * pageSize; + console.log('counters', encounters); const paginatedEncounters = []; for (let i = startIndex; i < startIndex + pageSize; i++) { if (i < encounters.length) { @@ -206,6 +207,7 @@ export const EncounterList: React.FC = ({ findEncounterLatestDateIndex(encounters) != encounterIndex } // disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} + // disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex} /> ))} From ec8d4189787faf3729a1cc76ea15970a2c52cc41 Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 18 Dec 2023 07:59:30 +0200 Subject: [PATCH 08/14] removed logs --- .../src/components/encounter-list/encounter-list.component.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index 55116f884..f2b993c3e 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -127,7 +127,6 @@ export const EncounterList: React.FC = ({ const constructPaginatedTableRows = useCallback( (encounters: OpenmrsEncounter[], currentPage: number, pageSize: number) => { const startIndex = (currentPage - 1) * pageSize; - console.log('counters', encounters); const paginatedEncounters = []; for (let i = startIndex; i < startIndex + pageSize; i++) { if (i < encounters.length) { From a932fce941dad90d3c491d4b6abd35913ba5bc6d Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 18 Dec 2023 09:29:04 +0200 Subject: [PATCH 09/14] added an optional prop on the encounter list component to disable edit --- .../components/encounter-list/encounter-list.component.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index f2b993c3e..485378ddf 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -200,13 +200,13 @@ export const EncounterList: React.FC = ({ workspaceWindowSize, ); }} + // disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} + // disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex} disabled={ actionItem.label == 'Edit form' && disableEdit == true && findEncounterLatestDateIndex(encounters) != encounterIndex } - // disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} - // disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex} /> ))} From 9f91a9173533937f5c920857c1a3c5e03191fcc1 Mon Sep 17 00:00:00 2001 From: Hero Date: Tue, 19 Dec 2023 08:10:46 +0200 Subject: [PATCH 10/14] fixed lint --- .../components/encounter-list/encounter-list.component.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index 485378ddf..f2b993c3e 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -200,13 +200,13 @@ export const EncounterList: React.FC = ({ workspaceWindowSize, ); }} - // disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} - // disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex} disabled={ actionItem.label == 'Edit form' && disableEdit == true && findEncounterLatestDateIndex(encounters) != encounterIndex } + // disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} + // disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex} /> ))} From ed51836cb49d27f32f31fb4cf3158ac0296f01d4 Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 15 Jan 2024 08:39:41 +0200 Subject: [PATCH 11/14] added mock for test --- __mocks__/encounters.mocks.ts | 83 +++++++++++++++++++ .../encounter-list.component.tsx | 10 ++- .../src/components/encounter-list/helpers.ts | 10 +-- 3 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 __mocks__/encounters.mocks.ts diff --git a/__mocks__/encounters.mocks.ts b/__mocks__/encounters.mocks.ts new file mode 100644 index 000000000..a62468dd9 --- /dev/null +++ b/__mocks__/encounters.mocks.ts @@ -0,0 +1,83 @@ +import { OpenmrsEncounter } from '@openmrs/openmrs-form-engine-lib/src/api/types'; +export const mockEncounters: OpenmrsEncounter[] = [ + { + uuid: '2d8969e4-0b6b-4091-b918-edea29ccbc6c', + encounterDatetime: '2023-10-24T12:38:00.000+0000', + encounterType: '', + location: '', + patient: '', + encounterProviders: [ + { + uuid: '35ebbdfa-0eeb-44b8-8d00-5548ad5f0190', + provider: { + uuid: 'e3b1f354-da0e-40e3-b77b-493d8e86db3c', + name: 'Ff8e2 b400A Fcd3C', + }, + }, + ], + obs: [], + form: { + uuid: '60252155-f40d-3084-9d8e-5b7c8fafc68a', + name: 'Labour & Delivery Form', + }, + }, + { + uuid: 'e61810e9-cab0-403d-aea0-a08c66d17317', + encounterDatetime: '2023-09-25T14:00:54.000+0000', + encounterType: '', + location: '', + patient: '', + encounterProviders: [], + obs: [], + form: { + uuid: '2105c8ae-1935-375c-a7cc-e2ca04c8f6be', + name: 'Mother - Postnatal Form', + }, + }, + { + uuid: '65f7acf8-c610-46d2-a836-142776365cf7', + encounterDatetime: '2023-09-25T13:58:47.000+0000', + encounterType: { + uuid: '2678423c-0523-4d76-b0da-18177b439eed', + display: 'Labor and Delivery', + name: 'Labor and Delivery', + description: 'Labor and delivery visit by a mother', + retired: false, + links: [ + { + rel: 'self', + uri: 'http://ohri-namibia-dev.globalhealthapp.net/openmrs/ws/rest/v1/encountertype/2678423c-0523-4d76-b0da-18177b439eed', + resourceAlias: 'encountertype', + }, + { + rel: 'full', + uri: 'http://ohri-namibia-dev.globalhealthapp.net/openmrs/ws/rest/v1/encountertype/2678423c-0523-4d76-b0da-18177b439eed?v=full', + resourceAlias: 'encountertype', + }, + ], + resourceVersion: '1.8', + }, + location: { + uuid: 'Sf8ctjA7qjo', + name: 'Opuwo Clinic', + }, + patient: { + uuid: '1ffd8210-0098-4a9a-8706-e87bac8d1b32', + display: '10350A230066 - Maria Niilenge', + }, + encounterProviders: [ + { + uuid: '751cf65d-6238-4f06-8245-c2d6d002d4e0', + provider: { + uuid: 'f677d8be-4961-4f37-a361-7f5f8977495d', + name: 'PTracker_PMTCT PTracker_PMTCT', + }, + }, + ], + obs: [], + form: { + uuid: '60252155-f40d-3084-9d8e-5b7c8fafc68a', + name: 'Labour & Delivery Form', + }, + }, +]; diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index f2b993c3e..04f6595f7 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -13,6 +13,7 @@ import { useEncounterRows } from '../../hooks/useEncounterRows'; import { OpenmrsEncounter } from '../../api/types'; import { useFormsJson } from '../../hooks/useFormsJson'; import { usePatientDeathStatus } from '../../hooks/usePatientDeathStatus'; +import { fetchPatientLastEncounter } from '../../api/api'; export interface EncounterListColumn { key: string; @@ -200,10 +201,15 @@ export const EncounterList: React.FC = ({ workspaceWindowSize, ); }} + // disabled={ + // actionItem.label == 'Edit form' && + // disableEdit == true && + // findEncounterLatestDateIndex(encounters).then != encounterIndex + // } disabled={ - actionItem.label == 'Edit form' && disableEdit == true && - findEncounterLatestDateIndex(encounters) != encounterIndex + actionItem.label == 'Edit form' && + fetchPatientLastEncounter(patientUuid, encounterType) != encounter.uuid } // disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} // disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex} diff --git a/packages/esm-commons-lib/src/components/encounter-list/helpers.ts b/packages/esm-commons-lib/src/components/encounter-list/helpers.ts index 6b993cf9d..452f9226f 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/helpers.ts +++ b/packages/esm-commons-lib/src/components/encounter-list/helpers.ts @@ -28,8 +28,7 @@ export function launchEncounterForm( ); } -export const findEncounterLatestDateIndex = (encounters: OpenmrsEncounter[]) => { - +export const findEncounterLatestDateIndex = async (encounters: OpenmrsEncounter[]) => { if (!encounters || !encounters.length) { return; } @@ -37,7 +36,6 @@ export const findEncounterLatestDateIndex = (encounters: OpenmrsEncounter[]) => let latestDateIndex: number = 0; for (let i = 1; i < encounters?.length; i++) { - const currentDate = new Date(encounters[i].encounterDatetime); const latestDate = new Date(encounters[latestDateIndex].encounterDatetime); @@ -45,7 +43,7 @@ export const findEncounterLatestDateIndex = (encounters: OpenmrsEncounter[]) => latestDateIndex = i; } } + const encounterUuid = new Date(encounters[latestDateIndex].uuid); - return latestDateIndex; - -} + return { latestDateIndex, encounterUuid }; +}; From 53ca360184f56d45ef846ff2076e31de764360f5 Mon Sep 17 00:00:00 2001 From: Hero Date: Wed, 13 Dec 2023 16:09:11 +0200 Subject: [PATCH 12/14] OHRI-1857 : Users should only be able to edit the latest MNCH visit/encounter --- .../esm-commons-lib/src/components/encounter-list/helpers.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/helpers.ts b/packages/esm-commons-lib/src/components/encounter-list/helpers.ts index 452f9226f..9f1eeb640 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/helpers.ts +++ b/packages/esm-commons-lib/src/components/encounter-list/helpers.ts @@ -28,7 +28,7 @@ export function launchEncounterForm( ); } -export const findEncounterLatestDateIndex = async (encounters: OpenmrsEncounter[]) => { +export const findEncounterLatestDateIndex = (encounters: OpenmrsEncounter[]) => { if (!encounters || !encounters.length) { return; } @@ -43,7 +43,6 @@ export const findEncounterLatestDateIndex = async (encounters: OpenmrsEncounter[ latestDateIndex = i; } } - const encounterUuid = new Date(encounters[latestDateIndex].uuid); - return { latestDateIndex, encounterUuid }; + return latestDateIndex; }; From 0c48e2fd5d32afd910e59bfc6bef4aaa48e537bd Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 18 Dec 2023 09:29:04 +0200 Subject: [PATCH 13/14] added an optional prop on the encounter list component to disable edit --- .../encounter-list/encounter-list.component.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index 04f6595f7..871b6a4eb 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -201,15 +201,10 @@ export const EncounterList: React.FC = ({ workspaceWindowSize, ); }} - // disabled={ - // actionItem.label == 'Edit form' && - // disableEdit == true && - // findEncounterLatestDateIndex(encounters).then != encounterIndex - // } disabled={ - disableEdit == true && actionItem.label == 'Edit form' && - fetchPatientLastEncounter(patientUuid, encounterType) != encounter.uuid + disableEdit == true && + findEncounterLatestDateIndex(encounters) != encounterIndex } // disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} // disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex} From 3f3acf5141fd13920a8ce6f2506dd172b5b304d8 Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 15 Jan 2024 12:06:37 +0200 Subject: [PATCH 14/14] changed the check from label to the action index --- .../components/encounter-list/encounter-list.component.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx index 871b6a4eb..44c637d8e 100644 --- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx +++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx @@ -202,9 +202,7 @@ export const EncounterList: React.FC = ({ ); }} disabled={ - actionItem.label == 'Edit form' && - disableEdit == true && - findEncounterLatestDateIndex(encounters) != encounterIndex + index == 1 && disableEdit == true && findEncounterLatestDateIndex(encounters) != encounterIndex } // disabled={index == 1 && findEncounterLatestDateIndex(encounters) != encounterIndex} // disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex}