-
Notifications
You must be signed in to change notification settings - Fork 2
Resource Comparison and Diff Utilities #145
Copy link
Copy link
Open
Labels
Description
Summary
Add comprehensive resource comparison and diff utilities to enable testing, debugging, and change tracking for FHIR resources.
Background
When working with FHIR resources in development, testing, and production environments, developers frequently need to:
- Compare resources for equality beyond simple Python object comparison
- Generate meaningful diffs showing what changed between resource versions
- Validate transformations and mappings produce expected results
- Debug issues in resource processing pipelines
Proposed Solution
1. Resource Comparison
from fhircraft.fhir.utils import compare_resources, ResourceComparison
# Deep comparison with options
result = compare_resources(
resource1,
resource2,
ignore_fields=["meta.lastUpdated", "id"],
ignore_extensions=True,
semantic_comparison=True # Compare semantically equivalent values
)
assert result.is_equal
print(result.differences) # List of specific differences- Resource Diff Generation
from fhircraft.fhir.utils import generate_diff
diff = generate_diff(original_patient, updated_patient)
print(diff.to_text()) # Human-readable diff
print(diff.to_json()) # Structured diff format
print(diff.to_fhirpatch()) # FHIR Patch format (maybe?)Reactions are currently unavailable