Skip to content

Commit 05db712

Browse files
authored
VED-789: Gen Validation Schema (#916)
* build validation engine and refactor fhir and batch journey * refactor csv incoming data to dict * add test for validation and resolve reviews
1 parent 2d83929 commit 05db712

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3230
-16
lines changed

lambdas/shared/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
TEST_ENV := @PYTHONPATH=src:tests:src/common
2+
13
test:
2-
@PYTHONPATH=src:../ python -m unittest discover -s tests -p "test_*.py" -v
4+
$(TEST_ENV) python -m unittest discover -s tests -p "test_*.py" -v
5+
6+
test-validator:
7+
$(TEST_ENV) python -m unittest discover -s tests/test_common/validator -p "test_*.py" -v
38

49
test-list:
510
@PYTHONPATH=src:tests python -m unittest discover -s tests -p "test_*.py" --verbose | grep test_

lambdas/shared/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ coverage = "^7.10.7"
3232

3333
[build-system]
3434
requires = ["poetry-core"]
35-
build-backend = "poetry.core.masonry.api"
35+
build-backend = "poetry.core.masonry.api"

lambdas/shared/src/common/aws_lambda_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum
2-
from typing import Any, Dict
2+
from typing import Any
33

44

55
class AwsEventType(Enum):
@@ -10,7 +10,7 @@ class AwsEventType(Enum):
1010

1111

1212
class AwsLambdaEvent:
13-
def __init__(self, event: Dict[str, Any]):
13+
def __init__(self, event: dict[str, Any]):
1414
self.event_source = None
1515
self.event_type = AwsEventType.UNKNOWN
1616
self.event_source = event.get("eventSource")

lambdas/shared/src/common/cache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from typing import Optional
32

43

54
class Cache:
@@ -19,7 +18,7 @@ def put(self, key: str, value: dict):
1918
self.cache[key] = value
2019
self._overwrite()
2120

22-
def get(self, key: str) -> Optional[dict]:
21+
def get(self, key: str) -> dict | None:
2322
return self.cache.get(key, None)
2423

2524
def delete(self, key: str):

lambdas/shared/src/common/log_firehose.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import json
22

3-
from common.clients import (
4-
firehose_client,
5-
logger,
6-
)
3+
from common.clients import firehose_client, logger
74

85

96
# Not keen on including blocking calls in function code to forward log data to Splunk (via Firehose)

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

Whitespace-only changes.

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

Whitespace-only changes.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from enum import IntEnum, StrEnum
2+
3+
4+
# Used for error report messages in DQ Reporter to categorize error levels
5+
class ErrorLevels(IntEnum):
6+
CRITICAL_ERROR = 0
7+
WARNING = 1
8+
NOTIFICATION = 2
9+
10+
11+
MESSAGES = {
12+
ErrorLevels.CRITICAL_ERROR: "Critical Validation Error",
13+
ErrorLevels.WARNING: "Non-Critical Validation Error",
14+
ErrorLevels.NOTIFICATION: "Quality Issue Found",
15+
}
16+
17+
18+
# Constants for error report messages used in Expression Checker
19+
class MessageLabel(StrEnum):
20+
EXPECTED_LABEL = "Expected- "
21+
FOUND_LABEL = "Found- "
22+
VALUE_MISMATCH_MSG = "Value does not equal expected value, "
23+
24+
25+
class ExceptionLevels(IntEnum):
26+
UNEXPECTED_EXCEPTION = 0
27+
VALUE_CHECK_FAILED = 1
28+
HEADER_CHECK_FAILED = 2
29+
RECORD_LENGTH_CHECK_FAILED = 3
30+
VALUE_PREDICATE_FALSE = 4
31+
RECORD_CHECK_FAILED = 5
32+
RECORD_PREDICATE_FALSE = 6
33+
UNIQUE_CHECK_FAILED = 7
34+
ASSERT_CHECK_FAILED = 8
35+
FINALLY_ASSERT_CHECK_FAILED = 9
36+
PARSING_ERROR = 10
37+
PARENT_FAILED = 11
38+
KEY_CHECK_FAILED = 12
39+
40+
41+
MESSAGES = {
42+
ExceptionLevels.UNEXPECTED_EXCEPTION: "Unexpected exception [%s]: %s",
43+
ExceptionLevels.VALUE_CHECK_FAILED: "Value Check Failed",
44+
ExceptionLevels.HEADER_CHECK_FAILED: "Header Check Failed",
45+
ExceptionLevels.RECORD_LENGTH_CHECK_FAILED: "Record Length Check Failed",
46+
ExceptionLevels.RECORD_CHECK_FAILED: "Record Check Failed",
47+
ExceptionLevels.VALUE_PREDICATE_FALSE: "Value Predicate False",
48+
ExceptionLevels.RECORD_PREDICATE_FALSE: "Record Predicate False",
49+
ExceptionLevels.UNIQUE_CHECK_FAILED: "Unique Check Failed",
50+
ExceptionLevels.ASSERT_CHECK_FAILED: "Assert Check Failed",
51+
ExceptionLevels.FINALLY_ASSERT_CHECK_FAILED: "Finally Assert Check Failed",
52+
ExceptionLevels.PARSING_ERROR: "Parsing Error",
53+
ExceptionLevels.PARENT_FAILED: "Parent Failed",
54+
ExceptionLevels.KEY_CHECK_FAILED: "Key Check Failed",
55+
}
56+
57+
58+
class DataType(StrEnum):
59+
FHIR = "FHIR"
60+
FHIRJSON = "FHIRJSON"
61+
CSV = "CSV"
62+
CSVROW = "CSVROW"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error_report = {
2+
"eventId": "",
3+
"validationDate": "",
4+
"validated": "true",
5+
"results": {
6+
"totalErrors": 0,
7+
"completeness": {"errors": 0, "fields": []},
8+
"consistency": {"errors": 0, "fields": []},
9+
"validity": {"errors": 0, "fields": []},
10+
"timeliness_processed": 0,
11+
},
12+
}

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

Whitespace-only changes.

0 commit comments

Comments
 (0)