Skip to content

Commit

Permalink
Merge pull request #95 from NHS-NGS/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
efgstone authored Oct 25, 2018
2 parents c7726b1 + f6bb190 commit 1836f4c
Show file tree
Hide file tree
Showing 20 changed files with 482 additions and 36 deletions.
51 changes: 50 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
## [0.4.5]- 2018-08-2X
## [0.5.5]- 2018-10-XX
### Added
- Case alert feature
- Case code flag

### Changed
- Made cancer tweaks to proband page
- Proband page now shows related GELIRs

## [0.5.4]- 2018-10-03
### Added
- Cancer germline selection

### Changes
- Improved MDT selection page

## [0.5.3]- 2018-09-14
### Added
- Added binning to case updates

### Changed
- UI improvements
- Nicer display during update process
- Patched security flaws

## [0.5.2]- 2018-09-03
### Added
- Report history feature

### Changed
- Fixed cancer MDT page bug

## [0.5.1]- 2018-07-26
### Changed
- Updated reporting templates

## [0.5.0]- 2018-07-11
### Added
- PVFlag feature to describe variant flags

### Changed
- Labkey speed up
- Removed T0 feature
- speed improvements to updates

## [0.4.6]- 2018-06-18
### Changed
- Fixed minor bug where export buttons removed pagination

## [0.4.5]- 2018-06-18
### Added
- History tab to cases which shows history of changes to cases, ordered by oldest to newest

Expand Down
3 changes: 2 additions & 1 deletion gelweb/gel2mdt/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,6 @@ class Meta:
'recruiting_disease',
'sex',
'nhs_num',
'disease_subtype'
'disease_subtype',
'case_code'
)
15 changes: 12 additions & 3 deletions gelweb/gel2mdt/database_utils/case_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,19 @@ def get_tools_and_versions(self):
:return: A dictionary of tools and versions used for the case
'''
if self.json['sample_type'] == 'raredisease':
tools_dict = {'genome_build': self.json_request_data["genomeAssemblyVersion"]}
if self.json_request_data['genomeAssemblyVersion'].startswith('GRCh37'):
genome_build = 'GRCh37'
elif self.json_request_data['genomeAssemblyVersion'].startswith('GRCh38'):
genome_build = 'GRCh38'
elif self.json['sample_type'] == 'cancer':
tools_dict = {'genome_build': self.json["assembly"]}
return tools_dict
if self.json["assembly"].startswith('GRCh37'):
genome_build = 'GRCh37'
elif self.json["assembly"].startswith('GRCh38'):
genome_build = 'GRCh38'
else:
raise Exception(f'{self.request_id} has unknown genome build')

return {'genome_build': genome_build}

def get_status_json(self):
"""
Expand Down
33 changes: 18 additions & 15 deletions gelweb/gel2mdt/database_utils/multiple_case_adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ def __init__(self, sample_type, head=None, test_data=False,
set(self.cases_to_update)
self.update_database()

print("Finished processing bin", bin_count, "of", len(bins))

for case in self.cases_to_add:
del case
for case in self.cases_to_update:
Expand Down Expand Up @@ -217,6 +215,8 @@ def update_database(self):
listupdate.reports_added.add(*added_cases)
listupdate.reports_updated.add(*updated_cases)

# Add in case alert

def fetch_test_data(self):
"""
This will run and convert our test data to a list of jsons if
Expand All @@ -234,13 +234,14 @@ def fetch_test_data(self):
logger.info("Found case json at " + file_path + " for testing.")
with open(file_path) as json_file:
json_data = json.load(json_file)
list_of_cases.append(Case(
case_json=json_data,
panel_manager=self.panel_manager,
variant_manager=self.variant_manager,
gene_manager=self.gene_manager,
skip_demographics=self.skip_demographics,
pullt3=self.pullt3))
if json_data['sample_type'] == self.sample_type:
list_of_cases.append(Case(
case_json=json_data,
panel_manager=self.panel_manager,
variant_manager=self.variant_manager,
gene_manager=self.gene_manager,
skip_demographics=self.skip_demographics,
pullt3=self.pullt3))
logger.info("Found " + str(len(list_of_cases)) + " test cases.")
return list_of_cases

Expand Down Expand Up @@ -304,20 +305,22 @@ def check_cases_to_update(self):
cases_to_update = []
# use set subtraction to get only cases that haven't already been added
cases_to_check = set(self.list_of_cases) - set(self.cases_to_add)
all_latest_reports = GELInterpretationReport.objects.latest_cases_by_sample_type(sample_type=self.sample_type)
try:
latest_report_list = [
GELInterpretationReport.objects.filter(
ir_family=InterpretationReportFamily.objects.get(
ir_family_id=case.request_id
)).latest("updated") for case in cases_to_check]
latest_report_list = []
for case in cases_to_check:
for report in all_latest_reports:
if case.request_id == report.ir_family.ir_family_id:
latest_report_list.append(report)

latest_hashes = {
ir.ir_family.ir_family_id: ir.sha_hash
for ir in latest_report_list
}

for case in cases_to_check:
if case.json_hash != latest_hashes[case.request_id]:
latest_hash = latest_hashes.get(case.request_id, None)
if not latest_hash or case.json_hash != latest_hash:
cases_to_update.append(case)

except GELInterpretationReport.DoesNotExist as e:
Expand Down
5 changes: 4 additions & 1 deletion gelweb/gel2mdt/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ def write_mdt_outcome_template(report):
+ ' ' \
+ str(report.ir_family.participant_family.proband.surname)
row[1].text = str(report.ir_family.participant_family.proband.date_of_birth.date())
row[2].text = report.ir_family.participant_family.proband.nhs_number
try:
row[2].text = report.ir_family.participant_family.proband.nhs_number
except TypeError:
row[2].text = ''
if report.ir_family.participant_family.proband.local_id:
row[3].text = report.ir_family.participant_family.proband.local_id

Expand Down
17 changes: 16 additions & 1 deletion gelweb/gel2mdt/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class GELIRForm(forms.ModelForm):
'''
class Meta:
model = GELInterpretationReport
fields = ['case_status', 'mdt_status', 'pilot_case', 'case_sent', 'no_primary_findings']
fields = ['case_status', 'mdt_status', 'pilot_case', 'case_sent', 'no_primary_findings', 'case_code']

