Skip to content

Commit a11ee4c

Browse files
committed
resolve comments on typing and list return
1 parent e362177 commit a11ee4c

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

lambdas/shared/src/common/validator/parsers/base_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def __init__(self, fhir_data: dict):
2525
def get_data_format(self) -> str:
2626
return "fhir"
2727

28-
def extract_field_values(self, field_path) -> list[Any]:
29-
fhir_value = self.fhir_parser.get_fhir_value_list(field_path)
28+
def extract_field_values(self, field_path) -> Any:
29+
fhir_value = self.fhir_parser.get_fhir_value(field_path)
3030
return fhir_value
3131

3232

@@ -38,6 +38,6 @@ def __init__(self, csv_row: dict[str, str]):
3838
def get_data_format(self) -> str:
3939
return "batch"
4040

41-
def extract_field_values(self, field_path) -> list[str]:
41+
def extract_field_values(self, field_path) -> str:
4242
csv_value = self.csv_line_parser.get_key_value(field_path)
4343
return csv_value

lambdas/shared/src/common/validator/parsers/csv_line_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ def parse_csv_line(self, csv_row: dict[str, str]) -> None:
2424
self.csv_file_data = csv_row
2525

2626
# Retrieves the value of a specific column name as a list.
27-
def get_key_value(self, field_name: str) -> list[str]:
28-
retrieve_column_value = [self.csv_file_data[field_name]]
27+
def get_key_value(self, field_name: str) -> str:
28+
retrieve_column_value = self.csv_file_data[field_name]
2929
return retrieve_column_value

lambdas/shared/src/common/validator/validator.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
data_parser is the date parser object returned from the FetchParsers class which contains the data to be validated either fhir or csv
66
"""
77

8+
from typing import Optional
9+
810
from common.validator.constants.enums import MESSAGES, DataType, ErrorLevels, ExceptionLevels
911
from common.validator.error_report.error_reporter import add_error_record, check_error_record_for_fail
1012
from common.validator.error_report.record_error import ErrorReport
@@ -14,7 +16,7 @@
1416

1517

1618
class Validator:
17-
def __init__(self, schema_file=""):
19+
def __init__(self, schema_file: dict = {}):
1820
self.schema_file = schema_file
1921
self.schema_parser = SchemaParser()
2022

@@ -26,7 +28,7 @@ def _validate_expression(
2628
data_parser: BaseParser,
2729
error_records: list[ErrorReport],
2830
inc_header_in_row_count: bool,
29-
) -> ErrorReport | int:
31+
) -> Optional[int]:
3032
row = 2 if inc_header_in_row_count else 1
3133

3234
data_format = data_parser.get_data_format()
@@ -62,18 +64,17 @@ def _validate_expression(
6264
)
6365
return
6466

65-
for value in expression_values:
66-
try:
67-
error_record = expression_validator.validate_expression(
68-
expression_type, expression_rule, expression_fieldname, value, row
67+
try:
68+
error_record = expression_validator.validate_expression(
69+
expression_type, expression_rule, expression_fieldname, expression_values, row
70+
)
71+
if error_record is not None:
72+
add_error_record(
73+
error_records, error_record, expression_error_group, expression_name, expression_id, error_level
6974
)
70-
if error_record is not None:
71-
add_error_record(
72-
error_records, error_record, expression_error_group, expression_name, expression_id, error_level
73-
)
74-
except Exception:
75-
print(f"Exception validating expression {expression_id} on row {row}: {error_record}")
76-
row += 1
75+
except Exception:
76+
print(f"Exception validating expression {expression_id} on row {row}: {error_record}")
77+
row += 1
7778
return row
7879

7980
def validate_fhir(

lambdas/shared/tests/test_common/validator/test_csv_line_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_parse_normal(self):
1515
csv_parsers = CSVLineParser()
1616
csv_parsers.parse_csv_line(CSV_VALUES)
1717
self.assertEqual(csv_parsers.csv_file_data, CSV_VALUES)
18-
self.assertEqual(csv_parsers.get_key_value("NHS_NUMBER"), ["9000000009"])
18+
self.assertEqual(csv_parsers.get_key_value("NHS_NUMBER"), "9000000009")
1919

2020
def test_extra_values_ignored(self):
2121
"""
@@ -27,7 +27,7 @@ def test_extra_values_ignored(self):
2727
csv_parsers.csv_file_data,
2828
{"NHS_NUMBER": "9000000009", "PERSON_FORENAME": "Alex", "": "Trent"},
2929
)
30-
self.assertEqual(csv_parsers.get_key_value("PERSON_FORENAME"), ["Alex"])
30+
self.assertEqual(csv_parsers.get_key_value("PERSON_FORENAME"), "Alex")
3131

3232
def test_fewer_values_than_keys(self):
3333
"""

0 commit comments

Comments
 (0)