Skip to content

Commit 9105a20

Browse files
committed
Updated
1 parent 024bc85 commit 9105a20

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

delta_backend/src/Converter.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,17 @@
1414
get_valid_address,
1515
)
1616

17-
# Converter variables
18-
FHIRData = ""
19-
SchemaFile = {}
20-
imms = []
21-
Converted = {}
22-
2317

2418
# Converter
2519
class Converter:
2620

2721
def __init__(self, fhir_data):
28-
self.FHIRData = fhir_data # Store JSON data directly
29-
self.SchemaFile = ConversionLayout.ConvertLayout
30-
self.ErrorRecords = []
31-
22+
self.imms = []
23+
self.converted = {}
24+
self.error_records = []
25+
self.fhir_data = fhir_data # Store JSON data directly
26+
self.schema_file = ConversionLayout.ConvertLayout
27+
3228
# Utility logs tailored to conveter class errors
3329
def _log_error(self,e,code=ExceptionMessages.UNEXPECTED_EXCEPTION):
3430
message = str(e) # if a simple string message was passed
@@ -38,8 +34,8 @@ def _log_error(self,e,code=ExceptionMessages.UNEXPECTED_EXCEPTION):
3834
"message": message
3935
}
4036

41-
# if not any(existing.get("message") == message for existing in self.ErrorRecords):
42-
self.ErrorRecords.append(error_obj)
37+
# if not any(existing.get("message") == message for existing in self.error_records):
38+
self.error_records.append(error_obj)
4339
return error_obj
4440

4541
# create a FHIR parser - uses fhir json data from delta
@@ -78,20 +74,20 @@ def _convertData(self, ConversionValidate, expression, dataParser, json_data):
7874
if "address" in FHIRFieldName or "performer" in FHIRFieldName or "name" in FHIRFieldName:
7975
convertedData = self.extract_patient_details(json_data, FlatFieldName)
8076
if convertedData is not None:
81-
Converted[FlatFieldName] = convertedData
77+
self.converted[FlatFieldName] = convertedData
8278

8379
# run the conversion against the data
8480
def runConversion(self, json_data, summarise=False, report_unexpected_exception=True):
8581
try:
86-
dataParser = self._getFHIRParser(self.FHIRData)
82+
dataParser = self._getFHIRParser(self.fhir_data)
8783
except Exception as e:
8884
if report_unexpected_exception:
8985
message = "FHIR Parser Unexpected exception [%s]: %s" % (e.__class__.__name__, e)
9086
error = self._log_error(message,code=ExceptionMessages.UNEXPECTED_EXCEPTION)
9187
return error
9288

9389
try:
94-
schemaParser = self._getSchemaParser(self.SchemaFile)
90+
schemaParser = self._getSchemaParser(self.schema_file)
9591
except Exception as e:
9692
if report_unexpected_exception:
9793
message = "Schema Parser Unexpected exception [%s]: %s" % (e.__class__.__name__, e)
@@ -120,21 +116,21 @@ def runConversion(self, json_data, summarise=False, report_unexpected_exception=
120116

121117
# Collect and store any errors from ConversionChecker
122118
all_errors = ConversionValidate.get_error_records()
123-
self.ErrorRecords.extend(all_errors)
119+
self.error_records.extend(all_errors)
124120

125121
# Add CONVERSION_ERRORS as the 35th field
126122
error_records = self.getErrorRecords()
127123
if error_records:
128124
error_summary = error_records
129125
else:
130126
error_summary = ""
131-
Converted["CONVERSION_ERRORS"] = error_summary
127+
self.converted["CONVERSION_ERRORS"] = error_summary
132128

133-
imms.append(Converted)
134-
return imms
129+
self.imms.append(self.converted)
130+
return self.imms
135131

136132
def getErrorRecords(self):
137-
return self.ErrorRecords
133+
return self.error_records
138134

139135
def extract_patient_details(self, json_data, FlatFieldName):
140136
if not hasattr(self, "_cached_values"):

delta_backend/src/SchemaParser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class SchemaParser:
88
Conversions = {}
99

1010
def parseSchema(self, schemaFile): # changed to accept JSON better for cache
11-
self.SchemaFile = schemaFile
12-
self.Conversions = self.SchemaFile["conversions"]
11+
self.schema_file = schemaFile
12+
self.Conversions = self.schema_file["conversions"]
1313

1414
def conversionCount(self):
1515
count = 0

delta_backend/tests/test_convert_to_flat_json.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
request_json_data = ValuesForTests.json_data
2727
with patch.dict("os.environ", MOCK_ENV_VARS):
2828
from delta import handler, Converter
29-
from Converter import imms
3029

3130
class TestRecordError(unittest.TestCase):
3231
def test_fields_and_str(self):
@@ -94,6 +93,15 @@ def setUp(self):
9493
},
9594
],
9695
)
96+
self.logger_info_patcher = patch("logging.Logger.info")
97+
self.mock_logger_info = self.logger_info_patcher.start()
98+
99+
self.logger_exception_patcher = patch("logging.Logger.exception")
100+
self.mock_logger_exception = self.logger_exception_patcher.start()
101+
102+
def tearDown(self):
103+
self.logger_exception_patcher.stop()
104+
self.logger_info_patcher.stop()
97105

98106
@staticmethod
99107
def get_event(event_name="INSERT", operation="operation", supplier="EMIS"):
@@ -130,7 +138,6 @@ def assert_dynamodb_record(self, operation_flag, items, expected_values, expecte
130138

131139
def test_fhir_converter_json_direct_data(self):
132140
"""it should convert fhir json data to flat json"""
133-
imms.clear()
134141
json_data = json.dumps(ValuesForTests.json_data)
135142

136143
start = time.time()
@@ -159,7 +166,6 @@ def test_fhir_converter_json_error_scenario(self):
159166
error_test_cases = [ErrorValuesForTests.missing_json, ErrorValuesForTests.json_dob_error]
160167

161168
for test_case in error_test_cases:
162-
imms.clear()
163169
json_data = json.dumps(test_case)
164170

165171
start = time.time()
@@ -169,12 +175,6 @@ def test_fhir_converter_json_error_scenario(self):
169175

170176
flatJSON = json.dumps(FlatFile)
171177

172-
# if len(flatJSON) > 0:
173-
# print(flatJSON)
174-
# Fix error handling
175-
# expected_imms = ErrorValuesForTests.get_expected_imms_error_output
176-
# self.assertEqual(flatJSON, expected_imms)
177-
178178
errorRecords = FHIRConverter.getErrorRecords()
179179

180180
if len(errorRecords) > 0:
@@ -196,7 +196,6 @@ def test_handler_imms_convert_to_flat_json(self):
196196

197197
for test_case in expected_action_flags:
198198
with self.subTest(test_case["Operation"]):
199-
imms.clear()
200199

201200
event = self.get_event(operation=test_case["Operation"])
202201

0 commit comments

Comments
 (0)