Skip to content

Commit a34691d

Browse files
NRL-1554 Lowercase matching for extensions, remove unused code, add root_location to retrieval mechanism error
1 parent 04a0be5 commit a34691d

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

layer/nrlf/core/tests/test_validators.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,3 +1727,56 @@ def test_validate_two_content_with_different_retrieval_mechanisms():
17271727

17281728
assert result.is_valid is True
17291729
assert len(result.issues) == 0
1730+
1731+
1732+
def test_validate_content_retrieval_lowercase_urls():
1733+
"""Test that the extension is recognised when 'RetrievalMechanism' is in lowercase and throws an error for mismatching the URL case."""
1734+
validator = DocumentReferenceValidator()
1735+
document_ref_data = load_document_reference_json("Y05868-736253002-Valid")
1736+
1737+
document_ref_data["content"][0]["extension"] = [
1738+
{
1739+
"url": "https://fhir.nhs.uk/england/structuredefinition/extension-england-retrievalmechanism",
1740+
"valueCodeableConcept": {
1741+
"coding": [
1742+
{
1743+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-RetrievalMechanism",
1744+
"code": "Direct",
1745+
"display": "Direct",
1746+
}
1747+
]
1748+
},
1749+
},
1750+
{
1751+
"url": "https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability",
1752+
"valueCodeableConcept": {
1753+
"coding": [
1754+
{
1755+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability",
1756+
"code": "static",
1757+
"display": "Static",
1758+
}
1759+
]
1760+
},
1761+
},
1762+
]
1763+
1764+
with pytest.raises(ParseError) as exc_info:
1765+
validator.validate(document_ref_data)
1766+
1767+
assert len(exc_info.value.issues) == 1
1768+
assert exc_info.value.issues[0].model_dump(exclude_none=True) == {
1769+
"severity": "error",
1770+
"code": "invalid",
1771+
"details": {
1772+
"coding": [
1773+
{
1774+
"system": "https://fhir.nhs.uk/CodeSystem/Spine-ErrorOrWarningCode",
1775+
"code": "BAD_REQUEST",
1776+
"display": "Bad request",
1777+
}
1778+
]
1779+
},
1780+
"diagnostics": "Invalid content retrieval extension (content[0].extension[0].url: Input should be 'https://fhir.nhs.uk/England/StructureDefinition/Extension-England-RetrievalMechanism', see: https://fhir.nhs.uk/England/ValueSet/England-RetrievalMechanism)",
1781+
"expression": ["content[0].extension[0].url"],
1782+
}

layer/nrlf/core/validators.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ def _has_valid_extensions(self, extensions, i):
531531
content_retrieval_count = 0
532532

533533
for extension in extensions:
534-
if "ContentStability" in str(extension):
534+
if "contentstability" in str(extension).lower():
535535
content_stability_count += 1
536-
elif "RetrievalMechanism" in str(extension):
536+
elif "retrievalmechanism" in str(extension).lower():
537537
content_retrieval_count += 1
538538

539539
if content_stability_count != 1:
@@ -555,10 +555,10 @@ def _has_valid_extensions(self, extensions, i):
555555
return False
556556

557557
for j, extension in enumerate(extensions):
558-
if "ContentStability" in str(extension):
558+
if "contentstability" in str(extension).lower():
559559
if not self._validate_content_stability_extension(extension, i, j):
560560
return False
561-
elif "RetrievalMechanism" in str(extension):
561+
elif "retrievalmechanism" in str(extension).lower():
562562
if not self._validate_retrieval_mechanism_extension(extension, i, j):
563563
return False
564564

@@ -590,13 +590,12 @@ def _validate_retrieval_mechanism_extension(self, extension, i, j):
590590
try:
591591
RetrievalMechanismExtension.model_validate(extension.model_dump())
592592
except ValidationError as exc:
593-
for error in exc.errors():
594-
error["loc"] = ("content", i, "extension", j) + error["loc"]
595593
raise ParseError.from_validation_error(
596594
exc,
597595
details=SpineErrorConcept.from_code("BAD_REQUEST"),
598596
msg="Invalid content retrieval extension",
599597
value_set="https://fhir.nhs.uk/England/ValueSet/England-RetrievalMechanism",
598+
root_location=("content", i, "extension", j),
600599
) from None
601600
coding = extension.valueCodeableConcept.coding[0]
602601
expected_retrieval_display = CONTENT_RETRIEVAL_CODE_MAP.get(coding.code)

0 commit comments

Comments
 (0)