From fe195d276693de6e7ddc673f2ce27eb0e6719854 Mon Sep 17 00:00:00 2001 From: Daniel Yip Date: Thu, 8 Jan 2026 17:04:40 +0000 Subject: [PATCH 1/2] Increased given name length constraint --- lambdas/shared/src/common/models/constants.py | 10 +++++++--- .../common/models/fhir_immunization_pre_validators.py | 11 ++++++----- .../test_common/test_immunization_pre_validator.py | 9 ++++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lambdas/shared/src/common/models/constants.py b/lambdas/shared/src/common/models/constants.py index 73d6fe926..3dd690c1c 100644 --- a/lambdas/shared/src/common/models/constants.py +++ b/lambdas/shared/src/common/models/constants.py @@ -48,10 +48,14 @@ class Constants: ALLOWED_CONTAINED_RESOURCES = {"Practitioner", "Patient"} - # As per Personal Demographics Service FHIR API, the maximum length of a given name element or surname is 35 chars. - # Given name is a list with a maximum 5 elements. For more info see: + # As per Personal Demographics Service (PDS) FHIR API, the maximum length of a family name is 35 characters: # https://digital.nhs.uk/developer/api-catalogue/personal-demographics-service-fhir#post-/Patient - PERSON_NAME_ELEMENT_MAX_LENGTH = 35 + FAMILY_NAME_MAX_LENGTH = 35 + + # VED-980 The PDS constraint is that the given name list entry has a maximum of 5 entries and each item may be a + # maximum of 35 characters. Due to batch limitations, all entries are concatenated into one string. Therefore, the + # Imms FHIR API team agreed to use a more lenient figure given the nature of data flows we handle + GIVEN_NAME_ELEMENT_MAX_LENGTH = 180 COMPLETED_STATUS = "completed" REINSTATED_RECORD_STATUS = "reinstated" diff --git a/lambdas/shared/src/common/models/fhir_immunization_pre_validators.py b/lambdas/shared/src/common/models/fhir_immunization_pre_validators.py index 338263eca..a99a1d9cc 100644 --- a/lambdas/shared/src/common/models/fhir_immunization_pre_validators.py +++ b/lambdas/shared/src/common/models/fhir_immunization_pre_validators.py @@ -301,7 +301,8 @@ def pre_validate_patient_name(self, values: dict) -> None: def pre_validate_patient_name_given(self, values: dict) -> None: """ Pre-validate that, if contained[?(@.resourceType=='Patient')].name[{index}].given index dynamically determined - (legacy CSV field name:PERSON_FORENAME) exists, then it is an array containing a single non-empty string + (legacy CSV field name:PERSON_FORENAME) exists, then it is an array containing a maximum of 5 items an no items + may exceed the GIVEN_NAME_ELEMENT_MAX_LENGTH value """ field_location = patient_name_given_field_location(values) @@ -312,7 +313,7 @@ def pre_validate_patient_name_given(self, values: dict) -> None: field_location, elements_are_strings=True, max_length=5, - string_element_max_length=Constants.PERSON_NAME_ELEMENT_MAX_LENGTH, + string_element_max_length=Constants.GIVEN_NAME_ELEMENT_MAX_LENGTH, ) except (KeyError, IndexError, AttributeError): pass @@ -320,13 +321,13 @@ def pre_validate_patient_name_given(self, values: dict) -> None: def pre_validate_patient_name_family(self, values: dict) -> None: """ Pre-validate that, if a contained[?(@.resourceType=='Patient')].name[{index}].family (legacy CSV field name: - PERSON_SURNAME) exists, index dynamically determined then it is a non-empty string of maximum length - 35 characters + PERSON_SURNAME) exists, index dynamically determined then it is a non-empty string no longer than the + FAMILY_NAME_MAX_LENGTH value """ field_location = patient_name_family_field_location(values) try: field_value, _ = patient_and_practitioner_value_and_index(values, "family", "Patient") - PreValidation.for_string(field_value, field_location, max_length=Constants.PERSON_NAME_ELEMENT_MAX_LENGTH) + PreValidation.for_string(field_value, field_location, max_length=Constants.FAMILY_NAME_MAX_LENGTH) except (KeyError, IndexError, AttributeError): pass diff --git a/lambdas/shared/tests/test_common/test_immunization_pre_validator.py b/lambdas/shared/tests/test_common/test_immunization_pre_validator.py index e4842e964..88a701346 100644 --- a/lambdas/shared/tests/test_common/test_immunization_pre_validator.py +++ b/lambdas/shared/tests/test_common/test_immunization_pre_validator.py @@ -504,8 +504,11 @@ def test_pre_validate_patient_name_given_rejects_invalid_input(self): "contained[?(@.resourceType=='Patient')].name[0].given must be an array of maximum length 5", ), ( - ["Stringtoolongeruti olgkriahfyrtoiuhg"], - "contained[?(@.resourceType=='Patient')].name[0].given[0] must be 35 or fewer characters", + [ + "Stringtoolongtoolongtoolongtoolongt Stringtoolongtoolongtoolongtoolongt Stringtoolongtoolongtoolongto" + "olongt Stringtoolongtoolongtoolongtoolongt Stringtoolongtoolongtoolongtoolongt Oops" + ], + "contained[?(@.resourceType=='Patient')].name[0].given[0] must be 180 or fewer characters", ), ] @@ -546,7 +549,7 @@ def test_pre_validate_patient_name_family(self): self, field_location=patient_name_family_field_location(valid_json_data), valid_strings_to_test=["test", "Quitelongsurname", "Surnamewithjustthirtyfivecharacters"], - max_length=Constants.PERSON_NAME_ELEMENT_MAX_LENGTH, + max_length=Constants.FAMILY_NAME_MAX_LENGTH, invalid_length_strings_to_test=["Surnamethathasgotthirtysixcharacters"], ) From 9d3563ab64e852cc777b7a58b494c6a5981f3bf7 Mon Sep 17 00:00:00 2001 From: Daniel Yip Date: Fri, 9 Jan 2026 11:53:46 +0000 Subject: [PATCH 2/2] PR comment --- lambdas/shared/src/common/models/constants.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lambdas/shared/src/common/models/constants.py b/lambdas/shared/src/common/models/constants.py index 3dd690c1c..137b9c04c 100644 --- a/lambdas/shared/src/common/models/constants.py +++ b/lambdas/shared/src/common/models/constants.py @@ -54,7 +54,8 @@ class Constants: # VED-980 The PDS constraint is that the given name list entry has a maximum of 5 entries and each item may be a # maximum of 35 characters. Due to batch limitations, all entries are concatenated into one string. Therefore, the - # Imms FHIR API team agreed to use a more lenient figure given the nature of data flows we handle + # Imms FHIR API team agreed to use a more lenient figure given the nature of data flows we handle. i.e 5 * 35 + + # some extra wriggle room i.e. spaces between. GIVEN_NAME_ELEMENT_MAX_LENGTH = 180 COMPLETED_STATUS = "completed"