fix: reject duplicate resource ids in FHIR Bundle assembler#557
fix: reject duplicate resource ids in FHIR Bundle assembler#557gitcommit90 wants to merge 2 commits into
Conversation
to_bundle builds reference_map keyed by ResourceType/id. When two resources share the same resourceType and id, the second silently overwrites the first, corrupting internal cross-references. Detect the collision and raise a clear ValueError naming the colliding key. Resources without an id remain valid (unreferenceable).
maziyarpanahi
left a comment
There was a problem hiding this comment.
Thank you @gitcommit90. I reviewed this against #530 / OM-340.
The implementation matches the issue intent: duplicate ResourceType/id keys are rejected before the reference map can silently overwrite a target, the error names the colliding key, resources without an id remain valid/unreferenceable, and same-id resources of different FHIR types are still allowed. The docstring now records the duplicate-id contract.
I did not need to change the branch code. I copied the labels from #530 onto the PR.
Verification on the current PR checkout:
PYTHONPATH=/private/tmp/openmed-pr-557 /Users/maziyar/Developer/openmed/.venv/bin/python -m pytest tests/unit/clinical/test_fhir_bundle.py -q-> 17 passed/Users/maziyar/Developer/openmed/.venv/bin/ruff check openmed/clinical/exporters/fhir/bundle.py tests/unit/clinical/test_fhir_bundle.py-> passed/Users/maziyar/Developer/openmed/.venv/bin/ruff format --check openmed/clinical/exporters/fhir/bundle.py tests/unit/clinical/test_fhir_bundle.py-> passed
The branch is mergeable with no conflicts; GitHub has not attached hosted checks to this head commit yet, so I verified the touched behavior locally.
…licate-resource-ids # Conflicts: # openmed/clinical/exporters/fhir/bundle.py
|
Thank you @gitcommit90. I rechecked this PR against #530 after What changed:
Verification:
The issue labels are already on the PR. The branch is mergeable with no conflicts. GitHub has not reported hosted checks for this fork head, so the validation above is local. |
Description
to_bundlebuildsreference_mapkeyed by"ResourceType/id". When two resources share the same type and id, the second silently overwrites the first, corrupting internal cross-references. This PR detects the collision and raises a clearValueErrornaming the colliding key. Resources without anidremain valid (unreferenceable).Type of Change
Changes Made
"ResourceType/id"keys inreference_mapand raiseValueErrorto_bundledocstring (Raisessection)Testing
Code Quality
ruff checkandruff format --check— all passedDependencies
Related Issues
Closes #530