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 (Laborbericht): duplicate contained Specimen resources and invalid Observation.specimen assignment when analyte has no probe ID #180

@SevKohler

Description

@SevKohler

Description
When converting KDS_Laborbericht openEHR compositions to FHIR, the generated DiagnosticReport sometimes contains duplicate contained Specimen resources (same identifier), and Observation.specimen can be set even for analytes that do not have a probe ID in openEHR.

This leads to:

  • redundant contained resources
  • incorrect linkage semantics for analytes without specimen reference data

Current Behavior

  1. Multiple contained Specimen resources are created with identical identifiers (same system|value) instead of reusing one contained specimen reference.
  2. For patient-1, analyte 788-0 has no at0026 (Probe ID) in openEHR, but generated Observation still has specimen.reference.

Expected Behavior

  1. Identical specimens should be reused (single contained Specimen per identifier signature).
  2. Observation.specimen should only be generated if analyte-level probe ID/reference input exists (e.g. at0026 present).

Repro
Use existing test data:

  • openEHR input:
    src/test/resources/kds/laborbericht/toOpenEHR/output/Composition-mii-exa-test-data-patient-1-labreport-1.json
  • generated/expected FHIR sample showing issue:
    src/test/resources/kds/laborbericht/toFHIR/output/DiagnosticReport-mii-exa-test-data-patient-1-labreport-1.json

Evidence:

Likely Root Cause
Mapping flow for CLUSTER.laboratory_test_analyte.v1 (specimen mapping to Observation.specimen) is executed without strict presence guard for analyte probe ID and creates reference resources per analyte occurrence without dedup/reuse.

Relevant mapping file:

  • src/test/resources/kds_new/model/cluster/org.openehr/laboratory_test_analyte.v1.yml

Suggested Fix Direction

  • Add/ensure analyte-level condition so Observation.specimen is only mapped when at0026 is present.
  • Introduce generic contained-resource reuse/dedup strategy based on stable identifier signature, with safe reference rewriting (#old -> #kept) where needed.

Acceptance Criteria

  1. No duplicate contained Specimen with same identifier in generated DiagnosticReport.
  2. For analytes without probe ID, Observation.specimen is absent.
  3. Existing Laborbericht toFHIR tests pass, plus a regression test covering the patient-1 case.

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