Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

toFHIR creates duplicate Patient resources when Person data is split across multiple COMPOSITION/content[n] entries (multiple=true) #178

@SevKohler

Description

@SevKohler

Body

Summary

When mapping KDS_Person from openEHR to FHIR with multiple=true, the engine may produce multiple Patient resources for a single logical patient if mapped fields come from different COMPOSITION/content[n] roots.

Current Behavior

OpenEhrToFhir groups created resources by a key derived from the first openEHR index of each mapped path.
If mappings resolve from different content[n] entries (e.g. ADMIN_ENTRY.person_data.v0, EVALUATION.gender.v1, ADMIN_ENTRY.versicherungsinformationen.v0), separate Patient instances are created.

Expected Behavior

All Person-related mappings for one composition should merge into one Patient (unless the model explicitly represents multiple patients).

Impact

  • Partial duplicate Patient resources in output bundle.
  • Users currently need multiple: false as workaround in Person mapping models.

Reproduction

  1. Use Person context/model with:
  • ADMIN_ENTRY.person_data.v0 as start
  • extensions mapping additional patient fields from other content[...] archetypes (gender, insurance).
  1. Run toFHIR on composition containing those archetypes in separate content[n].
  2. Observe bundle contains 2+ Patient entries (one partial, one fuller).

Root Cause (technical)

Resource creation key is index-based (derived from openEHR path index) when fhirConfig.multiple=true, so logically-related data from different content[n] does not merge.

Proposed Fix

Introduce a stable logical grouping strategy for toFHIR resource assembly, instead of using only openEHR index:

  • group by primary target resource/root mapping context, and/or
  • allow explicit grouping key in mapping config.

Keep index-based behavior only where truly needed for repeated resource instances.

Workaround

Set spec.fhirConfig.multiple: false in Person model (ADMIN_ENTRY.person_data.v0) to force single Patient.

Acceptance Criteria

  • Given Person data split across multiple content[n], toFHIR returns exactly one Patient.
  • Existing genuinely multi-instance models remain supported.
  • Add regression test covering split-content Person mappings.

NOTE:

This might be fixed with the introduction of the composition layer as it is planned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions