Skip to content

Commit 1685fcc

Browse files
committed
comments addressed
1 parent a9ceeeb commit 1685fcc

File tree

9 files changed

+40
-17
lines changed

9 files changed

+40
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ openapi.json
2929
!**/.vscode/settings.json.default
3030

3131
devtools/volume/
32+
backend/tests/.coverage

backend/src/constants.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,3 @@ class Urls:
2323

2424

2525
GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE = "Unable to process request. Issue may be transient."
26-
27-
VACCINE_TYPE_TO_DISEASES_HASH_KEY = "vacc_to_diseases"
28-
DISEASES_TO_VACCINE_TYPE_HASH_KEY = "diseases_to_vacc"

backend/src/models/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ class Constants:
4242

4343
SUPPLIER_PERMISSIONS_KEY = "supplier_permissions"
4444
VACCINE_TYPE_TO_DISEASES_HASH_KEY = "vacc_to_diseases"
45-
DISEASES_TO_VACCINE_TYPE_HASH_KEY = "diseases_to_vacc"
45+
DISEASES_TO_VACCINE_TYPE_HASH_KEY = "diseases_to_vacc"

backend/src/models/utils/validation_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Utils for backend folder"""
22

33
import json
4-
import inspect
54

65
from typing import Union
76
from .generic_utils import create_diagnostics_error
87
from base_utils.base_utils import obtain_field_location
98
from models.obtain_field_value import ObtainFieldValue
109
from models.field_names import FieldNames
1110
from models.errors import MandatoryError
12-
from constants import Urls, DISEASES_TO_VACCINE_TYPE_HASH_KEY
11+
from constants import Urls
12+
from models.constants import Constants
1313
from clients import redis_client
1414

1515

@@ -53,7 +53,7 @@ def convert_disease_codes_to_vaccine_type(disease_codes_input: list) -> Union[st
5353
otherwise raises a value error
5454
"""
5555
key = ":".join(sorted(disease_codes_input))
56-
vaccine_type = redis_client.hget(DISEASES_TO_VACCINE_TYPE_HASH_KEY, key)
56+
vaccine_type = redis_client.hget(Constants.DISEASES_TO_VACCINE_TYPE_HASH_KEY, key)
5757

