@@ -1360,3 +1360,73 @@ def test_validate_content_invalid_content_type():
13601360 "diagnostics" : "Invalid contentType: invalid/type. Must be 'application/pdf' or 'text/html'" ,
13611361 "expression" : ["content[0].attachment.contentType" ],
13621362 }
1363+
1364+
1365+ @pytest .mark .parametrize (
1366+ "format_code, format_display" ,
1367+ [
1368+ ("urn:nhs-ic:record-contact" , "Contact details (HTTP Unsecured)" ),
1369+ ("urn:nhs-ic:unstructured" , "Unstructured Document" ),
1370+ ],
1371+ )
1372+ def test_validate_nrl_format_code_valid_match (format_code , format_display ):
1373+ validator = DocumentReferenceValidator ()
1374+ document_ref_data = load_document_reference_json ("Y05868-736253002-Valid" )
1375+
1376+ document_ref_data ["content" ][0 ]["format" ] = {
1377+ "system" : "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode" ,
1378+ "code" : format_code ,
1379+ "display" : format_display ,
1380+ }
1381+
1382+ result = validator .validate (document_ref_data )
1383+
1384+ assert result .is_valid is True
1385+
1386+
1387+ @pytest .mark .parametrize (
1388+ "format_code, format_display, expected_display" ,
1389+ [
1390+ (
1391+ "urn:nhs-ic:unstructured" ,
1392+ "Contact details (HTTP Unsecured)" ,
1393+ "Unstructured Document" ,
1394+ ),
1395+ (
1396+ "urn:nhs-ic:record-contact" ,
1397+ "Unstructured Document" ,
1398+ "Contact details (HTTP Unsecured)" ,
1399+ ),
1400+ ],
1401+ )
1402+ def test_validate_nrl_format_code_display_mismatch (
1403+ format_code , format_display , expected_display
1404+ ):
1405+ validator = DocumentReferenceValidator ()
1406+ document_ref_data = load_document_reference_json ("Y05868-736253002-Valid" )
1407+
1408+ document_ref_data ["content" ][0 ]["format" ] = {
1409+ "system" : "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode" ,
1410+ "code" : format_code ,
1411+ "display" : format_display ,
1412+ }
1413+
1414+ result = validator .validate (document_ref_data )
1415+
1416+ assert result .is_valid is False
1417+ assert len (result .issues ) == 1
1418+ assert result .issues [0 ].model_dump (exclude_none = True ) == {
1419+ "severity" : "error" ,
1420+ "code" : "value" ,
1421+ "details" : {
1422+ "coding" : [
1423+ {
1424+ "system" : "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1" ,
1425+ "code" : "INVALID_RESOURCE" ,
1426+ "display" : "Invalid validation of resource" ,
1427+ }
1428+ ]
1429+ },
1430+ "diagnostics" : f"Invalid display for format code '{ format_code } '. Expected '{ expected_display } '" ,
1431+ "expression" : ["content[0].format.display" ],
1432+ }
0 commit comments