<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="EPMedDispenseBundle-609d5cfb-5e7a-46e5-a341-67b291c6bebd" />
  <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-category">
    <valueString value="Foundation.Other" />
  </extension>
  <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category">
    <valueCode value="not-classified" />
  </extension>
  <url value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseBundle" />
  <version value="0.1.0" />
  <name value="EPMedDispenseBundle" />
  <status value="draft" />
  <fhirVersion value="4.0.1" />
  <mapping>
    <identity value="v2" />
    <uri value="http://hl7.org/v2" />
    <name value="HL7 v2 Mapping" />
  </mapping>
  <mapping>
    <identity value="rim" />
    <uri value="http://hl7.org/v3" />
    <name value="RIM Mapping" />
  </mapping>
  <mapping>
    <identity value="cda" />
    <uri value="http://hl7.org/v3/cda" />
    <name value="CDA (R2)" />
  </mapping>
  <mapping>
    <identity value="w5" />
    <uri value="http://hl7.org/fhir/fivews" />
    <name value="FiveWs Pattern Mapping" />
  </mapping>
  <kind value="resource" />
  <abstract value="false" />
  <type value="Bundle" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Bundle" />
  <derivation value="constraint" />
  <differential>
    <element id="Bundle">
      <path value="Bundle" />
      <condition value="val-SamePatientMedDisp" />
      <condition value="val-SamePharmMedDisp" />
      <condition value="val-SamePSMedDisp" />
      <constraint>
        <key value="val-SamePatientMedDisp" />
        <severity value="error" />
        <human value="Patient SHALL be the same" />
        <expression value="Bundle.entry.resource.ofType(MedicationDispense).subject.reference.union(Bundle.entry.resource.ofType(Encounter).subject.reference).count()=1" />
        <source value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseBundle-609d5cfb-5e7a-46e5-a341-67b291c6bebd" />
      </constraint>
      <constraint>
        <key value="val-SamePharmMedDisp" />
        <severity value="error" />
        <human value="Organization SHALL be the same" />
        <expression value="Bundle.entry.resource.ofType(MedicationDispense).performer.actor.where(type='Organization').reference.union(Bundle.entry.resource.ofType(Encounter).serviceProvider.reference).count()=1" />
        <source value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseBundle-609d5cfb-5e7a-46e5-a341-67b291c6bebd" />
      </constraint>
      <constraint>
        <key value="val-SamePSMedDisp" />
        <severity value="error" />
        <human value="Practitioner SHALL be the same" />
        <expression value="Bundle.entry.resource.ofType(MedicationDispense).performer.actor.where(type='Practitioner').reference.union(Bundle.entry.resource.ofType(Encounter).participant.individual.reference).count()=1" />
        <source value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseBundle-609d5cfb-5e7a-46e5-a341-67b291c6bebd" />
      </constraint>
    </element>
    <element id="Bundle.id">
      <path value="Bundle.id" />
      <definition value="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.&#xD;&#xA;Is assigned by the server, do not provide a value." />
    </element>
    <element id="Bundle.meta">
      <path value="Bundle.meta" />
      <min value="1" />
    </element>
    <element id="Bundle.meta.id">
      <path value="Bundle.meta.id" />
      <max value="0" />
    </element>
    <element id="Bundle.meta.versionId">
      <path value="Bundle.meta.versionId" />
      <max value="0" />
    </element>
    <element id="Bundle.meta.lastUpdated">
      <path value="Bundle.meta.lastUpdated" />
      <max value="0" />
    </element>
    <element id="Bundle.meta.source">
      <path value="Bundle.meta.source" />
      <max value="0" />
    </element>
    <element id="Bundle.meta.profile">
      <path value="Bundle.meta.profile" />
      <min value="1" />
      <max value="1" />
      <fixedCanonical value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseBundle" />
    </element>
    <element id="Bundle.meta.security">
      <path value="Bundle.meta.security" />
      <max value="0" />
    </element>
    <element id="Bundle.meta.tag">
      <path value="Bundle.meta.tag" />
      <max value="0" />
    </element>
    <element id="Bundle.implicitRules">
      <path value="Bundle.implicitRules" />
      <max value="0" />
    </element>
    <element id="Bundle.language">
      <path value="Bundle.language" />
      <max value="0" />
    </element>
    <element id="Bundle.identifier">
      <path value="Bundle.identifier" />
      <max value="0" />
    </element>
    <element id="Bundle.type">
      <path value="Bundle.type" />
      <definition value="Constant" />
      <fixedCode value="transaction" />
    </element>
    <element id="Bundle.timestamp">
      <path value="Bundle.timestamp" />
      <max value="0" />
    </element>
    <element id="Bundle.total">
      <path value="Bundle.total" />
      <max value="0" />
    </element>
    <element id="Bundle.link">
      <path value="Bundle.link" />
      <max value="0" />
    </element>
    <element id="Bundle.entry">
      <path value="Bundle.entry" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="resource.meta.profile" />
        </discriminator>
        <rules value="closed" />
      </slicing>
      <min value="2" />
    </element>
    <element id="Bundle.entry:dispensation">
      <path value="Bundle.entry" />
      <sliceName value="dispensation" />
      <short value="The dispensation" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Bundle.entry:dispensation.id">
      <path value="Bundle.entry.id" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensation.link">
      <path value="Bundle.entry.link" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensation.fullUrl">
      <path value="Bundle.entry.fullUrl" />
      <short value="UUID of the resource" />
      <definition value="This is a UUID to identify the element inside the Bundle.&#xD;&#xA;It SHALL start with urn:uuid: and then an UUID version 4 randomly generated. Its scope is only the Bundle, it is not linked outside from it and not saved." />
      <min value="1" />
      <example>
        <label value="Valid example" />
        <valueUri value="urn:uuid:d00069b7-1fc8-4397-bc7c-c9571319d890" />
      </example>
      <condition value="val-uuid" />
      <constraint>
        <key value="val-uuid" />
        <severity value="error" />
        <human value="SHALL be a v4 UUID prefixed by urn:uuid:" />
        <expression value="startsWith('urn:uuid:') and length()=45" />
        <source value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseBundle" />
      </constraint>
    </element>
    <element id="Bundle.entry:dispensation.resource">
      <path value="Bundle.entry.resource" />
      <short value="The dispensation" />
      <min value="1" />
      <type>
        <code value="Encounter" />
        <profile value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispense" />
      </type>
    </element>
    <element id="Bundle.entry:dispensation.search">
      <path value="Bundle.entry.search" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensation.request">
      <path value="Bundle.entry.request" />
      <min value="1" />
    </element>
    <element id="Bundle.entry:dispensation.request.id">
      <path value="Bundle.entry.request.id" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensation.request.method">
      <path value="Bundle.entry.request.method" />
      <definition value="Constant" />
      <fixedCode value="POST" />
    </element>
    <element id="Bundle.entry:dispensation.request.url">
      <path value="Bundle.entry.request.url" />
      <short value="Constant" />
      <fixedUri value="Encounter" />
    </element>
    <element id="Bundle.entry:dispensation.request.ifNoneMatch">
      <path value="Bundle.entry.request.ifNoneMatch" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensation.request.ifModifiedSince">
      <path value="Bundle.entry.request.ifModifiedSince" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensation.request.ifMatch">
      <path value="Bundle.entry.request.ifMatch" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensation.request.ifNoneExist">
      <path value="Bundle.entry.request.ifNoneExist" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensation.response">
      <path value="Bundle.entry.response" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensationLine">
      <path value="Bundle.entry" />
      <sliceName value="dispensationLine" />
      <short value="Dispensation lines" />
      <min value="1" />
      <max value="*" />
    </element>
    <element id="Bundle.entry:dispensationLine.id">
      <path value="Bundle.entry.id" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensationLine.link">
      <path value="Bundle.entry.link" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensationLine.fullUrl">
      <path value="Bundle.entry.fullUrl" />
      <short value="UUID of the resource" />
      <definition value="This is a UUID to identify the element inside the Bundle.&#xD;&#xA;It SHALL start with urn:uuid: and then an UUID version 4 randomly generated. Its scope is only the Bundle, it is not linked outside from it and not saved." />
      <min value="1" />
      <condition value="val-uuid" />
      <constraint>
        <key value="val-uuid" />
        <severity value="error" />
        <human value="SHALL be a v4 UUID prefixed by urn:uuid:" />
        <expression value="startsWith('urn:uuid:') and length()=45" />
        <source value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseBundle" />
      </constraint>
    </element>
    <element id="Bundle.entry:dispensationLine.resource">
      <path value="Bundle.entry.resource" />
      <short value="Dispensation lines" />
      <min value="1" />
      <type>
        <code value="MedicationDispense" />
        <profile value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseLine" />
      </type>
    </element>
    <element id="Bundle.entry:dispensationLine.search">
      <path value="Bundle.entry.search" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensationLine.request">
      <path value="Bundle.entry.request" />
      <min value="1" />
    </element>
    <element id="Bundle.entry:dispensationLine.request.id">
      <path value="Bundle.entry.request.id" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensationLine.request.method">
      <path value="Bundle.entry.request.method" />
      <definition value="Constnat" />
      <fixedCode value="POST" />
    </element>
    <element id="Bundle.entry:dispensationLine.request.url">
      <path value="Bundle.entry.request.url" />
      <short value="Constant" />
      <fixedUri value="MedicationDispense" />
    </element>
    <element id="Bundle.entry:dispensationLine.request.ifNoneMatch">
      <path value="Bundle.entry.request.ifNoneMatch" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensationLine.request.ifModifiedSince">
      <path value="Bundle.entry.request.ifModifiedSince" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensationLine.request.ifMatch">
      <path value="Bundle.entry.request.ifMatch" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensationLine.request.ifNoneExist">
      <path value="Bundle.entry.request.ifNoneExist" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:dispensationLine.response">
      <path value="Bundle.entry.response" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:update">
      <path value="Bundle.entry" />
      <sliceName value="update" />
      <short value="Update of the prescription line" />
      <min value="0" />
      <max value="*" />
    </element>
    <element id="Bundle.entry:update.id">
      <path value="Bundle.entry.id" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:update.link">
      <path value="Bundle.entry.link" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:update.fullUrl">
      <path value="Bundle.entry.fullUrl" />
      <short value="UUID of the resource" />
      <definition value="This is a UUID to identify the element inside the Bundle.&#xD;&#xA;It SHALL start with urn:uuid: and then an UUID version 4 randomly generated. Its scope is only the Bundle, it is not linked outside from it and not saved." />
      <max value="0" />
      <condition value="val-uuid" />
      <constraint>
        <key value="val-uuid" />
        <severity value="error" />
        <human value="SHALL be a v4 UUID prefixed by urn:uuid:" />
        <expression value="startsWith('urn:uuid:') and length()=45" />
        <source value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseBundle" />
      </constraint>
    </element>
    <element id="Bundle.entry:update.resource">
      <path value="Bundle.entry.resource" />
      <short value="The update" />
      <min value="1" />
      <type>
        <code value="Parameters" />
        <profile value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedLineUpdate" />
      </type>
    </element>
    <element id="Bundle.entry:update.search">
      <path value="Bundle.entry.search" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:update.request">
      <path value="Bundle.entry.request" />
      <min value="1" />
    </element>
    <element id="Bundle.entry:update.request.id">
      <path value="Bundle.entry.request.id" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:update.request.method">
      <path value="Bundle.entry.request.method" />
      <definition value="Constant" />
      <fixedCode value="PATCH" />
    </element>
    <element id="Bundle.entry:update.request.url">
      <path value="Bundle.entry.request.url" />
      <short value="The MedicationRequest (prescription line) to update, referenced by its identifier" />
      <example>
        <label value="Example" />
        <valueUri value="MedicationRequest?identifier=urn:ietf:rfc:3986|urn:uuid:c734092c-b7d4-4d63-a839-9d829fcd33e8" />
      </example>
      <condition value="val-refMedRequest" />
      <constraint>
        <key value="val-refMedRequest" />
        <severity value="error" />
        <human value="SHALL reference the prescription line by its identifier" />
        <expression value="startsWith('MedicationRequest?identifier=urn:ietf:rfc:3986|urn:uuid:') and length()=92" />
        <source value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseBundle" />
      </constraint>
    </element>
    <element id="Bundle.entry:update.request.ifNoneMatch">
      <path value="Bundle.entry.request.ifNoneMatch" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:update.request.ifModifiedSince">
      <path value="Bundle.entry.request.ifModifiedSince" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:update.request.ifMatch">
      <path value="Bundle.entry.request.ifMatch" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:update.request.ifNoneExist">
      <path value="Bundle.entry.request.ifNoneExist" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:update.response">
      <path value="Bundle.entry.response" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:nonRefMedication">
      <path value="Bundle.entry" />
      <sliceName value="nonRefMedication" />
      <min value="0" />
      <max value="*" />
    </element>
    <element id="Bundle.entry:nonRefMedication.id">
      <path value="Bundle.entry.id" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:nonRefMedication.link">
      <path value="Bundle.entry.link" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:nonRefMedication.fullUrl">
      <path value="Bundle.entry.fullUrl" />
      <short value="UUID of the resource" />
      <definition value="This is a UUID to identify the element inside the Bundle.&#xD;&#xA;It SHALL start with urn:uuid: and then an UUID version 4 randomly generated. Its scope is only the Bundle, it is not linked outside from it and not saved." />
      <min value="1" />
    </element>
    <element id="Bundle.entry:nonRefMedication.resource">
      <path value="Bundle.entry.resource" />
      <short value="Medication not in referential" />
      <min value="1" />
      <type>
        <code value="Medication" />
        <profile value="https://www.esante.lu/fhir-spec/StructureDefinition/EPMedicationNoRef" />
      </type>
    </element>
    <element id="Bundle.entry:nonRefMedication.search">
      <path value="Bundle.entry.search" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:nonRefMedication.request">
      <path value="Bundle.entry.request" />
      <min value="1" />
    </element>
    <element id="Bundle.entry:nonRefMedication.request.id">
      <path value="Bundle.entry.request.id" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:nonRefMedication.request.method">
      <path value="Bundle.entry.request.method" />
      <short value="Constant" />
      <fixedCode value="POST" />
    </element>
    <element id="Bundle.entry:nonRefMedication.request.url">
      <path value="Bundle.entry.request.url" />
      <short value="Constant" />
      <fixedUri value="Medication" />
    </element>
    <element id="Bundle.entry:nonRefMedication.request.ifNoneMatch">
      <path value="Bundle.entry.request.ifNoneMatch" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:nonRefMedication.request.ifModifiedSince">
      <path value="Bundle.entry.request.ifModifiedSince" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:nonRefMedication.request.ifMatch">
      <path value="Bundle.entry.request.ifMatch" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:nonRefMedication.request.ifNoneExist">
      <path value="Bundle.entry.request.ifNoneExist" />
      <max value="0" />
    </element>
    <element id="Bundle.entry:nonRefMedication.response">
      <path value="Bundle.entry.response" />
      <max value="0" />
    </element>
    <element id="Bundle.signature">
      <path value="Bundle.signature" />
      <max value="0" />
    </element>
  </differential>
</StructureDefinition>