Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lambdas/shared/src/common/models/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ 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. i.e 5 * 35 +
# some extra wriggle room i.e. spaces between.
GIVEN_NAME_ELEMENT_MAX_LENGTH = 180

COMPLETED_STATUS = "completed"
REINSTATED_RECORD_STATUS = "reinstated"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -312,21 +313,21 @@ 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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
]

Expand Down Expand Up @@ -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"],
)

Expand Down