diff --git a/packages/esm-commons-lib/src/utils/patient-list-tabs-config-builder.ts b/packages/esm-commons-lib/src/utils/patient-list-tabs-config-builder.ts index 74fdd3e6d..591f1be13 100644 --- a/packages/esm-commons-lib/src/utils/patient-list-tabs-config-builder.ts +++ b/packages/esm-commons-lib/src/utils/patient-list-tabs-config-builder.ts @@ -1,4 +1,5 @@ -import { getObsFromEncounter } from './encounter-list-utils'; +import dayjs from 'dayjs'; +import { findObs, getObsFromEncounter } from './encounter-list-utils'; import { extractSchemaValues, replaceWithConfigDefaults } from './schema-manipulation'; export const getPatientListTabsData = (patientListTabsSchema, config) => { @@ -12,6 +13,8 @@ export const getPatientListTabsData = (patientListTabsSchema, config) => { header: column.title, index: column.index || null, getValue: (row) => { + const { encounter } = row; + if (column.type === 'patientId') { return row.id; } @@ -24,7 +27,26 @@ export const getPatientListTabsData = (patientListTabsSchema, config) => { return '03/03/2021'; } - const { encounter } = row; + if (column.type === 'encounterDate') { + return encounter && dayjs(encounter.encounterDatetime).format('DD-MMM-YYYY'); + } + + if (column.type === 'vaccination') { + const obs = findObs(encounter, column.concept); + + if (typeof obs !== 'undefined' && obs) { + if (typeof obs.value === 'object') { + const vaccineNAME = + obs.value.names?.find((conceptName) => conceptName.conceptNameType === 'SHORT')?.name || + obs.value.name.name; + if (vaccineNAME === 'Other non-coded') { + return getObsFromEncounter(encounter, column.fallbackConcepts[0]); + } + } + } + return getObsFromEncounter(encounter, column.concept); + } + return getObsFromEncounter(encounter, column.concept, column.isDate); }, }; diff --git a/packages/esm-covid-app/src/covid/dashboard/patient-list-tabs/covid-patient-list-schema-config.json b/packages/esm-covid-app/src/covid/dashboard/patient-list-tabs/covid-patient-list-schema-config.json new file mode 100644 index 000000000..0a63e6df1 --- /dev/null +++ b/packages/esm-covid-app/src/covid/dashboard/patient-list-tabs/covid-patient-list-schema-config.json @@ -0,0 +1,100 @@ +{ + "menuId": "covidHome", + "tabDefinitions": [ + { + "tabName": "All COVID-19 Clients", + "cohortId": "clientsAssessedForCovid", + "isReportingCohort": true, + "cohortSlotName": "clients-assessed-for-covid-slot", + "launchableForm": { + "package": "covid", + "name": "COVID Assessment Form", + "actionText": "Edit case assessment form", + "targetDashboard": "covid-assessments" + }, + "associatedEncounterType": "covid_Assessment_EncounterUUID", + "excludeColumns": ["timeAddedToList", "waitingTime", "location", "phoneNumber", "hivResult"], + "otherColumns": [ + { + "id": "assessmentDate", + "title": "Assessment date", + "type": "encounterDate", + "index": 1 + }, + { + "id": "finalAssessment", + "title": "Final result", + "concept": "rapidTestResult" + }, + { + "id": "outcome", + "title": "Outcome", + "concept": "covidOutcome" + } + ] + }, + { + "tabName": "Pending lab results", + "cohortId": "covidClientsWithPendingLabResults", + "isReportingCohort": true, + "cohortSlotName": "pending-covid-lab-results-slot", + "launchableForm": { + "package": "covid", + "name": "COVID Lab Test", + "actionText": "Enter test result", + "targetDashboard": "covid-lab-results" + }, + "associatedEncounterType": "covid_Assessment_EncounterUUID", + "excludedColumns": ["timeAddedToList", "waitingTime", "location", "phoneNumber", "hivResult"], + "otherColumns": [ + { + "id": "testDate", + "isDate": true, + "title": "Test date", + "concept": "dateSpecimenCollected", + "index": 1 + }, + { + "id": "testType", + "title": "Test type", + "concept": "covidTestType" + } + ] + }, + { + "tabName": "Scheduled Vaccination", + "cohortId": "covidVaccinatedClients", + "isReportingCohort": true, + "cohortSlotName": "clients-vaccinated-for-covid-slot", + "launchableForm": { + "package": "covid", + "name": "COVID Vaccination Form", + "actionText": "Edit covid vaccination form", + "targetDashboard": "covid_vaccination" + }, + "associatedEncounterType": "covidVaccinationEncounterUUID", + "excludedColumns": ["timeAddedToList", "waitingTime", "location", "phoneNumber", "hivResult"], + "otherColumns": [ + { + "id": "lastDoseAdministered", + "title": "Last dose administered", + "concept": "covidVaccinationDose_UUID", + "index": 1 + }, + { + "id": "vaccine", + "title": "Vaccine", + "type": "vaccination", + "concept": "covidVaccineAdministeredConcept_UUID", + "fallbackConcepts": ["covidVaccineConcept_UUID"] + }, + { + "id": "returnVisitDate", + "isDate": true, + "title": "Return visit date", + "concept": "returnVisitDateConcept" + } + ] + } + ] + } \ No newline at end of file diff --git a/packages/esm-covid-app/src/covid/dashboard/patient-list-tabs/covid-patient-list-tabs.component.tsx b/packages/esm-covid-app/src/covid/dashboard/patient-list-tabs/covid-patient-list-tabs.component.tsx index e13b01d57..649f567b3 100644 --- a/packages/esm-covid-app/src/covid/dashboard/patient-list-tabs/covid-patient-list-tabs.component.tsx +++ b/packages/esm-covid-app/src/covid/dashboard/patient-list-tabs/covid-patient-list-tabs.component.tsx @@ -1,162 +1,17 @@ -import React, { useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; +import React from 'react'; import { - findObs, - getObsFromEncounter, - getObsFromEncounters, + getPatientListTabsData, OHRIPatientListTabs, } from '@ohri/openmrs-esm-ohri-commons-lib'; import { moduleName } from '../../../index'; import { useConfig } from '@openmrs/esm-framework'; -import dayjs from 'dayjs'; +import covidPatientListConfig from './covid-patient-list-schema-config.json'; function CovidHomePatientTabs() { - const { t } = useTranslation(); const config = useConfig(); + const patientListTabs = getPatientListTabsData(covidPatientListConfig, config); - const tabsConfigs = useMemo( - () => [ - { - label: t('allCTClients', 'All COVID-19 Clients'), - cohortId: config.cohorts.clientsAssessedForCovid, - isReportingCohort: true, - cohortSlotName: 'clients-assessed-for-covid-slot', - launchableForm: { - editActionText: t('editAssessmentForm', 'Edit case assessment form'), - editLatestEncounter: true, - targetDashboard: 'covid-assessments', - name: 'COVID Assessment Form', - }, - associatedEncounterType: config.obsConcepts.covidCaseAssessmentEncType, - excludeColumns: ['timeAddedToList', 'waitingTime', 'location', 'phoneNumber', 'hivResult'], - otherColumns: [ - { - key: 'assessmentDate', - header: t('assessmentDate', 'Assessment date'), - getValue: ({ latestEncounter }) => { - return latestEncounter && dayjs(latestEncounter.encounterDatetime).format('DD-MMM-YYYY'); - }, - index: 3, - }, - { - key: 'finalAssessment', - header: t('finalResults', 'Final result'), - getValue: ({ latestExtraEncounters }) => { - const pcrResult = getObsFromEncounters(latestExtraEncounters, config.obsConcepts.pcrTestResult); - return pcrResult && pcrResult != '--' - ? pcrResult - : getObsFromEncounters(latestExtraEncounters, config.obsConcepts.rapidTestResult); - }, - }, - { - key: 'outcome', - header: t('outcome', 'Outcome'), - getValue: ({ latestEncounter }) => { - return getObsFromEncounter(latestEncounter, config.obsConcepts.covidOutcome); - }, - }, - ], - extraAssociatedEncounterTypes: [config.obsConcepts.covidLabTestEncType], - }, - { - label: t('pendingLabResults', 'Pending lab results'), - cohortId: config.cohorts.covidClientsWithPendingLabResults, - isReportingCohort: true, - cohortSlotName: 'pending-covid-lab-results-slot', - launchableForm: { - name: 'COVID Lab Test', - editActionText: 'Enter test result', - editLatestEncounter: true, - targetDashboard: 'covid-lab-results', - }, - excludeColumns: ['timeAddedToList', 'waitingTime', 'location', 'phoneNumber', 'hivResult'], - associatedEncounterType: config.obsConcepts.covidCaseAssessmentEncType, - otherColumns: [ - { - key: 'testDate', - header: t('testDate', 'Test Date'), - getValue: ({ latestEncounter }) => { - return getObsFromEncounter(latestEncounter, config.obsConcepts.dateSpecimenCollected, true); - }, - }, - { - key: 'testType', - header: t('testType', 'Test Type'), - getValue: ({ latestEncounter }) => { - return getObsFromEncounter(latestEncounter, config.obsConcepts.covidTestType); - }, - }, - ], - }, - { - label: t('scheduledVaccination', 'Scheduled Vaccination'), - cohortId: config.obsConcepts.covidVaccinatedClients, - isReportingCohort: true, - cohortSlotName: 'clients-vaccinated-for-covid-slot', - launchableForm: { - name: 'COVID Vaccination Form', - editActionText: 'Edit covid vaccination form', - editLatestEncounter: true, - targetDashboard: 'covid_vaccination', - }, - associatedEncounterType: config.obsConcepts.covidVaccinationEncType, - excludeColumns: ['timeAddedToList', 'waitingTime', 'location', 'phoneNumber', 'hivResult'], - otherColumns: [ - { - key: 'lastDoseAdministered', - header: t('lastDoseAdministered', 'Last Dose Administered'), - getValue: ({ latestEncounter }) => { - return getObsFromEncounter(latestEncounter, config.obsConcepts.covidVaccinationDose_UUID); - }, - }, - { - key: 'vaccine', - header: t('vaccine', 'Vaccine'), - getValue: ({ latestEncounter }) => { - const obs = findObs(latestEncounter, config.obsConcepts.covidVaccineAdministeredConcept_UUID); - if (typeof obs !== 'undefined' && obs) { - if (typeof obs.value === 'object') { - const vaccineNAME = - obs.value.names?.find((conceptName) => conceptName.conceptNameType === 'SHORT')?.name || - obs.value.name.name; - if (vaccineNAME === 'Other non-coded') { - return getObsFromEncounter(latestEncounter, config.obsConcepts.covidVaccineConcept_UUID); - } - } - } - return getObsFromEncounter(latestEncounter, config.obsConcepts.covidVaccineAdministeredConcept_UUID); - }, - }, - { - key: 'returnVisitDate', - header: t('returnVisitDate', 'Return Visit Date'), - getValue: ({ latestEncounter }) => { - return getObsFromEncounter(latestEncounter, config.obsConcepts.returnVisitDateConcept, true); - }, - }, - ], - }, - ], - [ - config.cohorts.clientsAssessedForCovid, - config.cohorts.covidClientsWithPendingLabResults, - config.obsConcepts.covidCaseAssessmentEncType, - config.obsConcepts.covidLabTestEncType, - config.obsConcepts.covidOutcome, - config.obsConcepts.covidTestType, - config.obsConcepts.covidVaccinatedClients, - config.obsConcepts.covidVaccinationDose_UUID, - config.obsConcepts.covidVaccinationEncType, - config.obsConcepts.covidVaccineAdministeredConcept_UUID, - config.obsConcepts.covidVaccineConcept_UUID, - config.obsConcepts.dateSpecimenCollected, - config.obsConcepts.pcrTestResult, - config.obsConcepts.rapidTestResult, - config.obsConcepts.returnVisitDateConcept, - t, - ], - ); - return ; + return ; } export default CovidHomePatientTabs;