Skip to content

Commit

Permalink
Merge pull request #535 from bento-platform/chore/remove-opa
Browse files Browse the repository at this point in the history
chore!: clear out old CanDIG code
  • Loading branch information
davidlougheed authored Sep 10, 2024
2 parents 5847192 + c7a61a6 commit 7e9eaf3
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 457 deletions.
45 changes: 0 additions & 45 deletions Dockerfile

This file was deleted.

16 changes: 0 additions & 16 deletions chord_metadata_service/metadata/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import sys
import logging
import json
from os.path import exists

from bento_lib.service_info.types import GA4GHServiceType
from urllib.parse import quote, urlparse
Expand Down Expand Up @@ -129,16 +128,6 @@
NGINX_INTERNAL_SOCKET = quote(os.environ.get("NGINX_INTERNAL_SOCKET", "/chord/tmp/nginx_internal.sock"), safe="")
DRS_URL = os.environ.get("DRS_URL", f"http+unix://{NGINX_INTERNAL_SOCKET}/api/drs").strip().rstrip("/")

# Candig-specific settings

CANDIG_AUTHORIZATION = os.getenv("CANDIG_AUTHORIZATION", "")
CANDIG_OPA_URL = os.getenv("CANDIG_OPA_URL", "")
CANDIG_OPA_SECRET = os.getenv("CANDIG_OPA_SECRET", "my-secret-beacon-token")
CANDIG_OPA_SITE_ADMIN_KEY = os.getenv("CANDIG_OPA_SITE_ADMIN_KEY", "site-admin")
if exists("/run/secrets/opa-root-token"):
with open("/run/secrets/opa-root-token", "r") as f:
CANDIG_OPA_SECRET = f.read()

# Application definition

