diff --git a/intrahospital_api/apis/prod_api.py b/intrahospital_api/apis/prod_api.py index b191c575f..e816f4ce3 100644 --- a/intrahospital_api/apis/prod_api.py +++ b/intrahospital_api/apis/prod_api.py @@ -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 @@ -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;" @@ -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( @@ -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): """ @@ -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( diff --git a/intrahospital_api/test/test_prod_api.py b/intrahospital_api/test/test_prod_api.py index 16cf3d3f1..5f610885b 100644 --- a/intrahospital_api/test/test_prod_api.py +++ b/intrahospital_api/test/test_prod_api.py @@ -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: @@ -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()