Skip to content

Commit 0be0f57

Browse files
NRL-1554 Remove check for empty content extension as it is checked in pydantic, add relevant tests
1 parent e4ad92d commit 0be0f57

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

layer/nrlf/core/tests/test_pydantic_errors.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,31 @@ def test_validate_missing_display_from_coding_where_mandatory():
439439
"diagnostics": "Failed to parse DocumentReference resource (context.practiceSetting.coding[0].display: Field required)",
440440
"expression": ["context.practiceSetting.coding[0].display"],
441441
}
442+
443+
444+
def test_validate_content_no_content_extension():
445+
validator = DocumentReferenceValidator()
446+
document_ref_data = load_document_reference_json("Y05868-736253002-Valid")
447+
448+
document_ref_data["content"][0].pop("extension")
449+
450+
with pytest.raises(ParseError) as error:
451+
validator.validate(document_ref_data)
452+
453+
exc = error.value
454+
assert len(exc.issues) == 1
455+
assert exc.issues[0].model_dump(exclude_none=True) == {
456+
"severity": "error",
457+
"code": "invalid",
458+
"details": {
459+
"coding": [
460+
{
461+
"system": "https://fhir.nhs.uk/CodeSystem/Spine-ErrorOrWarningCode",
462+
"code": "BAD_REQUEST",
463+
"display": "Bad request",
464+
}
465+
]
466+
},
467+
"diagnostics": "Failed to parse DocumentReference resource (content[0].extension: Field required)",
468+
"expression": ["content[0].extension"],
469+
}

layer/nrlf/core/validators.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -514,15 +514,6 @@ def _validate_content_extension(self, model: DocumentReference):
514514
logger.debug("Validating extension")
515515

516516
for i, content in enumerate(model.content):
517-
if not content.extension:
518-
self.result.add_error(
519-
issue_code="business-rule",
520-
error_code="UNPROCESSABLE_ENTITY",
521-
diagnostics="Invalid content extension: Extension must have at least one value",
522-
field=f"content[{i}].extension",
523-
)
524-
return
525-
526517
if not self._has_valid_extensions(content.extension, i):
527518
return
528519

tests/features/producer/createDocumentReference-failure.feature

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,3 +1044,48 @@ Feature: Producer - createDocumentReference - Failure Scenarios
10441044
"expression": ["DocumentReference"]
10451045
}
10461046
"""
1047+
1048+
Scenario: RetrievalMechanism extension is empty
1049+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
1050+
And the organisation 'TSTCUS' is authorised to access pointer types:
1051+
| system | value |
1052+
| http://snomed.info/sct | 736253002 |
1053+
When producer 'TSTCUS' requests creation of a DocumentReference with default test values except 'content' is:
1054+
"""
1055+
"content": [
1056+
{
1057+
"attachment": {
1058+
"contentType": "application/pdf",
1059+
"url": "https://example.org/my-doc.pdf"
1060+
},
1061+
"format": {
1062+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode",
1063+
"code": "urn:nhs-ic:unstructured",
1064+
"display": "Unstructured Document"
1065+
},
1066+
"extension": []
1067+
}
1068+
]
1069+
"""
1070+
Then the response status code is 400
1071+
And the response is an OperationOutcome with 1 issue
1072+
And the OperationOutcome contains the issue:
1073+
"""
1074+
{
1075+
"severity": "error",
1076+
"code": "invalid",
1077+
"details": {
1078+
"coding": [
1079+
{
1080+
"system": "https://fhir.nhs.uk/CodeSystem/Spine-ErrorOrWarningCode",
1081+
"code": "MESSAGE_NOT_WELL_FORMED",
1082+
"display": "Message not well formed"
1083+
}
1084+
]
1085+
},
1086+
"diagnostics": "Request body could not be parsed (DocumentReference: Value error, The following fields are empty: content[0].extension)",
1087+
"expression": [
1088+
"DocumentReference"
1089+
]
1090+
}
1091+
"""

0 commit comments

Comments
 (0)