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

Starred obs #1224

Open
wants to merge 22 commits into
base: v0.98
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6493948
Adds the starred observation model
Sep 28, 2021
5a55ae7
Adds the star observation api
Sep 28, 2021
621a129
Adds in the front end to star observations in the result view
Sep 28, 2021
3df995f
Adds in the star in the results view observation serialization
Sep 28, 2021
f97f09e
Fixes an issue in the starred observation where the star would not va…
Sep 28, 2021
150b1f9
Changes the api lab test api to return the id of the Observation star…
Sep 28, 2021
dbc92d2
Adds in the front end for the panel so that the user can star and uns…
Sep 28, 2021
03f2a08
Disable the caching of the infection service page and the lab test lo…
Sep 28, 2021
ec496a2
Adds in the show hide logic on the stars on the infection summary page
Sep 28, 2021
7ac9978
Fixes up the css around the display and hiding of starred results
Sep 28, 2021
a401a67
Removes the stars from the summary panel but keep the starred observa…
Sep 30, 2021
8ca7d2b
Removes the star from the tabular view
Sep 30, 2021
5a45c40
Moves the star to the left of the long form result in the results view
Sep 30, 2021
012e315
If we have an extra long observation in the lab test summary panel th…
Sep 30, 2021
a97a3a5
Remove the ng-if around the results page, but make sure we only load …
Sep 30, 2021
45f3662
Fixup: Colors
davidmiller Oct 1, 2021
06b426f
Remove fields that we no longer need to translate in the infection su…
Oct 13, 2021
8914d57
Merge branch 'starred-obs' of github.com:openhealthcare/elcid-rfh int…
Oct 13, 2021
58f941f
Remove fields that we no longer need to translate in the covid lab as…
Oct 13, 2021
5a89f7f
We had changes implemented that allowed you to 'unstar' results in th…
Nov 1, 2021
599bc82
Changes the covid lab ticker to return the test name and the lab number
Nov 1, 2021
5b5a091
also load data if the view changes as going to test results and back …
Nov 4, 2021
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
110 changes: 103 additions & 7 deletions elcid/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from operator import itemgetter

from django.conf import settings
from django.utils.functional import cached_property
from django.utils.text import slugify
from django.http import HttpResponseBadRequest
from rest_framework import viewsets, status
Expand Down Expand Up @@ -70,6 +71,30 @@ class LabTestResultsView(LoginRequiredViewset):
"""
base_name = 'lab_test_results_view'

@cached_property
def starred_results_dict(self):
starred_obs = lab_test_models.StarredObservation.objects.filter(
patient_id=self.kwargs["pk"]
)
result = {}
for starred_ob in starred_obs:
key = (
starred_ob.test_name,
starred_ob.lab_number,
starred_ob.observation_name,
)
result[key] = starred_ob.id
return result

def get_starred_id(self, test, observation):
key = (
test.test_name,
test.lab_number,
observation.observation_name,
)
return self.starred_results_dict.get(key)


def get_non_comments_for_patient(self, patient):
"""
Returns all non comments for a patient, ensuring they are
Expand Down Expand Up @@ -203,8 +228,9 @@ def serialise_long_form_instance(self, instance):
serialised_observations.append(
{
'name' : o.observation_name.rstrip('.'),
'value': o.observation_value,
'units': o.units
'value': o.observation_value.replace("~", "\n"),
'units': o.units,
'star': self.get_starred_id(instance, o),
}
)

Expand Down Expand Up @@ -300,6 +326,58 @@ class InfectionServiceTestSummaryApi(LoginRequiredViewset):

NUM_RESULTS = 5

@cached_property
def starred_results_dict(self):
"""
A cached property of test_name, lab_number, observation_name to StarredObservation.id
"""
starred_obs = lab_test_models.StarredObservation.objects.filter(
patient_id=self.kwargs["pk"]
)
result = {}
for starred_ob in starred_obs:
key = (
starred_ob.test_name,
starred_ob.lab_number,
starred_ob.observation_name,
)
result[key] = starred_ob.id
return result

def get_starred(self, patient, ticker):
"""
If a lab test has been starred and is not already
in the ticker add it
"""
result = []
already_starred = {i["star"] for i in ticker}
others_starred = [
key for key, starred_id in self.starred_results_dict.items()
if starred_id not in already_starred
]
if not others_starred:
return []
observations = lab_test_models.Observation.objects.filter(
test__patient=patient,
test__test_name__in=[i[0] for i in others_starred],
test__lab_number__in=[i[1] for i in others_starred],
observation_name__in=[i[2] for i in others_starred],
).select_related('test')
for observation in observations:
test = observation.test
starred_id = self.starred_results_dict.get((
test.test_name, test.lab_number, observation.observation_name
))
if starred_id:
timestamp = observation.observation_datetime
result.append({
'date_str': observation.observation_datetime.strftime('%d/%m/%Y %H:%M'),
'timestamp': timestamp,
'name': observation.observation_name,
'value': "\n".join(observation.observation_value.strip().split("~")),
'star': starred_id,
})
return result

def _get_antifungal_ticker_dict(self, test):
"""
Expand All @@ -311,26 +389,30 @@ def _get_antifungal_ticker_dict(self, test):
test_name = test.test_name

result_string = ''
star_id = None

for observation in observations:

if observation.observation_name in self.ANTIFUNGAL_TESTS[test_name]:
result_string += ' {} {}'.format(
self.ANTIFUNGAL_SHORT_NAMES[observation.observation_name],
observation.observation_value.split('~')[0]
)
if not star_id:
star_id = self.starred_results_dict.get(
(test_name, test.lab_number, observation.observation_name,)
)

display_name = '{} {}'.format(
self.ANTIFUNGAL_SHORT_NAMES[test_name],
test.site.replace('&', ' ').split(' ')[0]
)


return {
'date_str' : timestamp.strftime('%d/%m/%Y %H:%M'),
'timestamp': timestamp,
'name' : display_name,
'value' : result_string.strip()
'value' : result_string.strip(),
'star' : star_id,
}

def get_antifungal_observations(self, patient):
Expand Down Expand Up @@ -369,16 +451,30 @@ def get_antifungal_observations(self, patient):

return ticker

def get_covid_ticker(self, patient):
"""
Get the covid ticker, add the property
'star' which points is the id of the StarredObservation
if its been starred, otherwise its None
"""
ticker = covid_lab.get_covid_result_ticker(patient)
for t in ticker:
star_id = self.starred_results_dict.get(
(t["test_name"], t["lab_number"], t["name"],)
)
t["star"] = star_id
t["observation_name"] = t["name"]
return ticker

def get_ticker_observations(self, patient):
"""
Some results are displayed as a ticker in chronological
order.
"""
ticker = covid_lab.get_covid_result_ticker(patient)
ticker = self.get_covid_ticker(patient)
ticker += self.get_antifungal_observations(patient)
ticker += self.get_starred(patient, ticker)
ticker = list(reversed(sorted(ticker, key=lambda i: i['timestamp'])))

return ticker

def get_recent_dates_to_observations(self, qs):
Expand Down
Loading