@@ -14,16 +14,15 @@ def setUp(self):
1414 validation_folder = Path (__file__ ).resolve ().parent
1515 self .FHIRFilePath = validation_folder / "sample_data/vaccination.json"
1616 self .schemaFilePath = validation_folder / "test_schemas/test_schema.json"
17+ self .SchemaFile = parse_test_file (self .schemaFilePath )
18+ self .fhir_resources = parse_test_file (self .FHIRFilePath )
1719
1820 def test_fhir_validation (self ):
1921 start = time .time ()
20-
21- SchemaFile = parse_test_file (self .schemaFilePath )
22- self .fhir_resources = parse_test_file (self .FHIRFilePath )
2322 fhir_parser = Mock ()
2423 fhir_parser .extract_field_value .return_value = "2025-11-06T12:00:00Z"
2524
26- validator = Validator (SchemaFile )
25+ validator = Validator (self . SchemaFile )
2726 error_list = validator .validate_fhir (self .fhir_resources , True , True , True )
2827 error_report = build_error_report (
2928 "25a8cc4d-1875-4191-ac6d-2d63a0ebc64b" , fhir_parser , error_list
@@ -45,3 +44,16 @@ def test_fhir_validation(self):
4544 end = time .time ()
4645 print ("Time Taken : " )
4746 print (end - start )
47+
48+ def test_fhir_validation_fail (self ):
49+ """Test validation failure when a required field is missing or invalid."""
50+ # Create an invalid FHIR resource by removing a required key
51+ self .fhir_resources ["contained" ][0 ]["identifier" ][0 ]["value" ] = ""
52+
53+ fhir_parser = Mock ()
54+ fhir_parser .extract_field_value .return_value = None
55+
56+ validator = Validator (self .SchemaFile )
57+ error_list = validator .validate_fhir (self .fhir_resources , True , True , True )
58+ self .assertGreater (len (error_list ), 0 , "Expected at least one validation error" )
59+ self .assertTrue (validator .has_validation_failed (error_list ))
0 commit comments