CDA to FHIR Maps
0.1.0 - ci-build IT

CDA to FHIR Maps - Local Development build (v0.1.0) built by the FHIR (HL7® FHIR® Standard) Build Tools. See the Directory of published versions

: CDA to FHIR - PRESCRIZIONE FARMACEUTICA - XML Representation

Draft as of 2024-04-11

Raw xml | Download



<StructureMap xmlns="http://hl7.org/fhir">
  <id value="cda2fhirMedPrescription"/>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml">
         <pre>map &quot;http://hl7.it/fhir/cda2fhir/StructureMap/cda2fhirMedPrescription&quot; = &quot;cda2fhirMedPrescription&quot;

uses &quot;http://hl7.org/fhir/cda/StructureDefinition/ClinicalDocument&quot; alias ClinicalDocument as source
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/AssignedAuthor&quot; alias AssignedAuthor as queried
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/AssignedEntity&quot; alias AssignedEntity as queried
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/AssociatedEntity&quot; alias AssociatedEntity as queried
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/CustodianOrganization&quot; alias CustodianOrganization as queried
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/OrganizationPartOf&quot; alias OrganizationPartOf as queried
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/Organization&quot; alias rapresentedOrganization as queried
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/Section&quot; alias Section as queried
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/PatientRole&quot; alias PatientRole as queried
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/AD&quot; alias AD as source
uses &quot;http://hl7.org/fhir/StructureDefinition/Bundle&quot; alias Bundle as target
uses &quot;http://hl7.org/fhir/StructureDefinition/Composition&quot; alias Composition as produced
uses &quot;http://hl7.org/fhir/StructureDefinition/Patient&quot; alias Patient as produced
uses &quot;http://hl7.org/fhir/StructureDefinition/Encounter&quot; alias Encounter as produced
uses &quot;http://hl7.org/fhir/StructureDefinition/Person&quot; alias Patient as produced
uses &quot;http://hl7.org/fhir/StructureDefinition/Practitioner&quot; alias Practitioner as produced
uses &quot;http://hl7.org/fhir/StructureDefinition/Organization&quot; alias Organization as produced
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/Act&quot; alias Act as produced
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/IVL-PQ&quot; alias IVL_PQ as source
uses &quot;http://hl7.org/fhir/cda/StructureDefinition/PQ&quot; alias PQ as source
uses &quot;http://hl7.org/fhir/StructureDefinition/SimpleQuantity&quot; alias SimpleQuantity as target

imports &quot;http://hl7.it/fhir/cda2fhir/StructureMap/cda2fhirDataTypes&quot;
imports &quot;http://hl7.it/fhir/cda2fhir/StructureMap/cda2fhirHeader&quot;

group CdaToBundle(source cda : ClinicalDocument, target bundle : Bundle) {
  cda -&gt;  bundle.entry as e,  e.request = create('BackboneElement') as request,  request.method = 'POST',  e.resource = create('Composition') as composition,  composition.id = uuid() as uuid1,  e.fullUrl = append('https://example/Composition/', uuid1),  request.url = 'Composition',  bundle.entry as e2,  e2.request = create('BackboneElement') as requestPAT,  requestPAT.method = 'PUT',  e2.resource = create('Patient') as patient,  patient.id = uuid() as uuid2,  e2.fullUrl = append('https://example/Patient/', uuid2),  bundle.entry as e3,  e3.request = create('BackboneElement') as request,  request.method = 'POST',  e3.resource = create('Encounter') as encounter,  encounter.id = uuid() as uuid3,  e3.fullUrl = append('https://example/Encounter/', uuid3),  request.url = 'Encounter',  bundle.entry as e5,  e5.request = create('BackboneElement') as request,  request.method = 'POST',  e5.resource = create('DocumentReference') as DocumentReference,  DocumentReference.id = uuid() as uuid5,  e5.fullUrl = append('https://example/DocumentReference/', uuid5),  request.url = 'DocumentReference' then {
    cda then ClinicalDocumentToBundle(cda, patient, composition, encounter, bundle, DocumentReference) &quot;cdatobundle&quot;;
    cda.recordTarget as recordTarget then {
      recordTarget.patientRole as patient then {
        patient.id as id -&gt; patient.identifier as identifier then {
          id.root as r -&gt; identifier.system = translate(r, 'http://hl7.org/fhir/ConceptMap/special-oid2uri', 'uri') &quot;root1&quot;;
          id.extension as ext -&gt; identifier.value = ext;
          id.assigningAuthorityName as s -&gt;  identifier.assigner as a,  a.display = s;
        } &quot;record&quot;;
        patient.id as id where (root = '2.16.840.1.113883.2.9.4.3.2') or (root = '2.16.840.1.113883.2.9.4.3.7') or (root = '2.16.840.1.113883.2.9.4.3.3') or (root = '2.16.840.1.113883.2.9.4.3.17') or (root = '2.16.840.1.113883.2.9.4.3.18') or (root = '2.16.840.1.113883.2.9.2.10.4.1.1') or (root = '2.16.840.1.113883.2.9.2.20.4.1.1') or (root = '2.16.840.1.113883.2.9.2.30.4.1.1') or (root = '2.16.840.1.113883.2.9.2.41.4.1.1') or (root = '2.16.840.1.113883.2.9.2.42.4.1.1') or (root = '2.16.840.1.113883.2.9.2.50.4.1.1') or (root = '2.16.840.1.113883.2.9.2.60.4.1.1') or (root = '2.16.840.1.113883.2.9.2.70.4.1.1') or (root = '2.16.840.1.113883.2.9.2.80.4.1.1') or (root = '2.16.840.1.113883.2.9.2.90.4.1.1') or (root = '2.16.840.1.113883.2.9.2.100.4.1.1') or (root = '2.16.840.1.113883.2.9.2.110.4.1.1') or (root = '2.16.840.1.113883.2.9.2.120.4.1.1') or (root = '2.16.840.1.113883.2.9.2.130.4.1.1') or (root = '2.16.840.1.113883.2.9.2.140.4.1.1') or (root = '2.16.840.1.113883.2.9.2.150.4.1.1') or (root = '2.16.840.1.113883.2.9.2.160.4.1.1') or (root = '2.16.840.1.113883.2.9.2.170.4.1.1') or (root = '2.16.840.1.113883.2.9.2.180.4.1.1') or (root = '2.16.840.1.113883.2.9.2.190.4.1.1') or (root = '2.16.840.1.113883.2.9.2.200.4.1.1') or (root = '2.16.840.1.113883.2.9.2.10.4.1') or (root = '2.16.840.1.113883.2.9.2.20.4.1') or (root = '2.16.840.1.113883.2.9.2.30.4.1') or (root = '2.16.840.1.113883.2.9.2.41.4.1') or (root = '2.16.840.1.113883.2.9.2.42.4.1') or (root = '2.16.840.1.113883.2.9.2.50.4.1') or (root = '2.16.840.1.113883.2.9.2.60.4.1') or (root = '2.16.840.1.113883.2.9.2.70.4.1') or (root = '2.16.840.1.113883.2.9.2.80.4.1') or (root = '2.16.840.1.113883.2.9.2.90.4.1') or (root = '2.16.840.1.113883.2.9.2.100.4.1') or (root = '2.16.840.1.113883.2.9.2.110.4.1') or (root = '2.16.840.1.113883.2.9.2.120.4.1') or (root = '2.16.840.1.113883.2.9.2.130.4.1') or (root = '2.16.840.1.113883.2.9.2.140.4.1') or (root = '2.16.840.1.113883.2.9.2.150.4.1') or (root = '2.16.840.1.113883.2.9.2.160.4.1') or (root = '2.16.840.1.113883.2.9.2.170.4.1') or (root = '2.16.840.1.113883.2.9.2.180.4.1') or (root = '2.16.840.1.113883.2.9.2.190.4.1') or (root = '2.16.840.1.113883.2.9.2.200.4.1') or (root = '2.16.840.1.113883.2.9.4.3.15') then {
          id.extension as ext -&gt; requestPAT.url = append('Patient?identifier=', ext) &quot;UUID&quot;;
        } &quot;ext&quot;;
      } &quot;recPat&quot;;
    } &quot;patient&quot;;
  } &quot;ClinicalDocumentToBody&quot;;
}

group ClinicalDocumentToBundle(source cda : ClinicalDocument, target patient : Patient, target composition : Composition, target encounter : Encounter, target bundle : Bundle, target DocumentReference : DocumentReference) {
  cda -&gt; bundle.id = uuid() &quot;id&quot;;
  cda.id -&gt; bundle.identifier &quot;identifier&quot;;
  cda -&gt; bundle.type = 'transaction' &quot;type&quot;;
  cda -&gt; bundle.timestamp = (timestamp.now()) &quot;date&quot;;
  cda then ClinicalDocumentComposition(cda, composition, patient, encounter, bundle, DocumentReference) &quot;composition&quot;;
  cda.component as component then {
    component.structuredBody as body then {
      body -&gt;  bundle.entry as e1,  e1.request = create('BackboneElement') as request,  request.method = 'POST',  e1.resource = create('Coverage') as coverage,  coverage.id = uuid() as uuid1,  e1.fullUrl = append('https://example/Coverage/', uuid1),  request.url = 'Coverage' then {
        body -&gt;  bundle.entry as e2,  e2.request = create('BackboneElement') as request,  request.method = 'POST',  e2.resource = create('MedicationRequest') as medRq,  medRq.id = uuid() as uuid1,  e2.fullUrl = append('https://example/MedicationRequest/', uuid1),  request.url = 'MedicationRequest' then {
          body.component as component then {
            // discretizzi il primo livello di component
            component.section as srcSection then {
              srcSection.code where (code = '57827-8') -&gt; composition.section as tgtSection then ClinicalDocumentSectionEsenzioni(cda, srcSection, patient, tgtSection, bundle, encounter, coverage) &quot;esenz&quot;;
              srcSection.code where (code = '57828-6') -&gt; composition.section as tgtSection then ClinicalDocumentSectionPrescrizioneFarmaceutica(cda, srcSection, patient, tgtSection, bundle, encounter, coverage, medRq) &quot;prescfarm&quot;;
              srcSection.code where (code = '48767-8') -&gt; composition.section as tgtSection then ClinicalDocumentSectionAnnotazioni(cda, srcSection, patient, tgtSection, bundle, encounter, medRq) &quot;annot&quot;;
              srcSection.code where (code = '51851-4') -&gt; composition.section as tgtSection then ClinicalDocumentSectionMessaggioRegionale(cda, srcSection, patient, tgtSection, bundle, encounter, medRq) &quot;messregg&quot;;
              srcSection.code where (code = '8716-3') -&gt; composition.section as tgtSection then ClinicalDocumentSectionParametriVitali(cda, srcSection, patient, tgtSection, bundle, encounter) &quot;paramvit&quot;;
              srcSection.code where (code = '48765-2') -&gt; composition.section as tgtSection then ClinicalDocumentSectionAllergieaiFarmaci(cda, srcSection, patient, tgtSection, bundle, encounter) &quot;allergfarm&quot;;
              srcSection.code where (code = '47420-5') -&gt; composition.section as tgtSection then ClinicalDocumentSectionStatoClinicoPaziente(cda, srcSection, patient, tgtSection, bundle, encounter) &quot;statclinpaz&quot;;
            } &quot;cov&quot;;
          };
        } &quot;medreq&quot;;
      } &quot;coverage&quot;;
    } &quot;body&quot;;
  };
}

group ClinicalDocumentSectionEsenzioni(source cda : ClinicalDocument, source src : Section, target patient : Patient, target tgt, target bundle : Bundle, target enc : Encounter, target coverage : Coverage) {
  src.title as t -&gt; tgt.title = (t.dataString);
  src.code -&gt; tgt.code;
  src.text as cdaText -&gt;  tgt.entry = create('Reference') as reference,  reference.reference = ('https://example/Coverage/' + %coverage.id),  tgt.text as fhirText then {
    cdaText -&gt; fhirText.status = 'generated' &quot;narrativeStatus&quot;;
    cdaText as t -&gt; fhirText.div = t &quot;narrativeText&quot;;
    src.entry as srcse then {
      srcse.act as srcsec then {
        srcsec.code -&gt; coverage.type;
        srcsec.code as srctxt then {
          srctxt -&gt; coverage.type as typetxt then {
            srctxt.originalText as ref then {
              ref.reference as t then {
                t.value as l -&gt; typetxt.text = l &quot;reference&quot;;
              } &quot;tcf&quot;;
            } &quot;rfde&quot;;
          } &quot;reftxt&quot;;
        } &quot;origtxt&quot;;
        srcsec where coverage.status.exists().not() then {
          srcsec -&gt; coverage.status = 'active' &quot;status&quot;;
        } &quot;statuscode&quot;;
        srcsec -&gt;  coverage.beneficiary = create('Reference') as reference,  reference.reference = ('https://example/Patient/' + %patient.id) &quot;reference&quot;;
        srcsec -&gt;  coverage.payor = create('Reference') as reference,  reference.reference = ('https://example/Patient/' + %patient.id) &quot;reference&quot;;
      } &quot;cdaText&quot;;
    } &quot;secact&quot;;
  } &quot;cff&quot;;
}

