Skip to content

Commit 535e577

Browse files
committed
tidy
1 parent bbbe310 commit 535e577

File tree

4 files changed

+70
-53
lines changed

4 files changed

+70
-53
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def validateExpression(self, expression_type, rule, field_name, field_value, ro
7878
def _validate_datetime(self, rule, field_name, field_value, row):
7979
try:
8080
datetime.date.fromisoformat(field_value)
81+
# TODO - rule is not used - could be date only, date time, past, future etc
82+
if rule:
83+
pass
84+
8185
except RecordError as e:
8286
code = e.code if e.code is not None else ExceptionMessages.RECORD_CHECK_FAILED
8387
message = (e.message if e.message is not None

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

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Test application file
2+
from pathlib import Path
3+
from common.validator.validator import Validator
4+
import json
5+
import time
6+
import unittest
7+
8+
9+
class TestApplication(unittest.TestCase):
10+
def setUp(self):
11+
12+
fhir_data_folder = Path("./data")
13+
self.FHIRFilePath = fhir_data_folder / "vaccination.json"
14+
15+
self.schema_data_folder = Path("./schemas")
16+
self.schemaFilePath = self.schema_data_folder / "schema.json"
17+
18+
def test_validation(self):
19+
20+
DATA_TYPE = 'FHIR'
21+
22+
start = time.time()
23+
24+
# get the JSON of the schema, changed to cope with elasticache
25+
with open(self.schemaFilePath, 'r') as JSON:
26+
SchemaFile = json.load(JSON)
27+
28+
# get the FHIR Data as JSON
29+
with open(self.FHIRFilePath, 'r') as JSON:
30+
FHIRData = json.load(JSON)
31+
32+
validator = Validator(self.FHIRFilePath, FHIRData, SchemaFile, '', '',
33+
DATA_TYPE) # FHIR File Path not needed
34+
error_list = validator.run_validation(True, True, True)
35+
error_report = validator.build_error_report(
36+
'25a8cc4d-1875-4191-ac6d-2d63a0ebc64b') # include eventID if known
37+
38+
failed_validation = validator.has_validation_failed()
39+
40+
self.assertTrue(len(error_list) == 0,
41+
f"Validation failed. Errors: {error_list}")
42+
self.assertTrue(len(error_report['errors']) == 0,
43+
f"Validation failed. Errors: {error_report['errors']}")
44+
45+
self.assertFalse(failed_validation, 'Validation failed')
46+
47+
end = time.time()
48+
print('Time Taken : ')
49+
print(end - start)

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,26 @@
66

77

88
class TestParse(unittest.TestCase):
9-
def test_parse_fhir_file(self):
109

11-
fhir_data_folder = Path("./data")
12-
fhirFilePath = fhir_data_folder / "vaccination.json"
10+
def setUp(self):
11+
self.fhir_data_folder = Path("./data")
12+
13+
def test_parse_fhir_key_exists(self):
14+
15+
fhirFilePath = self.fhir_data_folder / "vaccination.json"
1316

1417
fhir_parser = FHIRParser()
1518
fhir_parser.parse_fhir_file(fhirFilePath)
1619
my_value = fhir_parser.get_key_value('vaccineCode|coding|0|code')
1720
self.assertEqual(my_value, ['42223111000001107'])
21+
22+
def test_parse_fhir_key_not_exists(self):
23+
24+
fhirFilePath = self.fhir_data_folder / "vaccination.json"
25+
26+
fhir_parser = FHIRParser()
27+
fhir_parser.parse_fhir_file(fhirFilePath)
28+
my_value = fhir_parser.get_key_value('vaccineCode|coding|1')
29+
self.assertEqual(my_value, [''])
30+
my_value = fhir_parser.get_key_value('vaccineCode|coding|1|codes')
31+
self.assertEqual(my_value, [''])

0 commit comments

Comments
 (0)