Skip to content

Commit da26e47

Browse files
authored
VED-382: Use configurable disease mappings in backend. (#618)
* remock for redis * clean up test_utils * PYTHONPATH for builds * remove relative paths * remocked batch service * remock test imm post valid * remock test_fhir_repo
1 parent 613bd88 commit da26e47

33 files changed

+533
-364
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
- name: Run unittest with recordforwarder-coverage
6060
working-directory: backend
6161
id: recordforwarder
62+
env:
63+
PYTHONPATH: ${{ github.workspace }}/backend/src:${{ github.workspace }}/backend/tests
6264
continue-on-error: true
6365
run: |
6466
poetry env use 3.11
@@ -90,6 +92,8 @@ jobs:
9092
9193
- name: Run unittest with coverage-fhir-api
9294
working-directory: backend
95+
env:
96+
PYTHONPATH: ${{ github.workspace }}/backend/src:${{ github.workspace }}/backend/tests
9397
id: fhirapi
9498
continue-on-error: true
9599
run: |

.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

ack_backend/tests/test_splunk_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from tests.utils_for_ack_backend_tests.utils_for_ack_backend_tests import generate_event
2020

2121
with patch.dict("os.environ", MOCK_ENVIRONMENT_DICT):
22-
from src.ack_processor import lambda_handler
22+
from ack_processor import lambda_handler
2323

2424
s3_client = boto3_client("s3")
2525

backend/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ package: build
66
docker run --rm -v $(shell pwd)/build:/build imms-lambda-build
77

88
test:
9-
python -m unittest
9+
@PYTHONPATH=src:tests python -m unittest
1010

1111
.PHONY: build package test

backend/src/mappings.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

backend/src/models/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ class Constants:
3939
}
4040

4141
ALLOWED_CONTAINED_RESOURCES = {"Practitioner", "Patient"}
42+
43+
SUPPLIER_PERMISSIONS_KEY = "supplier_permissions"
44+
VACCINE_TYPE_TO_DISEASES_HASH_KEY = "vacc_to_diseases"
45+
DISEASES_TO_VACCINE_TYPE_HASH_KEY = "diseases_to_vacc"

backend/src/models/fhir_immunization_post_validators.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,8 @@ def validate(self):
126126
# Initialise the mandation validation functions
127127
mandation_functions = MandationFunctions(self.imms, self.vaccine_type)
128128

129-
# Identify whether to use the vaccine_type_agnostic, or else a vaccine type specific, validation rule set
130-
validation_set_to_use = (
131-
"vaccine_type_agnostic"
132-
if self.vaccine_type in ValidationSets.vaccine_types_which_use_agnostic_set
133-
else self.vaccine_type.lower()
134-
)
135-
136129
# Obtain the relevant validation set
137-
validation_set = getattr(ValidationSets, validation_set_to_use)
130+
validation_set = getattr(ValidationSets, self.vaccine_type.lower(), ValidationSets.vaccine_type_agnostic)
138131

139132
# Create an instance of FieldLocations and set dynamic fields
140133
field_locations = FieldLocations()

backend/src/models/utils/validation_utils.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import json
44

5-
65
from typing import Union
7-
from mappings import vaccine_type_mappings
86
from .generic_utils import create_diagnostics_error
97
from base_utils.base_utils import obtain_field_location
108
from models.obtain_field_value import ObtainFieldValue
119
from models.field_names import FieldNames
1210
from models.errors import MandatoryError
1311
from constants import Urls
12+
from models.constants import Constants
13+
from clients import redis_client
1414

1515

1616
def get_target_disease_codes(immunization: dict):
@@ -52,17 +52,15 @@ def convert_disease_codes_to_vaccine_type(disease_codes_input: list) -> Union[st
5252
Takes a list of disease codes and returns the corresponding vaccine type if found,
5353
otherwise raises a value error
5454
"""
55-
try:
56-
return next(
57-
vaccine_type
58-
for disease_codes, vaccine_type in vaccine_type_mappings
59-
if sorted(disease_codes_input) == disease_codes
60-
)
61-
except Exception as e:
55+
key = ":".join(sorted(disease_codes_input))
56+
vaccine_type = redis_client.hget(Constants.DISEASES_TO_VACCINE_TYPE_HASH_KEY, key)
57+
58+
if not vaccine_type:
6259
raise ValueError(
6360
f"Validation errors: protocolApplied[0].targetDisease[*].coding[?(@.system=='http://snomed.info/sct')].code - "
6461
f"{disease_codes_input} is not a valid combination of disease codes for this service"
65-
) from e
62+
)
63+
return vaccine_type
6664

6765

6866
def get_vaccine_type(immunization: dict):

backend/src/models/validation_sets.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Validation sets for each vaccine type"""
22

33
from models.mandation_functions import MandationRules
4-
from mappings import VaccineTypes
54

65

76
class ValidationSets:
@@ -11,7 +10,7 @@ class ValidationSets:
1110
1211
TO ADD A NEW VACCINE TYPE:
1312
* If the mandation rules for the new vaccine type are identical to the vaccine_type_agnostic rules, then
14-
add the vaccine type to the vaccine_types_which_use_agnostic_set list.
13+
no action is required.
1514
* If some of the mandation rules for the new vaccine type are different than the agnostic rules, then create a
1615
new validation set, with the same name as the vaccine type. This can be done by copying and pasting the
1716
vaccine_type_agnostic set, and amending any rules as required.
@@ -21,8 +20,6 @@ class ValidationSets:
2120
def __init__(self) -> None:
2221
pass
2322

24-
vaccine_types_which_use_agnostic_set = [VaccineTypes.covid_19, VaccineTypes.flu, VaccineTypes.hpv, VaccineTypes.mmr,VaccineTypes.rsv]
25-
2623
vaccine_type_agnostic = {
2724
"patient_identifier_value": MandationRules.required,
2825
"patient_name_given": MandationRules.mandatory,

backend/src/parameter_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
from typing import Optional
77
from urllib.parse import parse_qs, urlencode, quote
88

9-
from mappings import VaccineTypes
9+
from clients import redis_client
1010
from models.errors import ParameterException
11+
from models.constants import Constants
1112

1213
ParamValue = list[str]
1314
ParamContainer = dict[str, ParamValue]
@@ -107,9 +108,11 @@ def process_search_params(params: ParamContainer) -> SearchParams:
107108
vaccine_type is not None]
108109
if len(vaccine_types) < 1:
109110
raise ParameterException(f"Search parameter {immunization_target_key} must have one or more values.")
110-
if any([x not in VaccineTypes().all for x in vaccine_types]):
111+
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):
111114
raise ParameterException(
112-
f"immunization-target must be one or more of the following: {','.join(VaccineTypes().all)}")
115+
f"immunization-target must be one or more of the following: {', '.join(valid_vaccine_types)}")
113116

114117
# date.from
115118
date_froms = params.get(date_from_key, [])

0 commit comments

Comments
 (0)