Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3429 replace classification visual ID #883

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion classification/models/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,15 @@ def _evidence(self):
def id_str(self):
return str(self.id)

@property
def cr_lab_id(self):
if settings.VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX:
return f"CR_{self.id}"
return self.lab_record_id

@property
def friendly_label(self):
return self.lab.name + ' / ' + self.lab_record_id
return self.lab.name + ' / ' + self.cr_lab_id

@staticmethod
def to_date(date_str: str) -> Optional[datetime]:
Expand Down Expand Up @@ -1816,6 +1822,7 @@ def as_json(self, params: ClassificationJsonParams) -> dict:
'lab_record_id': self.lab_record_id,
'institution_name': self.lab.organization.name,
'lab_id': self.lab.group_name,
'cr_lab_id': self.cr_lab_id,
'org_name': self.lab.organization.shortest_name,
'lab_name': self.lab.name,
'title': title,
Expand Down Expand Up @@ -2276,6 +2283,12 @@ def _evidence(self):
def id_str(self) -> str:
return self.classification.id_str + '.' + str(self.created.timestamp())

@property
def cr_lab_id(self) -> str:
if settings.VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX:
return f"CR_{self.classification.id_str}"
return self.classification.lab_record_id

@property
def curated_date(self) -> datetime:
return CuratedDate(self).date
Expand Down
18 changes: 13 additions & 5 deletions classification/signals/classification_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from functools import reduce
from typing import Optional, List

from django.conf import settings
from django.contrib.auth.models import User
from django.db.models import Q
from django.dispatch import receiver
Expand All @@ -18,16 +19,19 @@
search_type=Classification,
example=SearchExample(
note="The lab record ID",
examples=["vc1545"]
examples=["CR_1545" if settings.VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX else "vc1545"]
)
)
def classification_search(search_input: SearchInputInstance):

search_string = search_input.search_string
""" Search for LabId which can be either:
"vc1080" or "Molecular Genetics, Frome Road / vc1080" (as it appears in classification) """

