CDA-FHIR-Maps (R4)
0.3.0 - DSTU 1

This page is part of the CDA-FHIR-Maps (R4) (v0.3.0: DSTU 1) based on FHIR R4. . For a full list of available versions, see the Directory of published versions

StructureMap: CDA-CH-EMED Medication Dispense document to Bundle

map "http://fhir.ch/ig/cda-fhir-maps/StructureMap/CdaChEmedMedicationDispenseDocumentToBundle" = "CdaChEmedMedicationDispenseDocumentToBundle"

// Medication Dispense document, 2.16.756.5.30.1.1.10.1.5
// 2020-02-11 Oliver Egger, Michaela Ziegler, copyright ahdis ag, Apache License
// CDA-CH-EMED:  https://art-decor.org/art-decor/decor-project--cdachemed-
// FHIR CH-EMED: http://fhir.ch/ig/ch-emed/index.html

uses "http://hl7.org/fhir/cda/StructureDefinition/ClinicalDocument" alias ClinicalDocument as source
uses "http://hl7.org/fhir/cda/StructureDefinition/AssignedAuthor" alias AssignedAuthor as source
uses "http://hl7.org/fhir/cda/StructureDefinition/AssignedEntity" alias AssignedEntity as source
uses "http://hl7.org/fhir/cda/StructureDefinition/Author" alias Author as source
uses "http://hl7.org/fhir/cda/StructureDefinition/CustodianOrganization" alias CustodianOrganization as source
uses "http://hl7.org/fhir/cda/StructureDefinition/IVL_TS" alias IVL_TS as source
uses "http://hl7.org/fhir/cda/StructureDefinition/EIVL_TS" alias EIVL_TS as source
uses "http://hl7.org/fhir/cda/StructureDefinition/Observation" alias Observation as source
uses "http://hl7.org/fhir/cda/StructureDefinition/PatientRole" alias PatientRole as source
uses "http://hl7.org/fhir/cda/StructureDefinition/RecordTarget" alias RecordTarget as source
uses "http://hl7.org/fhir/cda/StructureDefinition/Section" alias Section as source
uses "http://hl7.org/fhir/cda/StructureDefinition/SubstanceAdministration" alias SubstanceAdministration as source
uses "http://hl7.org/fhir/cda/StructureDefinition/Supply" alias Supply as source
uses "http://hl7.org/fhir/cda/StructureDefinition/SXPR_TS" alias SXPR_TS as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as target
uses "http://hl7.org/fhir/StructureDefinition/Composition" alias Composition as produced
uses "http://hl7.org/fhir/StructureDefinition/Patient" alias Patient as produced
uses "http://hl7.org/fhir/StructureDefinition/Practitioner" alias Practitioner as produced
uses "http://hl7.org/fhir/StructureDefinition/Organization" alias Organization as produced
uses "http://hl7.org/fhir/StructureDefinition/MedicationDispense" alias MedicationDispense as produced
uses "http://hl7.org/fhir/StructureDefinition/Dosage" alias Dosage as produced

imports "http://fhir.ch/ig/cda-fhir-maps/StructureMap/CdaToFhirTypes"
imports "http://fhir.ch/ig/cda-fhir-maps/StructureMap/CdaToBundle"
imports "http://fhir.ch/ig/cda-fhir-maps/StructureMap/CdaChToBundle"
imports "http://fhir.ch/ig/cda-fhir-maps/StructureMap/CdaChEmedToBundle"

// source: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.1.5
// target: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-composition-medicationdispense.html
group CdaChEmedMedicationDispenseDocumentToBundle(source cda : ClinicalDocument, target bundle : Bundle) {
  cda ->  bundle.entry as e,  e.resource = create('Composition') as composition,  composition.id = uuid() as uuid,  e.fullUrl = append('urn:uuid:', uuid),  bundle.entry as e2,  e2.resource = create('Patient') as patient,  patient.id = uuid() as uuid2,  e2.fullUrl = append('urn:uuid:', uuid2) then ClinicalDocumentChEmedMedicationDispenseDocumentToBundle(cda, patient, composition, bundle) "ClinicalDocumentToBody";
}

// source: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.1.5
// target: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-composition-medicationdispense.html
group ClinicalDocumentChEmedMedicationDispenseDocumentToBundle(source cda : ClinicalDocument, target patient : Patient, target composition : Composition, target bundle : Bundle) extends ClinicalDocumentToBundle {
  cda then ClinicalDocumentCompositionCh(cda, composition, patient, bundle) "composition";
  cda.component as component then {
    component.structuredBody as body then {
      body.component as component then {
        component.section as srcSection where (templateId.where(root = '2.16.756.5.30.1.1.10.3.11')) -> composition.section as tgtSection then SectionDispenseSectionContentModule(cda, srcSection, patient, tgtSection, bundle);
        component.section as srcSection where (templateId.where(root = '2.16.756.5.30.1.1.10.3.2')) -> composition.section as tgtSection then ClinicalDocumentSection(cda, srcSection, patient, tgtSection, bundle);
        component.section as srcSection where (templateId.where(root = '2.16.756.5.30.1.1.10.3.45')) -> composition.section as tgtSection then SectionOriginalRepresentation(cda, srcSection, patient, tgtSection, bundle);
      };
    } "body";
  };
}

// _________________________ Section Level Templates _________________________
// source: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.3.11
// target: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-composition-medicationdispense.html
group SectionDispenseSectionContentModule(source cda : ClinicalDocument, source src : Section, source patient : Patient, target tgt, target bundle : Bundle) extends ClinicalDocumentSection {
  src.entry as cdaEntry where (supply.templateId.where(root = '2.16.756.5.30.1.1.10.4.42')) ->  bundle.entry as e,  e.resource = create('MedicationDispense') as medicationdispense,  medicationdispense.id = uuid() as uuid,  e.fullUrl = append('urn:uuid:', uuid),  tgt.entry = create('Reference') as reference,  reference.reference = append('urn:uuid:', uuid) then {
    cdaEntry.supply as supply then DispenseItemEntryContentModule(src, supply, patient, medicationdispense);
  } "DispenseItemEntryContentModule";
}