From 798e94c756fe134a31226bd749baac70d9dbf5d7 Mon Sep 17 00:00:00 2001 From: lucyjemutai <130601439+lucyjemutai@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:28:21 +0300 Subject: [PATCH] Updates on the All TB Clients Table in the Tuberculosis Treatment dashboard (#1723) Co-authored-by: lucyjemutai --- .../cohort-patient-list.component.tsx | 3 + .../cohort-patient-list/helpers.tsx | 56 ++++++++++++++++++- .../ohri-patient-list-tabs.component.tsx | 1 + .../tb-patient-list-tabs.component.tsx | 7 ++- packages/esm-tb-app/translations/en.json | 3 +- 5 files changed, 65 insertions(+), 5 deletions(-) diff --git a/packages/esm-commons-lib/src/components/cohort-patient-list/cohort-patient-list.component.tsx b/packages/esm-commons-lib/src/components/cohort-patient-list/cohort-patient-list.component.tsx index 399ddd7f3..2a348a737 100644 --- a/packages/esm-commons-lib/src/components/cohort-patient-list/cohort-patient-list.component.tsx +++ b/packages/esm-commons-lib/src/components/cohort-patient-list/cohort-patient-list.component.tsx @@ -23,6 +23,7 @@ interface CohortPatientListProps { excludeColumns?: Array; queryParams?: Array; associatedEncounterType?: string; + viewPatientProgramSummary?: boolean; addPatientToListOptions?: { isEnabled: boolean; excludeCohorts?: Array }; launchableForm?: { name: string; @@ -52,6 +53,7 @@ export const CohortPatientList: React.FC = ({ addPatientToListOptions, extraAssociatedEncounterTypes, moduleName, + viewPatientProgramSummary, }) => { const [isLoading, setIsLoading] = useState(true); const [hasLoadedPatients, setHasLoadedPatients] = useState(false); @@ -145,6 +147,7 @@ export const CohortPatientList: React.FC = ({ ...addPatientToListOptions, displayText: t('moveToListSideNav', 'Move to list'), }, + viewPatientProgramSummary }), }; }); diff --git a/packages/esm-commons-lib/src/components/cohort-patient-list/helpers.tsx b/packages/esm-commons-lib/src/components/cohort-patient-list/helpers.tsx index c8c4c447a..454ad5f92 100644 --- a/packages/esm-commons-lib/src/components/cohort-patient-list/helpers.tsx +++ b/packages/esm-commons-lib/src/components/cohort-patient-list/helpers.tsx @@ -15,6 +15,7 @@ interface PatientMetaConfig { launchableFormProps: Record; moduleName: string; addPatientToListOptions: { isEnabled: boolean; excludeCohorts?: Array; displayText: string }; + viewPatientProgramSummary?: boolean; } export interface PatientListColumn { @@ -71,8 +72,51 @@ export const LaunchableFormMenuItem = ({ ); }; +export const ViewSummaryMenuItem = ({ + patientUuid, + ViewSummary, + encounterType, +}) => { + const [actionText, setActionText] = useState(ViewSummary.actionText); + const [encounterUuid, setEncounterUuid] = useState(null); + const [isLoading, setIsLoading] = useState(false); + const viewSummaryActionText = ViewSummary.actionText || 'View Summary '; + + useEffect(() => { + if (ViewSummary.editLatestEncounter && encounterType && !encounterUuid) { + setIsLoading(true); + fetchPatientLastEncounter(patientUuid, encounterType).then((latestEncounter) => { + if (latestEncounter) { + setActionText(viewSummaryActionText); + setEncounterUuid(latestEncounter.uuid); + } + setIsLoading(false); + }); + } else { + setIsLoading(false); + } + }, []); + + return ( + <> + {isLoading ? ( + + ) : ( + { + navigate({ + to: `/openmrs/spa/patient/${patientUuid}/chart/tb-patient-summary`, + }); + }} + /> + )} + + ); +}; + export function consolidatatePatientMeta(rawPatientMeta, form, config: PatientMetaConfig) { - const { isDynamicCohort, location, encounterType, launchableFormProps, moduleName, addPatientToListOptions } = config; + const { isDynamicCohort, location, encounterType, launchableFormProps, moduleName, addPatientToListOptions,viewPatientProgramSummary } = config; const patientUuid = !isDynamicCohort ? rawPatientMeta.patient.uuid : rawPatientMeta.person.uuid; return { timeAddedToList: !isDynamicCohort ? moment(rawPatientMeta.startDate).format('LL') : null, @@ -102,6 +146,16 @@ export function consolidatatePatientMeta(rawPatientMeta, form, config: PatientMe excludeCohorts={addPatientToListOptions?.excludeCohorts || []} /> )} + {viewPatientProgramSummary ? ( + + ) : ( + <> + )} ), }; diff --git a/packages/esm-commons-lib/src/components/patient-list-tabs/ohri-patient-list-tabs.component.tsx b/packages/esm-commons-lib/src/components/patient-list-tabs/ohri-patient-list-tabs.component.tsx index 2f35962f5..3e3e59849 100644 --- a/packages/esm-commons-lib/src/components/patient-list-tabs/ohri-patient-list-tabs.component.tsx +++ b/packages/esm-commons-lib/src/components/patient-list-tabs/ohri-patient-list-tabs.component.tsx @@ -26,6 +26,7 @@ export function OHRIPatientListTabs({ patientListConfigs, moduleName }) { launchableForm={config.launchableForm} extraAssociatedEncounterTypes={config.extraAssociatedEncounterTypes} moduleName={moduleName} + viewPatientProgramSummary={config.viewPatientProgramSummary} /> ); diff --git a/packages/esm-tb-app/src/views/dashboard/patient-list-tabs/tb-patient-list-tabs.component.tsx b/packages/esm-tb-app/src/views/dashboard/patient-list-tabs/tb-patient-list-tabs.component.tsx index 0ec65b5a0..68b0a6e21 100644 --- a/packages/esm-tb-app/src/views/dashboard/patient-list-tabs/tb-patient-list-tabs.component.tsx +++ b/packages/esm-tb-app/src/views/dashboard/patient-list-tabs/tb-patient-list-tabs.component.tsx @@ -4,7 +4,6 @@ import { getObsFromEncounter, OHRIPatientListTabs, } from '@ohri/openmrs-esm-ohri-commons-lib'; -import moment from 'moment'; import { moduleName } from '../../../index'; import { useConfig } from '@openmrs/esm-framework'; @@ -20,11 +19,12 @@ function TbHomePatientTabs() { isReportingCohort: true, cohortSlotName: 'clients-assessed-for-covid-tb', launchableForm: { - editActionText: t('editAssessmentForm', 'Edit TB case assessment form'), + editActionText: t('editFollowUpForm', 'Edit TB Follow-up Form'), editLatestEncounter: true, targetDashboard: 'tb-assessments', - name: 'TB Case Enrollment Form', + name: 'TB Follow-up Form', }, + associatedEncounterType: config.encounterTypes.tbProgramEnrollment, excludeColumns: ['timeAddedToList', 'waitingTime', 'location', 'phoneNumber', 'hivResult'], otherColumns: [ { @@ -64,6 +64,7 @@ function TbHomePatientTabs() { }, }, ], + viewPatientProgramSummary:true }, ], [], diff --git a/packages/esm-tb-app/translations/en.json b/packages/esm-tb-app/translations/en.json index 1f5b20e83..24a0c4408 100644 --- a/packages/esm-tb-app/translations/en.json +++ b/packages/esm-tb-app/translations/en.json @@ -27,5 +27,6 @@ "adherenceAssessment": "Adherence", "nextAppointment": "Next Appointment", "siteOfTb": "Site of TB", - "appointmentDate": "Appointment Date" + "appointmentDate": "Appointment Date", + "editFollowUpForm": "Edit TB Follow-up Form" }