Specifying FHIR version when validating bundle #169
Answered
by
nazrulworld
davide-aloi
asked this question in
Q&A
-
Dear FHIR community. I have the following function to load a json and validate a FHIR bundle contained in it. def validate_fhir_bundle(json_file_path):
"""
Validate a FHIR Bundle from a JSON file and print validation errors.
Args:
json_file_path (str): Path to the JSON file containing the FHIR Bundle.
Returns:
bool: True if the Bundle is valid, False otherwise.
"""
import json
from fhir.resources.bundle import Bundle
from pydantic import ValidationError
try:
# Load JSON from file
with open(json_file_path, "r") as f:
bundle_json = json.load(f)
# Attempt to construct a Bundle object
bundle = Bundle(**bundle_json)
print("FHIR Bundle is valid.")
return True
except ValidationError as e:
print("FHIR Bundle validation failed.")
print("Validation Errors:")
for error in e.errors():
print(f"Field: {error['loc']}")
print(f"Error: {error['msg']}")
print(f"Type: {error['type']}")
print("-" * 40)
return False
except FileNotFoundError:
print(f"File not found: {json_file_path}")
return False
except json.JSONDecodeError:
print(f"Invalid JSON format in file: {json_file_path}")
return False I can't get my head around how to load a Subpackage so that I can specify which FHIR version to use. I was interested, for testing purposes, in validating synthea FHIR data. Thanks, |
Beta Was this translation helpful? Give feedback.
Answered by
nazrulworld
Jan 8, 2025
Replies: 1 comment 1 reply
-
Example import from subpackage |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
davide-aloi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example import from subpackage
from fhir.resources.R4B.bundle import Bundle