Kerndatensatz Senologie
0.9.0 - ci-build

Kerndatensatz Senologie - Local Development build (v0.9.0) built by the FHIR (HL7® FHIR® Standard) Build Tools. See the Directory of published versions

StructureMap: SenologieToObdsTod

Official URL: https://www.senologie.org/fhir/StructureMap/SenologieToObdsTod Version: 0.9.0
Draft as of 2026-05-04 Computable Name: SenologieToObdsTod

title: Senologie Patient + Conditions to oBDS Todesmeldung status: draft

map "https://www.senologie.org/fhir/StructureMap/SenologieToObdsTod" = "SenologieToObdsTod"

// title: Senologie Patient + Conditions to oBDS Todesmeldung
// status: draft

uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as source
uses "http://hl7.org/fhir/StructureDefinition/Patient" alias Patient as source
uses "http://hl7.org/fhir/StructureDefinition/Condition" alias Condition as source
uses "https://www.senologie.org/fhir/StructureDefinition/obds-meldung" alias OBDSMeldung as target

imports "https://www.senologie.org/fhir/StructureMap/SenologieToObdsTumorzuordnung"

// Known limitation: Sub-groups (MapTod, MapTodesursache) use
// `target tgt : BackboneElement` because FML has no syntax to declare the
// Logical Model sub-path for BackboneElement slices. The IG Publisher produces
// SM_TARGET_PATH errors (~10). Element names are correct per the oBDS LM.
// ============================================================================
// Hauptgruppe: Bundle -> oBDS Todesmeldung
// Das Bundle enthaelt einen Patient (mit deceasedDateTime) und ggf.
// Conditions fuer Todesursachen (category = cause-of-death).
// Die Tumorzuordnung wird aus der Tumor-Condition abgeleitet.
// ============================================================================
group SenologieToObdsTod(source src : Bundle, target tgt : OBDSMeldung) {
  // Tumorzuordnung: aus der Tumor-Condition (nicht cause-of-death)
  src.entry as entry where resource.is(Condition) and resource.category.coding.exists(code = 'encounter-diagnosis') then {
    entry.resource as condition then {
      condition -> tgt.tumorzuordnung as tz then MapTumorzuordnung(condition, tz) "CallMapTumorzuordnung";
    } "ConditionContext";
  } "EntryConditionTZ";
  // Tod: aus Patient + Todesursachen-Conditions
  src.entry as patEntry where resource.is(Patient) then {
    patEntry.resource as patient -> tgt.tod as tod then MapTod(patient, tod) "CallMapTod";
    // Bundle lookups moved from MapTod
    src.entry as codEntry where resource.is(Condition) and resource.category.coding.exists(code = 'cause-of-death') then {
      codEntry.resource as codCondition then {
        codCondition.code as code then {
          code.coding as c where (system = 'http://fhir.de/CodeSystem/bfarm/icd-10-gm') and code.startsWith('C') then {
            c -> tod.todTumorbedingt = 'J' "SetTodTumorbedingtJa";
          } "CheckIsCancer";
        } "CheckCodCode";
      } "AnalyseCodCondition";
    } "EntryCheckTumorbedingt";
    src.entry as codEntry2 where resource.is(Condition) and resource.category.coding.exists(code = 'cause-of-death') then {
      codEntry2.resource as codCondition -> tod.todesursachen as tu then MapTodesursache(codCondition, tu) "CallMapTodesursache";
    } "EntryTodesursachen";
  } "EntryPatient";
}

// ============================================================================
// Tod: Patient -> OBDSMeldung.tod
// Sterbedatum, Tod tumorbedingt, Todesursachen
// ============================================================================
group MapTod(source src : Patient, target tgt : BackboneElement) {
  // Abschluss_ID: aus Patient.identifier oder generiert
  src.id as id -> tgt.abschlussID = id "SetAbschlussID";
  // Sterbedatum: aus Patient.deceasedDateTime
  src.deceased as d where $this.is(dateTime) -> tgt.sterbedatum = d "SetSterbedatum";
  // Tod_tumorbedingt: Default U; bundle lookups moved to calling group.
  src -> tgt.todTumorbedingt = 'U' "SetTodTumorbedingtDefault";
  // Tod tumorbedingt: aus Extension (falls explizit angegeben)
  src.extension as ext where url = 'https://www.medizininformatik-initiative.de/fhir/ext/modul-onko/StructureDefinition/mii-ex-onko-tod-tumorbedingt' then {
    ext.value as val then {
      val.coding as c then {
        c.code as cd -> tgt.todTumorbedingt = cd "SetTodTumorbedingtExplicit";
      } "ExtractTodTumorbedingtCode";
    } "MapTodTumorbedingtValue";
  } "MapTodTumorbedingtExtension";
}

// ============================================================================
// Todesursache: Condition (cause-of-death) -> OBDSMeldung.tod.todesursachen
// ICD-10-GM Code und Version der Todesursache
// ============================================================================
group MapTodesursache(source src : Condition, target tgt : BackboneElement) {
  // ICD-10-Code der Todesursache
  src.code as code then {
    code.coding as c where system = 'http://fhir.de/CodeSystem/bfarm/icd-10-gm' then {
      c.code as cd -> tgt.code = cd "SetTodesursacheCode";
      c.version as v -> tgt.version = v "SetTodesursacheVersion";
    } "ExtractTodesursacheICD";
  } "MapTodesursacheCode";
}