Skip to content

Commit 5c51cc2

Browse files
committed
resolve error report
1 parent 12f8fe4 commit 5c51cc2

File tree

5 files changed

+37
-117
lines changed

5 files changed

+37
-117
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from common.validator.error_report.dq_reporter import DQReporter
22
from src.common.validator.constants.enums import ErrorLevels
33
from src.common.validator.error_report.record_error import ErrorReport
4+
from src.common.validator.parsers.paser_interface import PaserInterface
45

56

67
# Collect and add error record to the list
@@ -28,7 +29,15 @@ def check_error_record_for_fail(expression_identifier: str, error_records: list[
2829
return False
2930

3031

31-
def build_error_report(event_id: str, data_parser: dict, error_records: list[ErrorReport]) -> dict:
32-
occurrence_date_time = data_parser.extract_field_value("occurrenceDateTime")
32+
def build_error_report(event_id: str, data_parser: PaserInterface, error_records: list[ErrorReport]) -> dict:
33+
if data_parser.get_data_format() == "fhir":
34+
occurrence_date_time = data_parser.extract_field_value("occurrenceDateTime")
35+
else:
36+
occurrence_date_time = data_parser.extract_field_value("DATE_AND_TIME")
37+
3338
dq_reporter = DQReporter()
3439
return dq_reporter.generate_error_report(event_id, occurrence_date_time, error_records)
40+
41+
42+
def has_validation_failed(error_records: list[ErrorReport]) -> bool:
43+
return any(er.error_level == ErrorLevels.CRITICAL_ERROR for er in error_records)

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def extract_field_values(self, field_path: str) -> dict:
1717
def get_data_format(self) -> str:
1818
pass
1919

20+
@abstractmethod
21+
def _get_field_path_from_schema(self, schema_expressions: list[dict], common_key: str, data_format: str) -> str:
22+
pass
23+
2024

2125
class FHIRInterface(PaserInterface):
2226
def __init__(self, fhir_data: dict):
@@ -30,6 +34,13 @@ def extract_field_values(self, field_path) -> list[str]:
3034
fhir_value = self.fhir_parser.get_fhir_value_list(field_path)
3135
return fhir_value
3236

37+
def _get_field_path_from_schema(self, schema_expressions: list[dict], common_key: str, data_format: str) -> str:
38+
data_format = data_format.lower()
39+
for expr in schema_expressions:
40+
if expr.get("fieldNameFlat") == common_key or expr.get("fieldNameFHIR") == common_key:
41+
return expr.get("fieldNameFlat") if data_format == "batch" else expr.get("fieldNameFHIR")
42+
return ""
43+
3344

3445
class BatchInterface(PaserInterface):
3546
def __init__(self, csv_row: str, csv_header: str):
@@ -42,3 +53,10 @@ def get_data_format(self) -> str:
4253
def extract_field_values(self, field_path) -> list[str]:
4354
csv_value = self.csv_line_parser.get_key_value(field_path)
4455
return csv_value
56+
57+
def _get_field_path_from_schema(self, schema_expressions: list[dict], common_key: str, data_format: str) -> str:
58+
data_format = data_format.lower()
59+
for expression in schema_expressions:
60+
if expression.get("fieldNameFlat") == common_key or expression.get("fieldNameFHIR") == common_key:
61+
return expression.get("fieldNameFlat") if data_format == "batch" else expression.get("fieldNameFHIR")
62+
return ""

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ def run_validation(
135135
message = f"Data Parser Unexpected exception [{e.__class__.__name__}]: {e}"
136136
return [ErrorReport(code=0, message=message)]
137137

138-
schema_parser = self.schema_parser.parse_schema(self.schema_file)
138+
try:
139+
schema_parser = self.schema_parser.parse_schema(self.schema_file)
140+
except Exception as e:
141+
if report_unexpected_exception:
142+
message = f"Schema Parser Unexpected exception [{e.__class__.__name__}]: {e}"
143+
return [ErrorReport(code=0, message=message)]
144+
139145
expression_validator = ExpressionChecker(data_parser, summarise, report_unexpected_exception)
140146
expressions_in_schema = schema_parser.get_expressions()
141147

lambdas/shared/tests/test_common/validator/sample_data/vaccination2.json

Lines changed: 0 additions & 113 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class TestApplication(unittest.TestCase):
1313
def setUp(self):
1414
validation_folder = Path(__file__).resolve().parent
15-
self.FHIRFilePath = validation_folder / "sample_data/vaccination2.json"
15+
self.FHIRFilePath = validation_folder / "sample_data/vaccination.json"
1616
self.schemaFilePath = validation_folder / "test_schemas/test_schema.json"
1717

1818
def test_validation(self):

0 commit comments

Comments
 (0)