group ClinicalDocumentSectionPrescrizioneFarmaceutica(source cda : ClinicalDocument, source src : Section, target patient : Patient, target tgt, target bundle : Bundle, target enc : Encounter, target coverage : Coverage, target medRq : MedicationRequest) {
  src.title as t -&gt; tgt.title = (t.dataString);
  src.code -&gt; tgt.code;
  src.text as cdaText -&gt;  tgt.entry = create('Reference') as reference,  reference.reference = ('https://example/MedicationRequest/' + %medRq.id),  tgt.text as fhirText then {
    src.id -&gt; medRq.identifier;
    cdaText -&gt; fhirText.status = 'generated' &quot;narrativeStatus&quot;;
    cdaText as t -&gt; fhirText.div = t &quot;narrativeText&quot;;
    cdaText -&gt;  medRq.subject = create('Reference') as reference,  reference.reference = ('https://example/Patient/' + %patient.id) &quot;reference&quot;;
    cdaText -&gt;  medRq.encounter = create('Reference') as reference,  reference.reference = ('https://example/Encounter/' + %enc.id) &quot;reference&quot;;
    cdaText -&gt; medRq.status = 'active' &quot;status&quot;;
    cdaText -&gt; medRq.intent = 'order' &quot;intent&quot;;
    src.entry as srcent then {
      srcent.substanceAdministration as subAdm then {
        subAdm.effectiveTime : IVL_TS as eff -&gt; medRq.dosageInstruction = create('Dosage') as dosage then {
          subAdm -&gt; dosage.timing = create('Timing') as tim then {
            subAdm -&gt; tim.repeat as repeat then {
              eff -&gt; repeat.bounds = create('Period') as period then IVLTSPeriod(eff, period) &quot;boundsperiod&quot;;
              eff.width as width then {
                width.value as v -&gt; repeat.duration = v;
                width.unit as u -&gt; repeat.durationUnit = u;
              };
            } &quot;repeat&quot;;
          } &quot;timing&quot;;
        } &quot;dosage&quot;;
        subAdm.effectiveTime as eff -&gt; medRq.dosageInstruction = create('Dosage') as dosage then {
          subAdm -&gt; dosage.timing = create('Timing') as tim then {
            eff where eff.low.exists().not() and eff.high.exists().not() then {
              eff.value as v -&gt; tim.event = create('dateTime') as event then TSDateTime(v, event) &quot;evnt&quot;;
            } &quot;effct1&quot;;
          } &quot;timing1&quot;;
        } &quot;dosage1&quot;;
        subAdm.effectiveTime : PIVL_TS as effp -&gt; medRq.dosageInstruction = create('Dosage') as dosage then {
          effp -&gt; dosage.timing = create('Timing') as timing then {
            effp -&gt; timing then periodTiming(effp, timing) &quot;cod&quot;;
            effp where effp.phase.exists() then {
              effp.phase as phase -&gt; timing.repeat as r then {
                phase.low -&gt; r.bounds = create('Period') as period then {
                  phase.low -&gt; period.start &quot;lo&quot;;
                };
                phase.width as wid then {
                  wid.value as v -&gt; r.duration = v &quot;vals&quot;;
                  wid.unit as u -&gt; r.durationUnit = u;
                } &quot;dur&quot;;
              } &quot;rep&quot;;
            } &quot;phase&quot;;
          } &quot;timing&quot;;
        } &quot;eff&quot;;
        subAdm.effectiveTime : EIVL_TS as effe -&gt; medRq.dosageInstruction = create('Dosage') as dosage then {
          effe -&gt; dosage.timing = create('Timing') as timing then {
            effe -&gt; timing.repeat as r then {
              effe.event -&gt; r.when;
              effe.offset as offset then {
                offset.low as v then {
                  v.value as o -&gt; r.offset = o &quot;barabar&quot;;
                } &quot;offs&quot;;
              } &quot;poi&quot;;
            } &quot;lkj&quot;;
          } &quot;ghj&quot;;
        } &quot;eff&quot;;
        subAdm.doseQuantity as doseQuant -&gt; medRq.dosageInstruction = create('Dosage') as dosage then {
          doseQuant.originalText as ot then {
            ot.reference -&gt; dosage.text;
          } &quot;ot&quot;;
          doseQuant -&gt; dosage.doseAndRate as dosageRate then {
            doseQuant -&gt; dosageRate.dose = create('Range') as d then {
              doseQuant -&gt; d.low = create('SimpleQuantity') as l then {
                doseQuant.low as lo -&gt; l.value = (lo.value);
                doseQuant.low as lo -&gt; l.unit = (lo.unit);
              } &quot;low&quot;;
              doseQuant -&gt; d.high = create('SimpleQuantity') as h then {
                doseQuant.high as hi -&gt; h.value = (hi.value);
                doseQuant.high as hi -&gt; h.unit = (hi.unit);
              } &quot;low&quot;;
            } &quot;d&quot;;
          } &quot;dosageRate&quot;;
        } &quot;doseQuant&quot;;
        subAdm -&gt;  bundle.entry as e1,  e1.request = create('BackboneElement') as request,  request.method = 'POST',  e1.resource = create('Medication') as medication,  medication.id = uuid() as uuid1,  e1.fullUrl = append('https://example/Medication/', uuid1),  request.url = 'Medication',  medRq.medication = create('Reference') as reference,  reference.reference = ('https://example/Medication/' + %medication.id) then {
          subAdm.consumable as cons then {
            cons.manufacturedProduct as manuprod then {
              manuprod.manufacturedLabeledDrug as manudrug then {
                manudrug.code -&gt; medication.code;
                manudrug -&gt; medication.identifier as medid then {
                  manudrug.name -&gt; medid.value;
                } &quot;idmedname&quot;;
                manudrug.code as srctxt then {
                  srctxt -&gt; medication.code as typetxt then {
                    srctxt.originalText as ref then {
                      ref.reference as reference then {
                        reference.value as l -&gt; typetxt.text = l &quot;reference&quot;;
                      } &quot;tcf&quot;;
                    } &quot;tcfg&quot;;
                  } &quot;reftxtd&quot;;
                } &quot;origtxtd&quot;;
              } &quot;manudrug&quot;;
              manuprod.manufacturedMaterial as manufact then {
                manufact.code -&gt; medication.code;
                manufact.code as srctxt then {
                  srctxt -&gt; medication.code as typetxt then {
                    srctxt.originalText as ref then {
                      ref.reference as reference then {
                        reference.value as l -&gt; typetxt.text = l &quot;reference&quot;;
                      } &quot;tcf&quot;;
                    } &quot;tcfg&quot;;
                  } &quot;reftxt&quot;;
                } &quot;origtxt&quot;;
                manufact.ingredient as ingredient -&gt; medication.ingredient as ing then {
                  ingredient.quantity as quantity -&gt; ing.strength = create('Ratio') as strength then EmedRTOPQPQRatio(quantity, strength) &quot;strength&quot;;
                  manufact -&gt;  ing.item = create('CodeableConcept') as ingcode,  ingcode.text = (%manufact.name.other) &quot;ingredientCode&quot;;
                } &quot;ingr&quot;;
                manufact.formCode -&gt; medication.form;
                manufact -&gt; medication.identifier as medid &quot;transl&quot;;
              } &quot;manuFact&quot;;
            } &quot;manumat&quot;;
          } &quot;cons&quot;;
          subAdm.entryRelationship as entryrel1 then {
            entryrel1.supply as sup -&gt; medRq.dispenseRequest as dispreq then {
              sup -&gt; dispreq.quantity = create('SimpleQuantity') as quantity then {
                sup.quantity as q -&gt; quantity.value = (q.value);
              } &quot;quantity&quot;;
            };
          } &quot;entry1&quot;;
          subAdm.entryRelationship as entryrel2 where (typeCode = 'REFR') then {
            subAdm -&gt;  medRq.insurance = create('Reference') as reference,  reference.reference = ('https://example/Coverage/' + %coverage.id) then {
              entryrel2.act as act2 -&gt; coverage.costToBeneficiary as cost then {
                act2 -&gt; cost.value = create('SimpleQuantity') as val then {
                  act2 -&gt; val.value = '0' &quot;bnm&quot;;
                } &quot;beneficmoney&quot;;
                act2 -&gt; cost.exception as except then {
                  act2.code -&gt; except.type;
                } &quot;exept&quot;;
              } &quot;act2&quot;;
            } &quot;Cover&quot;;
          } &quot;entry2&quot;;
          subAdm.entryRelationship as entryrel3 where (typeCode = 'RSON') then {
            entryrel3.observation as obs3 where (classCode = 'OBS') then {
              obs3.code -&gt; medRq.reasonCode;
              obs3.text as text then {
                text -&gt; medRq.reasonCode as ce then {
                  // text.reference as reference-&gt; ce.text=reference;
                  text.reference as reference then {
                    reference.value as l -&gt; ce.text = l &quot;reference&quot;;
                  } &quot;tcf&quot;;
                } &quot;originltext&quot;;
              } &quot;txt&quot;;
            } &quot;obs3&quot;;
          } &quot;entry2&quot;;
          subAdm.entryRelationship as entryrel4 where (typeCode = 'SUBJ') then {
            entryrel4.observation as obs3 -&gt; medRq.substitution as sub then {
              obs3.code as Code -&gt; sub.allowed = create('CodeableConcept') as allowed then CECodeableConcept(Code, allowed);
              obs3.entryRelationship as entry then {
                entry.observation as obs4 then {
                  obs4.code -&gt; sub.reason;
                } &quot;obs4&quot;;
              } &quot;entry&quot;;
            } &quot;obs&quot;;
          } &quot;code&quot;;
          subAdm.entryRelationship as entryrel2 where (typeCode = 'SUBJ') then {
            entryrel2.act as act2 where (classCode = 'ACT') then {
              act2.text as text -&gt; medRq.note as note then {
                text.reference as t then {
                  t.value as l -&gt; note.text = l &quot;reference&quot;;
                } &quot;tcx&quot;;
              } &quot;reference&quot;;
            } &quot;obs3&quot;;
          } &quot;entry2&quot;;
        } &quot;subsadm&quot;;
      } &quot;subadm&quot;;
    } &quot;hnjh&quot;;
  } &quot;xxx&quot;;
}

// ------------Sezione Annotazioni-----------------------------------------------------------------------------------------------------------------------------------------
group ClinicalDocumentSectionAnnotazioni(source cda : ClinicalDocument, source src : Section, target patient : Patient, target tgt, target bundle : Bundle, target enc : Encounter, target medRq : MedicationRequest) {
  src.title as t -&gt; tgt.title = (t.dataString);
  src.code -&gt; tgt.code;
  src.text as cdaText -&gt;  tgt.entry = create('Reference') as reference,  reference.reference = ('https://example/MedicationRequest/' + %medRq.id),  tgt.text as fhirText then {
    cdaText -&gt; fhirText.status = 'generated' &quot;narrativeStatus&quot;;
    cdaText as t -&gt; fhirText.div = t &quot;narrativeText&quot;;
    src.entry as entry then {
      entry.act as act then {
        act.text as text -&gt; medRq.note as note then {
          text.reference as t then {
            t.value as l -&gt; note.text = l &quot;reference&quot;;
          } &quot;tcx&quot;;
        } &quot;reference&quot;;
      };
    };
  } &quot;entry&quot;;
}

// ------------Sezione Messaggio Regionale-----------------------------------------------------------------------------------------------------------------------------------------
group ClinicalDocumentSectionMessaggioRegionale(source cda : ClinicalDocument, source src : Section, target patient : Patient, target tgt, target bundle : Bundle, target enc : Encounter, target medRq : MedicationRequest) {
  src.title as t -&gt; tgt.title = (t.dataString);
  src.code -&gt; tgt.code;
  src.text as cdaText -&gt;  tgt.entry = create('Reference') as reference,  reference.reference = ('https://example/MedicationRequest/' + %medRq.id) then {
    cdaText as text -&gt; medRq.note as note then {
      text as t -&gt; note.text = t &quot;reference&quot;;
    } &quot;nota&quot;;
  } &quot;entry&quot;;
}

// ------------Sezione Parametri Vitali-----------------------------------------------------------------------------------------------------------------------------------------
group ClinicalDocumentSectionParametriVitali(source cda : ClinicalDocument, source src : Section, target patient : Patient, target tgt, target bundle : Bundle, target enc : Encounter) {
  src.title as t -&gt; tgt.title = (t.dataString);
  src.code -&gt; tgt.code;
  src.text as cdaText -&gt;  bundle.entry as e8,  e8.request = create('BackboneElement') as request,  request.method = 'POST',  e8.resource = create('Observation') as Observation,  Observation.id = uuid() as uuid8,  e8.fullUrl = append('https://example/Observation/', uuid8),  request.url = 'Observation',  tgt.entry = create('Reference') as reference,  reference.reference = ('https://example/Observation/' + %Observation.id) then {
    src -&gt;  Observation.subject = create('Reference') as reference,  reference.reference = ('https://example/Patient/' + %patient.id) &quot;reference&quot;;
    src -&gt;  Observation.encounter = create('Reference') as reference,  reference.reference = ('https://example/Encounter/' + %enc.id) &quot;reference&quot;;
    src.code -&gt; Observation.code;
    src where Observation.statusCode.exists().not() then {
      src -&gt; Observation.status = 'final' &quot;status&quot;;
    } &quot;statuscode&quot;;
    cdaText -&gt; Observation.note as note then {
      cdaText as t -&gt; note.text = t &quot;reference&quot;;
    } &quot;reference&quot;;
  } &quot;nota&quot;;
}

