Skip to content

Commit c3d53ed

Browse files
committed
Resolve some Sonar warnings.
1 parent da51d71 commit c3d53ed

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

backend/src/models/obtain_field_value.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def patient_gender(imms: dict):
6666
def patient_address_postal_code(imms: dict):
6767
"""Obtains patient_address_postal_code value"""
6868
patient = get_contained_patient(imms)
69-
contained_patient_postalCode = [x for x in patient.get("address") if len(x.get("postalCode", "")) >= 1][0][
69+
contained_patient_postal_code = [x for x in patient.get("address") if len(x.get("postalCode", "")) >= 1][0][
7070
"postalCode"
7171
]
72-
return contained_patient_postalCode
72+
return contained_patient_postal_code
7373

7474
@staticmethod
7575
def organization_identifier_value(imms: dict):

backend/src/models/utils/validation_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def get_target_disease_codes(immunization: dict):
4949

5050
def convert_disease_codes_to_vaccine_type(
5151
disease_codes_input: list,
52-
) -> Union[str, None]:
52+
) -> str | None:
5353
"""
5454
Takes a list of disease codes and returns the corresponding vaccine type if found,
5555
otherwise raises a value error

backend/src/parameter_parser.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from models.errors import ParameterException
1212
from models.utils.generic_utils import nhs_number_mod11_check
1313

14+
ERROR_MESSAGE_DUPLICATED_PARAMETERS = 'Parameters may not be duplicated. Use commas for "or".'
15+
1416
ParamValue = list[str]
1517
ParamContainer = dict[str, ParamValue]
1618

@@ -161,7 +163,7 @@ def parse_multi_value_query_parameters(
161163
multi_value_query_params: dict[str, list[str]],
162164
) -> ParamContainer:
163165
if any([len(v) > 1 for k, v in multi_value_query_params.items()]):
164-
raise ParameterException('Parameters may not be duplicated. Use commas for "or".')
166+
raise ParameterException(ERROR_MESSAGE_DUPLICATED_PARAMETERS)
165167
params = [(k, split_and_flatten(v)) for k, v in multi_value_query_params.items()]
166168

167169
return dict(params)
@@ -175,7 +177,7 @@ def parse_body_params(aws_event: APIGatewayProxyEventV1) -> ParamContainer:
175177
parsed_body = parse_qs(decoded_body)
176178

177179
if any([len(v) > 1 for k, v in parsed_body.items()]):
178-
raise ParameterException('Parameters may not be duplicated. Use commas for "or".')
180+
raise ParameterException(ERROR_MESSAGE_DUPLICATED_PARAMETERS)
179181
items = dict((k, split_and_flatten(v)) for k, v in parsed_body.items())
180182
return items
181183
return {}
@@ -184,7 +186,7 @@ def parse_body_params(aws_event: APIGatewayProxyEventV1) -> ParamContainer:
184186
body_params = parse_body_params(aws_event)
185187

186188
if len(set(query_params.keys()) & set(body_params.keys())) > 0:
187-
raise ParameterException('Parameters may not be duplicated. Use commas for "or".')
189+
raise ParameterException(ERROR_MESSAGE_DUPLICATED_PARAMETERS)
188190

189191
parsed_params = {
190192
key: sorted(query_params.get(key, []) + body_params.get(key, []))

batch_processor_filter/src/batch_processor_filter_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def apply_filter(self, batch_file_created_event: BatchFileCreatedEvent) -> None:
6363
filename,
6464
)
6565
raise EventAlreadyProcessingForSupplierAndVaccTypeError(
66-
f"Batch event already processing for supplier: " f"{supplier} and vacc type: {vaccine_type}"
66+
f"Batch event already processing for supplier: {supplier} and vacc type: {vaccine_type}"
6767
)
6868

6969
self._batch_audit_repository.update_status(message_id, FileStatus.PROCESSING)

recordprocessor/src/batch_processor.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from send_to_kinesis import send_to_kinesis
2020
from clients import logger
2121
from file_level_validation import file_level_validation, file_is_empty, move_file
22-
from errors import NoOperationPermissions, InvalidHeaders
2322
from utils_for_recordprocessor import get_csv_content_dict_reader
2423
from typing import Optional
2524

@@ -35,11 +34,7 @@ def process_csv_to_fhir(incoming_message_body: dict) -> int:
3534
try:
3635
incoming_message_body["encoder"] = encoder
3736
interim_message_body = file_level_validation(incoming_message_body=incoming_message_body)
38-
except (
39-
InvalidHeaders,
40-
NoOperationPermissions,
41-
Exception,
42-
) as e: # pylint: disable=broad-exception-caught
37+
except Exception as e: # pylint: disable=broad-exception-caught
4338
logger.error(f"File level validation failed: {e}") # If the file is invalid, processing should cease
4439
return 0
4540

0 commit comments

Comments
 (0)