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 ab3050434..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 @@ -8,11 +8,12 @@ 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'; import { usePatientDeathStatus } from '../../hooks/usePatientDeathStatus'; +import { fetchPatientLastEncounter } from '../../api/api'; export interface EncounterListColumn { key: string; @@ -40,6 +41,7 @@ export interface EncounterListProps { workspaceWindowSize?: 'minimized' | 'maximized'; }; filter?: (encounter: any) => boolean; + disableEdit?: boolean; } export const EncounterList: React.FC = ({ @@ -51,6 +53,7 @@ export const EncounterList: React.FC = ({ formList, filter, launchOptions, + disableEdit, }) => { const { t } = useTranslation(); const [paginatedRows, setPaginatedRows] = useState([]); @@ -131,7 +134,7 @@ export const EncounterList: React.FC = ({ 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 encounter['launchFormActions'] = { @@ -198,6 +201,11 @@ export const EncounterList: React.FC = ({ workspaceWindowSize, ); }} + disabled={ + index == 1 && disableEdit == true && findEncounterLatestDateIndex(encounters) != encounterIndex + } + // 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 04730dd31..9f1eeb640 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,22 @@ 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; +}; 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} /> ); };