def save(self):
gelir = self.instance
Expand All @@ -117,6 +117,7 @@ def save(self):
gelir.pilot_case = data['pilot_case']
gelir.case_sent = data['case_sent']
gelir.no_primary_findings = data['no_primary_findings']
gelir.case_code = data['case_code']
gelir.save(overwrite=True)


Expand Down Expand Up @@ -380,3 +381,17 @@ class GenomicsEnglandform(forms.Form):

class GeneSearchForm(forms.Form):
gene = forms.CharField(max_length=25, widget = forms.TextInput(attrs={'style': 'width:200px'}))


class AddCaseAlert(forms.ModelForm):

def clean_gel_id(self):
if self.cleaned_data['gel_id'].isdigit() and len(self.cleaned_data['gel_id']) >= 8:
return self.cleaned_data['gel_id'].strip()
else:
forms.ValidationError("Doesn't look like a GELID")


class Meta:
model = CaseAlert
fields = ['gel_id', 'comment', 'sample_type']
20 changes: 18 additions & 2 deletions gelweb/gel2mdt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ class GELInterpretationReport(models.Model):
('R', 'Required'), ('N', 'Not Required'), ('I', 'In Progress'), ('D', 'Done'),), default='U')
pilot_case = models.BooleanField(default=False)
no_primary_findings = models.BooleanField(default=False)
case_code = models.CharField(max_length=20, null=True, blank=True, choices=(
('REANALYSE', 'REANALYSE'), ('URGENT', 'URGENT')), )

