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

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

// Medication List document, 2.16.756.5.30.1.1.10.1.13
// 2020-10-30 Oliver Egger, 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/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/MedicationStatement" alias MedicationStatement 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.13
// target: http://fhir.ch/ig/ch-emed/medication-list-document.html
group CdaChEmedMedicationListDocumentToBundle(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 ClinicalDocumentChEmedMedicationListDocumentToBundle(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.13
// target: http://build.fhir.org/ig/hl7ch/ch-emed/StructureDefinition-ch-emed-composition-MedicationList.html
group ClinicalDocumentChEmedMedicationListDocumentToBundle(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.44')) -> composition.section as tgtSection then SectionMedicationListSectionContentModule(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: http://build.fhir.org/ig/hl7ch/ch-emed/StructureDefinition-ch-emed-composition-MedicationList.html
// target:
group SectionMedicationListSectionContentModule(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.34')) ->  bundle.entry as e,  e.resource = create('MedicationStatement') as medicationstatement,  medicationstatement.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 MedicationTreatmentPlanItemEntryContentModule(src, substanceAdministration, patient, medicationstatement);
  } "MedicationTreatmentPlanItemEntryContentModule";
  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);
  } "PrescriptionItemEntryContentModule";
  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";
  src.entry as cdaEntry where (observation.templateId.where(root = '2.16.756.5.30.1.1.10.4.44')) ->  bundle.entry as e,  e.resource = create('Observation') as fhirobservation,  fhirobservation.id = uuid() as uuid,  e.fullUrl = append('urn:uuid:', uuid),  tgt.entry = create('Reference') as reference,  reference.reference = append('urn:uuid:', uuid) then {
    cdaEntry.observation as cdaobservation then PharmaceuticalAdviceItemEntryContentModule(src, cdaobservation, patient, fhirobservation, bundle);
  } "PharmaceuticalAdviceItemEntryContentModule";
}