Implementation Guide
E-T-Rezept Datenaustausch
Version 1.1.0-ballot-1 - ballot

StructureMap: E-T-Rezept Structure Map for CarbonCopy

Official URL: https://gematik.de/fhir/erp-t-prescription/StructureMap/ERPTPrescriptionStructureMapCarbonCopy Version: 1.1.0-ballot-1
Draft as of 2025-07-07 Computable Name: ERPTPrescriptionStructureMapCarbonCopy

Diese Ressource beschreibt das Mapping und führt die Mappings aller Teilressourcen zusammen. Weitere Informationen und Beschreibungen zum Mapping können auf der Seite Mapping des digitalen Durchschlag E-T-Rezept eingesehen werden.

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

// Diese Ressource beschreibt das Mapping und führt die Mappings aller Teilressourcen zusammen. Weitere Informationen und Beschreibungen zum Mapping können auf der Seite [Mapping des digitalen Durchschlag E-T-Rezept](./trezept.html#mapping-des-digitalen-durchschlags-e-t-rezept) eingesehen werden.

uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias bundle as source
uses "https://gematik.de/fhir/erp-t-prescription/StructureDefinition/erp-tprescription-carbon-copy" alias erpTCarbonCopy as target

imports "https://gematik.de/fhir/erp-t-prescription/StructureMap/ERPTPrescriptionStructureMapMedicationDispense"
imports "https://gematik.de/fhir/erp-t-prescription/StructureMap/ERPTPrescriptionStructureMapMedicationRequest"
imports "https://gematik.de/fhir/erp-t-prescription/StructureMap/ERPTPrescriptionStructureMapOrganization"
imports "https://gematik.de/fhir/erp-t-prescription/StructureMap/ERPTPrescriptionStructureMapTask"
imports "https://gematik.de/fhir/erp-t-prescription/StructureMap/ERPTPrescriptionStructureMapMedication"

