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

Remove unused pathology demographics #1296

Open
wants to merge 1 commit into
base: v0.105
Choose a base branch
from
Open
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
61 changes: 0 additions & 61 deletions intrahospital_api/apis/prod_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
API for production
"""
from collections import defaultdict
import datetime
from functools import wraps
import itertools
import json
import time

from django.conf import settings
Expand All @@ -27,9 +24,6 @@

PATIENT_MASTERFILE_VIEW = "VIEW_CRS_Patient_Masterfile"

PATHOLOGY_DEMOGRAPHICS_QUERY = "SELECT top(1) * FROM {view} WHERE Patient_Number = \
@hospital_number ORDER BY date_inserted DESC;"

PATIENT_MASTERFILE_QUERY = "SELECT top(1) * FROM {view} WHERE Patient_Number = \
@hospital_number ORDER BY last_updated DESC;"

Expand Down Expand Up @@ -552,12 +546,6 @@ def execute_warehouse_query(self, query, params=None):
logger.debug(result)
return result

@property
def pathology_demographics_query(self):
return PATHOLOGY_DEMOGRAPHICS_QUERY.format(
view=self.trust_settings["view"]
)

@property
def all_data_for_hospital_number_query(self):
return ALL_DATA_QUERY_FOR_HOSPITAL_NUMBER.format(
Expand Down Expand Up @@ -586,22 +574,6 @@ def all_data_query_for_lab_test_type(self):
def patient_masterfile_query(self):
return PATIENT_MASTERFILE_QUERY.format(view=PATIENT_MASTERFILE_VIEW)

def demographics(self, hospital_number):
hospital_number = hospital_number.strip()
demographics_result = None

master_file_result = self.patient_masterfile(hospital_number)

if master_file_result:
demographics_result = master_file_result[Demographics.get_api_name()]

if not demographics_result:
demographics_result = self.pathology_demographics(hospital_number)

if demographics_result:
demographics_result["external_system"] = EXTERNAL_SYSTEM
return demographics_result

@timing
def patient_masterfile_since(self, last_updated):
"""
Expand Down Expand Up @@ -643,39 +615,6 @@ def patient_masterfile(self, hospital_number):
MasterFileMeta.get_api_name(): get_master_file_meta(rows[0]),
}

@timing
@db_retry
def pathology_demographics(self, hn):
hospital_number = hn
rows = list(self.execute_trust_query(
self.pathology_demographics_query,
params=dict(hospital_number=hospital_number)
))
if not len(rows):
# If the hn begins with leading 0(s)
# the data is sometimes empty in the CRS_* fields.
# So if we cannot find rows with 0 prefixes
# remove the prefix.
if not hospital_number.startswith("0"):
return
hospital_number = hospital_number.lstrip('0')

# some hns are just 0s, if we've stripped the hn
# away don't query again.
if not hospital_number:
return
rows = list(self.execute_trust_query(
self.pathology_demographics_query,
params=dict(hospital_number=hospital_number)
))
if not len(rows):
return
# If we've stripped off the leading 0, restore it.
if not hn == hospital_number:
for row in rows:
row["Patient_Number"] = hn
return PathologyRow(rows[0]).get_demographics_dict()

def raw_data(self, hospital_number, lab_number=None, test_type=None):
if lab_number:
return self.execute_trust_query(
Expand Down
59 changes: 0 additions & 59 deletions intrahospital_api/test/test_prod_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,6 @@ def test_pathology_demographics_success(self):
execute_query.call_args[1]["params"], dict(hospital_number="123")
)

def test_pathology_demographics_hospital_number_fail(self):
api = self.get_api()
with mock.patch.object(api, "execute_trust_query") as execute_query:
execute_query.return_value = []
result = api.pathology_demographics("A1' 23")

self.assertIsNone(result)

def test_patient_masterfile_success(self):
api = self.get_api()
with mock.patch.object(api, "execute_hospital_query") as execute_query:
Expand Down Expand Up @@ -625,57 +617,6 @@ def test_patient_masterfile_fail(self):

self.assertIsNone(result)

def test_demographics_found_in_main(self):
api = self.get_api()
with mock.patch.object(api, "patient_masterfile") as patient_masterfile:
with mock.patch.object(api, "pathology_demographics") as pathology_demographics:
patient_masterfile.return_value = dict(demographics=dict(first_name="Wilma"))
result = api.demographics("111")

self.assertEqual(
result,
dict(first_name="Wilma", external_system=constants.EXTERNAL_SYSTEM)
)

patient_masterfile.assert_called_once_with("111")
self.assertFalse(pathology_demographics.called)

def test_demographics_found_in_pathology(self):
api = self.get_api()
with mock.patch.object(api, "patient_masterfile") as patient_masterfile:
with mock.patch.object(api, "pathology_demographics") as pathology_demographics:
patient_masterfile.return_value = None
pathology_demographics.return_value = dict(first_name="Wilma")
result = api.demographics("111")

self.assertEqual(
result,
dict(
first_name="Wilma",
external_system=constants.EXTERNAL_SYSTEM
)
)

patient_masterfile.assert_called_once_with("111")
pathology_demographics.assert_called_once_with("111")

def test_demographics_not_found_in_either(self):
api = self.get_api()

with mock.patch.object(
api, "execute_hospital_query"
) as execute_hospital_query:
with mock.patch.object(
api, "execute_trust_query"
) as execute_trust_query:
execute_hospital_query.return_value = []
execute_trust_query.return_value = []
result = api.demographics("123")

self.assertTrue(execute_hospital_query.called)
self.assertTrue(execute_trust_query.called)
self.assertIsNone(result)

def test_data_deltas(self):
api = self.get_api()
patient, _ = self.new_patient_and_episode_please()
Expand Down