Skip to content

Commit

Permalink
Undo code to NA and Date
Browse files Browse the repository at this point in the history
  • Loading branch information
anagperal committed Aug 13, 2024
1 parent 1fade6d commit ac15f49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 90 deletions.
16 changes: 8 additions & 8 deletions src/data/repositories/consts/DiseaseOutbreakConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() ??
"",
Expand Down
98 changes: 16 additions & 82 deletions src/data/repositories/utils/DiseaseOutbreakMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -123,86 +119,24 @@ function getMultipleOUFromText(text: string): string[] {
return [text].filter(ou => ou !== "");
}

function getValueOfCodeIfSpecifyDateIsTrue(
attributeValues: Record<DiseaseOutbreakCode, string>,
code: DiseaseOutbreakCode,
specifyDateCode: DiseaseOutbreakCode
): string | undefined {
return attributeValues[specifyDateCode] === "true" ? attributeValues[code] : undefined;
}

function getValueByDiseaseOutbreakCode(
attributeValues: Record<DiseaseOutbreakCode, string>,
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[]
): D2TrackerTrackedEntity {
const attributeValues: Record<DiseaseOutbreakCode, string> =
getValueFromDiseaseOutbreak(diseaseOutbreak);

const attributeValuesCleaned = (Object.keys(attributeValues) as DiseaseOutbreakCode[]).reduce(
(acc: Record<DiseaseOutbreakCode, string>, code: DiseaseOutbreakCode) => {
const value = getValueByDiseaseOutbreakCode(attributeValues, code);
return value
? { ...acc, [code]: getValueByDiseaseOutbreakCode(attributeValues, code) }
: acc;
},
{} as Record<DiseaseOutbreakCode, string>
);

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,
Expand Down

0 comments on commit ac15f49

Please sign in to comment.