From 85e4b424f89f1036802e1fa1ffb6adae25d7cc91 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Fri, 11 Oct 2024 18:36:15 +0200 Subject: [PATCH] feat(#639): add single lookup with fallback check --- scripts/README.md | 1 + scripts/analyze.py | 3 ++- ...ck_guideline.py => fallback_guidelines.py} | 24 +++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) rename scripts/analyze_functions/checks/{single_any_fallback_guideline.py => fallback_guidelines.py} (50%) diff --git a/scripts/README.md b/scripts/README.md index 8040dad1..1ab2443f 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -95,6 +95,7 @@ and optionally correct what can be corrected easily in | ----- | ----------- | ------------- | ----------------------------- | | `brand_whitespace` | Drug brand names should not have leading or trailing white space. | ✅ | ❌ | | `single_any_fallback` | If any fallback guidelines `*` are present, only one guideline should be present (otherwise other guidelines are ignored) | ❌ | ❌ | +| `fallback_single_lookup` | If fallback guidelines `*` or `~` are present, only one lookup value per gene should be present (otherwise other lookup values are ignored) | ❌ | ❌ | ### Guideline annotation checks diff --git a/scripts/analyze.py b/scripts/analyze.py index 8a94f1e7..d065f283 100644 --- a/scripts/analyze.py +++ b/scripts/analyze.py @@ -2,7 +2,7 @@ from analyze_functions.checks.brand_name_whitespace import check_brand_name_whitespace from analyze_functions.checks.metabolization_before_consequence import check_metabolization_before_consequence -from analyze_functions.checks.single_any_fallback_guideline import check_single_any_fallback_guideline +from analyze_functions.checks.fallback_guidelines import check_single_any_fallback_guideline, check_single_lookup_fallback_guideline from analyze_functions.checks.warning_levels import check_green_warning_level, \ check_none_warning_level, check_red_warning_level, \ check_yellow_warning_level @@ -20,6 +20,7 @@ DRUG_CHECKS = { 'brand_whitespace': check_brand_name_whitespace, 'single_any_fallback': check_single_any_fallback_guideline, + 'fallback_single_lookup': check_single_lookup_fallback_guideline, } DRUG_CORRECTIONS = { diff --git a/scripts/analyze_functions/checks/single_any_fallback_guideline.py b/scripts/analyze_functions/checks/fallback_guidelines.py similarity index 50% rename from scripts/analyze_functions/checks/single_any_fallback_guideline.py rename to scripts/analyze_functions/checks/fallback_guidelines.py index 4e7a8474..ace0a44b 100644 --- a/scripts/analyze_functions/checks/single_any_fallback_guideline.py +++ b/scripts/analyze_functions/checks/fallback_guidelines.py @@ -1,5 +1,21 @@ from common.get_data import get_guideline_by_id +def check_single_lookup_fallback_guideline(args): + drug = args['item'] + data = args['data'] + guidelines = list(map( + lambda guideline_id: get_guideline_by_id(data, guideline_id), + drug['guidelines'], + )) + check_applies = True + for guideline in guidelines: + for gene in guideline['lookupkey'].keys(): + for lookupValue in guideline['lookupkey'][gene]: + is_special = lookupValue == '*' or lookupValue == '~' + check_applies = check_applies and \ + (not is_special or len( guideline['lookupkey'][gene]) == 1) + return check_applies + def check_single_any_fallback_guideline(args): drug = args['item'] data = args['data'] @@ -12,12 +28,6 @@ def check_single_any_fallback_guideline(args): for gene in guideline['lookupkey'].keys(): for lookupValue in guideline['lookupkey'][gene]: is_any_fallback = lookupValue == '*' - if is_any_fallback and len(guideline['lookupkey'][gene]) != 1: - print(gene) - print(guideline['lookupkey']) - print( - '[WARNING] Multiple lookupkeys with present "any ' - 'fallback", all other than * are ignored' - ) + has_any_fallback = has_any_fallback or is_any_fallback return not has_any_fallback or len(guidelines) == 1 \ No newline at end of file