|
7 | 7 | from nrlf.consumer.fhir.r4.model import RequestQueryCategory |
8 | 8 | from nrlf.core.codes import SpineErrorConcept |
9 | 9 | from nrlf.core.constants import ( |
| 10 | + ATTACHMENT_CONTENT_TYPES, |
10 | 11 | CATEGORY_ATTRIBUTES, |
| 12 | + CONTENT_FORMAT_CODE_MAP, |
11 | 13 | ODS_SYSTEM, |
12 | 14 | PRACTICE_SETTING_VALUE_SET_URL, |
13 | 15 | REQUIRED_CREATE_FIELDS, |
@@ -483,6 +485,21 @@ def _validate_content_format(self, model: DocumentReference): |
483 | 485 | diagnostics=f"Invalid content format code: {content.format.code} format code must be 'urn:nhs-ic:unstructured' for Unstructured Document attachments.", |
484 | 486 | field=f"content[{i}].format.code", |
485 | 487 | ) |
| 488 | + elif ( |
| 489 | + content.attachment.contentType |
| 490 | + in { |
| 491 | + "application/json", |
| 492 | + "application/fhir+json", |
| 493 | + "application/json+fhir", |
| 494 | + } |
| 495 | + and content.format.code != "urn:nhs-ic:structured" |
| 496 | + ): |
| 497 | + self.result.add_error( |
| 498 | + issue_code="business-rule", |
| 499 | + error_code="UNPROCESSABLE_ENTITY", |
| 500 | + diagnostics=f"Invalid content format code: {content.format.code} format code must be 'urn:nhs-ic:structured' for Structured Document attachments.", |
| 501 | + field=f"content[{i}].format.code", |
| 502 | + ) |
486 | 503 |
|
487 | 504 | def _validate_content_extension(self, model: DocumentReference): |
488 | 505 | """ |
@@ -613,28 +630,23 @@ def _validate_practiceSetting(self, model: DocumentReference): |
613 | 630 |
|
614 | 631 | def _validate_content(self, model: DocumentReference): |
615 | 632 | """ |
616 | | - Validate that the contentType is present and is either 'application/pdf' or 'text/html'. |
| 633 | + Validate that the contentType is present and supported. |
617 | 634 | """ |
618 | 635 | logger.log(LogReference.VALIDATOR001, step="content") |
619 | 636 |
|
620 | | - format_code_display_map = { |
621 | | - "urn:nhs-ic:record-contact": "Contact details (HTTP Unsecured)", |
622 | | - "urn:nhs-ic:unstructured": "Unstructured Document", |
623 | | - } |
624 | | - |
625 | 637 | for i, content in enumerate(model.content): |
626 | | - if content.attachment.contentType not in ["application/pdf", "text/html"]: |
| 638 | + if content.attachment.contentType not in ATTACHMENT_CONTENT_TYPES: |
627 | 639 | self.result.add_error( |
628 | 640 | issue_code="business-rule", |
629 | 641 | error_code="UNPROCESSABLE_ENTITY", |
630 | | - diagnostics=f"Invalid contentType: {content.attachment.contentType}. Must be 'application/pdf' or 'text/html'", |
| 642 | + diagnostics=f"Invalid contentType: {content.attachment.contentType}. Must be 'application/pdf', 'text/html' or 'application/fhir+json'", |
631 | 643 | field=f"content[{i}].attachment.contentType", |
632 | 644 | ) |
633 | 645 |
|
634 | 646 | # Validate NRLFormatCode |
635 | 647 | format_code = content.format.code |
636 | 648 | format_display = content.format.display |
637 | | - expected_display = format_code_display_map.get(format_code) |
| 649 | + expected_display = CONTENT_FORMAT_CODE_MAP.get(format_code) |
638 | 650 | if expected_display and format_display != expected_display: |
639 | 651 | self.result.add_error( |
640 | 652 | issue_code="business-rule", |
|
0 commit comments