Skip to content

Commit

Permalink
Only show recent clinical advice/blood cultures in the renal handover
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Jan 29, 2020
1 parent 5513834 commit 972cfce
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
44 changes: 42 additions & 2 deletions elcid/test/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def test_vanilla(self):
location.bed = "1"
location.save()
microinput = episode_1.microbiologyinput_set.create(
clinical_discussion=["some_discussion"]
clinical_discussion=["some_discussion"],
when=timezone.now() - datetime.timedelta(1)
)
diagnosis = episode_1.diagnosis_set.create()
diagnosis.condition = "Cough"
Expand All @@ -164,7 +165,10 @@ def test_vanilla(self):
line.line_type = "Hickman"
line.save()

bcs = episode_1.patient.bloodcultureset_set.create(lab_number="123")
bcs = episode_1.patient.bloodcultureset_set.create(
lab_number="123",
date_ordered=timezone.now() - datetime.timedelta(1)
)

ctx = views.RenalHandover().get_context_data()
episode = ctx["ward_and_episodes"][0]["episodes"][0]
Expand Down Expand Up @@ -309,6 +313,42 @@ def test_aggregate_clinical_advice(self):
discussion, ["first", "second", "third"]
)

def test_ignore_old_clinical_advice(self):
patient, episode = self.new_patient_and_episode_please()
over_hundred_days = timezone.now().date() - datetime.timedelta(101)
episode.microbiologyinput_set.create(
clinical_discussion="something",
when=over_hundred_days
)
location = episode.location_set.get()
location.ward = "10 East"
location.bed = "1"
location.save()

episode.set_tag_names(["renal"], None)
ctx = views.RenalHandover().get_context_data()
ca = ctx["ward_and_episodes"][0]["episodes"][0]["clinical_advices"]
self.assertEqual(len(ca), 0)

def test_ignore_old_blood_tests(self):
patient, episode = self.new_patient_and_episode_please()
over_hundred_days = timezone.now() - datetime.timedelta(101)
episode.microbiologyinput_set.create(
clinical_discussion="something",
when=over_hundred_days
)
location = episode.location_set.get()
location.ward = "10 East"
location.bed = "1"
location.save()
bcs = episode.patient.bloodcultureset_set.create(
lab_number="123", date_ordered=over_hundred_days
)
episode.set_tag_names(["renal"], None)
ctx = views.RenalHandover().get_context_data()
bcs = ctx["ward_and_episodes"][0]["episodes"][0]["blood_culture_sets"]
self.assertEqual(len(bcs), 0)

def test_other(self):
# if the patient has no ward we should just put them in `other`
patient_1, episode_1 = self.new_patient_and_episode_please()
Expand Down
13 changes: 11 additions & 2 deletions elcid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import csv
import random
import datetime
from collections import defaultdict, OrderedDict

from django.apps import apps
Expand Down Expand Up @@ -181,9 +182,13 @@ def get_context_data(self, *args, **kwargs):
# regardless as to whether it is on that specific episode
# this is because from the user perspective micro input
# is shown which ever episode the medical professional is viewing
hundred_days_ago = datetime.datetime.now() - datetime.timedelta(
days=100
)
microbiology_inputs = models.MicrobiologyInput.objects.filter(
episode__patient_id=episode.patient_id
).order_by("when")
).filter(when__gte=hundred_days_ago).order_by("when")

primary_diagnosis = episode.primarydiagnosis_set.all()[0].condition
ward = location.ward
if not ward:
Expand All @@ -197,7 +202,11 @@ def get_context_data(self, *args, **kwargs):
"diagnosis": diagnosis,
"lines": episode.line_set.all(),
"clinical_advices": microbiology_inputs,
"blood_culture_sets": episode.patient.bloodcultureset_set.all()
"blood_culture_sets": episode.patient.bloodcultureset_set.filter(
date_ordered__gte=datetime.date.today() - datetime.timedelta(
days=100
)
)
})

ward_names = sorted(by_ward.keys())
Expand Down

0 comments on commit 972cfce

Please sign in to comment.