From a1697212dd6707903c4cd21fcae16938d919c4e8 Mon Sep 17 00:00:00 2001 From: TheMadBug Date: Wed, 31 Jul 2024 14:45:59 +1000 Subject: [PATCH] # Conflicts: # annotation/models/models.py # annotation/vep_annotation.py # classification/migrations/0151_one_off_tier_1_2.py # snpdb/management/commands/one_off_fix_symbolic_variants.py --- .../migrations/0151_one_off_tier_1_2.py | 2 +- .../0152_allele_origin_confirmed_ekey.py | 43 +++++++++++++++++++ .../views/classification_export_utils.py | 11 ++++- .../classification_export_formatter_csv.py | 2 +- library/log_utils.py | 22 ++++++++-- 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 classification/migrations/0152_allele_origin_confirmed_ekey.py diff --git a/classification/migrations/0151_one_off_tier_1_2.py b/classification/migrations/0151_one_off_tier_1_2.py index 5ae22391c..88056b009 100644 --- a/classification/migrations/0151_one_off_tier_1_2.py +++ b/classification/migrations/0151_one_off_tier_1_2.py @@ -15,7 +15,7 @@ def inject_tier_1_2(apps, schema_editor): "key": "tier_1_or_2", "tier": "1", "index": 5, - "label": "Tier I or II", + "label": "Tier I / II", "aliases": ["1 or 2"] } ) diff --git a/classification/migrations/0152_allele_origin_confirmed_ekey.py b/classification/migrations/0152_allele_origin_confirmed_ekey.py new file mode 100644 index 000000000..9bccbd8b2 --- /dev/null +++ b/classification/migrations/0152_allele_origin_confirmed_ekey.py @@ -0,0 +1,43 @@ +# Generated by Django 4.2.11 on 2024-07-31 01:02 + +from django.db import migrations + + +def add_evidence_key(apps, schema_editor): + data = { + "key": "allele_origin_confirmation", + "order": 12, + "evidence_category": "V", + "value_type": "S", + "description": "Paired or follow up testing to confirm allele origin of variant.", + "options": [ + { + "key": "confirmed", + "index": 1 + }, + { + "key": "unconfirmed", + "index": 2 + } + ], + "copy_consensus": False + } + EvidenceKey = apps.get_model('classification', 'EvidenceKey') + EvidenceKey.objects.get_or_create(key="allele_origin_confirmation", defaults=data) + + +def remove_evidence_key(apps, schema_editor): + EvidenceKey = apps.get_model('classification', 'EvidenceKey') + if ek := EvidenceKey.objects.filter(key="allele_origin_confirmation").first(): + ek.delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('classification', '0151_one_off_tier_1_2'), + ] + + operations = [ + migrations.RunPython(add_evidence_key, remove_evidence_key) + ] diff --git a/classification/views/classification_export_utils.py b/classification/views/classification_export_utils.py index d5a45cd48..0897b79cc 100644 --- a/classification/views/classification_export_utils.py +++ b/classification/views/classification_export_utils.py @@ -7,6 +7,7 @@ from django.db.models import Count from django.db.models.query import QuerySet +from classification.enums import CriteriaEvaluation from classification.models.classification import ClassificationModification from classification.models.evidence_key import EvidenceKeyMap, EvidenceKey from genes.hgvs import CHGVS @@ -47,7 +48,7 @@ def value_for(self, ekey: EvidenceKey, value, pretty: bool = False, cell_formatt class UsedKey: def __init__(self): - self.ekey = None + self.ekey: Optional[EvidenceKey] = None self.has_value = False self.has_note = False self.has_explain = False @@ -189,6 +190,14 @@ def row(self, classification_modification: ClassificationModification, formatter cols.append(None) else: value = value_obj.get('value') + + # prettyValue for a horak code will say Met: 2 Points + # we just want to say 2 + if used_key.ekey.crit_uses_points: + points = CriteriaEvaluation.POINTS.get(value) + if points is not None: + value = str(points) + cols.append(self.key_value_formatter.value_for(used_key.ekey, value, pretty=self.pretty, cell_formatter=self.cell_formatter)) if used_key.has_note: if not value_obj: diff --git a/classification/views/exports/classification_export_formatter_csv.py b/classification/views/exports/classification_export_formatter_csv.py index 0227d38a1..47c910bcc 100644 --- a/classification/views/exports/classification_export_formatter_csv.py +++ b/classification/views/exports/classification_export_formatter_csv.py @@ -168,7 +168,7 @@ def resolved_condition(self): return (self.vc.condition_resolution_dict or {}).get('display_text') @export_column() - def acmg_criteria(self): + def criteria(self): return self.cm.criteria_strength_summary(self.e_keys) @export_column() diff --git a/library/log_utils.py b/library/log_utils.py index fa9f60f9b..246a46b18 100644 --- a/library/log_utils.py +++ b/library/log_utils.py @@ -406,9 +406,13 @@ def slack_bot_username(): return f"{site_name} ({env_name})" +# message limit is actually 4000, but this gives us a lot of leway +SLACK_CHARACTER_LIMIT = 3500 + + def send_notification( message: str, - blocks: Optional[list] = None, + blocks: Optional[list[NotificationBuilder.Block]] = None, slack_webhook_url: Optional[str] = None): """ Sends a message to your notification service, currently Slack centric. @@ -435,8 +439,20 @@ def send_notification( "text": message, "icon_emoji": emoji } - if blocks: - data["blocks"] = blocks + character_count = 0 + data_blocks = [] + for block in blocks: + this_block = json.dumps(block) + character_count += len(this_block) + if character_count >= SLACK_CHARACTER_LIMIT: + data_blocks.append( + NotificationBuilder.MarkdownBlock("Message is too big for slack, check EventLog for the full message").as_slack() + ) + break + data_blocks.append(block) + + if data_blocks: + data["blocks"] = data_blocks r = requests.post( headers={"Content-Type": "application/json"},