Skip to content

Commit

Permalink
feat(scripts): adapt warning level checks
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Oct 10, 2024
1 parent 645c765 commit 584d269
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 deletions.
7 changes: 4 additions & 3 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ optionally correct what can be corrected easily in
| ----- | ----------- | ------------- | ----------------------------- |
| `has_consult` | Is "consult your pharmacist..." included in recommendation? |||
| `implication_severity` | "Much" keyword, should only be used if reflected by guideline implication. |||
| `red_warning` | Red warning level should always have recommendation "may not be the right medication" and vice versa. |||
| `yellow_warning` | Recommendation containing "adjusted" or "higher" or "lower" but not "may not be the right" should have yellow warning level. |||
| `green_warning` | Green warning level should have recommendation "at standard dose" but not "adjusted" and vise versa. |||
| `red_warning` | Red warning level should be present with recommendation containing "may not be the right medication". |||
| `yellow_warning` | Yellow warning level should be present when the red warning level does not apply but the implication contains "may not work" or "side effects" or the recommendation contains non-standard dose. |||
| `green_warning` | Green warning level should be applied in all non-red and non-yellow cases and when the recommendation states "at standard dose" or similar formulations. |||
| `none_warning` | None warning level should be applied in all not handled warning level cases. |||
| `brand_whitespace` | Drug brand names should not have leading or trailing white space. |||

\* Skips guidelines with multiple genes unless all results but one are missing
Expand Down
68 changes: 59 additions & 9 deletions scripts/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,27 @@
from common.write_data import write_data, write_log

CONSULT_TEXT = 'consult your pharmacist or doctor'
RED_TEXT = 'may not be the right medication'
RED_TEXT = 'not be the right medication'
NOT_RED_TEXTS = [
'if more than this dose is needed',
"if #drug-name isn't working for you",
]
ADJUST_TEXT = 'adjusted'
YELLOW_TEXTS = [ADJUST_TEXT, 'higher', 'lower']
GREEN_TEXT = 'at standard dose'
YELLOW_RECOMMENDATION_TEXTS = NOT_RED_TEXTS + [
ADJUST_TEXT,
'increased',
'decreased',
'lower dose',
'higher dose',
'up to a certain dose',
'dose increases should be done cautiously and slowly',
'further testing is recommended',
]
YELLOW_IMPLICATION_TEXTS = [
'increased risk',
'may not work',
]
GREEN_TEXTS = ['at standard dose', 'there is no reason to avoid']

def ensure_unique_item(item_filter, field_name, value):
item = list(item_filter)
Expand Down Expand Up @@ -109,22 +126,54 @@ def check_implication_severity(guideline, annotations):
)
return much_is_implied == implication_has_much

def should_be_red(annotations):
return RED_TEXT in annotations['recommendation'] and all(map(
lambda not_red_text: not_red_text not in annotations['recommendation'],
NOT_RED_TEXTS,
))

def should_be_yellow(annotations):
return any(map(
lambda yellow_text: yellow_text in annotations['recommendation'],
YELLOW_RECOMMENDATION_TEXTS,
)) or any(map(
lambda yellow_text: yellow_text in annotations['implication'],
YELLOW_IMPLICATION_TEXTS,
)) or (
# Special case: no other recommendation given
annotations['recommendation'] == \
'consult your pharmacist or doctor for more information.'
)

def should_be_green(annotations):
return any(map(
lambda green_text: green_text in annotations['recommendation'],
GREEN_TEXTS,
))

def check_red_warning_level(_, annotations):
has_warning_level = annotations['warning_level'] == 'red'
should_have_warning_level = RED_TEXT in annotations['recommendation']
should_have_warning_level = should_be_red(annotations)
return has_warning_level == should_have_warning_level

def check_yellow_warning_level(_, annotations):
has_warning_level = annotations['warning_level'] == 'yellow'
should_have_warning_level = any(map(
lambda yellow_text: yellow_text in annotations['recommendation'],
YELLOW_TEXTS)) and not RED_TEXT in annotations['recommendation']
should_have_warning_level = not should_be_red(annotations) and \
should_be_yellow(annotations)
return has_warning_level if should_have_warning_level else True

def check_green_warning_level(_, annotations):
has_warning_level = annotations['warning_level'] == 'green'
should_have_warning_level = GREEN_TEXT in annotations['recommendation'] \
and not ADJUST_TEXT in annotations['recommendation']
should_have_warning_level = not should_be_red(annotations) and \
not should_be_yellow(annotations) and \
should_be_green(annotations)
return has_warning_level == should_have_warning_level

def check_none_warning_level(_, annotations):
has_warning_level = annotations['warning_level'] == 'none'
should_have_warning_level = not should_be_red(annotations) and \
not should_be_yellow(annotations) and \
not should_be_green(annotations)
return has_warning_level == should_have_warning_level

def analyze_annotations(item, annotations, checks):
Expand Down Expand Up @@ -212,6 +261,7 @@ def handle_failed_checks(
'red_warning_level': check_red_warning_level,
'yellow_warning_level': check_yellow_warning_level,
'green_warning_level': check_green_warning_level,
'none_warning_level': check_none_warning_level,
}

GUIDELINE_CORRECTIONS = {
Expand Down

0 comments on commit 584d269

Please sign in to comment.