Support alternate validator / newer validation result property names and do additional aggregations
This commit is contained in:
+59
-12
@@ -29,7 +29,8 @@ class Validator():
|
|||||||
def fhir_operation_validate(self, resource_type, resource, send_pretty=False):
|
def fhir_operation_validate(self, resource_type, resource, send_pretty=False):
|
||||||
|
|
||||||
headers = {'User-Agent': 'Bulk FHIR validator',
|
headers = {'User-Agent': 'Bulk FHIR validator',
|
||||||
'Content-Type': 'application/fhir+json'}
|
'Content-Type': 'application/fhir+json',
|
||||||
|
'Accept': 'application/fhir+json'}
|
||||||
|
|
||||||
if send_pretty:
|
if send_pretty:
|
||||||
data = json.dumps(resource, indent=4)
|
data = json.dumps(resource, indent=4)
|
||||||
@@ -55,14 +56,21 @@ class Validator():
|
|||||||
df = pd.DataFrame()
|
df = pd.DataFrame()
|
||||||
|
|
||||||
for issue in outcome.get('issue'):
|
for issue in outcome.get('issue'):
|
||||||
diagnostics = issue.get('diagnostics')
|
diagnostics = issue.get('details').get('text')
|
||||||
|
if not diagnostics:
|
||||||
|
# fallback to (old?) HAPI validator properties
|
||||||
|
diagnostics = issue.get('diagnostics')
|
||||||
|
|
||||||
diagnostics_aggregated = remove_value_code(diagnostics)
|
diagnostics_aggregated = remove_value_code(diagnostics)
|
||||||
diagnostics_aggregated = remove_array_index(diagnostics_aggregated)
|
diagnostics_aggregated = remove_array_index(diagnostics_aggregated)
|
||||||
|
|
||||||
severity = issue.get('severity')
|
severity = issue.get('severity')
|
||||||
|
|
||||||
location = issue.get('location')
|
location = issue.get('expression')
|
||||||
|
if not location:
|
||||||
|
# fallback to (old?) HAPI validator properties
|
||||||
|
location = issue.get('location')
|
||||||
|
|
||||||
location = location[0]
|
location = location[0]
|
||||||
location_aggregated = remove_array_index(location)
|
location_aggregated = remove_array_index(location)
|
||||||
|
|
||||||
@@ -188,18 +196,45 @@ def get_next_page_url(bundle_dict):
|
|||||||
|
|
||||||
|
|
||||||
def remove_value_code(diagnostics):
|
def remove_value_code(diagnostics):
|
||||||
find_value_code = re.search(r"Coding provided \(.+?\#(.+?)\) is not in the value set", diagnostics)
|
|
||||||
|
|
||||||
if not find_value_code:
|
|
||||||
find_value_code = re.search(r"Unknown code in fragment CodeSystem \'.+?\#(.+?)\'", diagnostics)
|
|
||||||
|
|
||||||
|
find_value_code = re.search(r"Coding provided \(.+?\#(.+?)\)", diagnostics)
|
||||||
if find_value_code:
|
if find_value_code:
|
||||||
value_code = find_value_code.groups()[0]
|
value_code = find_value_code.groups()[0]
|
||||||
diagnostics_removed_valuecode = diagnostics.replace(value_code, "REMOVEDCODE")
|
diagnostics = diagnostics.replace(value_code, "REMOVEDCODE")
|
||||||
else:
|
|
||||||
diagnostics_removed_valuecode = diagnostics
|
|
||||||
|
|
||||||
return diagnostics_removed_valuecode
|
find_value_code = re.search(r"code provided \(.+?\#(.+?)\) was not found", diagnostics)
|
||||||
|
if find_value_code:
|
||||||
|
value_code = find_value_code.groups()[0]
|
||||||
|
diagnostics = diagnostics.replace(value_code, "REMOVEDCODE")
|
||||||
|
|
||||||
|
find_value_code = re.search(r"Unknown code in fragment CodeSystem \'.+?\#(.+?)\'", diagnostics)
|
||||||
|
if find_value_code:
|
||||||
|
value_code = find_value_code.groups()[0]
|
||||||
|
diagnostics = diagnostics.replace(value_code, "REMOVEDCODE")
|
||||||
|
|
||||||
|
find_value_code = re.search(r"code \`(.+?)\` was not found in the code system", diagnostics)
|
||||||
|
if find_value_code:
|
||||||
|
value_code = find_value_code.groups()[0]
|
||||||
|
diagnostics = diagnostics.replace(value_code, "REMOVEDCODE")
|
||||||
|
|
||||||
|
find_value_code = re.search(r"Invalid display \`(.+?)\` for code \`.+?\#(.+?)\`. A valid display is \`(.+?)\`", diagnostics)
|
||||||
|
if find_value_code:
|
||||||
|
value_display = find_value_code.groups()[0]
|
||||||
|
value_code = find_value_code.groups()[1]
|
||||||
|
valid_display = find_value_code.groups()[2]
|
||||||
|
diagnostics = diagnostics.replace(value_code, "REMOVEDCODE")
|
||||||
|
diagnostics = diagnostics.replace(value_display, "REMOVEDDISPLAY")
|
||||||
|
diagnostics = diagnostics.replace(valid_display, "REMOVEDVALIDDISPLAY")
|
||||||
|
|
||||||
|
find_value_code = re.search(r"Invalid display \`(.+?)\` for code \`.+?\#(.+?)\`", diagnostics)
|
||||||
|
if find_value_code:
|
||||||
|
value_display = find_value_code.groups()[0]
|
||||||
|
value_code = find_value_code.groups()[1]
|
||||||
|
diagnostics = diagnostics.replace(value_code, "REMOVEDCODE")
|
||||||
|
diagnostics = diagnostics.replace(value_display, "REMOVEDDISPLAY")
|
||||||
|
|
||||||
|
return diagnostics
|
||||||
|
|
||||||
|
|
||||||
def remove_array_index(diagnostics):
|
def remove_array_index(diagnostics):
|
||||||
@@ -256,7 +291,13 @@ def render_validation_outcome(resource, outcome, resource_url=None, do_print_lin
|
|||||||
summary_html = ''
|
summary_html = ''
|
||||||
|
|
||||||
for issue in issues_sorted:
|
for issue in issues_sorted:
|
||||||
location_element = issue['location'][0]
|
|
||||||
|
location_element = issue.get('expression')
|
||||||
|
|
||||||
|
if not location_element:
|
||||||
|
# Fallback to old(?) HAPI validator properties
|
||||||
|
location_element = issue['location'][0]
|
||||||
|
|
||||||
location_line = select_location_line(issue)
|
location_line = select_location_line(issue)
|
||||||
|
|
||||||
match issue['severity']:
|
match issue['severity']:
|
||||||
@@ -285,8 +326,14 @@ def render_validation_outcome(resource, outcome, resource_url=None, do_print_lin
|
|||||||
|
|
||||||
issue_html += '</small><br>'
|
issue_html += '</small><br>'
|
||||||
|
|
||||||
|
|
||||||
|
diagnostics = issue.get('details').get('text')
|
||||||
|
if not diagnostics:
|
||||||
|
# fallback to (old?) HAPI validator properties
|
||||||
|
diagnostics = issue.get('diagnostics')
|
||||||
|
|
||||||
issue_html += f'{issue["severity"]} for element <i><b>{location_element}</b></i> (beginning at line ' + str(
|
issue_html += f'{issue["severity"]} for element <i><b>{location_element}</b></i> (beginning at line ' + str(
|
||||||
location_line) + f'):<br><b>{issue["diagnostics"]}</b>'
|
location_line) + f'):<br><b>{diagnostics}</b>'
|
||||||
|
|
||||||
issue_html += '</li></span>'
|
issue_html += '</li></span>'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user