filters = [Q(classification__lab_record_id__iexact=search_string)] # exact match
"vc1080" or "Molecular Genetics/ Frome Road / vc1080" (as it appears in classification) or CR_1080 or Molecular Genetics/ Frome Road / CR_1080 """
if search_string.startswith("CR_"):
search_string = search_string[3:]
filters = [Q(classification__id=search_string)]
else:
filters = [Q(classification__lab_record_id__iexact=search_string)] # exact match
slash_index = search_string.find("/")
if slash_index > 0:
parts = [p.strip() for p in search_string.split("/")]
Expand All @@ -50,7 +54,11 @@ def classification_search(search_input: SearchInputInstance):
lab_qs = lab_qs.filter(organization=org)

if lab_qs:
filters.append(Q(classification__lab_record_id=lab_record_id) & Q(classification__lab__in=lab_qs))
if lab_record_id.startswith("CR_"):
lab_record_id = lab_record_id[3:]
filters.append(Q(classification__id=lab_record_id) & Q(classification__lab__in=lab_qs))
else:
filters.append(Q(classification__lab_record_id=lab_record_id) & Q(classification__lab__in=lab_qs))

q_cm = reduce(operator.or_, filters)
cm_qs = ClassificationModification.filter_for_user(search_input.user).filter(is_last_published=True)
Expand Down
3 changes: 2 additions & 1 deletion classification/templates/classification/classification.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
vcform.init(
{
userAdmin: {{ user.is_superuser | jsonify }},
lab_record_id: "{{ record.lab_record_id }}",
genomeBuild: "{{ genome_build.pk }}",
// citations: new Citations($('#citations')),
citations: $('#citations'),
Expand Down Expand Up @@ -124,7 +125,7 @@ <h5 class="mt-4">Literature Citations</h5>
</div>
<div id="vc-extras">
<div id="vcform-summary" class="card m-2">
<div class="card-header">{{ record.org_name }} / {{ record.lab_name }} / {{ record.lab_record_id }}</div>
<div class="card-header">{{ record.org_name }} / {{ record.lab_name }} / {{ record.cr_lab_id }}</div>
<div class="card-body"></div>
</div>
<div id="vcform-flags" class="card m-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<div>
{% for record in group.modifications %}
<div class="mt-2 d-flex" style="align-items:center;position:relative;top:5px">
<a class="hover-link" style="font-weight:bold" href="{% url 'view_classification' record.classification_id %}">{{ record.classification.lab_record_id }}</a>
<a class="hover-link" style="font-weight:bold" href="{% url 'view_classification' record.classification_id %}">{{ record.classification.cr_lab_id}}</a>
{{ record.classification.allele_info.issue_icon|default_if_none:'' }}
<div class="flags d-inline-block" style="margin-left:12px" data-flags="{{ record.classification.flag_collection_id }}">...</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load static %}
{% if vcm and vcm.classification.id %}
{% if mode == "compact" %}
<a class="hover-link" href="{% url 'view_classification' vcm.classification.id %}">{{ vcm.classification.lab }} / {{ vcm.classification.lab_record_id }}</a>
<a class="hover-link" href="{% url 'view_classification' vcm.classification.id %}">{{ vcm.classification.lab }} / {{ vcm.cr_lab_id }}</a>
{% else %}
<span class="share-level-{{ vcm.share_level_enum.name }} sig-level-{{ vcm.evidence.clinical_significance.value}}">
{% if show_clinical_grouping %}{% if vcm.classification.clinical_grouping_name != 'default' %}<span class="font-weight-bold text-uppercase text-secondary mr-1">{{ vcm.classification.clinical_grouping_name }} </span>{% endif %}{% endif %}
Expand All @@ -11,9 +11,9 @@
&nbsp;
<img src="{% static vcm.share_level_enum.icon %}" width="12px" height="12px" style="margin-right:4px;" />
{% if vcm.vc.withdrawn %}
<span style="text-decoration: line-through">{{vcm.classification.lab.name}} / {{vcm.classification.lab_record_id }}</span>
<span style="text-decoration: line-through">{{vcm.classification.lab.name}} / {{vcm.cr_lab_id }}</span>
{% else %}
{{vcm.classification.lab.name}} / {{vcm.classification.lab_record_id }}
{{vcm.classification.lab.name}} / {{vcm.cr_lab_id }}
{% endif %}
</a>
{% endif %}
Expand Down
6 changes: 5 additions & 1 deletion classification/views/classification_datatables.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ def classification_id(self, row: Dict[str, Any]) -> JsonDataType:
value = str(value)
if id_filter.lower() in value.lower():
matches[key] = value
if settings.VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX:
cr_lab_id = f"CR_{row.get('classification__id')}"
else:
cr_lab_id = row.get('classification__lab_record_id')

return {
"id": row.get('classification__id'),
# should we start using short names?
"org_name": row.get('classification__lab__organization__short_name') or row.get('classification__lab__organization__name'),
"lab_name": row.get('classification__lab__name'),
"lab_record_id": row.get('classification__lab_record_id'),
"lab_record_id": cr_lab_id,
"share_level": row.get('classification__share_level'),
"matches": matches,
"search": id_filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from functools import cached_property
from typing import List, Optional, Dict, Set, Any

from django.conf import settings
from django.http import HttpRequest

from classification.models import Classification, ClassificationModification, EvidenceKeyMap
Expand Down Expand Up @@ -85,6 +85,8 @@ def genome_build(self) -> GenomeBuild:

@export_column(categories={"transient": True})
def id(self):
if settings.VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX:
return self.vc.cr_lab_id
return self.vc.id

@export_column()
Expand Down
2 changes: 1 addition & 1 deletion classification/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def classification_history(request, classification_id: Any):
'changes': changes,
'can_create_classifications': Classification.can_create_via_web_form(request.user),
'now': now(),
'page_title': f'Classification Activity ({classification.lab_record_id})',
'page_title': f'Classification Activity ({classification.cr_lab_id})',
'import_details': classification
}
return render(request, 'classification/activity.html', context)
Expand Down
3 changes: 3 additions & 0 deletions variantgrid/settings/components/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@

PREFER_ALLELE_LINKS = False

# if True, CR_lab_id will be used in all instances
VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX = False

CLINGEN_ALLELE_REGISTRY_DOMAIN = "http://reg.genome.network"
CLINGEN_ALLELE_REGISTRY_MAX_RECORDS = 2000
CLINGEN_ALLELE_REGISTRY_LOGIN = get_secret("CLINGEN_ALLELE_REGISTRY.login")
Expand Down
3 changes: 3 additions & 0 deletions variantgrid/settings/env/shariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,6 @@
VIEW_GENE_HOTSPOT_GRAPH = False

GENE_RELATION_PANEL_APP_LIVE_UPDATE = True

# if False lab record ID will be used for records instead of CR_lab_id
VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX = True
11 changes: 9 additions & 2 deletions variantgrid/static_files/default_static/js/vc_diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const Diff = (function() {
}

let ltd = $('<td>').appendTo(tr);
let label = $('<label>', {for: `ch-${uniqueId}`, text: `${v.lab_name} / ${v.lab_record_id}`}).appendTo(ltd);
let label = $('<label>', {for: `ch-${uniqueId}`, text: `${v.org_name} / ${v.lab_name} / ${v.cr_lab_id}`}).appendTo(ltd);
});
modalContent.on('');
modalContent.modal({
Expand Down Expand Up @@ -279,7 +279,7 @@ const Diff = (function() {

let titleDom = $('<a>', {class:'hover-link text-center d-flex flex-column flex-align-center', href: url});

let titlePart = $('<div>', {text: v.lab_name + ' / ' + v.lab_record_id}).appendTo(titleDom);
let titlePart = $('<div>', {text: v.org_name + ' / ' + v.lab_name + ' / ' + v.cr_lab_id}).appendTo(titleDom);
if (v.first_seen) {
let first_seen_date = moment(v.first_seen * 1000).format('DD/MMM/YYYY HH:mm');
let last_seen_date = moment(v.version * 1000).format('DD/MMM/YYYY HH:mm');
Expand Down Expand Up @@ -334,6 +334,13 @@ const Diff = (function() {
// conditionRow
]}).appendTo(headerRow);
});

let rowLabRecordId = $('<tr>', {class: 'group no-compare'}).appendTo(table);
$('<th>', {text: "Lab Id", style: 'font-weight:normal'}).appendTo(rowLabRecordId);
includedVersions.forEach(v => {
$('<td>', {text: v.lab_record_id}).appendTo(rowLabRecordId);
});

let all_db_refs = {};

// loop through groups of keys
Expand Down
4 changes: 4 additions & 0 deletions variantgrid/static_files/default_static/js/vc_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ const VCForm = (function() {

jSyncStatus.empty();

if (this.lab_record_id) {
appendLabelHeading('Lab ID', $('<span>', {text: this.lab_record_id}));
}
appendLabelHeadingForKey(SpecialEKeys.GENOME_BUILD, true, 'Build');

if (this.record.allele && this.record.allele.resolved) {
Expand Down Expand Up @@ -1130,6 +1133,7 @@ const VCForm = (function() {
jLinks = $(params.links);
jShareButtons = $(params.shareButtons);
this.userAdmin = params.userAdmin;
this.lab_record_id = params.lab_record_id;
this.citations = params.citations;
this.attachmentsEnabled = params.attachmentsEnabled || false;

Expand Down
Loading