5858
if not vaccine_type:
5959
raise ValueError(

backend/src/parameter_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from clients import redis_client
1010
from models.errors import ParameterException
11-
from constants import VACCINE_TYPE_TO_DISEASES_HASH_KEY
11+
from models.constants import Constants
1212

1313
ParamValue = list[str]
1414
ParamContainer = dict[str, ParamValue]
@@ -109,8 +109,8 @@ def process_search_params(params: ParamContainer) -> SearchParams:
109109
if len(vaccine_types) < 1:
110110
raise ParameterException(f"Search parameter {immunization_target_key} must have one or more values.")
111111

112-
valid_vaccine_types = redis_client.hkeys(VACCINE_TYPE_TO_DISEASES_HASH_KEY)
113-
if any([x not in valid_vaccine_types for x in vaccine_types]):
112+
valid_vaccine_types = redis_client.hkeys(Constants.VACCINE_TYPE_TO_DISEASES_HASH_KEY)
113+
if any(x not in valid_vaccine_types for x in vaccine_types):
114114
raise ParameterException(
115115
f"immunization-target must be one or more of the following: {', '.join(valid_vaccine_types)}")
116116

backend/tests/.coverage

-52 KB
Binary file not shown.

backend/tests/sample_data/permissions_config.py

Whitespace-only changes.

backend/tests/test_fhir_controller.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from parameter_parser import patient_identifier_system, process_search_params
3333
from tests.utils.generic_utils import load_json_data
3434
from tests.utils.values_for_tests import ValidValues
35-
from utils.mock_redis import MOCK_REDIS_V2D_RESPONSE
3635

3736
class TestFhirControllerBase(unittest.TestCase):
3837
"""Base class for all tests to set up common fixtures"""
@@ -1607,6 +1606,19 @@ def test_immunization_unhandled_error(self, mock_get_supplier_permissions):
16071606
self.assertEqual(body["issue"][0]["code"], "exception")
16081607

16091608
class TestSearchImmunizations(TestFhirControllerBase):
1609+
MOCK_REDIS_V2D_RESPONSE = {
1610+
"PERTUSSIS": "[{\"code\": \"27836007\", \"term\": \"Pertussis (disorder)\"}]",
1611+
"RSV": "[{\"code\": \"55735004\", \"term\": \"Respiratory syncytial virus infection (disorder)\"}]",
1612+
"3in1": "[{\"code\": \"398102009\", \"term\": \"Acute poliomyelitis\"}, {\"code\": \"397430003\", \"term\": \"Diphtheria caused by Corynebacterium diphtheriae\"}, {\"code\": \"76902006\", \"term\": \"Tetanus (disorder)\"}]",
1613+
"MMR": "[{\"code\": \"14189004\", \"term\": \"Measles (disorder)\"}, {\"code\": \"36989005\", \"term\": \"Mumps (disorder)\"}, {\"code\": \"36653000\", \"term\": \"Rubella (disorder)\"}]",
1614+
"HPV": "[{\"code\": \"240532009\", \"term\": \"Human papillomavirus infection\"}]",
1615+
"MMRV": "[{\"code\": \"14189004\", \"term\": \"Measles (disorder)\"}, {\"code\": \"36989005\", \"term\": \"Mumps (disorder)\"}, {\"code\": \"36653000\", \"term\": \"Rubella (disorder)\"}, {\"code\": \"38907003\", \"term\": \"Varicella (disorder)\"}]",
1616+
"PCV13": "[{\"code\": \"16814004\", \"term\": \"Pneumococcal infectious disease\"}]",
1617+
"SHINGLES": "[{\"code\": \"4740000\", \"term\": \"Herpes zoster\"}]",
1618+
"COVID19": "[{\"code\": \"840539006\", \"term\": \"Disease caused by severe acute respiratory syndrome coronavirus 2\"}]",
1619+
"FLU": "[{\"code\": \"6142004\", \"term\": \"Influenza caused by seasonal influenza virus (disorder)\"}]",
1620+
"MENACWY": "[{\"code\": \"23511006\", \"term\": \"Meningococcal infectious disease\"}]"
1621+
}
16101622
def setUp(self):
16111623
super().setUp()
16121624
self.service = create_autospec(FhirService)
@@ -1919,7 +1931,7 @@ def test_post_search_immunizations_for_unauthorized_vaccine_type_search_403(self
19191931

19201932
@patch("fhir_controller.process_search_params", wraps=process_search_params)
19211933
def test_uses_parameter_parser(self, process_search_params: Mock):
1922-
self.mock_redis_client.hkeys.return_value = MOCK_REDIS_V2D_RESPONSE
1934+
self.mock_redis_client.hkeys.return_value = self.MOCK_REDIS_V2D_RESPONSE
19231935
lambda_event = {
19241936
"multiValueQueryStringParameters": {
19251937
self.patient_identifier_key: ["https://fhir.nhs.uk/Id/nhs-number|9000000009"],

backend/tests/test_immunization_pre_validator.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import unittest
44
from copy import deepcopy
55
from decimal import Decimal
6-
from unittest import mock
7-
import json
86
from unittest.mock import patch
97

108
from jsonpath_ng.ext import parse
119

1210
from clients import redis_client
1311
from models.fhir_immunization import ImmunizationValidator
1412
from models.utils.generic_utils import get_generic_extension_value
15-
from .utils.generic_utils import (
13+
from utils.generic_utils import (
1614
# these have an underscore to avoid pytest collecting them as tests
1715
test_valid_values_accepted as _test_valid_values_accepted,
1816
test_invalid_values_rejected as _test_invalid_values_rejected,
@@ -26,11 +24,25 @@
2624
)
2725
from utils.pre_validation_test_utils import ValidatorModelTests
2826
from utils.values_for_tests import ValidValues, InvalidValues
29-
from utils.mock_redis import MOCK_REDIS_D2V_RESPONSE
27+
from models.constants import Constants
3028

3129
class TestImmunizationModelPreValidationRules(unittest.TestCase):
3230
"""Test immunization pre validation rules on the FHIR model using the covid sample data"""
3331

32+
MOCK_REDIS_D2V_RESPONSE = {
33+
"4740000": "SHINGLES",
34+
"6142004": "FLU",
35+
"16814004": "PCV13",
36+
"23511006": "MENACWY",
37+
"27836007": "PERTUSSIS",
38+
"55735004": "RSV",
39+
"240532009": "HPV",
40+
"840539006": "COVID19",
41+
"14189004:36653000:36989005": "MMR",
42+
"14189004:36653000:36989005:38907003": "MMRV",
43+
"397430003:398102009:76902006": "3in1"
44+
}
45+
3446
def setUp(self):
3547
"""Set up for each test. This runs before every test"""
3648
self.json_data = load_json_data(filename="completed_covid19_immunization_event.json")
@@ -39,6 +51,7 @@ def setUp(self):
3951
self.mock_redis_client = self.redis_patcher.start()
4052

4153

54+
4255
def tearDown(self):
4356
patch.stopall()
4457

@@ -700,7 +713,7 @@ def test_pre_validate_missing_valueCodeableConcept2(self):
700713

701714
def test_pre_validate_missing_valueCodeableConcept3(self):
702715
# Test case: valid data (should not raise an exception)
703-
self.mock_redis_client.hget.return_value = MOCK_REDIS_D2V_RESPONSE
716+
self.mock_redis_client.hget.return_value = self.MOCK_REDIS_D2V_RESPONSE
704717
valid_json_data = deepcopy(self.json_data)
705718
try:
706719
self.validator.validate(valid_json_data)

0 commit comments

Comments
 (0)