@@ -419,66 +419,45 @@ def test_validate_category_too_many_category():
419419 }
420420
421421
422- # TODO: Parameterize this test and the one below
423- def test_validate_category_coding_display_mismatch_care_plan ():
422+ @pytest .mark .parametrize (
423+ "category_code, category_display" ,
424+ [
425+ (category_str .split ("|" )[1 ], display_dict ["display" ])
426+ for category_str , display_dict in CATEGORY_ATTRIBUTES .items ()
427+ ],
428+ )
429+ def test_validate_category_coding_display_mismatch (category_code : str , category_display : str ):
424430 validator = DocumentReferenceValidator ()
425431 document_ref_data = load_document_reference_json ("Y05868-736253002-Valid" )
426432
427433 document_ref_data ["category" ][0 ] = {
428434 "coding" : [
429435 {
430436 "system" : "http://snomed.info/sct" ,
431- "code" : "734163000" ,
437+ "code" : category_code ,
432438 "display" : "some random display name" ,
433439 }
434440 ]
435441 }
436442
437- result = validator .validate (document_ref_data )
438-
439- assert result .is_valid is False
440- assert result .resource .id == "Y05868-99999-99999-999999"
441- assert len (result .issues ) == 1
442- assert result .issues [0 ].model_dump (exclude_none = True ) == {
443- "severity" : "error" ,
444- "code" : "value" ,
445- "details" : {
443+ # Find the type string that matches the type code to avoid that error
444+ category_str = f"http://snomed.info/sct|{ category_code } "
445+ matching_type_str = next (
446+ (type_str for type_str in TYPE_CATEGORIES if TYPE_CATEGORIES [type_str ] == category_str ), None
447+ )
448+ if matching_type_str :
449+ type_parts = matching_type_str .split ("|" )
450+ type_system = type_parts [0 ]
451+ type_code = type_parts [1 ]
452+ document_ref_data ["type" ] = {
446453 "coding" : [
447454 {
448- "system" : "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1" ,
449- "code" : "INVALID_RESOURCE" ,
450- "display" : "Invalid validation of resource" ,
455+ "system" : type_system ,
456+ "code" : type_code ,
457+ "display" : TYPE_ATTRIBUTES [ matching_type_str ][ "display" ] ,
451458 }
452459 ]
453- },
454- "diagnostics" : "category code '734163000' must have a display value of 'Care plan'" ,
455- "expression" : ["category[0].coding[0].display" ],
456- }
457-
458-
459- def test_validate_category_coding_display_mismatch_observations ():
460- validator = DocumentReferenceValidator ()
461- document_ref_data = load_document_reference_json ("Y05868-736253002-Valid" )
462-
463- document_ref_data ["type" ] = {
464- "coding" : [
465- {
466- "system" : "http://snomed.info/sct" ,
467- "code" : "1363501000000100" ,
468- "display" : "Royal College of Physicians NEWS2 (National Early Warning Score 2) chart" ,
469- }
470- ]
471- }
472-
473- document_ref_data ["category" ][0 ] = {
474- "coding" : [
475- {
476- "system" : "http://snomed.info/sct" ,
477- "code" : "1102421000000108" ,
478- "display" : "some random display name" ,
479- }
480- ]
481- }
460+ }
482461
483462 result = validator .validate (document_ref_data )
484463
@@ -497,7 +476,7 @@ def test_validate_category_coding_display_mismatch_observations():
497476 }
498477 ]
499478 },
500- "diagnostics" : "category code '1102421000000108 ' must have a display value of 'Observations '" ,
479+ "diagnostics" : f "category code '{ category_code } ' must have a display value of '{ category_display } '" ,
501480 "expression" : ["category[0].coding[0].display" ],
502481 }
503482
@@ -758,8 +737,7 @@ def test_validate_type_coding_display_mismatch(type_str: str, display: str):
758737 ]
759738 }
760739
761- # match type to category to avoid getting that error
762- # TODO: Discuss in review if I should just ignore the error that happens to simplify test
740+ # Find the category string that matches the category code to avoid that error
763741 category_str = TYPE_CATEGORIES [type_str ]
764742 category_parts = category_str .split ("|" )
765743 category_system = category_parts [0 ]
@@ -778,6 +756,7 @@ def test_validate_type_coding_display_mismatch(type_str: str, display: str):
778756
779757 assert result .is_valid is False
780758 assert result .resource .id == "Y05868-99999-99999-999999"
759+ assert len (result .issues ) == 1
781760 assert result .issues [0 ].model_dump (exclude_none = True ) == {
782761 "severity" : "error" ,
783762 "code" : "value" ,
0 commit comments