99from common .models .constants import Constants
1010from common .models .utils .generic_utils import nhs_number_mod11_check
1111from common .redis_client import get_redis_client
12- from models .errors import ParameterException
12+ from models .errors import ParameterExceptionError
1313
1414ERROR_MESSAGE_DUPLICATED_PARAMETERS = 'Parameters may not be duplicated. Use commas for "or".'
1515
@@ -48,20 +48,20 @@ def process_patient_identifier(identifier_params: ParamContainer) -> str:
4848 patient_identifier = patient_identifiers [0 ] if len (patient_identifiers ) == 1 else None
4949
5050 if patient_identifier is None :
51- raise ParameterException (f"Search parameter { patient_identifier_key } must have one value." )
51+ raise ParameterExceptionError (f"Search parameter { patient_identifier_key } must have one value." )
5252
5353 patient_identifier_parts = patient_identifier .split ("|" )
5454 identifier_system = patient_identifier_parts [0 ]
5555 if len (patient_identifier_parts ) != 2 or identifier_system != patient_identifier_system :
56- raise ParameterException (
56+ raise ParameterExceptionError (
5757 "patient.identifier must be in the format of "
5858 f'"{ patient_identifier_system } |{{NHS number}}" '
5959 f'e.g. "{ patient_identifier_system } |9000000009"'
6060 )
6161
6262 nhs_number = patient_identifier_parts [1 ]
6363 if not nhs_number_mod11_check (nhs_number ):
64- raise ParameterException ("Search parameter patient.identifier must be a valid NHS number." )
64+ raise ParameterExceptionError ("Search parameter patient.identifier must be a valid NHS number." )
6565
6666 return nhs_number
6767
@@ -75,11 +75,11 @@ def process_immunization_target(imms_params: ParamContainer) -> list[str]:
7575 vaccine_type for vaccine_type in set (imms_params .get (immunization_target_key , [])) if vaccine_type is not None
7676 ]
7777 if len (vaccine_types ) < 1 :
78- raise ParameterException (f"Search parameter { immunization_target_key } must have one or more values." )
78+ raise ParameterExceptionError (f"Search parameter { immunization_target_key } must have one or more values." )
7979
8080 valid_vaccine_types = get_redis_client ().hkeys (Constants .VACCINE_TYPE_TO_DISEASES_HASH_KEY )
8181 if any (x not in valid_vaccine_types for x in vaccine_types ):
82- raise ParameterException (
82+ raise ParameterExceptionError (
8383 f"immunization-target must be one or more of the following: { ', ' .join (valid_vaccine_types )} "
8484 )
8585
@@ -148,7 +148,7 @@ def process_search_params(params: ParamContainer) -> SearchParams:
148148 errors .append (f"Search parameter { date_from_key } must be before { date_to_key } " )
149149
150150 if errors :
151- raise ParameterException ("; " .join (errors ))
151+ raise ParameterExceptionError ("; " .join (errors ))
152152
153153 return SearchParams (patient_identifier , vaccine_types , date_from , date_to , include )
154154
@@ -163,7 +163,7 @@ def parse_multi_value_query_parameters(
163163 multi_value_query_params : dict [str , list [str ]],
164164 ) -> ParamContainer :
165165 if any (len (v ) > 1 for k , v in multi_value_query_params .items ()):
166- raise ParameterException (ERROR_MESSAGE_DUPLICATED_PARAMETERS )
166+ raise ParameterExceptionError (ERROR_MESSAGE_DUPLICATED_PARAMETERS )
167167 params = [(k , split_and_flatten (v )) for k , v in multi_value_query_params .items ()]
168168
169169 return dict (params )
@@ -177,7 +177,7 @@ def parse_body_params(aws_event: APIGatewayProxyEventV1) -> ParamContainer:
177177 parsed_body = parse_qs (decoded_body )
178178
179179 if any (len (v ) > 1 for k , v in parsed_body .items ()):
180- raise ParameterException (ERROR_MESSAGE_DUPLICATED_PARAMETERS )
180+ raise ParameterExceptionError (ERROR_MESSAGE_DUPLICATED_PARAMETERS )
181181 items = {k : split_and_flatten (v ) for k , v in parsed_body .items ()}
182182 return items
183183 return {}
@@ -186,7 +186,7 @@ def parse_body_params(aws_event: APIGatewayProxyEventV1) -> ParamContainer:
186186 body_params = parse_body_params (aws_event )
187187
188188 if len (set (query_params .keys ()) & set (body_params .keys ())) > 0 :
189- raise ParameterException (ERROR_MESSAGE_DUPLICATED_PARAMETERS )
189+ raise ParameterExceptionError (ERROR_MESSAGE_DUPLICATED_PARAMETERS )
190190
191191 parsed_params = {
192192 key : sorted (query_params .get (key , []) + body_params .get (key , []))
0 commit comments