From ac15f4940f702b6a12d2c6ca53e2ae4e32d77a73 Mon Sep 17 00:00:00 2001 From: Ana Garcia Date: Tue, 13 Aug 2024 12:09:40 +0200 Subject: [PATCH] Undo code to NA and Date --- .../consts/DiseaseOutbreakConstants.ts | 16 +-- .../utils/DiseaseOutbreakMapper.ts | 98 +++---------------- 2 files changed, 24 insertions(+), 90 deletions(-) diff --git a/src/data/repositories/consts/DiseaseOutbreakConstants.ts b/src/data/repositories/consts/DiseaseOutbreakConstants.ts index 16528116..0f6d3ac0 100644 --- a/src/data/repositories/consts/DiseaseOutbreakConstants.ts +++ b/src/data/repositories/consts/DiseaseOutbreakConstants.ts @@ -88,28 +88,28 @@ export function getValueFromDiseaseOutbreak( diseaseOutbreak.earlyResponseActions.conductEpidemiologicalAnalysis.toISOString(), RTSL_ZEB_TEA_LABORATORY_CONFIRMATION: diseaseOutbreak.earlyResponseActions .laboratoryConfirmation.na - ? "" - : "true", + ? "true" + : "", RTSL_ZEB_TEA_SPECIFY_DATE1: diseaseOutbreak.earlyResponseActions.laboratoryConfirmation.date?.toISOString() ?? "", RTSL_ZEB_TEA_APPROPRIATE_CASE_MANAGEMENT: diseaseOutbreak.earlyResponseActions .appropriateCaseManagement.na - ? "" - : "true", + ? "true" + : "", RTSL_ZEB_TEA_SPECIFY_DATE2: diseaseOutbreak.earlyResponseActions.appropriateCaseManagement.date?.toISOString() ?? "", RTSL_ZEB_TEA_APPROPRIATE_PUBLIC_HEALTH: diseaseOutbreak.earlyResponseActions .initiatePublicHealthCounterMeasures.na - ? "" - : "true", + ? "true" + : "", RTSL_ZEB_TEA_SPECIFY_DATE3: diseaseOutbreak.earlyResponseActions.initiatePublicHealthCounterMeasures.date?.toISOString() ?? "", RTSL_ZEB_TEA_APPROPRIATE_RISK_COMMUNICATION: diseaseOutbreak.earlyResponseActions .initiateRiskCommunication.na - ? "" - : "true", + ? "true" + : "", RTSL_ZEB_TEA_SPECIFY_DATE4: diseaseOutbreak.earlyResponseActions.initiateRiskCommunication.date?.toISOString() ?? "", diff --git a/src/data/repositories/utils/DiseaseOutbreakMapper.ts b/src/data/repositories/utils/DiseaseOutbreakMapper.ts index 2711f1b1..1becec2b 100644 --- a/src/data/repositories/utils/DiseaseOutbreakMapper.ts +++ b/src/data/repositories/utils/DiseaseOutbreakMapper.ts @@ -85,27 +85,23 @@ export function mapTrackedEntityAttributesToDiseaseOutbreak( ), laboratoryConfirmation: { date: new Date(getValueFromMap("laboratoryConfirmationDate", trackedEntity)), - na: !(getValueFromMap("laboratoryConfirmationNA", trackedEntity) === "true"), + na: getValueFromMap("laboratoryConfirmationNA", trackedEntity) === "true", }, appropriateCaseManagement: { date: new Date(getValueFromMap("appropriateCaseManagementDate", trackedEntity)), - na: !(getValueFromMap("appropriateCaseManagementNA", trackedEntity) === "true"), + na: getValueFromMap("appropriateCaseManagementNA", trackedEntity) === "true", }, initiatePublicHealthCounterMeasures: { date: new Date( getValueFromMap("initiatePublicHealthCounterMeasuresDate", trackedEntity) ), - na: !( + na: getValueFromMap("initiatePublicHealthCounterMeasuresNA", trackedEntity) === - "true" - ), + "true", }, initiateRiskCommunication: { date: new Date(getValueFromMap("initiateRiskCommunicationDate", trackedEntity)), - na: - getValueFromMap("initiateRiskCommunicationNA", trackedEntity) === "true" - ? false - : true, + na: getValueFromMap("initiateRiskCommunicationNA", trackedEntity) === "true", }, establishCoordination: new Date( getValueFromMap("establishCoordination", trackedEntity) @@ -123,52 +119,6 @@ function getMultipleOUFromText(text: string): string[] { return [text].filter(ou => ou !== ""); } -function getValueOfCodeIfSpecifyDateIsTrue( - attributeValues: Record, - code: DiseaseOutbreakCode, - specifyDateCode: DiseaseOutbreakCode -): string | undefined { - return attributeValues[specifyDateCode] === "true" ? attributeValues[code] : undefined; -} - -function getValueByDiseaseOutbreakCode( - attributeValues: Record, - code: DiseaseOutbreakCode -): string | undefined { - switch (code) { - case "RTSL_ZEB_TEA_LABORATORY_CONFIRMATION": - case "RTSL_ZEB_TEA_SPECIFY_DATE1": - return getValueOfCodeIfSpecifyDateIsTrue( - attributeValues, - code, - "RTSL_ZEB_TEA_LABORATORY_CONFIRMATION" - ); - case "RTSL_ZEB_TEA_APPROPRIATE_CASE_MANAGEMENT": - case "RTSL_ZEB_TEA_SPECIFY_DATE2": - return getValueOfCodeIfSpecifyDateIsTrue( - attributeValues, - code, - "RTSL_ZEB_TEA_APPROPRIATE_CASE_MANAGEMENT" - ); - case "RTSL_ZEB_TEA_APPROPRIATE_PUBLIC_HEALTH": - case "RTSL_ZEB_TEA_SPECIFY_DATE3": - return getValueOfCodeIfSpecifyDateIsTrue( - attributeValues, - code, - "RTSL_ZEB_TEA_APPROPRIATE_PUBLIC_HEALTH" - ); - case "RTSL_ZEB_TEA_APPROPRIATE_RISK_COMMUNICATION": - case "RTSL_ZEB_TEA_SPECIFY_DATE4": - return getValueOfCodeIfSpecifyDateIsTrue( - attributeValues, - code, - "RTSL_ZEB_TEA_APPROPRIATE_RISK_COMMUNICATION" - ); - default: - return attributeValues[code]; - } -} - export function mapDiseaseOutbreakEventToTrackedEntityAttributes( diseaseOutbreak: DiseaseOutbreakEventBaseAttrs, attributesMetadata: D2TrackedEntityAttribute[] @@ -176,33 +126,17 @@ export function mapDiseaseOutbreakEventToTrackedEntityAttributes( const attributeValues: Record = getValueFromDiseaseOutbreak(diseaseOutbreak); - const attributeValuesCleaned = (Object.keys(attributeValues) as DiseaseOutbreakCode[]).reduce( - (acc: Record, code: DiseaseOutbreakCode) => { - const value = getValueByDiseaseOutbreakCode(attributeValues, code); - return value - ? { ...acc, [code]: getValueByDiseaseOutbreakCode(attributeValues, code) } - : acc; - }, - {} as Record - ); - - const attributes: Attribute[] = _( - attributesMetadata.map((attribute): Attribute | null => { - if (!isStringInDiseaseOutbreakCodes(attribute.trackedEntityAttribute.code)) { - throw new Error("Attribute code not found in DiseaseOutbreakCodes"); - } - const typedCode: KeyCode = attribute.trackedEntityAttribute.code; - - return attributeValuesCleaned[typedCode] - ? { - attribute: attribute.trackedEntityAttribute.id, - value: attributeValuesCleaned[typedCode], - } - : null; - }) - ) - .compact() - .value(); + const attributes: Attribute[] = attributesMetadata.map(attribute => { + if (!isStringInDiseaseOutbreakCodes(attribute.trackedEntityAttribute.code)) { + throw new Error("Attribute code not found in DiseaseOutbreakCodes"); + } + const typedCode: KeyCode = attribute.trackedEntityAttribute.code; + const populatedAttribute = { + attribute: attribute.trackedEntityAttribute.id, + value: attributeValues[typedCode], + }; + return populatedAttribute; + }); const enrollment: D2TrackerEnrollment = { orgUnit: RTSL_ZEBRA_ORG_UNIT_ID,