Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 3 additions & 35 deletions delta_backend/src/Converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
from SchemaParser import SchemaParser
from ConversionChecker import ConversionChecker
import ConversionLayout
from datetime import datetime
from Extractor import (
extract_person_names,
extract_practitioner_names,
extract_site_code,
get_patient,
get_valid_address,
)

# Converter variables
FHIRData = ""
Expand Down Expand Up @@ -42,7 +34,7 @@ def _getSchemaParser(self, schemafile):
return schemaParser

# Convert data against converter schema
def _convertData(self, ConversionValidate, expression, dataParser, json_data):
def _convertData(self, ConversionValidate, expression, dataParser):

FHIRFieldName = expression["fieldNameFHIR"]
FlatFieldName = expression["fieldNameFlat"]
Expand All @@ -62,13 +54,11 @@ def _convertData(self, ConversionValidate, expression, dataParser, json_data):
convertedData = ConversionValidate.convertData(
expressionType, expressionRule, FHIRFieldName, conversionValue
)
if "address" in FHIRFieldName or "performer" in FHIRFieldName or "name" in FHIRFieldName:
convertedData = self.extract_patient_details(json_data, FlatFieldName)
if convertedData is not None:
Converted[FlatFieldName] = convertedData

# run the conversion against the data
def runConversion(self, json_data, summarise=False, report_unexpected_exception=True):
def runConversion(self, summarise=False, report_unexpected_exception=True):
try:
dataParser = self._getFHIRParser(self.FHIRData)
except Exception as e:
Expand Down Expand Up @@ -107,32 +97,10 @@ def runConversion(self, json_data, summarise=False, report_unexpected_exception=
return p

for conversion in conversions:
rows = self._convertData(ConversionValidate, conversion, dataParser, json_data)
rows = self._convertData(ConversionValidate, conversion, dataParser)

imms.append(Converted)
return imms

def getErrorRecords(self):
return ErrorRecords

def extract_patient_details(self, json_data, FlatFieldName):
if not hasattr(self, "_cached_values"):
self._cached_values = {}

if not self._cached_values:
occurrence_time = datetime.strptime(json_data.get("occurrenceDateTime", ""), "%Y-%m-%dT%H:%M:%S%z")
patient = get_patient(json_data)
if not patient:
return None

self._cached_values = {
"PERSON_FORENAME": extract_person_names(patient, occurrence_time)[0],
"PERSON_SURNAME": extract_person_names(patient, occurrence_time)[1],
"PERSON_POSTCODE": get_valid_address(patient, occurrence_time),
"SITE_CODE": extract_site_code(json_data)[0],
"SITE_CODE_TYPE_URI": extract_site_code(json_data)[1],
"PERFORMING_PROFESSIONAL_FORENAME": extract_practitioner_names(json_data, occurrence_time)[0],
"PERFORMING_PROFESSIONAL_SURNAME": extract_practitioner_names(json_data, occurrence_time)[1]
}

return self._cached_values.get(FlatFieldName)
24 changes: 12 additions & 12 deletions delta_backend/src/ExceptionMessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


MESSAGES = {
UNEXPECTED_EXCEPTION: "Unexpected exception [%s]: %s",
VALUE_CHECK_FAILED: "Value check failed.",
HEADER_CHECK_FAILED: "Header check failed.",
RECORD_LENGTH_CHECK_FAILED: "Record length check failed.",
RECORD_CHECK_FAILED: "Record check failed.",
VALUE_PREDICATE_FALSE: "Value predicate returned false.",
RECORD_PREDICATE_FALSE: "Record predicate returned false.",
UNIQUE_CHECK_FAILED: "Unique check failed.",
ASSERT_CHECK_FAILED: "Assertion check failed.",
FINALLY_ASSERT_CHECK_FAILED: "Final assertion check failed.",
PARSING_ERROR: "Failed to parse data correctly.",
}
UNEXPECTED_EXCEPTION: 'Unexpected exception [%s]: %s',
VALUE_CHECK_FAILED: 'Value check failed.',
HEADER_CHECK_FAILED: 'Header check failed.',
RECORD_LENGTH_CHECK_FAILED: 'Record length check failed.',
RECORD_CHECK_FAILED: 'Record check failed.',
VALUE_PREDICATE_FALSE: 'Value predicate returned false.',
RECORD_PREDICATE_FALSE: 'Record predicate returned false.',
UNIQUE_CHECK_FAILED: 'Unique check failed.',
ASSERT_CHECK_FAILED: 'Assertion check failed.',
FINALLY_ASSERT_CHECK_FAILED: 'Final assertion check failed.',
PARSING_ERROR : 'Failed to parse data correctly.'
}
122 changes: 0 additions & 122 deletions delta_backend/src/Extractor.py

This file was deleted.

Loading
Loading