// ------------Sezione Allergie_Intolleranze-----------------------------------------------------------------------------------------------------------------------------------------
group ClinicalDocumentSectionAllergieaiFarmaci(source cda : ClinicalDocument, source src : Section, target patient : Patient, target tgt, target bundle : Bundle, target enc : Encounter) {
  src.title as t -&gt; tgt.title = (t.dataString);
  src.code -&gt; tgt.code;
  src -&gt;  bundle.entry as e9,  e9.request = create('BackboneElement') as request,  request.method = 'POST',  e9.resource = create('AllergyIntolerance') as allergyIntolerance,  allergyIntolerance.id = uuid() as uuid9,  e9.fullUrl = append('https://example/AllergyIntolerance/', uuid9),  request.url = 'AllergyIntolerance',  tgt.entry = create('Reference') as reference,  reference.reference = ('https://example/AllergyIntolerance/' + %allergyIntolerance.id) then {
    src -&gt;  allergyIntolerance.patient = create('Reference') as reference,  reference.reference = ('https://example/Patient/' + %patient.id) &quot;reference&quot;;
    src -&gt; allergyIntolerance.clinicalStatus = create('CodeableConcept') as status then {
      src -&gt; status.text = 'string' &quot;text&quot;;
      src -&gt; status.coding = create('Coding') as coding then {
        src -&gt; coding.code = 'active' &quot;active&quot;;
        src -&gt; coding.system = 'http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical' &quot;system&quot;;
      } &quot;coding&quot;;
    } &quot;allergy&quot;;
    src.text as cdaText -&gt; allergyIntolerance.note as note then {
      cdaText as t -&gt; note.text = t &quot;reference&quot;;
    } &quot;reference&quot;;
  } &quot;nota&quot;;
}

// ------------Sezione Stato Clinico del Paziente----------------------------------------------------------------------------------------------------------------------------------------
group ClinicalDocumentSectionStatoClinicoPaziente(source cda : ClinicalDocument, source src : Section, target patient : Patient, target tgt, target bundle : Bundle, target enc : Encounter) {
  src.title as t -&gt; tgt.title = (t.dataString);
  src.code -&gt; tgt.code;
  src.text as cdaText -&gt;  bundle.entry as e7,  e7.request = create('BackboneElement') as request,  request.method = 'POST',  e7.resource = create('Observation') as Observation,  Observation.id = uuid() as uuid7,  e7.fullUrl = append('https://example/Observation/', uuid7),  request.url = 'Observation',  tgt.entry = create('Reference') as reference,  reference.reference = ('https://example/Observation/' + %Observation.id) then {
    src -&gt;  Observation.subject = create('Reference') as reference,  reference.reference = ('https://example/Patient/' + %patient.id) &quot;reference&quot;;
    src -&gt;  Observation.encounter = create('Reference') as reference,  reference.reference = ('https://example/Encounter/' + %enc.id) &quot;reference&quot;;
    src.code -&gt; Observation.code;
    src where Observation.statusCode.exists().not() then {
      src -&gt; Observation.status = 'final' &quot;status&quot;;
    } &quot;statuscode&quot;;
    cdaText -&gt; Observation.note as note then {
      cdaText as t -&gt; note.text = t &quot;reference&quot;;
    } &quot;reference&quot;;
  } &quot;nota&quot;;
}

group periodTiming(source effectiveTime : PIVL_TS, target timing : Timing) {
  effectiveTime -&gt; timing.repeat as r then {
    effectiveTime.period as p -&gt; r.period = (p.value);
    effectiveTime.period as p -&gt; r.periodUnit = (p.unit);
  } &quot;repeat&quot;;
}

group EmedRTOPQPQRatio(source src : RTO_PQ_PQ, target tgt : Ratio) {
  src.numerator as numerator -&gt; tgt.numerator as targetNumerator then EmedPQQuantity(numerator, targetNumerator);
  src.denominator as denominator -&gt; tgt.denominator as targetDenominator then EmedPQQuantity(denominator, targetDenominator);
}

group EmedPQQuantity(source src : PQ, target tgt : Quantity) {
  src.value as value -&gt; tgt.value = value;
  src.unit as unit -&gt; tgt.code = unit;
  src.unit as unit -&gt; tgt.system = ('http://fhir.ch/ig/ch-emed/ValueSet/UnitCode'.resolve().compose.include.where(concept.where(code = %unit)).system);
  src.unit as unit -&gt; tgt.unit = ('http://fhir.ch/ig/ch-emed/ValueSet/UnitCode'.resolve().compose.include.concept.where(code = %unit).display);
}

