From 8831cc220dbf243b8a2799d26c36b749a20d4de0 Mon Sep 17 00:00:00 2001 From: hadijahkyampeire Date: Mon, 3 Jun 2024 23:47:23 +0300 Subject: [PATCH] implement schema based tab for hiv prevention --- .../utils/encounter-list-config-builder.ts | 2 +- .../src/utils/encounter-list-utils.ts | 8 ++ .../hts-prevention-schema-config.json | 64 +++++++++++ .../hts-prevention-summary.component.tsx | 27 +++-- .../tab-list/hts-overview-list.component.tsx | 100 ------------------ .../tab-list/hts-overview-list.scss | 25 ----- 6 files changed, 93 insertions(+), 133 deletions(-) create mode 100644 packages/esm-hiv-prevention-app/src/views/hiv-testing-services/hts-prevention-schema-config.json delete mode 100644 packages/esm-hiv-prevention-app/src/views/hiv-testing-services/tab-list/hts-overview-list.component.tsx delete mode 100644 packages/esm-hiv-prevention-app/src/views/hiv-testing-services/tab-list/hts-overview-list.scss diff --git a/packages/esm-commons-lib/src/utils/encounter-list-config-builder.ts b/packages/esm-commons-lib/src/utils/encounter-list-config-builder.ts index acd5914c8..69e260e3d 100644 --- a/packages/esm-commons-lib/src/utils/encounter-list-config-builder.ts +++ b/packages/esm-commons-lib/src/utils/encounter-list-config-builder.ts @@ -34,7 +34,7 @@ interface TabSchema { displayText: string; encounterType: string; columns: Array; - formList: Array<{ name: string; uuid: string }>; + formList: Array<{ name: string; uuid: string; fixedIntent?: string; excludedIntents?: Array }>; launchOptions: LaunchOptions; } diff --git a/packages/esm-commons-lib/src/utils/encounter-list-utils.ts b/packages/esm-commons-lib/src/utils/encounter-list-utils.ts index 399fa522b..def12d5e5 100644 --- a/packages/esm-commons-lib/src/utils/encounter-list-utils.ts +++ b/packages/esm-commons-lib/src/utils/encounter-list-utils.ts @@ -170,6 +170,14 @@ export function getObsFromEncounter( } } + if (type === 'location') { + return encounter.location.name; + } + + if (type === 'provider') { + return encounter.encounterProviders.map((p) => p.provider.name).join(' | '); + } + if (!obs && fallBackConcepts?.length) { const concept = fallBackConcepts.find((c) => findObs(encounter, c) != null); obs = findObs(encounter, concept); diff --git a/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/hts-prevention-schema-config.json b/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/hts-prevention-schema-config.json new file mode 100644 index 000000000..3c96055d8 --- /dev/null +++ b/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/hts-prevention-schema-config.json @@ -0,0 +1,64 @@ +{ + "menuId": "hivTesting", + "tabDefinitions": [ + { + "tabName": "HIV Testing", + "headerTitle": "HIV Testing", + "displayText": "HIV Testing", + "encounterType": "79c1f50f-f77d-42e2-ad2a-d29304dde2fe", + "columns": [ + { + "id": "date", + "isDate": true, + "title": "Date of HIV Test", + "concept": "164400AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "id": "location", + "title": "Location", + "type": "location" + }, + { + "id": "hivTestResult", + "title": "HIV Test result", + "concept": "e16b0068-b6a2-46b7-aba9-e3be00a7b4ab" + }, + { + "id": "provider", + "title": "HTS Provider", + "type": "provider" + }, + { + "id": "actions", + "title": "Actions", + "actionOptions": [ + { + "formName": "HIV Testing", + "package": "hiv-prevention", + "label": "View Details", + "mode": "view" + }, + { + "formName": "HIV Testing", + "package": "hiv-prevention", + "label": "Edit Form", + "mode": "edit" + } + ] + } + ], + "launchOptions": { + "displayText": "Add", + "moduleName": "@ohri/openmrs-esm-ohri-hiv-prevention-app" + }, + "formList": [ + { + "name": "HIV Testing", + "uuid": "43ffea77-49dc-3ebd-8d83-c2aedb654030", + "excludedIntents": ["HTS_PRE_TEST", "HTS_TEST", "HTS_POST_TEST"], + "fixedIntent": "*" + } + ] + } + ] +} diff --git a/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/hts-prevention-summary.component.tsx b/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/hts-prevention-summary.component.tsx index 50605251f..f82a67c1b 100644 --- a/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/hts-prevention-summary.component.tsx +++ b/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/hts-prevention-summary.component.tsx @@ -1,26 +1,39 @@ import React from 'react'; import { Tabs, Tab, TabList, TabPanels, TabPanel } from '@carbon/react'; +import { EncounterList, getMenuItemTabConfiguration } from '@ohri/openmrs-esm-ohri-commons-lib'; +import htsTestingSchemaConfig from './hts-prevention-schema-config.json'; + import styles from '../common.scss'; -import HtsOverviewList from './tab-list/hts-overview-list.component'; -import { useTranslation } from 'react-i18next'; interface OverviewListProps { patientUuid: string; } const HTSPreventionSummary: React.FC = ({ patientUuid }) => { - const { t } = useTranslation(); + const tabs = getMenuItemTabConfiguration(htsTestingSchemaConfig); return (
- {t('HtsHivTesting', 'HIV Testing')} + {tabs.map((tab) => ( + {tab.name} + ))} - - - + {tabs.map((tab) => ( + + + + ))}
diff --git a/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/tab-list/hts-overview-list.component.tsx b/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/tab-list/hts-overview-list.component.tsx deleted file mode 100644 index f093916fe..000000000 --- a/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/tab-list/hts-overview-list.component.tsx +++ /dev/null @@ -1,100 +0,0 @@ -import React, { useMemo, useState } from 'react'; -import { EncounterList, EncounterListColumn, getObsFromEncounter } from '@ohri/openmrs-esm-ohri-commons-lib'; -import { useTranslation } from 'react-i18next'; -import { moduleName } from '../../../index'; -import { useConfig } from '@openmrs/esm-framework'; - -interface HtsOverviewListProps { - patientUuid: string; -} - -const HtsOverviewList: React.FC = ({ patientUuid }) => { - const { t } = useTranslation(); - const [counter, setCounter] = useState(0); - const htsRetrospectiveTypeUUID = '79c1f50f-f77d-42e2-ad2a-d29304dde2fe'; // HTS Retrospective - const forceComponentUpdate = () => setCounter(counter + 1); - const headerTitle = t('hivTesting', 'HIV Testing'); - const { obsConcepts, formNames, formUuids } = useConfig(); - - const columns: EncounterListColumn[] = useMemo( - () => [ - { - key: 'date', - header: t('hivTestDate', 'Date of HIV Test'), - getValue: (encounter) => { - return getObsFromEncounter(encounter, obsConcepts.dateOfHIVTestingConceptUUID, true); - }, - }, - { - key: 'location', - header: t('location', 'Location'), - getValue: (encounter) => { - return encounter.location.name; - }, - }, - { - key: 'hivTestResult', - header: t('hivTestResult', 'HIV Test result'), - getValue: (encounter) => { - return getObsFromEncounter(encounter, obsConcepts.hivTestResultConceptUUID); - }, - }, - { - key: 'provider', - header: t('htsProvider', 'HTS Provider'), - getValue: (encounter) => { - return encounter.encounterProviders.map((p) => p.provider.name).join(' | '); - }, - }, - - { - key: 'actions', - header: t('actions', 'Actions'), - getValue: (encounter) => { - const baseActions = [ - { - form: { package: 'hiv', name: formNames.HIVTestingFormName }, - encounterUuid: encounter.uuid, - intent: '*', - label: t('viewDetails', 'View Details'), - mode: 'view', - }, - { - form: { package: 'hiv', name: formNames.HIVTestingFormName }, - encounterUuid: encounter.uuid, - intent: '*', - label: t('editForm', 'Edit Form'), - mode: 'edit', - }, - ]; - return baseActions; - }, - }, - ], - [], - ); - - return ( - - ); -}; - -export default HtsOverviewList; diff --git a/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/tab-list/hts-overview-list.scss b/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/tab-list/hts-overview-list.scss deleted file mode 100644 index ec2847073..000000000 --- a/packages/esm-hiv-prevention-app/src/views/hiv-testing-services/tab-list/hts-overview-list.scss +++ /dev/null @@ -1,25 +0,0 @@ -@import "../../../root.scss"; - -.widgetContainer { - background-color: $ui-background; -} - -.widgetHeaderContainer { - display: flex; - justify-content: space-between; - align-items: center; - padding: spacing.$spacing-04 0 spacing.$spacing-04 spacing.$spacing-05; -} - -.widgetHeaderContainer > h4:after { - content: ""; - display: block; - width: 2rem; - padding-top: 0.188rem; - border-bottom: 0.375rem solid var(--brand-01); -} - -.toggleButtons { - width: fit-content; - margin: 0 spacing.$spacing-03; -}