@@ -101,6 +101,29 @@ def test_create_immunization_post_validation_error(self):
101101 self .assertTrue (expected_msg in error .exception .message )
102102 self .mock_repo .create_immunization .assert_not_called ()
103103
104+ def test_create_immunization_invalid_patient_identifier_system (self ):
105+ """it should reject create when the patient identifier system is not the NHS number URI"""
106+
107+ imms = create_covid_immunization_dict_no_id ()
108+ patient = next (resource for resource in imms ["contained" ] if resource ["resourceType" ] == "Patient" )
109+ patient ["identifier" ][0 ]["system" ] = "https://1234/Id/nhs-number"
110+ patient ["identifier" ][0 ]["value" ] = "ABCD"
111+
112+ with self .assertRaises (CustomValidationError ) as error :
113+ self .pre_validate_fhir_service .create_immunization (
114+ immunization = imms ,
115+ supplier_system = "test_supplier" ,
116+ vax_type = "test_vax" ,
117+ table = self .mock_table ,
118+ imms_pk = None ,
119+ )
120+
121+ self .assertIn (
122+ "contained[?(@.resourceType=='Patient')].identifier[0].system must equal" ,
123+ error .exception .message ,
124+ )
125+ self .mock_repo .create_immunization .assert_not_called ()
126+
104127 def test_create_immunization_duplicate_site_snomed_still_rejected_for_batch (self ):
105128 """it should keep batch validation unchanged for duplicate site SNOMED codings"""
106129
@@ -192,6 +215,29 @@ def test_update_immunization_post_validation_error(self):
192215 self .assertTrue (expected_msg in error .exception .message )
193216 self .mock_repo .update_immunization .assert_not_called ()
194217
218+ def test_update_immunization_invalid_patient_identifier_system (self ):
219+ """it should reject update when the patient identifier system is not the NHS number URI"""
220+
221+ imms = create_covid_immunization_dict_no_id ()
222+ patient = next (resource for resource in imms ["contained" ] if resource ["resourceType" ] == "Patient" )
223+ patient ["identifier" ][0 ]["system" ] = "https://1234/Id/nhs-number"
224+ patient ["identifier" ][0 ]["value" ] = "ABCD"
225+
226+ with self .assertRaises (CustomValidationError ) as error :
227+ self .pre_validate_fhir_service .update_immunization (
228+ immunization = imms ,
229+ supplier_system = "test_supplier" ,
230+ vax_type = "test_vax" ,
231+ table = self .mock_table ,
232+ imms_pk = None ,
233+ )
234+
235+ self .assertIn (
236+ "contained[?(@.resourceType=='Patient')].identifier[0].system must equal" ,
237+ error .exception .message ,
238+ )
239+ self .mock_repo .update_immunization .assert_not_called ()
240+
195241
196242class TestDeleteImmunizationBatchService (unittest .TestCase ):
197243 def setUp (self ):
0 commit comments