</pre>
      </div>
  </text>
  <url
       value="http://hl7.it/fhir/cda2fhir/StructureMap/cda2fhirMedPrescription"/>
  <version value="0.1.0"/>
  <name value="cda2fhirMedPrescription"/>
  <status value="draft"/>
  <date value="2024-04-11T15:38:19+02:00"/>
  <publisher value="HL7 Italy"/>
  <contact>
    <name value="HL7 Italy"/>
    <telecom>
      <system value="url"/>
      <value value="http://hl7.it"/>
    </telecom>
  </contact>
  <jurisdiction>
    <coding>
      <system value="urn:iso:std:iso:3166"/>
      <code value="IT"/>
      <display value="Italy"/>
    </coding>
  </jurisdiction>
  <structure>
    <url
         value="http://hl7.org/fhir/cda/StructureDefinition/ClinicalDocument"/>
    <mode value="source"/>
    <alias value="ClinicalDocument"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/cda/StructureDefinition/AssignedAuthor"/>
    <mode value="queried"/>
    <alias value="AssignedAuthor"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/cda/StructureDefinition/AssignedEntity"/>
    <mode value="queried"/>
    <alias value="AssignedEntity"/>
  </structure>
  <structure>
    <url
         value="http://hl7.org/fhir/cda/StructureDefinition/AssociatedEntity"/>
    <mode value="queried"/>
    <alias value="AssociatedEntity"/>
  </structure>
  <structure>
    <url
         value="http://hl7.org/fhir/cda/StructureDefinition/CustodianOrganization"/>
    <mode value="queried"/>
    <alias value="CustodianOrganization"/>
  </structure>
  <structure>
    <url
         value="http://hl7.org/fhir/cda/StructureDefinition/OrganizationPartOf"/>
    <mode value="queried"/>
    <alias value="OrganizationPartOf"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/cda/StructureDefinition/Organization"/>
    <mode value="queried"/>
    <alias value="rapresentedOrganization"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/cda/StructureDefinition/Section"/>
    <mode value="queried"/>
    <alias value="Section"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/cda/StructureDefinition/PatientRole"/>
    <mode value="queried"/>
    <alias value="PatientRole"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/cda/StructureDefinition/AD"/>
    <mode value="source"/>
    <alias value="AD"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Bundle"/>
    <mode value="target"/>
    <alias value="Bundle"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Composition"/>
    <mode value="produced"/>
    <alias value="Composition"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Patient"/>
    <mode value="produced"/>
    <alias value="Patient"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Encounter"/>
    <mode value="produced"/>
    <alias value="Encounter"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Person"/>
    <mode value="produced"/>
    <alias value="Patient"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Practitioner"/>
    <mode value="produced"/>
    <alias value="Practitioner"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Organization"/>
    <mode value="produced"/>
    <alias value="Organization"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/cda/StructureDefinition/Act"/>
    <mode value="produced"/>
    <alias value="Act"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/cda/StructureDefinition/IVL-PQ"/>
    <mode value="source"/>
    <alias value="IVL_PQ"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/cda/StructureDefinition/PQ"/>
    <mode value="source"/>
    <alias value="PQ"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/SimpleQuantity"/>
    <mode value="target"/>
    <alias value="SimpleQuantity"/>
  </structure>
  <import value="http://hl7.it/fhir/cda2fhir/StructureMap/cda2fhirDataTypes"/>
  <import value="http://hl7.it/fhir/cda2fhir/StructureMap/cda2fhirHeader"/>
  <group>
    <name value="CdaToBundle"/>
    <typeMode value="none"/>
    <input>
      <name value="cda"/>
      <type value="ClinicalDocument"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="ClinicalDocumentToBody"/>
      <source>
        <context value="cda"/>
      </source>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="e"/>
      </target>
      <target>
        <context value="e"/>
        <contextType value="variable"/>
        <element value="request"/>
        <variable value="request"/>
        <transform value="create"/>
        <parameter>
          <valueString value="BackboneElement"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="method"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="POST"/>
        </parameter>
      </target>
      <target>
        <context value="e"/>
        <contextType value="variable"/>
        <element value="resource"/>
        <variable value="composition"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Composition"/>
        </parameter>
      </target>
      <target>
        <context value="composition"/>
        <contextType value="variable"/>
        <element value="id"/>
        <variable value="uuid1"/>
        <transform value="uuid"/>
      </target>
      <target>
        <context value="e"/>
        <contextType value="variable"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://example/Composition/"/>
        </parameter>
        <parameter>
          <valueId value="uuid1"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="url"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="Composition"/>
        </parameter>
      </target>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="e2"/>
      </target>
      <target>
        <context value="e2"/>
        <contextType value="variable"/>
        <element value="request"/>
        <variable value="requestPAT"/>
        <transform value="create"/>
        <parameter>
          <valueString value="BackboneElement"/>
        </parameter>
      </target>
      <target>
        <context value="requestPAT"/>
        <contextType value="variable"/>
        <element value="method"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="PUT"/>
        </parameter>
      </target>
      <target>
        <context value="e2"/>
        <contextType value="variable"/>
        <element value="resource"/>
        <variable value="patient"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Patient"/>
        </parameter>
      </target>
      <target>
        <context value="patient"/>
        <contextType value="variable"/>
        <element value="id"/>
        <variable value="uuid2"/>
        <transform value="uuid"/>
      </target>
      <target>
        <context value="e2"/>
        <contextType value="variable"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://example/Patient/"/>
        </parameter>
        <parameter>
          <valueId value="uuid2"/>
        </parameter>
      </target>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="e3"/>
      </target>
      <target>
        <context value="e3"/>
        <contextType value="variable"/>
        <element value="request"/>
        <variable value="request"/>
        <transform value="create"/>
        <parameter>
          <valueString value="BackboneElement"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="method"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="POST"/>
        </parameter>
      </target>
      <target>
        <context value="e3"/>
        <contextType value="variable"/>
        <element value="resource"/>
        <variable value="encounter"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Encounter"/>
        </parameter>
      </target>
      <target>
        <context value="encounter"/>
        <contextType value="variable"/>
        <element value="id"/>
        <variable value="uuid3"/>
        <transform value="uuid"/>
      </target>
      <target>
        <context value="e3"/>
        <contextType value="variable"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://example/Encounter/"/>
        </parameter>
        <parameter>
          <valueId value="uuid3"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="url"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="Encounter"/>
        </parameter>
      </target>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="e5"/>
      </target>
      <target>
        <context value="e5"/>
        <contextType value="variable"/>
        <element value="request"/>
        <variable value="request"/>
        <transform value="create"/>
        <parameter>
          <valueString value="BackboneElement"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="method"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="POST"/>
        </parameter>
      </target>
      <target>
        <context value="e5"/>
        <contextType value="variable"/>
        <element value="resource"/>
        <variable value="DocumentReference"/>
        <transform value="create"/>
        <parameter>
          <valueString value="DocumentReference"/>
        </parameter>
      </target>
      <target>
        <context value="DocumentReference"/>
        <contextType value="variable"/>
        <element value="id"/>
        <variable value="uuid5"/>
        <transform value="uuid"/>
      </target>
      <target>
        <context value="e5"/>
        <contextType value="variable"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://example/DocumentReference/"/>
        </parameter>
        <parameter>
          <valueId value="uuid5"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="url"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="DocumentReference"/>
        </parameter>
      </target>
      <rule>
        <name value="cdatobundle"/>
        <source>
          <context value="cda"/>
        </source>
        <dependent>
          <name value="ClinicalDocumentToBundle"/>
          <variable value="cda"/>
          <variable value="patient"/>
          <variable value="composition"/>
          <variable value="encounter"/>
          <variable value="bundle"/>
          <variable value="DocumentReference"/>
        </dependent>
      </rule>
      <rule>
        <name value="patient"/>
        <source>
          <context value="cda"/>
          <element value="recordTarget"/>
          <variable value="recordTarget"/>
        </source>
        <rule>
          <name value="recPat"/>
          <source>
            <context value="recordTarget"/>
            <element value="patientRole"/>
            <variable value="patient"/>
          </source>
          <rule>
            <name value="record"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="id"/>
            </source>
            <target>
              <context value="patient"/>
              <contextType value="variable"/>
              <element value="identifier"/>
              <variable value="identifier"/>
            </target>
            <rule>
              <name value="root1"/>
              <source>
                <context value="id"/>
                <element value="root"/>
                <variable value="r"/>
              </source>
              <target>
                <context value="identifier"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="translate"/>
                <parameter>
                  <valueId value="r"/>
                </parameter>
                <parameter>
                  <valueString
                               value="http://hl7.org/fhir/ConceptMap/special-oid2uri"/>
                </parameter>
                <parameter>
                  <valueString value="uri"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="extension"/>
              <source>
                <context value="id"/>
                <element value="extension"/>
                <variable value="ext"/>
              </source>
              <target>
                <context value="identifier"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="ext"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="assigningAuthorityName"/>
              <source>
                <context value="id"/>
                <element value="assigningAuthorityName"/>
                <variable value="s"/>
              </source>
              <target>
                <context value="identifier"/>
                <contextType value="variable"/>
                <element value="assigner"/>
                <variable value="a"/>
              </target>
              <target>
                <context value="a"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="s"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="ext"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="id"/>
              <condition
                         value="(root = '2.16.840.1.113883.2.9.4.3.2') or (root = '2.16.840.1.113883.2.9.4.3.7') or (root = '2.16.840.1.113883.2.9.4.3.3') or (root = '2.16.840.1.113883.2.9.4.3.17') or (root = '2.16.840.1.113883.2.9.4.3.18') or (root = '2.16.840.1.113883.2.9.2.10.4.1.1') or (root = '2.16.840.1.113883.2.9.2.20.4.1.1') or (root = '2.16.840.1.113883.2.9.2.30.4.1.1') or (root = '2.16.840.1.113883.2.9.2.41.4.1.1') or (root = '2.16.840.1.113883.2.9.2.42.4.1.1') or (root = '2.16.840.1.113883.2.9.2.50.4.1.1') or (root = '2.16.840.1.113883.2.9.2.60.4.1.1') or (root = '2.16.840.1.113883.2.9.2.70.4.1.1') or (root = '2.16.840.1.113883.2.9.2.80.4.1.1') or (root = '2.16.840.1.113883.2.9.2.90.4.1.1') or (root = '2.16.840.1.113883.2.9.2.100.4.1.1') or (root = '2.16.840.1.113883.2.9.2.110.4.1.1') or (root = '2.16.840.1.113883.2.9.2.120.4.1.1') or (root = '2.16.840.1.113883.2.9.2.130.4.1.1') or (root = '2.16.840.1.113883.2.9.2.140.4.1.1') or (root = '2.16.840.1.113883.2.9.2.150.4.1.1') or (root = '2.16.840.1.113883.2.9.2.160.4.1.1') or (root = '2.16.840.1.113883.2.9.2.170.4.1.1') or (root = '2.16.840.1.113883.2.9.2.180.4.1.1') or (root = '2.16.840.1.113883.2.9.2.190.4.1.1') or (root = '2.16.840.1.113883.2.9.2.200.4.1.1') or (root = '2.16.840.1.113883.2.9.2.10.4.1') or (root = '2.16.840.1.113883.2.9.2.20.4.1') or (root = '2.16.840.1.113883.2.9.2.30.4.1') or (root = '2.16.840.1.113883.2.9.2.41.4.1') or (root = '2.16.840.1.113883.2.9.2.42.4.1') or (root = '2.16.840.1.113883.2.9.2.50.4.1') or (root = '2.16.840.1.113883.2.9.2.60.4.1') or (root = '2.16.840.1.113883.2.9.2.70.4.1') or (root = '2.16.840.1.113883.2.9.2.80.4.1') or (root = '2.16.840.1.113883.2.9.2.90.4.1') or (root = '2.16.840.1.113883.2.9.2.100.4.1') or (root = '2.16.840.1.113883.2.9.2.110.4.1') or (root = '2.16.840.1.113883.2.9.2.120.4.1') or (root = '2.16.840.1.113883.2.9.2.130.4.1') or (root = '2.16.840.1.113883.2.9.2.140.4.1') or (root = '2.16.840.1.113883.2.9.2.150.4.1') or (root = '2.16.840.1.113883.2.9.2.160.4.1') or (root = '2.16.840.1.113883.2.9.2.170.4.1') or (root = '2.16.840.1.113883.2.9.2.180.4.1') or (root = '2.16.840.1.113883.2.9.2.190.4.1') or (root = '2.16.840.1.113883.2.9.2.200.4.1') or (root = '2.16.840.1.113883.2.9.4.3.15')"/>
            </source>
            <rule>
              <name value="UUID"/>
              <source>
                <context value="id"/>
                <element value="extension"/>
                <variable value="ext"/>
              </source>
              <target>
                <context value="requestPAT"/>
                <contextType value="variable"/>
                <element value="url"/>
                <transform value="append"/>
                <parameter>
                  <valueString value="Patient?identifier="/>
                </parameter>
                <parameter>
                  <valueId value="ext"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="ClinicalDocumentToBundle"/>
    <typeMode value="none"/>
    <input>
      <name value="cda"/>
      <type value="ClinicalDocument"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="patient"/>
      <type value="Patient"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="composition"/>
      <type value="Composition"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="encounter"/>
      <type value="Encounter"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="DocumentReference"/>
      <type value="DocumentReference"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="id"/>
      <source>
        <context value="cda"/>
      </source>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
    </rule>
    <rule>
      <name value="identifier"/>
      <source>
        <context value="cda"/>
        <element value="id"/>
        <variable value="vvv"/>
      </source>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="identifier"/>
        <variable value="vvv"/>
        <transform value="create"/>
      </target>
    </rule>
    <rule>
      <name value="type"/>
      <source>
        <context value="cda"/>
      </source>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="type"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="transaction"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="date"/>
      <source>
        <context value="cda"/>
      </source>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="timestamp"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="timestamp.now()"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="composition"/>
      <source>
        <context value="cda"/>
      </source>
      <dependent>
        <name value="ClinicalDocumentComposition"/>
        <variable value="cda"/>
        <variable value="composition"/>
        <variable value="patient"/>
        <variable value="encounter"/>
        <variable value="bundle"/>
        <variable value="DocumentReference"/>
      </dependent>
    </rule>
    <rule>
      <name value="component"/>
      <source>
        <context value="cda"/>
        <element value="component"/>
        <variable value="component"/>
      </source>
      <rule>
        <name value="body"/>
        <source>
          <context value="component"/>
          <element value="structuredBody"/>
          <variable value="body"/>
        </source>
        <rule>
          <name value="coverage"/>
          <source>
            <context value="body"/>
          </source>
          <target>
            <context value="bundle"/>
            <contextType value="variable"/>
            <element value="entry"/>
            <variable value="e1"/>
          </target>
          <target>
            <context value="e1"/>
            <contextType value="variable"/>
            <element value="request"/>
            <variable value="request"/>
            <transform value="create"/>
            <parameter>
              <valueString value="BackboneElement"/>
            </parameter>
          </target>
          <target>
            <context value="request"/>
            <contextType value="variable"/>
            <element value="method"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="POST"/>
            </parameter>
          </target>
          <target>
            <context value="e1"/>
            <contextType value="variable"/>
            <element value="resource"/>
            <variable value="coverage"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Coverage"/>
            </parameter>
          </target>
          <target>
            <context value="coverage"/>
            <contextType value="variable"/>
            <element value="id"/>
            <variable value="uuid1"/>
            <transform value="uuid"/>
          </target>
          <target>
            <context value="e1"/>
            <contextType value="variable"/>
            <element value="fullUrl"/>
            <transform value="append"/>
            <parameter>
              <valueString value="https://example/Coverage/"/>
            </parameter>
            <parameter>
              <valueId value="uuid1"/>
            </parameter>
          </target>
          <target>
            <context value="request"/>
            <contextType value="variable"/>
            <element value="url"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Coverage"/>
            </parameter>
          </target>
          <rule>
            <name value="medreq"/>
            <source>
              <context value="body"/>
            </source>
            <target>
              <context value="bundle"/>
              <contextType value="variable"/>
              <element value="entry"/>
              <variable value="e2"/>
            </target>
            <target>
              <context value="e2"/>
              <contextType value="variable"/>
              <element value="request"/>
              <variable value="request"/>
              <transform value="create"/>
              <parameter>
                <valueString value="BackboneElement"/>
              </parameter>
            </target>
            <target>
              <context value="request"/>
              <contextType value="variable"/>
              <element value="method"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="POST"/>
              </parameter>
            </target>
            <target>
              <context value="e2"/>
              <contextType value="variable"/>
              <element value="resource"/>
              <variable value="medRq"/>
              <transform value="create"/>
              <parameter>
                <valueString value="MedicationRequest"/>
              </parameter>
            </target>
            <target>
              <context value="medRq"/>
              <contextType value="variable"/>
              <element value="id"/>
              <variable value="uuid1"/>
              <transform value="uuid"/>
            </target>
            <target>
              <context value="e2"/>
              <contextType value="variable"/>
              <element value="fullUrl"/>
              <transform value="append"/>
              <parameter>
                <valueString value="https://example/MedicationRequest/"/>
              </parameter>
              <parameter>
                <valueId value="uuid1"/>
              </parameter>
            </target>
            <target>
              <context value="request"/>
              <contextType value="variable"/>
              <element value="url"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="MedicationRequest"/>
              </parameter>
            </target>
            <rule>
              <name value="component"/>
              <source>
                <context value="body"/>
                <element value="component"/>
                <variable value="component"/>
              </source>
              <rule>
                <name value="cov"/>
                <source>
                  <context value="component"/>
                  <element value="section"/>
                  <variable value="srcSection"/>
                </source>
                <rule>
                  <name value="esenz"/>
                  <source>
                    <context value="srcSection"/>
                    <element value="code"/>
                    <condition value="(code = '57827-8')"/>
                  </source>
                  <target>
                    <context value="composition"/>
                    <contextType value="variable"/>
                    <element value="section"/>
                    <variable value="tgtSection"/>
                  </target>
                  <dependent>
                    <name value="ClinicalDocumentSectionEsenzioni"/>
                    <variable value="cda"/>
                    <variable value="srcSection"/>
                    <variable value="patient"/>
                    <variable value="tgtSection"/>
                    <variable value="bundle"/>
                    <variable value="encounter"/>
                    <variable value="coverage"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="prescfarm"/>
                  <source>
                    <context value="srcSection"/>
                    <element value="code"/>
                    <condition value="(code = '57828-6')"/>
                  </source>
                  <target>
                    <context value="composition"/>
                    <contextType value="variable"/>
                    <element value="section"/>
                    <variable value="tgtSection"/>
                  </target>
                  <dependent>
                    <name
                          value="ClinicalDocumentSectionPrescrizioneFarmaceutica"/>
                    <variable value="cda"/>
                    <variable value="srcSection"/>
                    <variable value="patient"/>
                    <variable value="tgtSection"/>
                    <variable value="bundle"/>
                    <variable value="encounter"/>
                    <variable value="coverage"/>
                    <variable value="medRq"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="annot"/>
                  <source>
                    <context value="srcSection"/>
                    <element value="code"/>
                    <condition value="(code = '48767-8')"/>
                  </source>
                  <target>
                    <context value="composition"/>
                    <contextType value="variable"/>
                    <element value="section"/>
                    <variable value="tgtSection"/>
                  </target>
                  <dependent>
                    <name value="ClinicalDocumentSectionAnnotazioni"/>
                    <variable value="cda"/>
                    <variable value="srcSection"/>
                    <variable value="patient"/>
                    <variable value="tgtSection"/>
                    <variable value="bundle"/>
                    <variable value="encounter"/>
                    <variable value="medRq"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="messregg"/>
                  <source>
                    <context value="srcSection"/>
                    <element value="code"/>
                    <condition value="(code = '51851-4')"/>
                  </source>
                  <target>
                    <context value="composition"/>
                    <contextType value="variable"/>
                    <element value="section"/>
                    <variable value="tgtSection"/>
                  </target>
                  <dependent>
                    <name value="ClinicalDocumentSectionMessaggioRegionale"/>
                    <variable value="cda"/>
                    <variable value="srcSection"/>
                    <variable value="patient"/>
                    <variable value="tgtSection"/>
                    <variable value="bundle"/>
                    <variable value="encounter"/>
                    <variable value="medRq"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="paramvit"/>
                  <source>
                    <context value="srcSection"/>
                    <element value="code"/>
                    <condition value="(code = '8716-3')"/>
                  </source>
                  <target>
                    <context value="composition"/>
                    <contextType value="variable"/>
                    <element value="section"/>
                    <variable value="tgtSection"/>
                  </target>
                  <dependent>
                    <name value="ClinicalDocumentSectionParametriVitali"/>
                    <variable value="cda"/>
                    <variable value="srcSection"/>
                    <variable value="patient"/>
                    <variable value="tgtSection"/>
                    <variable value="bundle"/>
                    <variable value="encounter"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="allergfarm"/>
                  <source>
                    <context value="srcSection"/>
                    <element value="code"/>
                    <condition value="(code = '48765-2')"/>
                  </source>
                  <target>
                    <context value="composition"/>
                    <contextType value="variable"/>
                    <element value="section"/>
                    <variable value="tgtSection"/>
                  </target>
                  <dependent>
                    <name value="ClinicalDocumentSectionAllergieaiFarmaci"/>
                    <variable value="cda"/>
                    <variable value="srcSection"/>
                    <variable value="patient"/>
                    <variable value="tgtSection"/>
                    <variable value="bundle"/>
                    <variable value="encounter"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="statclinpaz"/>
                  <source>
                    <context value="srcSection"/>
                    <element value="code"/>
                    <condition value="(code = '47420-5')"/>
                  </source>
                  <target>
                    <context value="composition"/>
                    <contextType value="variable"/>
                    <element value="section"/>
                    <variable value="tgtSection"/>
                  </target>
                  <dependent>
                    <name
                          value="ClinicalDocumentSectionStatoClinicoPaziente"/>
                    <variable value="cda"/>
                    <variable value="srcSection"/>
                    <variable value="patient"/>
                    <variable value="tgtSection"/>
                    <variable value="bundle"/>
                    <variable value="encounter"/>
                  </dependent>
                </rule>
                <documentation
                               value="discretizzi il primo livello di component"/>
              </rule>
            </rule>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="ClinicalDocumentSectionEsenzioni"/>
    <typeMode value="none"/>
    <input>
      <name value="cda"/>
      <type value="ClinicalDocument"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="src"/>
      <type value="Section"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="patient"/>
      <type value="Patient"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="tgt"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="enc"/>
      <type value="Encounter"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="coverage"/>
      <type value="Coverage"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="title"/>
      <source>
        <context value="src"/>
        <element value="title"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="title"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="t.dataString"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="code"/>
      <source>
        <context value="src"/>
        <element value="code"/>
        <variable value="vvv"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="code"/>
        <variable value="vvv"/>
        <transform value="create"/>
      </target>
    </rule>
    <rule>
      <name value="cff"/>
      <source>
        <context value="src"/>
        <element value="text"/>
        <variable value="cdaText"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="reference"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="reference"/>
        <contextType value="variable"/>
        <element value="reference"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="'https://example/Coverage/' + %coverage.id"/>
        </parameter>
      </target>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="text"/>
        <variable value="fhirText"/>
      </target>
      <rule>
        <name value="narrativeStatus"/>
        <source>
          <context value="cdaText"/>
        </source>
        <target>
          <context value="fhirText"/>
          <contextType value="variable"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="generated"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="narrativeText"/>
        <source>
          <context value="cdaText"/>
          <variable value="t"/>
        </source>
        <target>
          <context value="fhirText"/>
          <contextType value="variable"/>
          <element value="div"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="t"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="secact"/>
        <source>
          <context value="src"/>
          <element value="entry"/>
          <variable value="srcse"/>
        </source>
        <rule>
          <name value="cdaText"/>
          <source>
            <context value="srcse"/>
            <element value="act"/>
            <variable value="srcsec"/>
          </source>
          <rule>
            <name value="code"/>
            <source>
              <context value="srcsec"/>
              <element value="code"/>
              <variable value="vvv"/>
            </source>
            <target>
              <context value="coverage"/>
              <contextType value="variable"/>
              <element value="type"/>
              <variable value="vvv"/>
              <transform value="create"/>
            </target>
          </rule>
          <rule>
            <name value="origtxt"/>
            <source>
              <context value="srcsec"/>
              <element value="code"/>
              <variable value="srctxt"/>
            </source>
            <rule>
              <name value="reftxt"/>
              <source>
                <context value="srctxt"/>
              </source>
              <target>
                <context value="coverage"/>
                <contextType value="variable"/>
                <element value="type"/>
                <variable value="typetxt"/>
              </target>
              <rule>
                <name value="rfde"/>
                <source>
                  <context value="srctxt"/>
                  <element value="originalText"/>
                  <variable value="ref"/>
                </source>
                <rule>
                  <name value="tcf"/>
                  <source>
                    <context value="ref"/>
                    <element value="reference"/>
                    <variable value="t"/>
                  </source>
                  <rule>
                    <name value="reference"/>
                    <source>
                      <context value="t"/>
                      <element value="value"/>
                      <variable value="l"/>
                    </source>
                    <target>
                      <context value="typetxt"/>
                      <contextType value="variable"/>
                      <element value="text"/>
                      <transform value="copy"/>
                      <parameter>
                        <valueId value="l"/>
                      </parameter>
                    </target>
                  </rule>
                </rule>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="statuscode"/>
            <source>
              <context value="srcsec"/>
              <condition value="coverage.status.exists().not()"/>
            </source>
            <rule>
              <name value="status"/>
              <source>
                <context value="srcsec"/>
              </source>
              <target>
                <context value="coverage"/>
                <contextType value="variable"/>
                <element value="status"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="active"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="reference"/>
            <source>
              <context value="srcsec"/>
            </source>
            <target>
              <context value="coverage"/>
              <contextType value="variable"/>
              <element value="beneficiary"/>
              <variable value="reference"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Reference"/>
              </parameter>
            </target>
            <target>
              <context value="reference"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString
                             value="'https://example/Patient/' + %patient.id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="reference"/>
            <source>
              <context value="srcsec"/>
            </source>
            <target>
              <context value="coverage"/>
              <contextType value="variable"/>
              <element value="payor"/>
              <variable value="reference"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Reference"/>
              </parameter>
            </target>
            <target>
              <context value="reference"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString
                             value="'https://example/Patient/' + %patient.id"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="ClinicalDocumentSectionPrescrizioneFarmaceutica"/>
    <typeMode value="none"/>
    <input>
      <name value="cda"/>
      <type value="ClinicalDocument"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="src"/>
      <type value="Section"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="patient"/>
      <type value="Patient"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="tgt"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="enc"/>
      <type value="Encounter"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="coverage"/>
      <type value="Coverage"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="medRq"/>
      <type value="MedicationRequest"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="title"/>
      <source>
        <context value="src"/>
        <element value="title"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="title"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="t.dataString"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="code"/>
      <source>
        <context value="src"/>
        <element value="code"/>
        <variable value="vvv"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="code"/>
        <variable value="vvv"/>
        <transform value="create"/>
      </target>
    </rule>
    <rule>
      <name value="xxx"/>
      <source>
        <context value="src"/>
        <element value="text"/>
        <variable value="cdaText"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="reference"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="reference"/>
        <contextType value="variable"/>
        <element value="reference"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString
                       value="'https://example/MedicationRequest/' + %medRq.id"/>
        </parameter>
      </target>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="text"/>
        <variable value="fhirText"/>
      </target>
      <rule>
        <name value="id"/>
        <source>
          <context value="src"/>
          <element value="id"/>
          <variable value="vvv"/>
        </source>
        <target>
          <context value="medRq"/>
          <contextType value="variable"/>
          <element value="identifier"/>
          <variable value="vvv"/>
          <transform value="create"/>
        </target>
      </rule>
      <rule>
        <name value="narrativeStatus"/>
        <source>
          <context value="cdaText"/>
        </source>
        <target>
          <context value="fhirText"/>
          <contextType value="variable"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="generated"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="narrativeText"/>
        <source>
          <context value="cdaText"/>
          <variable value="t"/>
        </source>
        <target>
          <context value="fhirText"/>
          <contextType value="variable"/>
          <element value="div"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="t"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="reference"/>
        <source>
          <context value="cdaText"/>
        </source>
        <target>
          <context value="medRq"/>
          <contextType value="variable"/>
          <element value="subject"/>
          <variable value="reference"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Reference"/>
          </parameter>
        </target>
        <target>
          <context value="reference"/>
          <contextType value="variable"/>
          <element value="reference"/>
          <transform value="evaluate"/>
          <parameter>
            <valueString value="'https://example/Patient/' + %patient.id"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="reference"/>
        <source>
          <context value="cdaText"/>
        </source>
        <target>
          <context value="medRq"/>
          <contextType value="variable"/>
          <element value="encounter"/>
          <variable value="reference"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Reference"/>
          </parameter>
        </target>
        <target>
          <context value="reference"/>
          <contextType value="variable"/>
          <element value="reference"/>
          <transform value="evaluate"/>
          <parameter>
            <valueString value="'https://example/Encounter/' + %enc.id"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="status"/>
        <source>
          <context value="cdaText"/>
        </source>
        <target>
          <context value="medRq"/>
          <contextType value="variable"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="active"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="intent"/>
        <source>
          <context value="cdaText"/>
        </source>
        <target>
          <context value="medRq"/>
          <contextType value="variable"/>
          <element value="intent"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="order"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="hnjh"/>
        <source>
          <context value="src"/>
          <element value="entry"/>
          <variable value="srcent"/>
        </source>
        <rule>
          <name value="subadm"/>
          <source>
            <context value="srcent"/>
            <element value="substanceAdministration"/>
            <variable value="subAdm"/>
          </source>
          <rule>
            <name value="dosage"/>
            <source>
              <context value="subAdm"/>
              <type value="IVL_TS"/>
              <element value="effectiveTime"/>
              <variable value="eff"/>
            </source>
            <target>
              <context value="medRq"/>
              <contextType value="variable"/>
              <element value="dosageInstruction"/>
              <variable value="dosage"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Dosage"/>
              </parameter>
            </target>
            <rule>
              <name value="timing"/>
              <source>
                <context value="subAdm"/>
              </source>
              <target>
                <context value="dosage"/>
                <contextType value="variable"/>
                <element value="timing"/>
                <variable value="tim"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="Timing"/>
                </parameter>
              </target>
              <rule>
                <name value="repeat"/>
                <source>
                  <context value="subAdm"/>
                </source>
                <target>
                  <context value="tim"/>
                  <contextType value="variable"/>
                  <element value="repeat"/>
                  <variable value="repeat"/>
                </target>
                <rule>
                  <name value="boundsperiod"/>
                  <source>
                    <context value="eff"/>
                  </source>
                  <target>
                    <context value="repeat"/>
                    <contextType value="variable"/>
                    <element value="bounds"/>
                    <variable value="period"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="Period"/>
                    </parameter>
                  </target>
                  <dependent>
                    <name value="IVLTSPeriod"/>
                    <variable value="eff"/>
                    <variable value="period"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="width"/>
                  <source>
                    <context value="eff"/>
                    <element value="width"/>
                    <variable value="width"/>
                  </source>
                  <rule>
                    <name value="value"/>
                    <source>
                      <context value="width"/>
                      <element value="value"/>
                      <variable value="v"/>
                    </source>
                    <target>
                      <context value="repeat"/>
                      <contextType value="variable"/>
                      <element value="duration"/>
                      <transform value="copy"/>
                      <parameter>
                        <valueId value="v"/>
                      </parameter>
                    </target>
                  </rule>
                  <rule>
                    <name value="unit"/>
                    <source>
                      <context value="width"/>
                      <element value="unit"/>
                      <variable value="u"/>
                    </source>
                    <target>
                      <context value="repeat"/>
                      <contextType value="variable"/>
                      <element value="durationUnit"/>
                      <transform value="copy"/>
                      <parameter>
                        <valueId value="u"/>
                      </parameter>
                    </target>
                  </rule>
                </rule>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="dosage1"/>
            <source>
              <context value="subAdm"/>
              <element value="effectiveTime"/>
              <variable value="eff"/>
            </source>
            <target>
              <context value="medRq"/>
              <contextType value="variable"/>
              <element value="dosageInstruction"/>
              <variable value="dosage"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Dosage"/>
              </parameter>
            </target>
            <rule>
              <name value="timing1"/>
              <source>
                <context value="subAdm"/>
              </source>
              <target>
                <context value="dosage"/>
                <contextType value="variable"/>
                <element value="timing"/>
                <variable value="tim"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="Timing"/>
                </parameter>
              </target>
              <rule>
                <name value="effct1"/>
                <source>
                  <context value="eff"/>
                  <condition
                             value="eff.low.exists().not() and eff.high.exists().not()"/>
                </source>
                <rule>
                  <name value="evnt"/>
                  <source>
                    <context value="eff"/>
                    <element value="value"/>
                    <variable value="v"/>
                  </source>
                  <target>
                    <context value="tim"/>
                    <contextType value="variable"/>
                    <element value="event"/>
                    <variable value="event"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="dateTime"/>
                    </parameter>
                  </target>
                  <dependent>
                    <name value="TSDateTime"/>
                    <variable value="v"/>
                    <variable value="event"/>
                  </dependent>
                </rule>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="eff"/>
            <source>
              <context value="subAdm"/>
              <type value="PIVL_TS"/>
              <element value="effectiveTime"/>
              <variable value="effp"/>
            </source>
            <target>
              <context value="medRq"/>
              <contextType value="variable"/>
              <element value="dosageInstruction"/>
              <variable value="dosage"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Dosage"/>
              </parameter>
            </target>
            <rule>
              <name value="timing"/>
              <source>
                <context value="effp"/>
              </source>
              <target>
                <context value="dosage"/>
                <contextType value="variable"/>
                <element value="timing"/>
                <variable value="timing"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="Timing"/>
                </parameter>
              </target>
              <rule>
                <name value="cod"/>
                <source>
                  <context value="effp"/>
                </source>
                <target>
                  <contextType value="variable"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="timing"/>
                  </parameter>
                </target>
                <dependent>
                  <name value="periodTiming"/>
                  <variable value="effp"/>
                  <variable value="timing"/>
                </dependent>
              </rule>
              <rule>
                <name value="phase"/>
                <source>
                  <context value="effp"/>
                  <condition value="effp.phase.exists()"/>
                </source>
                <rule>
                  <name value="rep"/>
                  <source>
                    <context value="effp"/>
                    <element value="phase"/>
                    <variable value="phase"/>
                  </source>
                  <target>
                    <context value="timing"/>
                    <contextType value="variable"/>
                    <element value="repeat"/>
                    <variable value="r"/>
                  </target>
                  <rule>
                    <name value="low"/>
                    <source>
                      <context value="phase"/>
                      <element value="low"/>
                    </source>
                    <target>
                      <context value="r"/>
                      <contextType value="variable"/>
                      <element value="bounds"/>
                      <variable value="period"/>
                      <transform value="create"/>
                      <parameter>
                        <valueString value="Period"/>
                      </parameter>
                    </target>
                    <rule>
                      <name value="lo"/>
                      <source>
                        <context value="phase"/>
                        <element value="low"/>
                        <variable value="vvv"/>
                      </source>
                      <target>
                        <context value="period"/>
                        <contextType value="variable"/>
                        <element value="start"/>
                        <variable value="vvv"/>
                        <transform value="create"/>
                      </target>
                    </rule>
                  </rule>
                  <rule>
                    <name value="dur"/>
                    <source>
                      <context value="phase"/>
                      <element value="width"/>
                      <variable value="wid"/>
                    </source>
                    <rule>
                      <name value="vals"/>
                      <source>
                        <context value="wid"/>
                        <element value="value"/>
                        <variable value="v"/>
                      </source>
                      <target>
                        <context value="r"/>
                        <contextType value="variable"/>
                        <element value="duration"/>
                        <transform value="copy"/>
                        <parameter>
                          <valueId value="v"/>
                        </parameter>
                      </target>
                    </rule>
                    <rule>
                      <name value="unit"/>
                      <source>
                        <context value="wid"/>
                        <element value="unit"/>
                        <variable value="u"/>
                      </source>
                      <target>
                        <context value="r"/>
                        <contextType value="variable"/>
                        <element value="durationUnit"/>
                        <transform value="copy"/>
                        <parameter>
                          <valueId value="u"/>
                        </parameter>
                      </target>
                    </rule>
                  </rule>
                </rule>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="eff"/>
            <source>
              <context value="subAdm"/>
              <type value="EIVL_TS"/>
              <element value="effectiveTime"/>
              <variable value="effe"/>
            </source>
            <target>
              <context value="medRq"/>
              <contextType value="variable"/>
              <element value="dosageInstruction"/>
              <variable value="dosage"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Dosage"/>
              </parameter>
            </target>
            <rule>
              <name value="ghj"/>
              <source>
                <context value="effe"/>
              </source>
              <target>
                <context value="dosage"/>
                <contextType value="variable"/>
                <element value="timing"/>
                <variable value="timing"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="Timing"/>
                </parameter>
              </target>
              <rule>
                <name value="lkj"/>
                <source>
                  <context value="effe"/>
                </source>
                <target>
                  <context value="timing"/>
                  <contextType value="variable"/>
                  <element value="repeat"/>
                  <variable value="r"/>
                </target>
                <rule>
                  <name value="event"/>
                  <source>
                    <context value="effe"/>
                    <element value="event"/>
                    <variable value="vvv"/>
                  </source>
                  <target>
                    <context value="r"/>
                    <contextType value="variable"/>
                    <element value="when"/>
                    <variable value="vvv"/>
                    <transform value="create"/>
                  </target>
                </rule>
                <rule>
                  <name value="poi"/>
                  <source>
                    <context value="effe"/>
                    <element value="offset"/>
                    <variable value="offset"/>
                  </source>
                  <rule>
                    <name value="offs"/>
                    <source>
                      <context value="offset"/>
                      <element value="low"/>
                      <variable value="v"/>
                    </source>
                    <rule>
                      <name value="barabar"/>
                      <source>
                        <context value="v"/>
                        <element value="value"/>
                        <variable value="o"/>
                      </source>
                      <target>
                        <context value="r"/>
                        <contextType value="variable"/>
                        <element value="offset"/>
                        <transform value="copy"/>
                        <parameter>
                          <valueId value="o"/>
                        </parameter>
                      </target>
                    </rule>
                  </rule>
                </rule>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="doseQuant"/>
            <source>
              <context value="subAdm"/>
              <element value="doseQuantity"/>
              <variable value="doseQuant"/>
            </source>
            <target>
              <context value="medRq"/>
              <contextType value="variable"/>
              <element value="dosageInstruction"/>
              <variable value="dosage"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Dosage"/>
              </parameter>
            </target>
            <rule>
              <name value="ot"/>
              <source>
                <context value="doseQuant"/>
                <element value="originalText"/>
                <variable value="ot"/>
              </source>
              <rule>
                <name value="reference"/>
                <source>
                  <context value="ot"/>
                  <element value="reference"/>
                  <variable value="vvv"/>
                </source>
                <target>
                  <context value="dosage"/>
                  <contextType value="variable"/>
                  <element value="text"/>
                  <variable value="vvv"/>
                  <transform value="create"/>
                </target>
              </rule>
            </rule>
            <rule>
              <name value="dosageRate"/>
              <source>
                <context value="doseQuant"/>
              </source>
              <target>
                <context value="dosage"/>
                <contextType value="variable"/>
                <element value="doseAndRate"/>
                <variable value="dosageRate"/>
              </target>
              <rule>
                <name value="d"/>
                <source>
                  <context value="doseQuant"/>
                </source>
                <target>
                  <context value="dosageRate"/>
                  <contextType value="variable"/>
                  <element value="dose"/>
                  <variable value="d"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="Range"/>
                  </parameter>
                </target>
                <rule>
                  <name value="low"/>
                  <source>
                    <context value="doseQuant"/>
                  </source>
                  <target>
                    <context value="d"/>
                    <contextType value="variable"/>
                    <element value="low"/>
                    <variable value="l"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="SimpleQuantity"/>
                    </parameter>
                  </target>
                  <rule>
                    <name value="low"/>
                    <source>
                      <context value="doseQuant"/>
                      <element value="low"/>
                      <variable value="lo"/>
                    </source>
                    <target>
                      <context value="l"/>
                      <contextType value="variable"/>
                      <element value="value"/>
                      <transform value="evaluate"/>
                      <parameter>
                        <valueString value="lo.value"/>
                      </parameter>
                    </target>
                  </rule>
                  <rule>
                    <name value="low"/>
                    <source>
                      <context value="doseQuant"/>
                      <element value="low"/>
                      <variable value="lo"/>
                    </source>
                    <target>
                      <context value="l"/>
                      <contextType value="variable"/>
                      <element value="unit"/>
                      <transform value="evaluate"/>
                      <parameter>
                        <valueString value="lo.unit"/>
                      </parameter>
                    </target>
                  </rule>
                </rule>
                <rule>
                  <name value="low"/>
                  <source>
                    <context value="doseQuant"/>
                  </source>
                  <target>
                    <context value="d"/>
                    <contextType value="variable"/>
                    <element value="high"/>
                    <variable value="h"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="SimpleQuantity"/>
                    </parameter>
                  </target>
                  <rule>
                    <name value="high"/>
                    <source>
                      <context value="doseQuant"/>
                      <element value="high"/>
                      <variable value="hi"/>
                    </source>
                    <target>
                      <context value="h"/>
                      <contextType value="variable"/>
                      <element value="value"/>
                      <transform value="evaluate"/>
                      <parameter>
                        <valueString value="hi.value"/>
                      </parameter>
                    </target>
                  </rule>
                  <rule>
                    <name value="high"/>
                    <source>
                      <context value="doseQuant"/>
                      <element value="high"/>
                      <variable value="hi"/>
                    </source>
                    <target>
                      <context value="h"/>
                      <contextType value="variable"/>
                      <element value="unit"/>
                      <transform value="evaluate"/>
                      <parameter>
                        <valueString value="hi.unit"/>
                      </parameter>
                    </target>
                  </rule>
                </rule>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="subsadm"/>
            <source>
              <context value="subAdm"/>
            </source>
            <target>
              <context value="bundle"/>
              <contextType value="variable"/>
              <element value="entry"/>
              <variable value="e1"/>
            </target>
            <target>
              <context value="e1"/>
              <contextType value="variable"/>
              <element value="request"/>
              <variable value="request"/>
              <transform value="create"/>
              <parameter>
                <valueString value="BackboneElement"/>
              </parameter>
            </target>
            <target>
              <context value="request"/>
              <contextType value="variable"/>
              <element value="method"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="POST"/>
              </parameter>
            </target>
            <target>
              <context value="e1"/>
              <contextType value="variable"/>
              <element value="resource"/>
              <variable value="medication"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Medication"/>
              </parameter>
            </target>
            <target>
              <context value="medication"/>
              <contextType value="variable"/>
              <element value="id"/>
              <variable value="uuid1"/>
              <transform value="uuid"/>
            </target>
            <target>
              <context value="e1"/>
              <contextType value="variable"/>
              <element value="fullUrl"/>
              <transform value="append"/>
              <parameter>
                <valueString value="https://example/Medication/"/>
              </parameter>
              <parameter>
                <valueId value="uuid1"/>
              </parameter>
            </target>
            <target>
              <context value="request"/>
              <contextType value="variable"/>
              <element value="url"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Medication"/>
              </parameter>
            </target>
            <target>
              <context value="medRq"/>
              <contextType value="variable"/>
              <element value="medication"/>
              <variable value="reference"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Reference"/>
              </parameter>
            </target>
            <target>
              <context value="reference"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString
                             value="'https://example/Medication/' + %medication.id"/>
              </parameter>
            </target>
            <rule>
              <name value="cons"/>
              <source>
                <context value="subAdm"/>
                <element value="consumable"/>
                <variable value="cons"/>
              </source>
              <rule>
                <name value="manumat"/>
                <source>
                  <context value="cons"/>
                  <element value="manufacturedProduct"/>
                  <variable value="manuprod"/>
                </source>
                <rule>
                  <name value="manudrug"/>
                  <source>
                    <context value="manuprod"/>
                    <element value="manufacturedLabeledDrug"/>
                    <variable value="manudrug"/>
                  </source>
                  <rule>
                    <name value="code"/>
                    <source>
                      <context value="manudrug"/>
                      <element value="code"/>
                      <variable value="vvv"/>
                    </source>
                    <target>
                      <context value="medication"/>
                      <contextType value="variable"/>
                      <element value="code"/>
                      <variable value="vvv"/>
                      <transform value="create"/>
                    </target>
                  </rule>
                  <rule>
                    <name value="idmedname"/>
                    <source>
                      <context value="manudrug"/>
                    </source>
                    <target>
                      <context value="medication"/>
                      <contextType value="variable"/>
                      <element value="identifier"/>
                      <variable value="medid"/>
                    </target>
                    <rule>
                      <name value="name"/>
                      <source>
                        <context value="manudrug"/>
                        <element value="name"/>
                        <variable value="vvv"/>
                      </source>
                      <target>
                        <context value="medid"/>
                        <contextType value="variable"/>
                        <element value="value"/>
                        <variable value="vvv"/>
                        <transform value="create"/>
                      </target>
                    </rule>
                  </rule>
                  <rule>
                    <name value="origtxtd"/>
                    <source>
                      <context value="manudrug"/>
                      <element value="code"/>
                      <variable value="srctxt"/>
                    </source>
                    <rule>
                      <name value="reftxtd"/>
                      <source>
                        <context value="srctxt"/>
                      </source>
                      <target>
                        <context value="medication"/>
                        <contextType value="variable"/>
                        <element value="code"/>
                        <variable value="typetxt"/>
                      </target>
                      <rule>
                        <name value="tcfg"/>
                        <source>
                          <context value="srctxt"/>
                          <element value="originalText"/>
                          <variable value="ref"/>
                        </source>
                        <rule>
                          <name value="tcf"/>
                          <source>
                            <context value="ref"/>
                            <element value="reference"/>
                            <variable value="reference"/>
                          </source>
                          <rule>
                            <name value="reference"/>
                            <source>
                              <context value="reference"/>
                              <element value="value"/>
                              <variable value="l"/>
                            </source>
                            <target>
                              <context value="typetxt"/>
                              <contextType value="variable"/>
                              <element value="text"/>
                              <transform value="copy"/>
                              <parameter>
                                <valueId value="l"/>
                              </parameter>
                            </target>
                          </rule>
                        </rule>
                      </rule>
                    </rule>
                  </rule>
                </rule>
                <rule>
                  <name value="manuFact"/>
                  <source>
                    <context value="manuprod"/>
                    <element value="manufacturedMaterial"/>
                    <variable value="manufact"/>
                  </source>
                  <rule>
                    <name value="code"/>
                    <source>
                      <context value="manufact"/>
                      <element value="code"/>
                      <variable value="vvv"/>
                    </source>
                    <target>
                      <context value="medication"/>
                      <contextType value="variable"/>
                      <element value="code"/>
                      <variable value="vvv"/>
                      <transform value="create"/>
                    </target>
                  </rule>
                  <rule>
                    <name value="origtxt"/>
                    <source>
                      <context value="manufact"/>
                      <element value="code"/>
                      <variable value="srctxt"/>
                    </source>
                    <rule>
                      <name value="reftxt"/>
                      <source>
                        <context value="srctxt"/>
                      </source>
                      <target>
                        <context value="medication"/>
                        <contextType value="variable"/>
                        <element value="code"/>
                        <variable value="typetxt"/>
                      </target>
                      <rule>
                        <name value="tcfg"/>
                        <source>
                          <context value="srctxt"/>
                          <element value="originalText"/>
                          <variable value="ref"/>
                        </source>
                        <rule>
                          <name value="tcf"/>
                          <source>
                            <context value="ref"/>
                            <element value="reference"/>
                            <variable value="reference"/>
                          </source>
                          <rule>
                            <name value="reference"/>
                            <source>
                              <context value="reference"/>
                              <element value="value"/>
                              <variable value="l"/>
                            </source>
                            <target>
                              <context value="typetxt"/>
                              <contextType value="variable"/>
                              <element value="text"/>
                              <transform value="copy"/>
                              <parameter>
                                <valueId value="l"/>
                              </parameter>
                            </target>
                          </rule>
                        </rule>
                      </rule>
                    </rule>
                  </rule>
                  <rule>
                    <name value="ingr"/>
                    <source>
                      <context value="manufact"/>
                      <element value="ingredient"/>
                      <variable value="ingredient"/>
                    </source>
                    <target>
                      <context value="medication"/>
                      <contextType value="variable"/>
                      <element value="ingredient"/>
                      <variable value="ing"/>
                    </target>
                    <rule>
                      <name value="strength"/>
                      <source>
                        <context value="ingredient"/>
                        <element value="quantity"/>
                        <variable value="quantity"/>
                      </source>
                      <target>
                        <context value="ing"/>
                        <contextType value="variable"/>
                        <element value="strength"/>
                        <variable value="strength"/>
                        <transform value="create"/>
                        <parameter>
                          <valueString value="Ratio"/>
                        </parameter>
                      </target>
                      <dependent>
                        <name value="EmedRTOPQPQRatio"/>
                        <variable value="quantity"/>
                        <variable value="strength"/>
                      </dependent>
                    </rule>
                    <rule>
                      <name value="ingredientCode"/>
                      <source>
                        <context value="manufact"/>
                      </source>
                      <target>
                        <context value="ing"/>
                        <contextType value="variable"/>
                        <element value="item"/>
                        <variable value="ingcode"/>
                        <transform value="create"/>
                        <parameter>
                          <valueString value="CodeableConcept"/>
                        </parameter>
                      </target>
                      <target>
                        <context value="ingcode"/>
                        <contextType value="variable"/>
                        <element value="text"/>
                        <transform value="evaluate"/>
                        <parameter>
                          <valueString value="%manufact.name.other"/>
                        </parameter>
                      </target>
                    </rule>
                  </rule>
                  <rule>
                    <name value="formCode"/>
                    <source>
                      <context value="manufact"/>
                      <element value="formCode"/>
                      <variable value="vvv"/>
                    </source>
                    <target>
                      <context value="medication"/>
                      <contextType value="variable"/>
                      <element value="form"/>
                      <variable value="vvv"/>
                      <transform value="create"/>
                    </target>
                  </rule>
                  <rule>
                    <name value="transl"/>
                    <source>
                      <context value="manufact"/>
                    </source>
                    <target>
                      <context value="medication"/>
                      <contextType value="variable"/>
                      <element value="identifier"/>
                      <variable value="medid"/>
                    </target>
                  </rule>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="entry1"/>
              <source>
                <context value="subAdm"/>
                <element value="entryRelationship"/>
                <variable value="entryrel1"/>
              </source>
              <rule>
                <name value="supply"/>
                <source>
                  <context value="entryrel1"/>
                  <element value="supply"/>
                  <variable value="sup"/>
                </source>
                <target>
                  <context value="medRq"/>
                  <contextType value="variable"/>
                  <element value="dispenseRequest"/>
                  <variable value="dispreq"/>
                </target>
                <rule>
                  <name value="quantity"/>
                  <source>
                    <context value="sup"/>
                  </source>
                  <target>
                    <context value="dispreq"/>
                    <contextType value="variable"/>
                    <element value="quantity"/>
                    <variable value="quantity"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="SimpleQuantity"/>
                    </parameter>
                  </target>
                  <rule>
                    <name value="quantity"/>
                    <source>
                      <context value="sup"/>
                      <element value="quantity"/>
                      <variable value="q"/>
                    </source>
                    <target>
                      <context value="quantity"/>
                      <contextType value="variable"/>
                      <element value="value"/>
                      <transform value="evaluate"/>
                      <parameter>
                        <valueString value="q.value"/>
                      </parameter>
                    </target>
                  </rule>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="entry2"/>
              <source>
                <context value="subAdm"/>
                <element value="entryRelationship"/>
                <variable value="entryrel2"/>
                <condition value="(typeCode = 'REFR')"/>
              </source>
              <rule>
                <name value="Cover"/>
                <source>
                  <context value="subAdm"/>
                </source>
                <target>
                  <context value="medRq"/>
                  <contextType value="variable"/>
                  <element value="insurance"/>
                  <variable value="reference"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="Reference"/>
                  </parameter>
                </target>
                <target>
                  <context value="reference"/>
                  <contextType value="variable"/>
                  <element value="reference"/>
                  <transform value="evaluate"/>
                  <parameter>
                    <valueString
                                 value="'https://example/Coverage/' + %coverage.id"/>
                  </parameter>
                </target>
                <rule>
                  <name value="act2"/>
                  <source>
                    <context value="entryrel2"/>
                    <element value="act"/>
                    <variable value="act2"/>
                  </source>
                  <target>
                    <context value="coverage"/>
                    <contextType value="variable"/>
                    <element value="costToBeneficiary"/>
                    <variable value="cost"/>
                  </target>
                  <rule>
                    <name value="beneficmoney"/>
                    <source>
                      <context value="act2"/>
                    </source>
                    <target>
                      <context value="cost"/>
                      <contextType value="variable"/>
                      <element value="value"/>
                      <variable value="val"/>
                      <transform value="create"/>
                      <parameter>
                        <valueString value="SimpleQuantity"/>
                      </parameter>
                    </target>
                    <rule>
                      <name value="bnm"/>
                      <source>
                        <context value="act2"/>
                      </source>
                      <target>
                        <context value="val"/>
                        <contextType value="variable"/>
                        <element value="value"/>
                        <transform value="copy"/>
                        <parameter>
                          <valueString value="0"/>
                        </parameter>
                      </target>
                    </rule>
                  </rule>
                  <rule>
                    <name value="exept"/>
                    <source>
                      <context value="act2"/>
                    </source>
                    <target>
                      <context value="cost"/>
                      <contextType value="variable"/>
                      <element value="exception"/>
                      <variable value="except"/>
                    </target>
                    <rule>
                      <name value="code"/>
                      <source>
                        <context value="act2"/>
                        <element value="code"/>
                        <variable value="vvv"/>
                      </source>
                      <target>
                        <context value="except"/>
                        <contextType value="variable"/>
                        <element value="type"/>
                        <variable value="vvv"/>
                        <transform value="create"/>
                      </target>
                    </rule>
                  </rule>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="entry2"/>
              <source>
                <context value="subAdm"/>
                <element value="entryRelationship"/>
                <variable value="entryrel3"/>
                <condition value="(typeCode = 'RSON')"/>
              </source>
              <rule>
                <name value="obs3"/>
                <source>
                  <context value="entryrel3"/>
                  <element value="observation"/>
                  <variable value="obs3"/>
                  <condition value="(classCode = 'OBS')"/>
                </source>
                <rule>
                  <name value="code"/>
                  <source>
                    <context value="obs3"/>
                    <element value="code"/>
                    <variable value="vvv"/>
                  </source>
                  <target>
                    <context value="medRq"/>
                    <contextType value="variable"/>
                    <element value="reasonCode"/>
                    <variable value="vvv"/>
                    <transform value="create"/>
                  </target>
                </rule>
                <rule>
                  <name value="txt"/>
                  <source>
                    <context value="obs3"/>
                    <element value="text"/>
                    <variable value="text"/>
                  </source>
                  <rule>
                    <name value="originltext"/>
                    <source>
                      <context value="text"/>
                    </source>
                    <target>
                      <context value="medRq"/>
                      <contextType value="variable"/>
                      <element value="reasonCode"/>
                      <variable value="ce"/>
                    </target>
                    <rule>
                      <name value="tcf"/>
                      <source>
                        <context value="text"/>
                        <element value="reference"/>
                        <variable value="reference"/>
                      </source>
                      <rule>
                        <name value="reference"/>
                        <source>
                          <context value="reference"/>
                          <element value="value"/>
                          <variable value="l"/>
                        </source>
                        <target>
                          <context value="ce"/>
                          <contextType value="variable"/>
                          <element value="text"/>
                          <transform value="copy"/>
                          <parameter>
                            <valueId value="l"/>
                          </parameter>
                        </target>
                      </rule>
                      <documentation
                                     value="text.reference as reference-&gt; ce.text=reference;"/>
                    </rule>
                  </rule>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="code"/>
              <source>
                <context value="subAdm"/>
                <element value="entryRelationship"/>
                <variable value="entryrel4"/>
                <condition value="(typeCode = 'SUBJ')"/>
              </source>
              <rule>
                <name value="obs"/>
                <source>
                  <context value="entryrel4"/>
                  <element value="observation"/>
                  <variable value="obs3"/>
                </source>
                <target>
                  <context value="medRq"/>
                  <contextType value="variable"/>
                  <element value="substitution"/>
                  <variable value="sub"/>
                </target>
                <rule>
                  <name value="code"/>
                  <source>
                    <context value="obs3"/>
                    <element value="code"/>
                    <variable value="Code"/>
                  </source>
                  <target>
                    <context value="sub"/>
                    <contextType value="variable"/>
                    <element value="allowed"/>
                    <variable value="allowed"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="CodeableConcept"/>
                    </parameter>
                  </target>
                  <dependent>
                    <name value="CECodeableConcept"/>
                    <variable value="Code"/>
                    <variable value="allowed"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="entry"/>
                  <source>
                    <context value="obs3"/>
                    <element value="entryRelationship"/>
                    <variable value="entry"/>
                  </source>
                  <rule>
                    <name value="obs4"/>
                    <source>
                      <context value="entry"/>
                      <element value="observation"/>
                      <variable value="obs4"/>
                    </source>
                    <rule>
                      <name value="code"/>
                      <source>
                        <context value="obs4"/>
                        <element value="code"/>
                        <variable value="vvv"/>
                      </source>
                      <target>
                        <context value="sub"/>
                        <contextType value="variable"/>
                        <element value="reason"/>
                        <variable value="vvv"/>
                        <transform value="create"/>
                      </target>
                    </rule>
                  </rule>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="entry2"/>
              <source>
                <context value="subAdm"/>
                <element value="entryRelationship"/>
                <variable value="entryrel2"/>
                <condition value="(typeCode = 'SUBJ')"/>
              </source>
              <rule>
                <name value="obs3"/>
                <source>
                  <context value="entryrel2"/>
                  <element value="act"/>
                  <variable value="act2"/>
                  <condition value="(classCode = 'ACT')"/>
                </source>
                <rule>
                  <name value="reference"/>
                  <source>
                    <context value="act2"/>
                    <element value="text"/>
                    <variable value="text"/>
                  </source>
                  <target>
                    <context value="medRq"/>
                    <contextType value="variable"/>
                    <element value="note"/>
                    <variable value="note"/>
                  </target>
                  <rule>
                    <name value="tcx"/>
                    <source>
                      <context value="text"/>
                      <element value="reference"/>
                      <variable value="t"/>
                    </source>
                    <rule>
                      <name value="reference"/>
                      <source>
                        <context value="t"/>
                        <element value="value"/>
                        <variable value="l"/>
                      </source>
                      <target>
                        <context value="note"/>
                        <contextType value="variable"/>
                        <element value="text"/>
                        <transform value="copy"/>
                        <parameter>
                          <valueId value="l"/>
                        </parameter>
                      </target>
                    </rule>
                  </rule>
                </rule>
              </rule>
            </rule>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="ClinicalDocumentSectionAnnotazioni"/>
    <typeMode value="none"/>
    <documentation
                   value="------------Sezione Annotazioni-----------------------------------------------------------------------------------------------------------------------------------------"/>
    <input>
      <name value="cda"/>
      <type value="ClinicalDocument"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="src"/>
      <type value="Section"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="patient"/>
      <type value="Patient"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="tgt"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="enc"/>
      <type value="Encounter"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="medRq"/>
      <type value="MedicationRequest"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="title"/>
      <source>
        <context value="src"/>
        <element value="title"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="title"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="t.dataString"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="code"/>
      <source>
        <context value="src"/>
        <element value="code"/>
        <variable value="vvv"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="code"/>
        <variable value="vvv"/>
        <transform value="create"/>
      </target>
    </rule>
    <rule>
      <name value="entry"/>
      <source>
        <context value="src"/>
        <element value="text"/>
        <variable value="cdaText"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="reference"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="reference"/>
        <contextType value="variable"/>
        <element value="reference"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString
                       value="'https://example/MedicationRequest/' + %medRq.id"/>
        </parameter>
      </target>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="text"/>
        <variable value="fhirText"/>
      </target>
      <rule>
        <name value="narrativeStatus"/>
        <source>
          <context value="cdaText"/>
        </source>
        <target>
          <context value="fhirText"/>
          <contextType value="variable"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="generated"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="narrativeText"/>
        <source>
          <context value="cdaText"/>
          <variable value="t"/>
        </source>
        <target>
          <context value="fhirText"/>
          <contextType value="variable"/>
          <element value="div"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="t"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="entry"/>
        <source>
          <context value="src"/>
          <element value="entry"/>
          <variable value="entry"/>
        </source>
        <rule>
          <name value="act"/>
          <source>
            <context value="entry"/>
            <element value="act"/>
            <variable value="act"/>
          </source>
          <rule>
            <name value="reference"/>
            <source>
              <context value="act"/>
              <element value="text"/>
              <variable value="text"/>
            </source>
            <target>
              <context value="medRq"/>
              <contextType value="variable"/>
              <element value="note"/>
              <variable value="note"/>
            </target>
            <rule>
              <name value="tcx"/>
              <source>
                <context value="text"/>
                <element value="reference"/>
                <variable value="t"/>
              </source>
              <rule>
                <name value="reference"/>
                <source>
                  <context value="t"/>
                  <element value="value"/>
                  <variable value="l"/>
                </source>
                <target>
                  <context value="note"/>
                  <contextType value="variable"/>
                  <element value="text"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="l"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="ClinicalDocumentSectionMessaggioRegionale"/>
    <typeMode value="none"/>
    <documentation
                   value="------------Sezione Messaggio Regionale-----------------------------------------------------------------------------------------------------------------------------------------"/>
    <input>
      <name value="cda"/>
      <type value="ClinicalDocument"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="src"/>
      <type value="Section"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="patient"/>
      <type value="Patient"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="tgt"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="enc"/>
      <type value="Encounter"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="medRq"/>
      <type value="MedicationRequest"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="title"/>
      <source>
        <context value="src"/>
        <element value="title"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="title"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="t.dataString"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="code"/>
      <source>
        <context value="src"/>
        <element value="code"/>
        <variable value="vvv"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="code"/>
        <variable value="vvv"/>
        <transform value="create"/>
      </target>
    </rule>
    <rule>
      <name value="entry"/>
      <source>
        <context value="src"/>
        <element value="text"/>
        <variable value="cdaText"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="reference"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="reference"/>
        <contextType value="variable"/>
        <element value="reference"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString
                       value="'https://example/MedicationRequest/' + %medRq.id"/>
        </parameter>
      </target>
      <rule>
        <name value="nota"/>
        <source>
          <context value="cdaText"/>
          <variable value="text"/>
        </source>
        <target>
          <context value="medRq"/>
          <contextType value="variable"/>
          <element value="note"/>
          <variable value="note"/>
        </target>
        <rule>
          <name value="reference"/>
          <source>
            <context value="text"/>
            <variable value="t"/>
          </source>
          <target>
            <context value="note"/>
            <contextType value="variable"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="t"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="ClinicalDocumentSectionParametriVitali"/>
    <typeMode value="none"/>
    <documentation
                   value="------------Sezione Parametri Vitali-----------------------------------------------------------------------------------------------------------------------------------------"/>
    <input>
      <name value="cda"/>
      <type value="ClinicalDocument"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="src"/>
      <type value="Section"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="patient"/>
      <type value="Patient"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="tgt"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="enc"/>
      <type value="Encounter"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="title"/>
      <source>
        <context value="src"/>
        <element value="title"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="title"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="t.dataString"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="code"/>
      <source>
        <context value="src"/>
        <element value="code"/>
        <variable value="vvv"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="code"/>
        <variable value="vvv"/>
        <transform value="create"/>
      </target>
    </rule>
    <rule>
      <name value="nota"/>
      <source>
        <context value="src"/>
        <element value="text"/>
        <variable value="cdaText"/>
      </source>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="e8"/>
      </target>
      <target>
        <context value="e8"/>
        <contextType value="variable"/>
        <element value="request"/>
        <variable value="request"/>
        <transform value="create"/>
        <parameter>
          <valueString value="BackboneElement"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="method"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="POST"/>
        </parameter>
      </target>
      <target>
        <context value="e8"/>
        <contextType value="variable"/>
        <element value="resource"/>
        <variable value="Observation"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <target>
        <context value="Observation"/>
        <contextType value="variable"/>
        <element value="id"/>
        <variable value="uuid8"/>
        <transform value="uuid"/>
      </target>
      <target>
        <context value="e8"/>
        <contextType value="variable"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://example/Observation/"/>
        </parameter>
        <parameter>
          <valueId value="uuid8"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="url"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="reference"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="reference"/>
        <contextType value="variable"/>
        <element value="reference"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString
                       value="'https://example/Observation/' + %Observation.id"/>
        </parameter>
      </target>
      <rule>
        <name value="reference"/>
        <source>
          <context value="src"/>
        </source>
        <target>
          <context value="Observation"/>
          <contextType value="variable"/>
          <element value="subject"/>
          <variable value="reference"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Reference"/>
          </parameter>
        </target>
        <target>
          <context value="reference"/>
          <contextType value="variable"/>
          <element value="reference"/>
          <transform value="evaluate"/>
          <parameter>
            <valueString value="'https://example/Patient/' + %patient.id"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="reference"/>
        <source>
          <context value="src"/>
        </source>
        <target>
          <context value="Observation"/>
          <contextType value="variable"/>
          <element value="encounter"/>
          <variable value="reference"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Reference"/>
          </parameter>
        </target>
        <target>
          <context value="reference"/>
          <contextType value="variable"/>
          <element value="reference"/>
          <transform value="evaluate"/>
          <parameter>
            <valueString value="'https://example/Encounter/' + %enc.id"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="src"/>
          <element value="code"/>
          <variable value="vvv"/>
        </source>
        <target>
          <context value="Observation"/>
          <contextType value="variable"/>
          <element value="code"/>
          <variable value="vvv"/>
          <transform value="create"/>
        </target>
      </rule>
      <rule>
        <name value="statuscode"/>
        <source>
          <context value="src"/>
          <condition value="Observation.statusCode.exists().not()"/>
        </source>
        <rule>
          <name value="status"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="Observation"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="final"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="reference"/>
        <source>
          <context value="cdaText"/>
        </source>
        <target>
          <context value="Observation"/>
          <contextType value="variable"/>
          <element value="note"/>
          <variable value="note"/>
        </target>
        <rule>
          <name value="reference"/>
          <source>
            <context value="cdaText"/>
            <variable value="t"/>
          </source>
          <target>
            <context value="note"/>
            <contextType value="variable"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="t"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="ClinicalDocumentSectionAllergieaiFarmaci"/>
    <typeMode value="none"/>
    <documentation
                   value="------------Sezione Allergie_Intolleranze-----------------------------------------------------------------------------------------------------------------------------------------"/>
    <input>
      <name value="cda"/>
      <type value="ClinicalDocument"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="src"/>
      <type value="Section"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="patient"/>
      <type value="Patient"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="tgt"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="enc"/>
      <type value="Encounter"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="title"/>
      <source>
        <context value="src"/>
        <element value="title"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="title"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="t.dataString"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="code"/>
      <source>
        <context value="src"/>
        <element value="code"/>
        <variable value="vvv"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="code"/>
        <variable value="vvv"/>
        <transform value="create"/>
      </target>
    </rule>
    <rule>
      <name value="nota"/>
      <source>
        <context value="src"/>
      </source>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="e9"/>
      </target>
      <target>
        <context value="e9"/>
        <contextType value="variable"/>
        <element value="request"/>
        <variable value="request"/>
        <transform value="create"/>
        <parameter>
          <valueString value="BackboneElement"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="method"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="POST"/>
        </parameter>
      </target>
      <target>
        <context value="e9"/>
        <contextType value="variable"/>
        <element value="resource"/>
        <variable value="allergyIntolerance"/>
        <transform value="create"/>
        <parameter>
          <valueString value="AllergyIntolerance"/>
        </parameter>
      </target>
      <target>
        <context value="allergyIntolerance"/>
        <contextType value="variable"/>
        <element value="id"/>
        <variable value="uuid9"/>
        <transform value="uuid"/>
      </target>
      <target>
        <context value="e9"/>
        <contextType value="variable"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://example/AllergyIntolerance/"/>
        </parameter>
        <parameter>
          <valueId value="uuid9"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="url"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="AllergyIntolerance"/>
        </parameter>
      </target>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="reference"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="reference"/>
        <contextType value="variable"/>
        <element value="reference"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString
                       value="'https://example/AllergyIntolerance/' + %allergyIntolerance.id"/>
        </parameter>
      </target>
      <rule>
        <name value="reference"/>
        <source>
          <context value="src"/>
        </source>
        <target>
          <context value="allergyIntolerance"/>
          <contextType value="variable"/>
          <element value="patient"/>
          <variable value="reference"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Reference"/>
          </parameter>
        </target>
        <target>
          <context value="reference"/>
          <contextType value="variable"/>
          <element value="reference"/>
          <transform value="evaluate"/>
          <parameter>
            <valueString value="'https://example/Patient/' + %patient.id"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="allergy"/>
        <source>
          <context value="src"/>
        </source>
        <target>
          <context value="allergyIntolerance"/>
          <contextType value="variable"/>
          <element value="clinicalStatus"/>
          <variable value="status"/>
          <transform value="create"/>
          <parameter>
            <valueString value="CodeableConcept"/>
          </parameter>
        </target>
        <rule>
          <name value="text"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="status"/>
            <contextType value="variable"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="string"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="coding"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="status"/>
            <contextType value="variable"/>
            <element value="coding"/>
            <variable value="coding"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Coding"/>
            </parameter>
          </target>
          <rule>
            <name value="active"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="coding"/>
              <contextType value="variable"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="active"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="system"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="coding"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString
                             value="http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="reference"/>
        <source>
          <context value="src"/>
          <element value="text"/>
          <variable value="cdaText"/>
        </source>
        <target>
          <context value="allergyIntolerance"/>
          <contextType value="variable"/>
          <element value="note"/>
          <variable value="note"/>
        </target>
        <rule>
          <name value="reference"/>
          <source>
            <context value="cdaText"/>
            <variable value="t"/>
          </source>
          <target>
            <context value="note"/>
            <contextType value="variable"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="t"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="ClinicalDocumentSectionStatoClinicoPaziente"/>
    <typeMode value="none"/>
    <documentation
                   value="------------Sezione Stato Clinico del Paziente----------------------------------------------------------------------------------------------------------------------------------------"/>
    <input>
      <name value="cda"/>
      <type value="ClinicalDocument"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="src"/>
      <type value="Section"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="patient"/>
      <type value="Patient"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="tgt"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="enc"/>
      <type value="Encounter"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="title"/>
      <source>
        <context value="src"/>
        <element value="title"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="title"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="t.dataString"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="code"/>
      <source>
        <context value="src"/>
        <element value="code"/>
        <variable value="vvv"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="code"/>
        <variable value="vvv"/>
        <transform value="create"/>
      </target>
    </rule>
    <rule>
      <name value="nota"/>
      <source>
        <context value="src"/>
        <element value="text"/>
        <variable value="cdaText"/>
      </source>
      <target>
        <context value="bundle"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="e7"/>
      </target>
      <target>
        <context value="e7"/>
        <contextType value="variable"/>
        <element value="request"/>
        <variable value="request"/>
        <transform value="create"/>
        <parameter>
          <valueString value="BackboneElement"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="method"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="POST"/>
        </parameter>
      </target>
      <target>
        <context value="e7"/>
        <contextType value="variable"/>
        <element value="resource"/>
        <variable value="Observation"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <target>
        <context value="Observation"/>
        <contextType value="variable"/>
        <element value="id"/>
        <variable value="uuid7"/>
        <transform value="uuid"/>
      </target>
      <target>
        <context value="e7"/>
        <contextType value="variable"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://example/Observation/"/>
        </parameter>
        <parameter>
          <valueId value="uuid7"/>
        </parameter>
      </target>
      <target>
        <context value="request"/>
        <contextType value="variable"/>
        <element value="url"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="entry"/>
        <variable value="reference"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="reference"/>
        <contextType value="variable"/>
        <element value="reference"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString
                       value="'https://example/Observation/' + %Observation.id"/>
        </parameter>
      </target>
      <rule>
        <name value="reference"/>
        <source>
          <context value="src"/>
        </source>
        <target>
          <context value="Observation"/>
          <contextType value="variable"/>
          <element value="subject"/>
          <variable value="reference"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Reference"/>
          </parameter>
        </target>
        <target>
          <context value="reference"/>
          <contextType value="variable"/>
          <element value="reference"/>
          <transform value="evaluate"/>
          <parameter>
            <valueString value="'https://example/Patient/' + %patient.id"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="reference"/>
        <source>
          <context value="src"/>
        </source>
        <target>
          <context value="Observation"/>
          <contextType value="variable"/>
          <element value="encounter"/>
          <variable value="reference"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Reference"/>
          </parameter>
        </target>
        <target>
          <context value="reference"/>
          <contextType value="variable"/>
          <element value="reference"/>
          <transform value="evaluate"/>
          <parameter>
            <valueString value="'https://example/Encounter/' + %enc.id"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="src"/>
          <element value="code"/>
          <variable value="vvv"/>
        </source>
        <target>
          <context value="Observation"/>
          <contextType value="variable"/>
          <element value="code"/>
          <variable value="vvv"/>
          <transform value="create"/>
        </target>
      </rule>
      <rule>
        <name value="statuscode"/>
        <source>
          <context value="src"/>
          <condition value="Observation.statusCode.exists().not()"/>
        </source>
        <rule>
          <name value="status"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="Observation"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="final"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="reference"/>
        <source>
          <context value="cdaText"/>
        </source>
        <target>
          <context value="Observation"/>
          <contextType value="variable"/>
          <element value="note"/>
          <variable value="note"/>
        </target>
        <rule>
          <name value="reference"/>
          <source>
            <context value="cdaText"/>
            <variable value="t"/>
          </source>
          <target>
            <context value="note"/>
            <contextType value="variable"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="t"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="periodTiming"/>
    <typeMode value="none"/>
    <input>
      <name value="effectiveTime"/>
      <type value="PIVL_TS"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="timing"/>
      <type value="Timing"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="repeat"/>
      <source>
        <context value="effectiveTime"/>
      </source>
      <target>
        <context value="timing"/>
        <contextType value="variable"/>
        <element value="repeat"/>
        <variable value="r"/>
      </target>
      <rule>
        <name value="period"/>
        <source>
          <context value="effectiveTime"/>
          <element value="period"/>
          <variable value="p"/>
        </source>
        <target>
          <context value="r"/>
          <contextType value="variable"/>
          <element value="period"/>
          <transform value="evaluate"/>
          <parameter>
            <valueString value="p.value"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="period"/>
        <source>
          <context value="effectiveTime"/>
          <element value="period"/>
          <variable value="p"/>
        </source>
        <target>
          <context value="r"/>
          <contextType value="variable"/>
          <element value="periodUnit"/>
          <transform value="evaluate"/>
          <parameter>
            <valueString value="p.unit"/>
          </parameter>
        </target>
      </rule>
    </rule>
  </group>
  <group>
    <name value="EmedRTOPQPQRatio"/>
    <typeMode value="none"/>
    <input>
      <name value="src"/>
      <type value="RTO_PQ_PQ"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="tgt"/>
      <type value="Ratio"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="numerator"/>
      <source>
        <context value="src"/>
        <element value="numerator"/>
        <variable value="numerator"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="numerator"/>
        <variable value="targetNumerator"/>
      </target>
      <dependent>
        <name value="EmedPQQuantity"/>
        <variable value="numerator"/>
        <variable value="targetNumerator"/>
      </dependent>
    </rule>
    <rule>
      <name value="denominator"/>
      <source>
        <context value="src"/>
        <element value="denominator"/>
        <variable value="denominator"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="denominator"/>
        <variable value="targetDenominator"/>
      </target>
      <dependent>
        <name value="EmedPQQuantity"/>
        <variable value="denominator"/>
        <variable value="targetDenominator"/>
      </dependent>
    </rule>
  </group>
  <group>
    <name value="EmedPQQuantity"/>
    <typeMode value="none"/>
    <input>
      <name value="src"/>
      <type value="PQ"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="tgt"/>
      <type value="Quantity"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="value"/>
      <source>
        <context value="src"/>
        <element value="value"/>
        <variable value="value"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="value"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="value"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="unit"/>
      <source>
        <context value="src"/>
        <element value="unit"/>
        <variable value="unit"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="code"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="unit"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="unit"/>
      <source>
        <context value="src"/>
        <element value="unit"/>
        <variable value="unit"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="system"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString
                       value="'http://fhir.ch/ig/ch-emed/ValueSet/UnitCode'.resolve().compose.include.where(concept.where(code = %unit)).system"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="unit"/>
      <source>
        <context value="src"/>
        <element value="unit"/>
        <variable value="unit"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="unit"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString
                       value="'http://fhir.ch/ig/ch-emed/ValueSet/UnitCode'.resolve().compose.include.concept.where(code = %unit).display"/>
        </parameter>
      </target>
    </rule>
  </group>
</StructureMap>