E-T-Rezept Datenaustausch
Version 1.1.0 - release

StructureMap: E-T-Rezept Structure Map for MedicationRequest

Official URL: https://gematik.de/fhir/erp-t-prescription/StructureMap/ERPTPrescriptionStructureMapMedicationRequest Version: 1.1.0
Active as of 2025-12-19 Computable Name: ERPTPrescriptionStructureMapMedicationRequest

Mapping-Anweisungen zur Transformation von KBV MedicationRequest zu BfArM T-Prescription MedicationRequest

map "https://gematik.de/fhir/erp-t-prescription/StructureMap/ERPTPrescriptionStructureMapMedicationRequest" = "ERPTPrescriptionStructureMapMedicationRequest"

// Mapping-Anweisungen zur Transformation von KBV MedicationRequest zu BfArM T-Prescription MedicationRequest

uses "https://fhir.kbv.de/StructureDefinition/KBV_PR_ERP_Prescription" alias kbvMedicationRequest as source
uses "https://gematik.de/fhir/erp-t-prescription/StructureDefinition/erp-tprescription-medication-request" alias bfarmMedicationRequest as target

// Mapping-Anweisungen zur Transformation von KBV MedicationRequest zu BfArM T-Prescription MedicationRequest
group ERPTPrescriptionStructureMapMedicationRequest(source kbvMedicationRequest : kbvMedicationRequest, target bfarmMedicationRequest : bfarmMedicationRequest) {
  kbvMedicationRequest.status as srcStatus -> bfarmMedicationRequest.status = 'completed' "medicationRequestStatus"; // Setzt den Status auf 'completed' für den digitalen Durchschlag (Verschreibung ist bereits abgeschlossen)
  kbvMedicationRequest.intent -> bfarmMedicationRequest.intent = 'order' "medicationRequestIntent"; // Setzt den Intent auf 'order' entsprechend der BfArM-Spezifikation für T-Prescription
  kbvMedicationRequest.extension as extVar where url='https://fhir.kbv.de/StructureDefinition/KBV_EX_ERP_Teratogenic' -> bfarmMedicationRequest.extension as tgtExtVar then {
    extVar as extMatchVar -> tgtExtVar.url = 'https://gematik.de/fhir/epa-medication/StructureDefinition/teratogenic-extension' "copyTPrescriptionExtensionUrl"; // Kopiert teratogene Extensions für T-Rezept Kennzeichnung
    extVar.extension as offLabelVar where url='Off-Label' ->  tgtExtVar.extension = create('Extension') as tgtOffLabelExt,  tgtOffLabelExt.url = 'off-label' then {
      offLabelVar.value as offLabelValue -> tgtOffLabelExt.value = offLabelValue "mapOffLabelValue"; // Übernimmt den Off-Label Booleschen Wert
    } "mapOffLabelExtension"; // Mappt Off-Label Extension
    extVar.extension as gebaerfaehigeFrauVar where url='GebaerfaehigeFrau' ->  tgtExtVar.extension = create('Extension') as tgtGebaerfaehigeFrauExt,  tgtGebaerfaehigeFrauExt.url = 'childbearing-potential' then {
      gebaerfaehigeFrauVar.value as gebaerfaehigeFrauValue -> tgtGebaerfaehigeFrauExt.value = gebaerfaehigeFrauValue "mapGebaerfaehigeFrauValue"; // Übernimmt den Booleschen Wert für childbearing-potential
    } "mapGebaerfaehigeFrauExtension"; // Mappt GebaerfaehigeFrau Extension zu childbearing-potential
    extVar.extension as sicherheitsVar where url='EinhaltungSicherheitsmassnahmen' ->  tgtExtVar.extension = create('Extension') as tgtSicherheitsExt,  tgtSicherheitsExt.url = 'security-compliance' then {
      sicherheitsVar.value as sicherheitsValue -> tgtSicherheitsExt.value = sicherheitsValue "mapEinhaltungSicherheitsmassnahmenValue"; // Übernimmt den Booleschen Wert für security-compliance
    } "mapEinhaltungSicherheitsmassnahmenExtension"; // Mappt EinhaltungSicherheitsmassnahmen Extension zu security-compliance
    extVar.extension as infoMatVar where url='AushaendigungInformationsmaterialien' ->  tgtExtVar.extension = create('Extension') as tgtInfoMatExt,  tgtInfoMatExt.url = 'hand-out-information-material' then {
      infoMatVar.value as infoMatValue -> tgtInfoMatExt.value = infoMatValue "mapAushaendigungInformationsmaterialienValue"; // Übernimmt den Booleschen Wert für hand-out-information-material
    } "mapAushaendigungInformationsmaterialienExtension"; // Mappt AushaendigungInformationsmaterialien Extension zu hand-out-information-material
    extVar.extension as sachkenntnisVar where url='ErklaerungSachkenntnis' ->  tgtExtVar.extension = create('Extension') as tgtSachkenntnisExt,  tgtSachkenntnisExt.url = 'declaration-of-expertise' then {
      sachkenntnisVar.value as sachkenntnisValue -> tgtSachkenntnisExt.value = sachkenntnisValue "mapErklaerungSachkenntnisValue"; // Übernimmt den Booleschen Wert für declaration-of-expertise
    } "mapErklaerungSachkenntnisExtension"; // Mappt ErklaerungSachkenntnis Extension zu declaration-of-expertise
  } "medicationRequestExt"; // Mappt T-Rezept spezifische Extensions vom KBV- zum BfArM-Format
  kbvMedicationRequest.extension as extDosageMetaVar where url='http://ig.fhir.de/igs/medication/StructureDefinition/GeneratedDosageInstructionsMeta' -> bfarmMedicationRequest.extension = extDosageMetaVar "medicationRequestExt"; // Kopiert Dosage Metadata Extension
  kbvMedicationRequest.extension as extDosageRenderedVar where url='http://hl7.org/fhir/5.0/StructureDefinition/extension-MedicationRequest.renderedDosageInstruction' -> bfarmMedicationRequest.extension = extDosageRenderedVar "medicationRequestExt"; // Kopiert RenderedDosageText
  kbvMedicationRequest.subject as srcSubject -> bfarmMedicationRequest.subject as tgtSubject then {
    kbvMedicationRequest.subject as srcSubject -> tgtSubject.identifier as tgtSubjectIdentifier then {
      kbvMedicationRequest.subject as srcSubject ->  tgtSubjectIdentifier.system as tgtSubjectIdentifierSystem,  tgtSubjectIdentifier.value as tgtSubjectIdentifierValue then {
        kbvMedicationRequest.subject as srcSubject ->  tgtSubjectIdentifierSystem.extension as tgtSubjectIdentifierSystemEx,  tgtSubjectIdentifierValue.extension as tgtSubjectIdentifierValueEx then {
          kbvMedicationRequest.subject as srcSubject ->  tgtSubjectIdentifierSystemEx.url = 'http://hl7.org/fhir/StructureDefinition/data-absent-reason',  tgtSubjectIdentifierSystemEx.value = cast('not-permitted', 'code') "medicationRequestsubjectIdentifierSystemExtension"; // Setzt data-absent-reason auf 'not-permitted' um Patientendaten zu anonymisieren
          kbvMedicationRequest.subject as srcSubject ->  tgtSubjectIdentifierValueEx.url = 'http://hl7.org/fhir/StructureDefinition/data-absent-reason',  tgtSubjectIdentifierValueEx.value = cast('not-permitted', 'code') "medicationRequestsubjectIdentifierValueExtension"; // Setzt data-absent-reason auf 'not-permitted' um Patientendaten zu anonymisieren
        } "medicationRequestsubjectIdentifierSystem"; // Erstellt data-absent-reason Extension für Subject Identifier
      } "medicationRequestsubjectIdentifierExtension"; // Erstellt data-absent-reason Extension für Subject Identifier
    } "medicationRequestsubjectIdentifier";
  } "medicationRequestsubject"; // Entfernt Patientenbezug durch data-absent-reason Extension für Datenschutz im digitalen Durchschlag
  kbvMedicationRequest.authoredOn as srcAuthoredOnVar -> bfarmMedicationRequest.authoredOn = srcAuthoredOnVar "medicationRequestAuthoredOn"; // Übernimmt das Verschreibungsdatum unverändert vom KBV MedicationRequest
  kbvMedicationRequest.dosageInstruction as srcDosageInstructionVar -> bfarmMedicationRequest.dosageInstruction = srcDosageInstructionVar "medicationRequestDosageInstruction"; // Kopiert die Dosierungsanweisungen vollständig für den digitalen Durchschlag
  kbvMedicationRequest.dispenseRequest as srcDispenseRequestVar -> bfarmMedicationRequest.dispenseRequest = srcDispenseRequestVar "medicationRequestDispenseRequest"; // Übernimmt Abgabeanweisungen (Menge, Wiederholungen) aus der ursprünglichen Verschreibung
  kbvMedicationRequest.medicationReference as medicationVar -> bfarmMedicationRequest.medication = create('Reference') as tgtMedicationReference then {
    medicationVar.reference as medicationReferenceValue then {
      medicationReferenceValue -> tgtMedicationReference.reference = (iif(%medicationReferenceValue.startsWith('urn:uuid:'), %medicationReferenceValue, 'urn:uuid:' & %medicationReferenceValue.replaceMatches('.*[:/]', ''))) "normalizeMedicationReferenceTransformation";
    } "normalizeMedicationReference";
  };
}