From e4f553c3a4985ca4ff1ff3f870b8ffe93bde3ee4 Mon Sep 17 00:00:00 2001 From: bharath Date: Tue, 26 Sep 2023 09:30:24 +1000 Subject: [PATCH 1/2] #3090 removed hyperlinks and displaying cooccurring/uncertain in MVL export. --- classification/models/classification_groups.py | 10 ++++++++-- .../classification/classification_groups_mvl.html | 10 ++++++++-- .../classification/tags/classification_group_row.html | 3 +++ .../templates/classification/tags/condition.html | 7 +++++-- classification/templatetags/classification_tags.py | 4 ++-- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/classification/models/classification_groups.py b/classification/models/classification_groups.py index fa1bca009..3486270e3 100644 --- a/classification/models/classification_groups.py +++ b/classification/models/classification_groups.py @@ -371,19 +371,25 @@ def __lt__(self, other): def conditions(self) -> List[ConditionResolved]: all_terms = set() all_plain_texts = set() + all_joins = set() for cm in self.modifications: c = cm.classification if resolved := c.condition_resolution_obj: for term in resolved.terms: all_terms.add(term) + all_joins.add(resolved.join) else: if text := cm.get(SpecialEKeys.CONDITION): all_plain_texts.add(text) all_condition_resolved = [] + shared_join = None + if len(all_joins) == 1: # if there's more than one join, we can't display it + shared_join = all_joins.pop() + for term in all_terms: - all_condition_resolved.append(ConditionResolved(terms=[term], join=None)) + all_condition_resolved.append(ConditionResolved(terms=[term], join=shared_join)) for plain_text in all_plain_texts: - all_condition_resolved.append(ConditionResolved(terms=[], join=None, plain_text=plain_text)) + all_condition_resolved.append(ConditionResolved(terms=[], join=shared_join, plain_text=plain_text)) all_condition_resolved.sort() return all_condition_resolved diff --git a/classification/templates/classification/classification_groups_mvl.html b/classification/templates/classification/classification_groups_mvl.html index 6232b1df4..c8ba7257e 100644 --- a/classification/templates/classification/classification_groups_mvl.html +++ b/classification/templates/classification/classification_groups_mvl.html @@ -1,5 +1,6 @@ {% load classification_tags %}
+{% spaceless %} @@ -22,11 +23,16 @@ {{ group.clinical_significance | ekey:'clinical_significance' }}
{{ group.clinical_significance_pending | ekey:'clinical_significance' }} (PENDING) {% else %}{{ group.clinical_significance | ekey:'clinical_significance' }}{% endif %} - + {% endfor %} -
{% for condition in group.conditions %}
{% condition condition_obj=condition limit=None %}
{% empty %}-{% endfor %}
{% for condition in group.conditions %}
{% condition condition_obj=condition limit=None no_links=True %}
{% empty %}-{% endfor %} + {% if group.conditions|length > 0 and group.conditions.0.join_text %} + {{ group.conditions.0.join_text }} + {% endif %} +
{{ group.zygosities | ekey:'zygosity' }} {% for acmg in group.acmg_criteria %}{% if not forloop.first %}, {% endif %}{{ acmg }}{% empty %}-{% endfor %}
{% with curated_date=group.most_recent_curated %}{% if curated_date.name %}{{ curated_date.name }} {% endif %}{{ curated_date.date | date:'Y-m-d' }}{% endwith %}
\ No newline at end of file + +{% endspaceless %} \ No newline at end of file diff --git a/classification/templates/classification/tags/classification_group_row.html b/classification/templates/classification/tags/classification_group_row.html index a23a438dc..145cc1abf 100644 --- a/classification/templates/classification/tags/classification_group_row.html +++ b/classification/templates/classification/tags/classification_group_row.html @@ -60,6 +60,9 @@ {% empty %}
-
{% endfor %} + {% if group.conditions|length > 0 and group.conditions.0.join_text %} + {{ group.conditions.0.join_text }} + {% endif %} {% if show_allele_origin %} diff --git a/classification/templates/classification/tags/condition.html b/classification/templates/classification/tags/condition.html index 4fbbb70fa..1927fc99c 100644 --- a/classification/templates/classification/tags/condition.html +++ b/classification/templates/classification/tags/condition.html @@ -2,7 +2,10 @@ {% if condition.terms %} {% for term in condition.terms %} {% if not forloop.first %}
{% endif %} - {{ term.id }} {{ term.name }} + {% if no_links %} + {{ term.id }} {{ term.name }} + {% else %} + {{ term.id }} {{ term.name }} + {% endif %} {% endfor %} - {% if condition.join_text %} {{ condition.join_text }}{% endif %} {% else %}{{ condition.plain_text | limit_length:limit }}{% endif %} \ No newline at end of file diff --git a/classification/templatetags/classification_tags.py b/classification/templatetags/classification_tags.py index 5b98ab5ba..d4a75fcbd 100644 --- a/classification/templatetags/classification_tags.py +++ b/classification/templatetags/classification_tags.py @@ -473,8 +473,8 @@ def db_ref(data: VCDbRefDict, css: Optional[str] = ''): @register.inclusion_tag("classification/tags/condition.html") -def condition(condition_obj: ConditionResolved, limit: Optional[int] = 100): - return {"condition": condition_obj, "limit": limit} +def condition(condition_obj: ConditionResolved, limit: Optional[int] = 100, no_links: Optional[bool] = None): + return {"condition": condition_obj, "limit": limit, "no_links": no_links} # look at removing this From 654b518185cf0fa159eb77c9d92bc8e7ace42d18 Mon Sep 17 00:00:00 2001 From: bharath Date: Tue, 26 Sep 2023 16:54:37 +1000 Subject: [PATCH 2/2] #3090 removed hyperlinks and displaying cooccurring/uncertain in MVL export. --- classification/models/classification.py | 9 +++++++ .../models/classification_groups.py | 26 ++++++++----------- .../classification_groups_mvl.html | 10 ++++--- .../tags/classification_group_row.html | 11 +++----- .../classification/tags/condition.html | 7 ++--- .../templatetags/classification_tags.py | 4 +-- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/classification/models/classification.py b/classification/models/classification.py index 39837b85c..8ffcdfba7 100644 --- a/classification/models/classification.py +++ b/classification/models/classification.py @@ -229,6 +229,15 @@ class ConditionResolved: join: Optional['MultiCondition'] = None plain_text: Optional[str] = field(default=None) # fallback, not populated in all contexts + def __hash__(self): + hash_total = 0 + if terms := self.terms: + for t in terms: + hash_total += hash(t) + hash_total += hash(self.join,) + hash_total += hash(self.plain_text) + return hash_total + @property def summary(self) -> str: text = ", ".join([term.id for term in self.terms]) diff --git a/classification/models/classification_groups.py b/classification/models/classification_groups.py index 3486270e3..2b038fab1 100644 --- a/classification/models/classification_groups.py +++ b/classification/models/classification_groups.py @@ -4,6 +4,7 @@ from typing import Optional, List, Iterable, TypeVar, Generic, Set, Dict from django.contrib.auth.models import User +from more_itertools import first from classification.criteria_strengths import CriteriaStrength from classification.enums import SpecialEKeys, CriteriaEvaluation, ShareLevel @@ -368,31 +369,26 @@ def __lt__(self, other): return my_curated < other_curated return self.most_recent.classification.created < other.most_recent.classification.created - def conditions(self) -> List[ConditionResolved]: + def conditions(self) -> ConditionResolved: all_terms = set() all_plain_texts = set() - all_joins = set() + all_condition_resolutions = set() + for cm in self.modifications: c = cm.classification if resolved := c.condition_resolution_obj: + all_condition_resolutions.add(resolved) for term in resolved.terms: all_terms.add(term) - all_joins.add(resolved.join) else: if text := cm.get(SpecialEKeys.CONDITION): all_plain_texts.add(text) - all_condition_resolved = [] - shared_join = None - if len(all_joins) == 1: # if there's more than one join, we can't display it - shared_join = all_joins.pop() - - for term in all_terms: - all_condition_resolved.append(ConditionResolved(terms=[term], join=shared_join)) - for plain_text in all_plain_texts: - all_condition_resolved.append(ConditionResolved(terms=[], join=shared_join, plain_text=plain_text)) - - all_condition_resolved.sort() - return all_condition_resolved + + if len(all_condition_resolutions) == 1: + return first(all_condition_resolutions) + + plain_text_combined = ", ".join(all_plain_texts) if all_plain_texts else None + return ConditionResolved(terms=list(all_terms), join=None, plain_text=plain_text_combined) # def sub_groups(self) -> Optional[List['ClassificationGroup']]: # if len(self.modifications) > 1: diff --git a/classification/templates/classification/classification_groups_mvl.html b/classification/templates/classification/classification_groups_mvl.html index c8ba7257e..6e77f87df 100644 --- a/classification/templates/classification/classification_groups_mvl.html +++ b/classification/templates/classification/classification_groups_mvl.html @@ -23,10 +23,12 @@ {{ group.clinical_significance | ekey:'clinical_significance' }}
{{ group.clinical_significance_pending | ekey:'clinical_significance' }} (PENDING) {% else %}{{ group.clinical_significance | ekey:'clinical_significance' }}{% endif %} - {% for condition in group.conditions %}
{% condition condition_obj=condition limit=None no_links=True %}
{% empty %}-{% endfor %} - {% if group.conditions|length > 0 and group.conditions.0.join_text %} - {{ group.conditions.0.join_text }} - {% endif %} + + {% if group.conditions %} +
{% condition condition_obj=group.conditions limit=None show_link=False %}
+ {% else %} +
-
+ {% endif %} {{ group.zygosities | ekey:'zygosity' }} {% for acmg in group.acmg_criteria %}{% if not forloop.first %}, {% endif %}{{ acmg }}{% empty %}-{% endfor %} diff --git a/classification/templates/classification/tags/classification_group_row.html b/classification/templates/classification/tags/classification_group_row.html index 145cc1abf..cb746cdb5 100644 --- a/classification/templates/classification/tags/classification_group_row.html +++ b/classification/templates/classification/tags/classification_group_row.html @@ -55,14 +55,11 @@ {% endif %} - {% for condition in group.conditions %} -
{% condition condition %}
- {% empty %} + {% if group.conditions %} +
{% condition group.conditions %}
+ {% else %}
-
- {% endfor %} - {% if group.conditions|length > 0 and group.conditions.0.join_text %} - {{ group.conditions.0.join_text }} - {% endif %} + {% endif %} {% if show_allele_origin %} diff --git a/classification/templates/classification/tags/condition.html b/classification/templates/classification/tags/condition.html index 1927fc99c..f5f78d9f7 100644 --- a/classification/templates/classification/tags/condition.html +++ b/classification/templates/classification/tags/condition.html @@ -2,10 +2,11 @@ {% if condition.terms %} {% for term in condition.terms %} {% if not forloop.first %}
{% endif %} - {% if no_links %} - {{ term.id }} {{ term.name }} - {% else %} + {% if show_link %} {{ term.id }} {{ term.name }} + {% else %} + {{ term.id }} {{ term.name }} {% endif %} {% endfor %} + {% if condition.join_text %} {{ condition.join_text }}{% endif %} {% else %}{{ condition.plain_text | limit_length:limit }}{% endif %} \ No newline at end of file diff --git a/classification/templatetags/classification_tags.py b/classification/templatetags/classification_tags.py index d4a75fcbd..118be2ae1 100644 --- a/classification/templatetags/classification_tags.py +++ b/classification/templatetags/classification_tags.py @@ -473,8 +473,8 @@ def db_ref(data: VCDbRefDict, css: Optional[str] = ''): @register.inclusion_tag("classification/tags/condition.html") -def condition(condition_obj: ConditionResolved, limit: Optional[int] = 100, no_links: Optional[bool] = None): - return {"condition": condition_obj, "limit": limit, "no_links": no_links} +def condition(condition_obj: ConditionResolved, limit: Optional[int] = 100, show_link: Optional[bool] = True): + return {"condition": condition_obj, "limit": limit, "show_link": show_link} # look at removing this