Skip to content

Reject duplicate resource ids in the FHIR Bundle assembler #530

Description

@maziyarpanahi

Summary

In openmed/clinical/exporters/fhir/bundle.py, to_bundle builds reference_map keyed by 'ResourceType/id'. When two input resources share the same resourceType and id, the second silently overwrites the first in reference_map, so internal references resolve to only one of them (whichever appears last). The assembler claims to produce no dangling internal references, but duplicate ids produce silently wrong cross-references.

Scope

  • Detect duplicate 'ResourceType/id' keys while building reference_map and raise a clear ValueError naming the colliding resourceType/id
  • Keep the existing behavior for resources without an id (they remain unreferenceable, which is valid)
  • Document the duplicate-id contract in the to_bundle docstring

Acceptance criteria

  • to_bundle raises a clear ValueError when two resources share the same resourceType and id
  • A Bundle with unique ids still assembles and rewrites references correctly
  • A regression test asserts the duplicate-id error
  • .venv/bin/python -m pytest tests/ -q

Out of scope

  • FHIR profile validation
  • Synthesizing or deduplicating resources

Files

  • openmed/clinical/exporters/fhir/bundle.py
  • tests/unit/clinical/test_fhir_bundle.py

Task: OM-340 · Milestone: v1.7 · Priority: P2 · Size: S
Depends on: — · Blocks: —
Roadmap: v1.7 expansion (post-1.6.0)
Spec: PLANS/V2/EXECUTION/tasks/OM-340.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2MediumbugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is neededroadmap-v2OpenMed V2 roadmap backlog

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions