-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#639): add check for guideline consistency
- Loading branch information
Showing
5 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from analyze_functions.data_helpers import get_guideline_content, joint_implication_text | ||
from common.get_data import get_phenotype | ||
|
||
def _group_check_args_by_guideline(guideline_check_args_list): | ||
check_args_per_external_guideline = {} | ||
for check_args in guideline_check_args_list: | ||
guideline = check_args['item'] | ||
guideline_url = get_guideline_content(guideline, 'guidelineUrl') | ||
guideline_key = guideline_url \ | ||
.replace('https://cpicpgx.org/guidelines/', '') \ | ||
.replace('https://www.fda.gov/medical-devices/precision-medicine/', 'fda-') \ | ||
.replace('/', '') | ||
if guideline_key in check_args_per_external_guideline: | ||
check_args_per_external_guideline[guideline_key] = [ | ||
*check_args_per_external_guideline[guideline_key], | ||
check_args, | ||
] | ||
else: | ||
check_args_per_external_guideline[guideline_key] = [check_args] | ||
return check_args_per_external_guideline | ||
|
||
def _group_annotations_by_guideline_content(check_args_list): | ||
same_guideline_annotations = {} | ||
for check_args in check_args_list: | ||
drug_name = check_args['drug_name'] | ||
guideline = check_args['item'] | ||
annotations = check_args['annotations'] | ||
grouped_content = { | ||
f'Implication "{joint_implication_text(guideline)}"': annotations['implication'], | ||
f'Recommendation "{get_guideline_content(guideline, "recommendation")}"': annotations['recommendation'], | ||
} | ||
content_identifier = f'{drug_name} {get_phenotype(guideline)}' | ||
for key, content in grouped_content.items(): | ||
normalized_key = key.replace(drug_name, '#drug-name').replace('phenytoin', '#drug-name') | ||
normalized_content = content.replace(' still', '') | ||
# TODO: add drug name to structure and log | ||
if normalized_key in same_guideline_annotations: | ||
if normalized_content in same_guideline_annotations[normalized_key]: | ||
same_guideline_annotations[normalized_key][normalized_content].append(content_identifier) | ||
else: | ||
same_guideline_annotations[normalized_key][normalized_content] = [content_identifier] | ||
else: | ||
same_guideline_annotations[normalized_key] = {normalized_content: [content_identifier]} | ||
return same_guideline_annotations | ||
|
||
def check_guideline_consistencies(guideline_check_args_list): | ||
check_args_per_external_guideline = \ | ||
_group_check_args_by_guideline(guideline_check_args_list) | ||
inconsistent_guidelines_count = 0 | ||
log_content = [] | ||
for guideline_key, check_args_list in check_args_per_external_guideline.items(): | ||
if (len(check_args_list) < 2): continue | ||
same_guideline_annotations = _group_annotations_by_guideline_content( | ||
check_args_list, | ||
) | ||
inconsistency_log_content = [] | ||
for same_guideline_key, guideline_content in same_guideline_annotations.items(): | ||
unique_guideline_content = set(guideline_content.keys()) | ||
if len(unique_guideline_content) != 1: | ||
inconsistency_log_content += f' * {same_guideline_key} maps to:\n' | ||
for content in unique_guideline_content: | ||
content_identifier = guideline_content[content] | ||
inconsistency_log_content += f' * {content} ({"; ".join(content_identifier)})\n' | ||
if (len(inconsistency_log_content) > 0): | ||
inconsistent_guidelines_count += 1 | ||
log_content += f'* {guideline_key}\n' | ||
for inconsistency in inconsistency_log_content: | ||
log_content += inconsistency | ||
return inconsistent_guidelines_count, log_content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters