Implementation Guide
TIFlow - Datenaustausch BfArM Webdienst
Version 2.0.0 - release

StructureMap: E-T-Rezept Structure Map for MedicationRequest

Official URL: https://gematik.de/fhir/tiflow-bfarm/StructureMap/ERPTPrescriptionStructureMapMedicationRequest Version: 2.0.0
Active as of 2026-10-02 Computable Name: ERPTPrescriptionStructureMapMedicationRequest

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

map "https://gematik.de/fhir/tiflow-bfarm/StructureMap/ERPTPrescriptionStructureMapMedicationRequest" = "ERPTPrescriptionStructureMapMedicationRequest"

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

uses "http://hl7.org/fhir/StructureDefinition/MedicationRequest" alias kbvMedicationRequest as source
uses "http://hl7.org/fhir/StructureDefinition/MedicationRequest" alias bfarmMedicationRequest as target

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