Skip to content

Commit

Permalink
Add procalcitonin to summary
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmiller authored and fredkingham committed Mar 27, 2020
1 parent 2e611c1 commit d0ddf67
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
21 changes: 20 additions & 1 deletion elcid/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class InfectionServiceTestSummaryApi(LoginRequiredViewset):
("CLOTTING SCREEN", ["INR"],),
("C REACTIVE PROTEIN", ["C Reactive Protein"]),
("LIVER PROFILE", ["ALT", "AST", "Alkaline Phosphatase"]),
("PROCALCITONIN", ["Procalcitonin"]),
),)

NUM_RESULTS = 5
Expand Down Expand Up @@ -342,9 +343,27 @@ def get_obs_queryset(self, patient, lab_test_name, observation_name):
observation_name=observation_name
)

def get_PROCALCITONIN_Procalcitonin(self, observation):
return observation.observation_value.split('~')[0]

def get_observation_value(self, observation):
"""
Return the observation value for this observation
Defaults to .value_numeric, but looks for a method
called get_TEST_NAME_OBSERVATION_NAME(observation)
and uses that if it exists.
"""
method_name = 'get_{}_{}'.format(
observation.test.test_name, observation.observation_name
)
if hasattr(self, method_name):
return getattr(self, method_name)(observation)
return observation.value_numeric

def serialize_observations(self, observations):
latest_results = {
serialization.serialize_date(i.observation_datetime.date()): i.value_numeric
serialization.serialize_date(i.observation_datetime.date()): self.get_observation_value(i)
for i in observations
}
return dict(
Expand Down
40 changes: 39 additions & 1 deletion elcid/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

from elcid import models as emodels
from elcid.api import (
UpstreamBloodCultureApi, LabTestResultsView
UpstreamBloodCultureApi, LabTestResultsView,
InfectionServiceTestSummaryApi
)


Expand Down Expand Up @@ -1106,6 +1107,8 @@ def test_results_date_crunching(self):
result = self.client.get(self.url)
self.assertEqual(result.data, expected)



def test_ignores_strings(self):
self.create_clotting_screen({
datetime.datetime(2019, 6, 4, 12, 10): "Pending"
Expand Down Expand Up @@ -1133,3 +1136,38 @@ def test_handles_no_tests(self):
'recent_dates': [None, None, None, None, None]
}
self.assertEqual(result.data, expected)

def test_get_procalcitonin(self):
api = InfectionServiceTestSummaryApi()

mock_observation = mock.MagicMock(name='Mock observation')
mock_observation.observation_value = "0.61~PCT 0.5-1.99 Suggestive of the presence of~bacterial infection. Please interpret within the~clinical picture. Consider repeat in 24-48 hours."

self.assertEqual(
"0.61",
api.get_PROCALCITONIN_Procalcitonin(mock_observation)
)

def test_get_observation_value_calls_getter(self):
api = InfectionServiceTestSummaryApi()

mock_observation = mock.MagicMock(name='Mock observation')
mock_observation.observation_name = 'Procalcitonin'
mock_observation.observation_value = 'ONE MILLION~TESTS'
mock_observation.test.test_name = 'PROCALCITONIN'

self.assertEqual(
"ONE MILLION",
api.get_observation_value(mock_observation)
)

def test_get_observation_value_default(self):
api = InfectionServiceTestSummaryApi()

mock_observation = mock.MagicMock(name='Mock observation')
mock_observation.value_numeric = 483

self.assertEqual(
483,
api.get_observation_value(mock_observation)
)

0 comments on commit d0ddf67

Please sign in to comment.