def save(self, overwrite=False, *args, **kwargs):
"""
Expand Down Expand Up @@ -352,6 +354,7 @@ def save(self, overwrite=False, *args, **kwargs):
latest_report.no_primary_findings = self.no_primary_findings
latest_report.archived_version = self.archived_version
latest_report.has_germline_variant = self.has_germline_variant
latest_report.case_code = self.case_code
super(GELInterpretationReport, latest_report).save(*args, **kwargs)
else:
self.assigned_user = latest_report.assigned_user
Expand All @@ -362,6 +365,7 @@ def save(self, overwrite=False, *args, **kwargs):
self.polled_at_datetime = timezone.now()
self.user = latest_report.user
self.no_primary_findings = latest_report.no_primary_findings
self.case_code = latest_report.case_code
# update the latest saved version.
self.archived_version = latest_report.archived_version + 1
super(GELInterpretationReport, self).save(*args, **kwargs)
Expand Down Expand Up @@ -400,7 +404,7 @@ def __str__(self):
class Meta:
managed = True
db_table = 'ClinicalScientist'
app_label= 'gel2mdt'
app_label = 'gel2mdt'


class Proband(models.Model):
Expand Down Expand Up @@ -890,4 +894,16 @@ class MDTReport(models.Model):
class Meta:
managed = True
db_table = 'MDTReport'
app_label= 'gel2mdt'
app_label = 'gel2mdt'


class CaseAlert(models.Model):
gel_id = models.CharField(max_length=30)
comment = models.CharField(max_length=255)
sample_type = models.CharField(max_length=20, choices=(('cancer', 'cancer'),
('raredisease', 'raredisease')))

class Meta:
managed = True
db_table = 'GELAlert'
app_label = 'gel2mdt'
40 changes: 40 additions & 0 deletions gelweb/gel2mdt/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,46 @@ def update_for_t3(report_id):
pullt3=True,
sample=report.ir_family.participant_family.proband.gel_id)

@task
def case_alert_email():
'''
Utility function designed to be run with celery. Emails GELTeam nightly about CaseAlert cases
:param report_id: GEL InterpretationReport ID
:return: Nothing
'''
sample_types = {'raredisease': False, 'cancer': False}
matching_cases = {}
for s_type in sample_types:
case_alerts = CaseAlert.objects.filter(sample_type=s_type)
gel_reports = GELInterpretationReport.objects.latest_cases_by_sample_type(
sample_type=s_type).prefetch_related('ir_family__participant_family__proband')
matching_cases[s_type] = {}
for case in case_alerts:
matching_cases[s_type][case.id] = []
for report in gel_reports:
try:
if report.ir_family.participant_family.proband.gel_id == str(case.gel_id):
matching_cases[s_type][case.id].append((report.id,
report.ir_family.ir_family_id))
sample_types[s_type] = True
except Proband.DoesNotExist:
pass

text_content = ''
if sample_types['cancer'] or sample_types['raredisease']:
for s_type in sample_types:
if matching_cases[s_type]:
text_content += f'{s_type} Case Alert:\n'
for case in matching_cases[s_type]:
case_alert = CaseAlert.objects.get(id=case)
text_content += f'Case {case_alert.gel_id} with CIP-ID of {matching_cases[s_type][case][0][1]} ' \
f'has been added to the database. CaseAlert comment: {case_alert.comment}\n'
subject, from_email, to = f'GeL2MDT CaseAlert', '[email protected]', '[email protected]'
msg = EmailMessage(subject, text_content, from_email, [to])
try:
msg.send()
except Exception as e:
pass

@task
def listupdate_email():
Expand Down
3 changes: 3 additions & 0 deletions gelweb/gel2mdt/templates/gel2mdt/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<ul class="nav navbar-nav">
<li><a href="{% url 'validation-list' sample_type=sample_type %}" ><i class="fas fa-check-circle"></i> Validation</a></li>
</ul>
<ul class="nav navbar-nav">
<li><a href="{% url 'case-alert' sample_type=sample_type %}" ><i class="fas fa-bell"></i> Case Alerts</a></li>
</ul>
{% endif %}


Expand Down
7 changes: 5 additions & 2 deletions gelweb/gel2mdt/templates/gel2mdt/cancer_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ <h4 name="filter-spec" class="panel-title">
<th>Surname</th>
<th>NHS No.</th>
<th>Date of Birth</th>
<th>Max Tier</th>
<th>Max Domain</th>
<th>Assembly</th>
<th>Status</th>
<th>Pilot</th>
Expand All @@ -282,11 +282,13 @@ <h4 name="filter-spec" class="panel-title">
<th>Priority</th>
<th>Recruiting Disease</th>
<th>CIP ID</th>
<th>GMC</th>
<th>LDP</th>
<th>Clinician</th>
<th>Case Code</th>
<th>Gender</th>
<th>Disease Subtype</th>
<th>NHS number</th>

</tr>
</thead>
</table>
Expand Down Expand Up @@ -558,6 +560,7 @@ <h4 name="filter-spec" class="panel-title">
{"data": "cip_id"},
{"data": "gmc"},
{"data": "clinician"},
{"data": "case_code"},
{
"data": "sex",
"visible": false
Expand Down
Loading

0 comments on commit 1836f4c

Please sign in to comment.