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