Skip to content

Commit da273a6

Browse files
authored
VED-980 Increased given name length constraint (#1102)
1 parent 734fca3 commit da273a6

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

lambdas/shared/src/common/models/constants.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ class Constants:
4848

4949
ALLOWED_CONTAINED_RESOURCES = {"Practitioner", "Patient"}
5050

51-
# As per Personal Demographics Service FHIR API, the maximum length of a given name element or surname is 35 chars.
52-
# Given name is a list with a maximum 5 elements. For more info see:
51+
# As per Personal Demographics Service (PDS) FHIR API, the maximum length of a family name is 35 characters:
5352
# https://digital.nhs.uk/developer/api-catalogue/personal-demographics-service-fhir#post-/Patient
54-
PERSON_NAME_ELEMENT_MAX_LENGTH = 35
53+
FAMILY_NAME_MAX_LENGTH = 35
54+
55+
# VED-980 The PDS constraint is that the given name list entry has a maximum of 5 entries and each item may be a
56+
# maximum of 35 characters. Due to batch limitations, all entries are concatenated into one string. Therefore, the
57+
# Imms FHIR API team agreed to use a more lenient figure given the nature of data flows we handle. i.e 5 * 35 +
58+
# some extra wriggle room i.e. spaces between.
59+
GIVEN_NAME_ELEMENT_MAX_LENGTH = 180
5560

5661
COMPLETED_STATUS = "completed"
5762
REINSTATED_RECORD_STATUS = "reinstated"

lambdas/shared/src/common/models/fhir_immunization_pre_validators.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ def pre_validate_patient_name(self, values: dict) -> None:
301301
def pre_validate_patient_name_given(self, values: dict) -> None:
302302
"""
303303
Pre-validate that, if contained[?(@.resourceType=='Patient')].name[{index}].given index dynamically determined
304-
(legacy CSV field name:PERSON_FORENAME) exists, then it is an array containing a single non-empty string
304+
(legacy CSV field name:PERSON_FORENAME) exists, then it is an array containing a maximum of 5 items an no items
305+
may exceed the GIVEN_NAME_ELEMENT_MAX_LENGTH value
305306
"""
306307
field_location = patient_name_given_field_location(values)
307308

@@ -312,21 +313,21 @@ def pre_validate_patient_name_given(self, values: dict) -> None:
312313
field_location,
313314
elements_are_strings=True,
314315
max_length=5,
315-
string_element_max_length=Constants.PERSON_NAME_ELEMENT_MAX_LENGTH,
316+
string_element_max_length=Constants.GIVEN_NAME_ELEMENT_MAX_LENGTH,
316317
)
317318
except (KeyError, IndexError, AttributeError):
318319
pass
319320

320321
def pre_validate_patient_name_family(self, values: dict) -> None:
321322
"""
322323
Pre-validate that, if a contained[?(@.resourceType=='Patient')].name[{index}].family (legacy CSV field name:
323-
PERSON_SURNAME) exists, index dynamically determined then it is a non-empty string of maximum length
324-
35 characters
324+
PERSON_SURNAME) exists, index dynamically determined then it is a non-empty string no longer than the
325+
FAMILY_NAME_MAX_LENGTH value
325326
"""
326327
field_location = patient_name_family_field_location(values)
327328
try:
328329
field_value, _ = patient_and_practitioner_value_and_index(values, "family", "Patient")
329-
PreValidation.for_string(field_value, field_location, max_length=Constants.PERSON_NAME_ELEMENT_MAX_LENGTH)
330+
PreValidation.for_string(field_value, field_location, max_length=Constants.FAMILY_NAME_MAX_LENGTH)
330331
except (KeyError, IndexError, AttributeError):
331332
pass
332333

lambdas/shared/tests/test_common/test_immunization_pre_validator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,11 @@ def test_pre_validate_patient_name_given_rejects_invalid_input(self):
504504
"contained[?(@.resourceType=='Patient')].name[0].given must be an array of maximum length 5",
505505
),
506506
(
507-
["Stringtoolongeruti olgkriahfyrtoiuhg"],
508-
"contained[?(@.resourceType=='Patient')].name[0].given[0] must be 35 or fewer characters",
507+
[
508+
"Stringtoolongtoolongtoolongtoolongt Stringtoolongtoolongtoolongtoolongt Stringtoolongtoolongtoolongto"
509+
"olongt Stringtoolongtoolongtoolongtoolongt Stringtoolongtoolongtoolongtoolongt Oops"
510+
],
511+
"contained[?(@.resourceType=='Patient')].name[0].given[0] must be 180 or fewer characters",
509512
),
510513
]
511514

@@ -546,7 +549,7 @@ def test_pre_validate_patient_name_family(self):
546549
self,
547550
field_location=patient_name_family_field_location(valid_json_data),
548551
valid_strings_to_test=["test", "Quitelongsurname", "Surnamewithjustthirtyfivecharacters"],
549-
max_length=Constants.PERSON_NAME_ELEMENT_MAX_LENGTH,
552+
max_length=Constants.FAMILY_NAME_MAX_LENGTH,
550553
invalid_length_strings_to_test=["Surnamethathasgotthirtysixcharacters"],
551554
)
552555

0 commit comments

Comments
 (0)