Skip to content

Commit 96c3cc4

Browse files
committed
NRL-1051 validate imaging values
1 parent 54b957f commit 96c3cc4

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

api/producer/processTransaction/process_transaction_bundle.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ def create_document_reference(
245245
metadata: ConnectionMetadata,
246246
repository: DocumentPointerRepository,
247247
body: DocumentReference,
248-
is_imaging_profile: bool = False,
249248
) -> Response:
250249

251250
logger.log(LogReference.PROCREATE000)
@@ -255,7 +254,7 @@ def create_document_reference(
255254
body.id = f"{id_prefix}-{uuid4()}"
256255

257256
validator = DocumentReferenceValidator()
258-
result = validator.validate(body, is_imaging_profile)
257+
result = validator.validate(body)
259258

260259
if not result.is_valid:
261260
logger.log(LogReference.PROCREATE002)
@@ -336,7 +335,6 @@ def handler(
336335
requested_profile = (
337336
body.meta.profile[0].root if body.meta and body.meta.profile else None
338337
)
339-
is_imaging_profile = False
340338
if requested_profile and not requested_profile.endswith(
341339
"profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.UnContained.Comprehensive.ProvideBundle"
342340
):
@@ -396,15 +394,14 @@ def handler(
396394
for entry in entries:
397395
try:
398396
if requested_profile:
399-
is_imaging_profile = True
400397
document_reference = _convert_document_reference(
401398
entry.resource, requested_profile
402399
)
403400
else:
404401
document_reference = DocumentReference(**(entry.resource))
405402

406403
create_response = create_document_reference(
407-
metadata, repository, document_reference, is_imaging_profile
404+
metadata, repository, document_reference
408405
)
409406
responses.append(create_response)
410407
except OperationOutcomeError as e:

api/producer/processTransaction/tests/test_process_transaction_bundle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_create_single_mhds_document_reference_imaging_format_with_transaction_h
224224

225225
raw_doc_ref.pop("author")
226226
raw_doc_ref.pop("context")
227-
raw_doc_ref["content"][0]["attachment"]["contentType"] = "application/dicom"
227+
raw_doc_ref["content"][0]["attachment"]["contentType"] = "application/dicom+fhir"
228228
raw_doc_ref["content"][0]["format"][
229229
"system"
230230
] = "https://profiles.ihe.net/fhir/ihe.formatcode.fhir/1.2.0/ValueSet-formatcode.html"

layer/nrlf/core/validators.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ def parse(cls, data: Dict[str, Any]):
118118
msg="Failed to parse DocumentReference resource",
119119
) from None
120120

121-
def validate(
122-
self, data: Dict[str, Any] | DocumentReference, is_imaging: bool = False
123-
):
121+
def validate(self, data: Dict[str, Any] | DocumentReference):
124122
"""
125123
Validate the document reference
126124
"""
@@ -139,7 +137,7 @@ def validate(
139137
self._validate_category(resource)
140138
self._validate_author(resource)
141139
self._validate_type_category_mapping(resource)
142-
self._validate_content(resource, is_imaging)
140+
self._validate_content(resource)
143141
self._validate_content_format(resource)
144142
self._validate_content_extension(resource)
145143
self._validate_practiceSetting(resource)
@@ -637,22 +635,27 @@ def _validate_practiceSetting(self, model: DocumentReference):
637635
)
638636
return
639637

640-
def _validate_content(self, model: DocumentReference, is_imaging: bool = False):
638+
def _validate_content(self, model: DocumentReference):
641639
"""
642640
Validate that the contentType is present and is either 'application/pdf' or 'text/html'.
643641
"""
644-
if is_imaging:
645-
return
646642

647643
logger.log(LogReference.VALIDATOR001, step="content")
648644

649645
format_code_display_map = {
650646
"urn:nhs-ic:record-contact": "Contact details (HTTP Unsecured)",
651647
"urn:nhs-ic:unstructured": "Unstructured Document",
648+
"direct": "Direct",
649+
"apiplatform": "API Platform",
652650
}
653651

654652
for i, content in enumerate(model.content):
655-
if content.attachment.contentType not in ["application/pdf", "text/html"]:
653+
if content.attachment.contentType not in [
654+
"application/pdf",
655+
"text/html",
656+
"application/dicom+fhir",
657+
"application/fhir+json",
658+
]:
656659
self.result.add_error(
657660
issue_code="value",
658661
error_code="INVALID_RESOURCE",

0 commit comments

Comments
 (0)