Skip to content

Commit

Permalink
(chore) (HCT, HP, Covid): Use concept keys from the schema for better…
Browse files Browse the repository at this point in the history
… configurability. (#1863)

* use config keys in our json(hct)

* implement the changes in hp and covid jsons

* fix the missing concept

* use the schema from the framework instead of importing manually
  • Loading branch information
hadijahkyampeire authored Jun 13, 2024
1 parent 4f8533d commit 82ff232
Show file tree
Hide file tree
Showing 22 changed files with 331 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getObsFromEncounter, findObs } from './encounter-list-utils';
export const renderTag = (encounter, concept, statusColorMappings) => {
const columnStatus = getObsFromEncounter(encounter, concept);
const columnStatusObs = findObs(encounter, concept);

if (columnStatus == '--') {
return '--';
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {
getConceptFromMappings,
} from './encounter-list-utils';
import { renderTag } from './encounter-list-component-util';
import { extractSchemaValues, replaceWithConfigDefaults } from './schema-manipulation';

interface ConfigSchema {
[key: string]: { [key: string]: string | Array<string> };
}

interface MenuProps {
menuId: string;
Expand Down Expand Up @@ -142,8 +147,13 @@ export const getTabColumns = (columnsDefinition: Array<ColumnDefinition>) => {
return columns;
};

export const getMenuItemTabConfiguration = (schemaConfig: MenuProps) => {
const tabs = schemaConfig.tabDefinitions.map((tab) => {
export const getMenuItemTabConfiguration = (schemaConfig: MenuProps, configSchema?: ConfigSchema) => {
// gonna make the configSchema optional for now until we implement it everywher
const configDefaults = extractSchemaValues(configSchema);

const transformedSchemaConfig = replaceWithConfigDefaults(schemaConfig, configDefaults);

const tabs = (configSchema ? transformedSchemaConfig.tabDefinitions : schemaConfig.tabDefinitions).map((tab) => {
return {
name: tab.tabName,
hasFilter: tab.hasFilter || false,
Expand Down
16 changes: 13 additions & 3 deletions packages/esm-commons-lib/src/utils/encounter-list-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export function getObsFromEncounters(encounters, obsConcept) {

export function resolveValueUsingMappings(encounter, concept, mappings) {
const obs = findObs(encounter, concept);
return obs ? mappings[obs.value.uuid] || obs.value : '--';
for (const key in mappings) {
if (mappings[key] === obs?.value?.uuid) {
return key;
}
}
return '--';
}

export function getConceptFromMappings(encounter, concepts) {
Expand Down Expand Up @@ -77,10 +82,15 @@ export function getObsFromEncounter(
let obs = findObs(encounter, obsConcept);

if (isTrueFalseConcept) {
if (obs?.value?.uuid == 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3') {
if (
(obs?.value?.uuid != 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3' && obs?.value?.name?.name !== 'Unknown') ||
obs?.value?.name?.name === 'FALSE'
) {
return 'No';
} else if (obs?.value?.uuid == 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3') {
return 'Yes';
} else {
return 'No';
return obs?.value?.name?.name;
}
}

Expand Down
47 changes: 47 additions & 0 deletions packages/esm-commons-lib/src/utils/schema-manipulation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export function extractSchemaValues(schema) {
const result = {};
function traverse(obj) {
Object.entries(obj).forEach(([key, value]) => {
if (typeof value === 'object' && !Array.isArray(value)) {
traverse(value);
} else {
result[key] = value;
}
});
}

traverse(schema);
return result;
}

export function replaceWithConfigDefaults(obj, configDefaults) {
if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === 'string' && configDefaults.hasOwnProperty(item)) {
return configDefaults[item];
} else {
return replaceWithConfigDefaults(item, configDefaults);
}
});
} else if (typeof obj === 'object' && obj !== null) {
const newObj = {};
for (const key in obj) {
if (typeof obj[key] === 'string') {
if (configDefaults.hasOwnProperty(key)) {
// Case where UUID is the value
newObj[configDefaults[key]] = obj[key];
} else if (configDefaults.hasOwnProperty(obj[key])) {
// Case where UUID is the key
newObj[key] = configDefaults[obj[key]];
} else {
newObj[key] = obj[key];
}
} else {
newObj[key] = replaceWithConfigDefaults(obj[key], configDefaults);
}
}
return newObj;
} else {
return obj;
}
}
10 changes: 4 additions & 6 deletions packages/esm-covid-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ export const configSchema = {
covidTypeofTestConcept_UUID: '069f6dfe-88c1-4a45-a894-0d99549c8718',
covidSpecimenCollectionDate_UUID: '159951AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
covidOutcomeUUID: 'a845f3e6-4432-4de4-9fff-37fa270b1a06',
covidTestType: '069f6dfe-88c1-4a45-a894-0d99549c8718',
covidOutcome: 'a845f3e6-4432-4de4-9fff-37fa270b1a06',
rapidAntigenResultDate: 'af159c77-bc5d-46dd-90d9-bcbffb22267f',
covidTreatementOutConcept_UUID: 'a845f3e6-4432-4de4-9fff-37fa270b1a06',
covidRapidTestResultDate_UUID: 'af159c77-bc5d-46dd-90d9-bcbffb22267f',
pcrTestResultDate: '4a77ab44-0323-490e-96be-e168c0e5c9de',
finalCovid19Result: '5da5c21b-969f-41bd-9091-e40d4c707544',
covidOutcomesCohortUUID: 'afb0d950-48fd-44d7-ae2c-79615cd125f0',
covidDiagnorticPcrResultDate_UUID: '4a77ab44-0323-490e-96be-e168c0e5c9de',
htsRetrospectiveEncounterType: '79c1f50f-f77d-42e2-ad2a-d29304dde2fe',
htsRetrospectiveType: '79c1f50f-f77d-42e2-ad2a-d29304dde2fe',
pcrTestResult: '3f4ee14b-b4ab-4597-9fe9-406883b63d76',
covidReasonsForTestingConcep_UUID: 'ae46f4b1-c15d-4bba-ab41-b9157b82b0ce',
covidDiagnosticPcrResult_UUID: '3f4ee14b-b4ab-4597-9fe9-406883b63d76',
covidTestResultUUID: '3f4ee14b-b4ab-4597-9fe9-406883b63d76',
covidPatientStatusUUID: 'de3bc9b7-05b5-41b6-a38d-8d2eec646c4f',
covidSARS_TestResultConcept_UUID: '89feed9c-1dd9-477a-ab1c-86f5f75f6762',
Expand Down Expand Up @@ -66,6 +61,10 @@ export const configSchema = {
covidVaccineAdministeredConcept_UUID: 'e41fbe17-4aee-4a44-950b-6676d6e0ede2',
covidVaccineConcept_UUID: '0cc868bd-e9dd-4b59-b278-f923afe22d82',
covidVaccineSeriesConcept_UUID: '45b3959d-f897-4e01-b6e5-16ef6ae0a687',
covidNotDoneStatus: '1118AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
covidCompletedStatus: '1267AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
covidCancelledStatus: '165170AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
covidPendingStatus: '162866AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
},
cohorts: {
Expand Down Expand Up @@ -109,7 +108,6 @@ export const configSchema = {
covidLabResultFormUuid: 'cf8cd756-baef-38df-b84d-92968b42c113',
covidLabCancellationFormUuid: 'd38bc949-c95b-39eb-a2c5-08b82a36409c',
covidSampleCollectionFormUuid: '371d19b6-485f-11ec-99cc-1fdd2d4e9d88',
covidLabOrderFormUuid: 'f5fb6bc4-6fc3-3462-a191-2fff0896bab3',
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,60 @@
"tabName": "COVID Assessment",
"headerTitle": "COVID Assessment",
"displayText": "COVID Assessment",
"encounterType": "253a43d3-c99e-415c-8b78-ee7d4d3c1d54",
"encounterType": "covid_Assessment_EncounterUUID",
"columns": [
{
"id": "encounterDate",
"isDate": true,
"title": "Date of Assessment",
"concept": "160753AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"concept": "covidEncounterDateTime_UUID",
"isLink": true
},
{
"id": "reasonsForTesting",
"title": "Reason for testing",
"concept": "ae46f4b1-c15d-4bba-ab41-b9157b82b0ce"
"concept": "covidReasonsForTestingConcep_UUID"
},
{
"id": "symptomatic",
"title": "Presentation",
"concept": "de3bc9b7-05b5-41b6-a38d-8d2eec646c4f"
"concept": "covidPatientStatusUUID"
},
{
"id": "outcome",
"title": "Outcome",
"concept": "a845f3e6-4432-4de4-9fff-37fa270b1a06"
"concept": "covidOutcomeUUID"
},
{
"id": "actions",
"title": "Actions",
"actionOptions": [
{
"formName": "COVID Case Form",
"formName": "CovidCaseFormName",
"package": "covid",
"label": "View Case",
"mode": "view"
},
{
"formName": "COVID Assessment Form",
"formName": "CovidAssessmentFormName",
"package": "covid",
"label": "View Assessment",
"mode": "view"
},
{
"formName": "COVID Assessment Form",
"formName": "CovidAssessmentFormName",
"package": "covid",
"label": "Edit Assessment",
"mode": "edit"
},
{
"formName": "COVID Case Form",
"formName": "CovidCaseFormName",
"package": "covid",
"label": "Edit Case",
"mode": "edit"
},
{
"formName": "COVID Outcome Form",
"formName": "CovidOutcomeFormName",
"package": "covid",
"label": "Add/Edit Outcome",
"mode": "edit"
Expand All @@ -72,18 +72,18 @@
},
"formList": [
{
"name": "COVID Assessment Form",
"name": "CovidAssessmentFormName",
"excludedIntents": ["COVID_LAB_ASSESSMENT_EMBED"],
"uuid": "f5fb6bc4-6fc3-3462-a191-2fff0896bab3"
"uuid": "covidAssessmentFormUuid"
},
{
"name": "COVID Case Form",
"uuid": "c0fd71bd-37bc-3c8d-b2ff-149c0ff4d6f0"
"name": "CovidCaseFormName",
"uuid": "covidCaseFormUuid"
},
{
"name": "COVID Outcome Form",
"name": "CovidOutcomeFormName",
"excludedIntents": ["COVID_OUTCOME_EMBED", "*"],
"uuid": "6515d898-439c-11ec-9103-238295f2dfd7"
"uuid": "covidOutcomeFormUuid"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { useConfig } from '@openmrs/esm-framework';
import { EncounterList, getMenuItemTabConfiguration } from '@ohri/openmrs-esm-ohri-commons-lib';
import caseAssessmentSchemaConfig from './case-assessment-schema-config.json';
import { configSchema } from '../../config-schema';

export const covidFormSlot = 'hts-encounter-form-slot';
export const covidEncounterRepresentation =
Expand All @@ -13,7 +15,8 @@ interface CovidAssessmentWidgetProps {
}

const CovidAssessment: React.FC<CovidAssessmentWidgetProps> = ({ patientUuid }) => {
const tabs = getMenuItemTabConfiguration(caseAssessmentSchemaConfig);
const config = useConfig();
const tabs = getMenuItemTabConfiguration(caseAssessmentSchemaConfig, config);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@
"tabName": "Vaccinations",
"headerTitle": "Vaccinations",
"displayText": "Vaccinations",
"encounterType": "5b37ce7a-c55e-4226-bdc8-5af04025a6de",
"encounterType": "covidVaccinationEncounterUUID",
"columns": [
{
"id": "vaccinationDate",
"isDate": true,
"title": "Vaccination Date",
"concept": "1410AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"concept": "covidVaccinationAdministeredConcept_UUID"
},
{
"id": "doseAdministered",
"title": "Vaccine Dose",
"concept": "6ec64cb3-e710-4d3e-9db4-38c135966a45"
"concept": "covidVaccinationDose_UUID"
},
{
"id": "vaccineSeries",
"title": "Vaccine Series",
"concept": "45b3959d-f897-4e01-b6e5-16ef6ae0a687"
"concept": "covidVaccineSeriesConcept_UUID"
},
{
"id": "covidVaccineType",
"title": "Vaccine Administered",
"concept": "e41fbe17-4aee-4a44-950b-6676d6e0ede2",
"secondaryConcept": "0cc868bd-e9dd-4b59-b278-f923afe22d82"
"concept": "covidVaccineAdministeredConcept_UUID",
"secondaryConcept": "covidVaccineConcept_UUID"
},
{
"id": "actions",
"title": "Actions",
"actionOptions": [
{
"formName": "COVID Vaccination Form",
"formName": "CovidVaccinationFormName",
"package": "covid",
"label": "View Details",
"mode": "view"
},
{
"formName": "COVID Vaccination Form",
"formName": "CovidVaccinationFormName",
"package": "covid",
"label": "Edit Form",
"mode": "edit"
Expand All @@ -54,8 +54,8 @@
},
"formList": [
{
"name": "COVID Vaccination Form",
"uuid": "3ae3a031-2e24-357d-81b3-205d5187090a"
"name": "CovidVaccinationFormName",
"uuid": "covidVaccinationFormUuid"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import { useConfig } from '@openmrs/esm-framework';
import { EncounterList, getMenuItemTabConfiguration } from '@ohri/openmrs-esm-ohri-commons-lib';

import covidVaccinationsSchemaConfig from './covid-vaccinations-schema.json';
import { configSchema } from '../../config-schema';

interface CovidVaccinationsWidgetProps {
patientUuid: string;
Expand All @@ -10,7 +12,8 @@ interface CovidVaccinationsWidgetProps {
export const covidFormSlot = 'hts-encounter-form-slot';

const CovidVaccinations: React.FC<CovidVaccinationsWidgetProps> = ({ patientUuid }) => {
const tabs = getMenuItemTabConfiguration(covidVaccinationsSchemaConfig);
const config = useConfig();
const tabs = getMenuItemTabConfiguration(covidVaccinationsSchemaConfig, config);

return (
<>
Expand Down
Loading

0 comments on commit 82ff232

Please sign in to comment.