@@ -43,43 +43,50 @@ def test_process_search_params_checks_patient_identifier_format(self):
4343 }
4444 )
4545
46- def test_process_search_params_whitelists_immunization_target (self ):
47- mock_redis_key = "RSV"
48- self .mock_redis .hkeys .return_value = [mock_redis_key ]
46+ def test_process_search_params_raises_error_when_all_immunization_targets_invalid (self ):
47+ self .mock_redis .hkeys .return_value = ["RSV" ]
4948 self .mock_redis_getter .return_value = self .mock_redis
5049
5150 with self .assertRaises (ParameterExceptionError ) as e :
5251 validate_and_retrieve_search_params (
5352 {
5453 self .patient_identifier_key : ["https://fhir.nhs.uk/Id/nhs-number|9000000009" ],
55- self .immunization_target_key : [
56- "FLU" ,
57- "COVID" ,
58- "NOT-A-REAL-VALUE" ,
59- ],
54+ self .immunization_target_key : ["NOT-A-REAL-VALUE" ],
6055 }
6156 )
62- self .assertEqual (
63- str (e .exception ), f"-immunization.target must be one or more of the following: { mock_redis_key } "
57+ self .assertEqual (str (e .exception ), "-immunization.target must be one or more of the following: RSV" )
58+
59+ def test_process_search_params_filters_invalid_immunization_targets_and_returns_valid_plus_invalid_list (self ):
60+ self .mock_redis .hkeys .return_value = ["RSV" , "FLU" , "COVID" ]
61+ self .mock_redis_getter .return_value = self .mock_redis
62+
63+ result = validate_and_retrieve_search_params (
64+ {
65+ self .patient_identifier_key : ["https://fhir.nhs.uk/Id/nhs-number|9000000009" ],
66+ self .immunization_target_key : ["FLU" , "COVID" , "NOT-A-REAL-VALUE" ],
67+ }
6468 )
69+ self .assertCountEqual (result .params .immunization_targets , {"FLU" , "COVID" })
70+ self .assertCountEqual (result .invalid_immunization_targets , ["NOT-A-REAL-VALUE" ])
6571
6672 def test_process_search_params_immunization_target (self ):
6773 mock_redis_key = "RSV"
6874 self .mock_redis .hkeys .return_value = [mock_redis_key ]
6975 self .mock_redis_getter .return_value = self .mock_redis
70- params = validate_and_retrieve_search_params (
76+ result = validate_and_retrieve_search_params (
7177 {
7278 self .patient_identifier_key : ["https://fhir.nhs.uk/Id/nhs-number|9000000009" ],
7379 self .immunization_target_key : ["RSV" ],
7480 }
7581 )
7682
77- self .assertIsNotNone (params )
83+ self .assertIsNotNone (result .params )
84+ self .assertEqual (result .invalid_immunization_targets , [])
7885
7986 def test_search_params_date_from_must_be_before_date_to (self ):
8087 self .mock_redis .hkeys .return_value = ["RSV" ]
8188 self .mock_redis_getter .return_value = self .mock_redis
82- params = validate_and_retrieve_search_params (
89+ result = validate_and_retrieve_search_params (
8390 {
8491 self .patient_identifier_key : ["https://fhir.nhs.uk/Id/nhs-number|9000000009" ],
8592 self .immunization_target_key : ["RSV" ],
@@ -88,9 +95,9 @@ def test_search_params_date_from_must_be_before_date_to(self):
8895 }
8996 )
9097
91- self .assertIsNotNone (params )
98+ self .assertIsNotNone (result . params )
9299
93- params = validate_and_retrieve_search_params (
100+ result = validate_and_retrieve_search_params (
94101 {
95102 self .patient_identifier_key : ["https://fhir.nhs.uk/Id/nhs-number|9000000009" ],
96103 self .immunization_target_key : ["RSV" ],
@@ -99,7 +106,7 @@ def test_search_params_date_from_must_be_before_date_to(self):
99106 }
100107 )
101108
102- self .assertIsNotNone (params )
109+ self .assertIsNotNone (result . params )
103110
104111 with self .assertRaises (ParameterExceptionError ) as e :
105112 _ = validate_and_retrieve_search_params (
@@ -149,7 +156,7 @@ def test_process_search_params_dedupes_immunization_targets_and_respects_include
149156 self .mock_redis .hkeys .return_value = ["RSV" , "FLU" ]
150157 self .mock_redis_getter .return_value = self .mock_redis
151158
152- params = validate_and_retrieve_search_params (
159+ result = validate_and_retrieve_search_params (
153160 {
154161 self .patient_identifier_key : ["https://fhir.nhs.uk/Id/nhs-number|9000000009" ],
155162 self .immunization_target_key : ["RSV" , "RSV" , "FLU" ],
@@ -158,11 +165,11 @@ def test_process_search_params_dedupes_immunization_targets_and_respects_include
158165 )
159166
160167 # immunization targets should be deduped and preserve valid entries
161- self .assertIsInstance (params .immunization_targets , set )
162- self .assertCountEqual (params .immunization_targets , {"RSV" , "FLU" })
168+ self .assertIsInstance (result . params .immunization_targets , set )
169+ self .assertCountEqual (result . params .immunization_targets , {"RSV" , "FLU" })
163170
164171 # include should be returned as provided
165- self .assertEqual (params .include , "immunization:patient" )
172+ self .assertEqual (result . params .include , "immunization:patient" )
166173
167174 def test_process_search_params_raises_date_errors (self ):
168175 """When multiple date-related errors occur they should be returned together."""
0 commit comments