INSTALLED_APPS = (['daphne'] if os.environ.get('BENTO_CONTAINER_LOCAL') else []) + [
Expand Down Expand Up @@ -180,11 +169,6 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

# This middlewares are specific to the CANDIG service
if os.getenv('INSIDE_CANDIG', ''):
MIDDLEWARE.append('chord_metadata_service.restapi.preflight_req_middleware.PreflightRequestMiddleware')
MIDDLEWARE.append('chord_metadata_service.restapi.candig_authz_middleware.CandigAuthzMiddleware')

CORS_ALLOWED_ORIGINS = [orig.strip() for orig in os.environ.get("CORS_ORIGINS", "").split(";") if orig.strip()]
CORS_ALLOW_CREDENTIALS = True

Expand Down
3 changes: 0 additions & 3 deletions chord_metadata_service/metadata/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from .settings import * # noqa: F403, F401

# This allowed to run the tests without keycloak running and we cannot get the token from keycloak
# If we figure out to do the integration tests, we can remove this
CANDIG_AUTHORIZATION = ''
# Tests are run locally with the Django dev server. Adding a sub-path which
# is managed by the gateway in production, creates wrong references and breaks
# almost every test. This resets the setting for when an environment variable
Expand Down
127 changes: 0 additions & 127 deletions chord_metadata_service/restapi/argo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,130 +30,3 @@ def argo_donor(obj):
if i in obj["extra_properties"]:
donor[i] = obj["extra_properties"][i]
return donor


def argo_specimen(obj):
"""
Convert Genetic Specimen to ARGO Specimen.
Takes Katsu genetic specimen object and converts its fields to ARGO according to the mapping.
"""
specimen = {
"submitter_specimen_id": obj["id"],
"specimen_type": obj["specimen_type"]
}
for argo_field, mcode_field in zip(
("specimen_tissue_source", "specimen_laterality"),
("collection_body", "laterality")
):
if mcode_field in obj:
specimen[argo_field] = obj[mcode_field]
return specimen


def argo_primary_diagnosis(obj):
"""
Convert Cancer Condition to ARGO Primary Diagnosis.
Takes Katsu cancer condition object and converts its fields to ARGO according to the mapping.
"""
primary_diagnosis = {
"submitter_primary_diagnosis_id": obj["id"],
"cancer_type_code": obj["code"]
}
if "tnm_staging" in obj and obj["tnm_staging"]:
primary_diagnosis["specimen"] = {}
for item in obj["tnm_staging"]:
# tnm_staging clinical is mapped to PrimaryDiagnosis fields
if item["tnm_type"] == "clinical":
for mcode_field, argo_field in zip(
["stage_group", "primary_tumor_category",
"regional_nodes_category", "distant_metastases_category"],
["clinical_stage_group", "clinical_t_category",
"clinical_n_category", "clinical_m_category"]
):
if mcode_field in item and item[mcode_field]:
if argo_field in primary_diagnosis and primary_diagnosis[argo_field]:
primary_diagnosis[argo_field].append(item[mcode_field]["data_value"])
else:
primary_diagnosis[argo_field] = [item[mcode_field]["data_value"]]

# tnm_staging pathologic is mapped to Specimen fields
else:
# need to instanciate a local specimen object here
for mcode_field, argo_field in zip(
["stage_group", "primary_tumor_category",
"regional_nodes_category", "distant_metastases_category"],
["pathological_stage_group", "pathological_t_category",
"pathological_n_category", "pathological_m_category"]
):
if mcode_field in item and item[mcode_field]:
if argo_field in primary_diagnosis["specimen"] and primary_diagnosis["specimen"][argo_field]:
primary_diagnosis["specimen"][argo_field].append(item[mcode_field]["data_value"])
else:
primary_diagnosis["specimen"][argo_field] = [item[mcode_field]["data_value"]]
# if no pathologic tnm staging delete specimen
if not primary_diagnosis["specimen"]:
del primary_diagnosis["specimen"]

# check for not mapped fields in extra_properties
if "extra_properties" in obj and obj["extra_properties"]:
for i in ["age_at_diagnosis", "lymph_nodes_examined_status",
"number_lymph_nodes_positive", "clinical_tumour_staging_system"]:
if i in obj["extra_properties"]:
primary_diagnosis[i] = obj["extra_properties"][i]

return primary_diagnosis


# a dict to map mCODE procedure type to ARGO treatment types
PROCEDUR_TYPE_TO_TREATMENT_TYPE = {
"radiation": "Radiation therapy",
"surgical": "Surgery"
}


def argo_treatment(obj):
"""
Convert Cancer Related Procedure to ARGO Treatment.
Takes Katsu cancer related procedure object and converts its fields to ARGO according to the mapping.
"""
treatment = {
"submitter_treatment_id": obj["id"],
"treatment_type": PROCEDUR_TYPE_TO_TREATMENT_TYPE[obj["procedure_type"]]
}
if "treatment_intent" in obj and obj["treatment_intent"]:
treatment["treatment_intent"] = obj["treatment_intent"]
# only radiation treatment fields
if obj["procedure_type"] == "radiation":
for mcode_field, argo_field in zip(
["code", "body_site"],
["radiation_therapy_modality", "anatomical_site_irradiated"]
):
if mcode_field in obj and obj[mcode_field]:
treatment[argo_field] = obj[mcode_field]
return treatment


def argo_therapy(obj):
"""
Convert Medication statement to ARGO Immunotherapy, Chemotherapy, Hormone Therapy.
Takes Katsu medication statement object and converts its fields to ARGO according to the mapping.
"""
therapy = {
"submitter_treatment_id": obj["id"],
"drug_rxnormcui": obj["medication_code"]
}
return therapy


def argo_composition_object(obj):
"""
Returns all Mcodepacket related objects converted to their ARGO element according to the mapping.
"""
composition_object = {
"donor": argo_donor(obj["subject"]),
"primary_diagnoses": [argo_primary_diagnosis(obj["cancer_condition"])],
"treatments": [argo_treatment(crp) for crp in obj["cancer_related_procedures"]],
# the name doesn't look nice but there is no therapy type field in mcode
"immunotherapies_chemotherapies_hormone_therapies": [argo_therapy(ms) for ms in obj["medication_statement"]]
}
return composition_object
143 changes: 0 additions & 143 deletions chord_metadata_service/restapi/candig_authz_middleware.py

This file was deleted.

Loading

0 comments on commit 7e9eaf3

Please sign in to comment.