Skip to content

Commit

Permalink
check for duplicate categories
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed May 23, 2024
1 parent 3b165c9 commit af6c22b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions backend/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,16 @@ def retrieve_cohorts_metadata(user_email: str) -> dict[str, Cohort]:

# Process categories of variables
if "varName" in row and "categoryLabel" in row and "categoryValue" in row:
target_dict[cohort_id].variables[var_id].categories.append(
VariableCategory(
value=str(row["categoryValue"]["value"]),
label=str(row["categoryLabel"]["value"]),
concept_id=get_curie_value("categoryConceptId", row),
mapped_id=get_curie_value("categoryMappedId", row),
mapped_label=get_value("categoryMappedLabel", row),
)
new_category = VariableCategory(
value=str(row["categoryValue"]["value"]),
label=str(row["categoryLabel"]["value"]),
concept_id=get_curie_value("categoryConceptId", row),
mapped_id=get_curie_value("categoryMappedId", row),
mapped_label=get_value("categoryMappedLabel", row),
)
# Check for duplicates before appending
if new_category not in target_dict[cohort_id].variables[var_id].categories:
target_dict[cohort_id].variables[var_id].categories.append(new_category)

# Merge dictionaries, cohorts with variables first
return {**cohorts_with_variables, **cohorts_without_variables}

0 comments on commit af6c22b

Please sign in to comment.