@@ -1157,6 +1157,40 @@ def test_validate_content_format_invalid_code_for_unstructured_document():
11571157 }
11581158
11591159
1160+ def test_validate_content_format_invalid_code_for_structured_document ():
1161+ validator = DocumentReferenceValidator ()
1162+ document_ref_data = load_document_reference_json ("Y05868-736253002-Valid" )
1163+
1164+ document_ref_data ["content" ][0 ]["attachment" ]["contentType" ] = "application/json"
1165+
1166+ document_ref_data ["content" ][0 ]["format" ] = {
1167+ "system" : "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode" ,
1168+ "code" : "urn:nhs-ic:record-contact" ,
1169+ "display" : "Contact details (HTTP Unsecured)" ,
1170+ }
1171+
1172+ result = validator .validate (document_ref_data )
1173+
1174+ assert result .is_valid is False
1175+ assert result .resource .id == "Y05868-99999-99999-999999"
1176+ assert len (result .issues ) == 1
1177+ assert result .issues [0 ].model_dump (exclude_none = True ) == {
1178+ "severity" : "error" ,
1179+ "code" : "business-rule" ,
1180+ "details" : {
1181+ "coding" : [
1182+ {
1183+ "system" : "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1" ,
1184+ "code" : "UNPROCESSABLE_ENTITY" ,
1185+ "display" : "Unprocessable Entity" ,
1186+ }
1187+ ]
1188+ },
1189+ "diagnostics" : "Invalid content format code: urn:nhs-ic:record-contact format code must be 'urn:nhs-ic:structured' for Structured Document attachments." ,
1190+ "expression" : ["content[0].format.code" ],
1191+ }
1192+
1193+
11601194def test_validate_content_format_invalid_code_for_contact_details ():
11611195 validator = DocumentReferenceValidator ()
11621196 document_ref_data = load_document_reference_json ("Y05868-736253002-Valid" )
@@ -1353,23 +1387,25 @@ def test_validate_content_invalid_content_type():
13531387 }
13541388 ]
13551389 },
1356- "diagnostics" : "Invalid contentType: invalid/type. Must be 'application/pdf' or 'text/html'" ,
1390+ "diagnostics" : "Invalid contentType: invalid/type. Must be 'application/pdf', 'text/html' or 'application/fhir+json '" ,
13571391 "expression" : ["content[0].attachment.contentType" ],
13581392 }
13591393
13601394
13611395@pytest .mark .parametrize (
1362- "format_code, format_display" ,
1396+ "content_type, format_code, format_display" ,
13631397 [
1364- ("urn:nhs-ic:record-contact" , "Contact details (HTTP Unsecured)" ),
1365- ("urn:nhs-ic:unstructured" , "Unstructured Document" ),
1398+ ("text/html" , "urn:nhs-ic:record-contact" , "Contact details (HTTP Unsecured)" ),
1399+ ("application/pdf" , "urn:nhs-ic:unstructured" , "Unstructured Document" ),
1400+ ("application/json+fhir" , "urn:nhs-ic:structured" , "Structured Document" ),
13661401 ],
13671402)
1368- def test_validate_nrl_format_code_valid_match (format_code , format_display ):
1403+ def test_validate_nrl_format_code_valid_match (
1404+ content_type , format_code , format_display
1405+ ):
13691406 validator = DocumentReferenceValidator ()
13701407 document_ref_data = load_document_reference_json ("Y05868-736253002-Valid" )
1371- if format_code == "urn:nhs-ic:record-contact" :
1372- document_ref_data ["content" ][0 ]["attachment" ]["contentType" ] = "text/html"
1408+ document_ref_data ["content" ][0 ]["attachment" ]["contentType" ] = content_type
13731409
13741410 document_ref_data ["content" ][0 ]["format" ] = {
13751411 "system" : "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode" ,
@@ -1383,27 +1419,34 @@ def test_validate_nrl_format_code_valid_match(format_code, format_display):
13831419
13841420
13851421@pytest .mark .parametrize (
1386- "format_code, format_display, expected_display" ,
1422+ "content_type, format_code, format_display, expected_display" ,
13871423 [
13881424 (
1425+ "application/pdf" ,
13891426 "urn:nhs-ic:unstructured" ,
13901427 "Contact details (HTTP Unsecured)" ,
13911428 "Unstructured Document" ,
13921429 ),
13931430 (
1431+ "text/html" ,
13941432 "urn:nhs-ic:record-contact" ,
13951433 "Unstructured Document" ,
13961434 "Contact details (HTTP Unsecured)" ,
13971435 ),
1436+ (
1437+ "application/fhir+json" ,
1438+ "urn:nhs-ic:structured" ,
1439+ "Unstructured Document" ,
1440+ "Structured Document" ,
1441+ ),
13981442 ],
13991443)
14001444def test_validate_nrl_format_code_display_mismatch (
1401- format_code , format_display , expected_display
1445+ content_type , format_code , format_display , expected_display
14021446):
14031447 validator = DocumentReferenceValidator ()
14041448 document_ref_data = load_document_reference_json ("Y05868-736253002-Valid" )
1405- if format_code == "urn:nhs-ic:record-contact" :
1406- document_ref_data ["content" ][0 ]["attachment" ]["contentType" ] = "text/html"
1449+ document_ref_data ["content" ][0 ]["attachment" ]["contentType" ] = content_type
14071450
14081451 document_ref_data ["content" ][0 ]["format" ] = {
14091452 "system" : "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode" ,
0 commit comments