// Mapping des digitalen Durchschlags T-Rezept aus einem E-Rezept Bundle in das BfArM CarbonCopy Format
group erpTPrescriptionCarbonCopy(source bundle : bundle, target erpTCarbonCopy : erpTCarbonCopy) {
  bundle -> erpTCarbonCopy.meta as erpTCarbonCopyMeta then {
    bundle -> erpTCarbonCopyMeta.profile = 'https://gematik.de/fhir/erp-t-prescription/StructureDefinition/erp-tprescription-carbon-copy|1.0' "tgtMetaProfile"; // Setzt das meta.profile des digitalen Durchschlags T-Rezept
  } "tgtMeta"; // Setzt die Metadaten für den digitalen Durchschlag
  bundle ->  erpTCarbonCopy.parameter as tgtRxPrescription,  tgtRxPrescription.part as tgtRxPrescriptionPartId,  tgtRxPrescription.part as tgtRxPrescriptionPartMR,  tgtRxPrescription.part as tgtRxPrescriptionPartMed,  tgtRxPrescription.name = 'rxPrescription' then {
    bundle.entry as srcEntryVar then {
      srcEntryVar.resource as srcEntryResourceVar then {
        srcEntryResourceVar as srcEntryTaskVar where ofType(Task) ->  tgtRxPrescriptionPartId.name = 'prescriptionId',  tgtRxPrescriptionPartId.value = create('Identifier') as newIdentifier then {
          srcEntryTaskVar then ERPTPrescriptionStructureMapTask(srcEntryTaskVar, newIdentifier) "parameterrXPrescriptionPartIdentifier"; // Mappt Task-Informationen auf Identifier für die Rezept-ID
        } "parameterrXPrescriptionPart"; // Extrahiert die E-Rezept-ID aus dem Task und erstellt den prescriptionId Parameter
        srcEntryResourceVar as srcEntryBundleMRVar where ofType(MedicationRequest) -> tgtRxPrescriptionPartMR.name = 'medicationRequest' then {
          srcEntryBundleMRVar -> tgtRxPrescriptionPartMR.resource = create('MedicationRequest') as newMedicationRequest then {
            srcEntryBundleMRVar then ERPTPrescriptionStructureMapMedicationRequest(srcEntryBundleMRVar, newMedicationRequest) "entryMedicationRequestPartResourceSet"; // Führt die detaillierte MedicationRequest-Transformation durch
          } "entryMedicationRequestPart"; // Transformiert KBV-MedicationRequest in BfArM MedicationRequest Format
        } "entryMedicationRequest"; // Erstellt den medicationRequest Parameter für Verschreibungsdetails
        srcEntryVar as srcMedicationRequestId where resource.ofType(MedicationRequest) -> tgtRxPrescriptionPartMed.name = 'medication' then {
          bundle.entry as srcEntryVar2 then {
            srcEntryVar2 as srcEntryBundleMRMedIdVar where resource.ofType(Medication).where(id=%srcMedicationRequestId.resource.medication.reference.replace('Medication/', '').toString()) -> tgtRxPrescriptionPartMed.resource = create('Medication') as newMedicationPrescriptionMedication then {
              srcEntryBundleMRMedIdVar.resource as srcEntryBundleMRMedIdVarRes then ERPTPrescriptionStructureMapMedication(srcEntryBundleMRMedIdVarRes, newMedicationPrescriptionMedication) "entryMedicationPrescriptionMedicationPartResourceSet"; // Führt die detaillierte Medication-Transformation für das verschriebene Arzneimittel durch
            } "entryMedicationPrescriptionMedicationPart"; // Findet die vom MedicationRequest referenzierte Medication und transformiert sie in BfArM Format
          } "prepMedication"; // Bereitet die Suche nach der referenzierten Medication vor
        } "entryMedicationRequestMedication"; // Erstellt den medication Parameter für das verschriebene Arzneimittel
      } "rxPrescriptionParameter"; // Extrahiert relevante Ressourcen für die Verschreibung
    } "bundleEntries"; // Verarbeitet alle Einträge des Quell-Bundles für Verschreibungsinformationen
  } "rxPrescriptionRule"; // Erstellt den rxPrescription Parameter mit allen Verschreibungsinformationen
  bundle ->  erpTCarbonCopy.parameter as tgtRxDispensation,  tgtRxDispensation.part as tgtRxDispensationPartOrg,  tgtRxDispensation.name = 'rxDispensation' then {
    bundle.entry as srcEntryVar then {
      srcEntryVar.resource as srcEntryResourceVar then {
        srcEntryResourceVar as srcEntryBundleOrgVar where ofType(Bundle).where(entry.first().fullUrl.contains('fhir-directory')) -> tgtRxDispensationPartOrg.name = 'organization' then {
          srcEntryBundleOrgVar -> tgtRxDispensationPartOrg.resource = create('Organization') as newOrganization then {
            srcEntryBundleOrgVar then ERPTPrescriptionStructureMapOrganization(srcEntryBundleOrgVar, newOrganization) "entryOrganizationPartResourceSet"; // Führt die detaillierte Organization-Transformation durch
          } "entryOrganizationPart"; // Transformiert VZD SearchSet in BfArM Organization Format für die abgebende Apotheke
        } "entryVZDSearchSet"; // Identifiziert VZD SearchSet Bundle für Apothekeninformationen
        srcEntryResourceVar as srcEntryBundleMDVar where ofType(MedicationDispense) -> tgtRxDispensation.part as tgtRxDispensationPartMD then {
          srcEntryBundleMDVar ->  tgtRxDispensationPartMD.name = 'medicationDispense',  tgtRxDispensationPartMD.resource = create('MedicationDispense') as newMedicationDispense then {
            srcEntryBundleMDVar then ERPTPrescriptionStructureMapMedicationDispense(srcEntryBundleMDVar, newMedicationDispense) "entryMedicationDispensePartResourceSet"; // Führt die detaillierte MedicationDispense-Transformation durch
          } "entryMedicationDispensePart"; // Transformiert gematik MedicationDispense in BfArM MedicationDispense Format
        } "entryMedicationDispense"; // Erstellt den medicationDispense Parameter für Abgabedetails
        srcEntryVar as srcMedicationDispenseId where resource.ofType(MedicationDispense) ->  tgtRxDispensation.part as tgtRxDispensationPartDispMed,  tgtRxDispensationPartDispMed.name = 'medication' then {
          bundle.entry as srcEntryVar2 then {
            srcEntryVar2 as srcEntryBundleMDMedIdVar where resource.ofType(Medication).where(id=%srcMedicationDispenseId.resource.medication.reference.replace('Medication/', '').toString()) -> tgtRxDispensationPartDispMed.resource = create('Medication') as newMedicationDispensationMedication then {
              srcEntryBundleMDMedIdVar.resource as srcEntryBundleMDMedIdVarRes then ERPTPrescriptionStructureMapMedication(srcEntryBundleMDMedIdVarRes, newMedicationDispensationMedication) "entryMedicationDispensationMedicationPartResourceSet"; // Führt die detaillierte Medication-Transformation für das abgegebene Arzneimittel durch
            } "entryMedicationDispensationMedicationPart"; // Findet die vom MedicationDispense referenzierte Medication und transformiert sie in BfArM Format
          } "prepMedication"; // Bereitet die Suche nach der vom MedicationDispense referenzierten Medication vor
        } "entryMedicationDispenseMedication"; // Erstellt den medication Parameter für das abgegebene Arzneimittel
      } "rxDispensationParameter"; // Extrahiert relevante Ressourcen für die Abgabe
    } "bundleEntries"; // Verarbeitet alle Einträge des Quell-Bundles für Abgabeinformationen
  } "MedicationDispenseFromBundle"; // Erstellt den rxDispensation Parameter mit allen Abgabeinformationen
}