Skip to content

Commit

Permalink
fix: Stringify option set codes
Browse files Browse the repository at this point in the history
  • Loading branch information
edvinstava committed Jul 31, 2024
1 parent 36b925e commit 30a3b16
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/utils/DataFetching/Sorting/useMappedTrackedEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ interface Attribute {
}

export interface MappedEntityValues {
[key: string]: string | undefined;
dateOfBirth: string | undefined;
gender: string | undefined;
firstName: string | undefined;
lastName: string | undefined;

[key: string]: string | undefined;
}

interface UseMappedTrackedEntityVariablesProps {
Expand All @@ -36,23 +37,24 @@ export const useMappedTrackedEntityVariables = ({
return mappedValues;
}

return Object.entries(variableMappings).reduce((acc, [key, attributeId]) => {
const attribute = trackedEntityAttributes.find((attr: Attribute) => attr.attribute === attributeId);
if (attribute) {
const value = trackedEntity.attributes.find((attr: Attribute) => attr.attribute === attributeId)?.value;
if (value !== undefined && value !== null) {
if (key === 'gender') {
if (value === variableMappings.femaleOptionCode) {
acc.gender = GenderCodes.CGC_Female;
}
if (value === variableMappings.maleOptionCode) {
acc.gender = GenderCodes.CGC_Male;
return Object.entries(variableMappings)
.reduce((acc, [key, attributeId]) => {
const attribute = trackedEntityAttributes.find((attr: Attribute) => attr.attribute === attributeId);
if (attribute) {
const value = trackedEntity.attributes.find((attr: Attribute) => attr.attribute === attributeId)?.value;
if (value !== undefined && value !== null) {
if (key === 'gender') {
if (value === String(variableMappings.femaleOptionCode)) {
acc.gender = GenderCodes.CGC_Female;
}
if (value === String(variableMappings.maleOptionCode)) {
acc.gender = GenderCodes.CGC_Male;
}
return acc;
}
return acc;
acc[key] = value;
}
acc[key] = value;
}
}
return acc;
}, mappedValues);
return acc;
}, mappedValues);
};

0 comments on commit 30a3b16

Please sign in to comment.