Skip to content

Commit

Permalink
upload metadata to the triplestore after generating mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Oct 7, 2024
1 parent 6972638 commit f6232fd
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions backend/src/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def load_cohort_dict_file(dict_path: str, cohort_id: str) -> Dataset:
df["categories"] = df["CATEGORICAL"].apply(parse_categorical_string)

# TODO: handle columns from Komal that maps variables:
# Variable Concept Label,Variable Concept Code,Variable Concept OMOP ID,DOMAIN,Additional Context Concept Label,Additional Context Concept Code,Additional Context OMOP ID,Primary to Secondary Context Relationship,Categorical Values Concept Label,Categorical Values Concept Code,Categorical Values Concept OMOP ID,Unit Concept Label,Unit Concept Code,Unit OMOP ID
if "Label Concept Code" in df.columns:
df["concept_id"] = df.apply(lambda row: str(row["Label Concept Code"]).strip(), axis=1)
else:
Expand Down Expand Up @@ -374,16 +375,16 @@ async def upload_cohort(
)

# NOTE: waiting for more tests before sending to production
# background_tasks.add_task(map_csv_to_standard_codes, metadata_path)
background_tasks.add_task(generate_mappings, cohort_id, metadata_path, g)
# TODO: move all the "delete_existing_triples" and "publish_graph_to_endpoint" logic to the background task after mappings have been generated
# Return "The cohort has been successfully uploaded. The variables are being mapped to standard codes and will be available in the Cohort Explorer in a few minutes."

# Delete previous graph for this file from triplestore
delete_existing_triples(
get_cohort_mapping_uri(cohort_id), f"<{get_cohort_uri(cohort_id)!s}>", "icare:previewEnabled"
)
delete_existing_triples(get_cohort_uri(cohort_id))
publish_graph_to_endpoint(g)
# # Delete previous graph for this file from triplestore
# delete_existing_triples(
# get_cohort_mapping_uri(cohort_id), f"<{get_cohort_uri(cohort_id)!s}>", "icare:previewEnabled"
# )
# delete_existing_triples(get_cohort_uri(cohort_id))
# publish_graph_to_endpoint(g)
except Exception as e:
os.remove(metadata_path)
raise e
Expand All @@ -394,6 +395,15 @@ async def upload_cohort(
# **cohort.dict(),
}

def generate_mappings(cohort_id: str, metadata_path: str, g: Graph) -> None:
"""Function to generate mappings for a cohort and publish them to the triplestore running as background task"""
map_csv_to_standard_codes(metadata_path)
delete_existing_triples(
get_cohort_mapping_uri(cohort_id), f"<{get_cohort_uri(cohort_id)!s}>", "icare:previewEnabled"
)
delete_existing_triples(get_cohort_uri(cohort_id))
publish_graph_to_endpoint(g)

@router.post(
"/create-provision-dcr",
name="Create Data Clean Room to provision the dataset",
Expand Down

0 comments on commit f6232fd

Please sign in to comment.