Skip to content

Commit bc826da

Browse files
nhsdevwsmfjarvis
authored andcommitted
VED-368 Dose Number Maximum (#736)
* DoseNumber Maximum * Maximum value is 9 * dose_number unit tests
1 parent 5db7a30 commit bc826da

File tree

4 files changed

+264
-244
lines changed

4 files changed

+264
-244
lines changed

backend/src/models/fhir_immunization_pre_validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,16 +626,16 @@ def pre_validate_protocol_applied(self, values: dict) -> dict:
626626
PreValidation.for_list(field_value, "protocolApplied", defined_length=1)
627627
except KeyError:
628628
pass
629-
629+
DOSE_NUMBER_MAX_VALUE = 9
630630
def pre_validate_dose_number_positive_int(self, values: dict) -> dict:
631631
"""
632632
Pre-validate that, if protocolApplied[0].doseNumberPositiveInt (legacy CSV field : dose_sequence)
633-
exists, then it is an integer from 1 to 9
633+
exists, then it is an integer from 1 to 9 (DOSE_NUMBER_MAX_VALUE)
634634
"""
635635
field_location = "protocolApplied[0].doseNumberPositiveInt"
636636
try:
637637
field_value = values["protocolApplied"][0]["doseNumberPositiveInt"]
638-
PreValidation.for_positive_integer(field_value, field_location)
638+
PreValidation.for_positive_integer(field_value, field_location, self.DOSE_NUMBER_MAX_VALUE)
639639
except (KeyError, IndexError):
640640
pass
641641

backend/tests/test_immunization_pre_validator.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from utils.pre_validation_test_utils import ValidatorModelTests
2626
from utils.values_for_tests import ValidValues, InvalidValues
2727
from models.constants import Constants
28+
from models.fhir_immunization_pre_validators import PreValidators
2829

2930
class TestImmunizationModelPreValidationRules(unittest.TestCase):
3031
"""Test immunization pre validation rules on the FHIR model using the covid sample data"""
@@ -819,6 +820,33 @@ def test_pre_validate_protocol_applied(self):
819820
)
820821

821822
def test_pre_validate_protocol_applied_dose_number_positive_int(self):
823+
"""
824+
Test pre_validate_protocol_applied_dose_number_positive_int accepts valid values and
825+
rejects invalid values
826+
"""
827+
for value in range(1, PreValidators.DOSE_NUMBER_MAX_VALUE + 1):
828+
data = {
829+
"protocolApplied": [
830+
{"doseNumberPositiveInt": value}
831+
]
832+
}
833+
validator = PreValidators(data)
834+
# Should not raise
835+
validator.pre_validate_dose_number_positive_int(data)
836+
837+
def test_out_of_range_dose_number(self):
838+
# Invalid: doseNumberPositiveInt < 1 or > 9
839+
for value in [0, PreValidators.DOSE_NUMBER_MAX_VALUE + 1, -1]:
840+
data = {
841+
"protocolApplied": [
842+
{"doseNumberPositiveInt": value}
843+
]
844+
}
845+
validator = PreValidators(data)
846+
with self.assertRaises(ValueError):
847+
validator.pre_validate_dose_number_positive_int(data)
848+
849+
def test_test_positive_integer_value(self):
822850
"""
823851
Test pre_validate_protocol_applied_dose_number_positive_int accepts valid values and
824852
rejects invalid values

0 commit comments

Comments
 (0)