From 16303ffffbfcb4cc4464a359094152ee8c172200 Mon Sep 17 00:00:00 2001 From: fnguyen Date: Fri, 1 Mar 2024 10:30:16 -0500 Subject: [PATCH 1/2] Fix NREs with missing required data --- query_server/query_operations.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/query_server/query_operations.py b/query_server/query_operations.py index c132932..fce32ef 100644 --- a/query_server/query_operations.py +++ b/query_server/query_operations.py @@ -64,25 +64,27 @@ def get_summary_stats(donors, headers): # A donor's date of birth is defined as the (negative) interval between actual DOB and the date of first diagnosis # So we just use that info donors_by_id[donor["submitter_donor_id"]] = donor - age = abs(donor['date_of_birth']['month_interval']) // 12 - age = age // 10 * 10 - if age < 20: - add_or_increment(age_at_diagnosis, '0-19 Years') - elif age > 79: - add_or_increment(age_at_diagnosis, '80+ Years') - else: - add_or_increment(age_at_diagnosis, f'{age}-{age+9} Years') + if donor['date_of_birth'] and donor['date_of_birth']['month_interval']: + age = abs(donor['date_of_birth']['month_interval']) // 12 + age = age // 10 * 10 + if age < 20: + add_or_increment(age_at_diagnosis, '0-19 Years') + elif age > 79: + add_or_increment(age_at_diagnosis, '80+ Years') + else: + add_or_increment(age_at_diagnosis, f'{age}-{age+9} Years') # Cancer types - for cancer_type in donor['primary_site']: - if cancer_type in cancer_type_count: - cancer_type_count[cancer_type] += 1 - else: - cancer_type_count[cancer_type] = 1 + if donor['primary_site']: + for cancer_type in donor['primary_site']: + if cancer_type in cancer_type_count: + cancer_type_count[cancer_type] += 1 + else: + cancer_type_count[cancer_type] = 1 program_id = donor['program_id'] if program_id in patients_per_cohort: patients_per_cohort[program_id] += 1 - else: + elif program_id is not None: patients_per_cohort[program_id] = 1 # Treatment types From 78f56c2cba30a1486268897cba4c959152d52099 Mon Sep 17 00:00:00 2001 From: fnguyen Date: Fri, 1 Mar 2024 10:30:38 -0500 Subject: [PATCH 2/2] Use the Query token when talking to Katsu/HTSGet --- query_server/query_operations.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/query_server/query_operations.py b/query_server/query_operations.py index fce32ef..91ab6c3 100644 --- a/query_server/query_operations.py +++ b/query_server/query_operations.py @@ -287,6 +287,12 @@ def query(treatment="", primary_site="", chemotherapy="", immunotherapy="", horm @app.route('/genomic_completeness') def genomic_completeness(): + # Add a service token to the headers so that Katsu will know this is from the query service: + headers = {} + for k in request.headers.keys(): + headers[k] = request.headers[k] + headers["X-Service-Token"] = config.SERVICE_TOKEN + params = { 'page_size': PAGE_SIZE } url = f"{config.KATSU_URL}/v2/authorized/sample_registrations/" r = safe_get_request_json(requests.get(f"{url}?{urllib.parse.urlencode(params)}", @@ -304,7 +310,7 @@ def genomic_completeness(): # Check with HTSGet to see whether or not this sample is complete r = requests.get(f"{config.HTSGET_URL}/htsget/v1/samples/{sample_id}", # Reuse their bearer token - headers=request.headers) + headers=headers) if r.ok: r_json = r.json() retVal[program_id]