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 Prescription document to Bundle

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

// Medication Prescription document,	2.16.756.5.30.1.1.10.1.4
// 2020-01-22 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, http://build.fhir.org/ig/hl7ch/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/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/MedicationRequest" alias MedicationRequest 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.4
// target: http://build.fhir.org/ig/hl7ch/ch-emed/StructureDefinition-ch-emed-composition-medicationprescription.html
group CdaChEmedMedicationPrescriptionDocumentToBundle(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 ClinicalDocumentChEmedMedicationPrescriptionDocumentToBundle(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.4
// target: http://build.fhir.org/ig/hl7ch/ch-emed/StructureDefinition-ch-emed-composition-medicationprescription.html
group ClinicalDocumentChEmedMedicationPrescriptionDocumentToBundle(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.10')) -> composition.section as tgtSection then SectionPrescriptionSectionContentModule(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.10
// target: http://build.fhir.org/ig/hl7ch/ch-emed/StructureDefinition-ch-emed-composition-medicationprescription.html
group SectionPrescriptionSectionContentModule(source cda : ClinicalDocument, source src : Section, source patient : Patient, target tgt, target bundle : Bundle) extends ClinicalDocumentSection {
  src.entry as cdaEntry where (substanceAdministration.templateId.where(root = '2.16.756.5.30.1.1.10.4.43')) ->  bundle.entry as e,  e.resource = create('MedicationRequest') as medicationrequest,  medicationrequest.id = uuid() as uuid,  e.fullUrl = append('urn:uuid:', uuid),  tgt.entry = create('Reference') as reference,  reference.reference = append('urn:uuid:', uuid) then {
    cdaEntry.substanceAdministration as substanceAdministration then PrescriptionItemEntryContentModule(src, substanceAdministration, patient, medicationrequest);
  } "PrescriptionSectionContentModule";
}