{
  "resourceType": "StructureDefinition",
  "id": "EPMedDispenseLine-23a31d45-7c0b-4217-81f5-210c4238efd4",
  "extension": [
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-category",
      "valueString": "Clinical.Medications"
    },
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category",
      "valueCode": "patient"
    }
  ],
  "url": "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseLine",
  "version": "0.1.0",
  "name": "EPMedDispenseLine",
  "status": "draft",
  "fhirVersion": "4.0.1",
  "mapping": [
    {
      "identity": "workflow",
      "uri": "http://hl7.org/fhir/workflow",
      "name": "Workflow Pattern"
    },
    {
      "identity": "rim",
      "uri": "http://hl7.org/v3",
      "name": "RIM Mapping"
    },
    {
      "identity": "w5",
      "uri": "http://hl7.org/fhir/fivews",
      "name": "FiveWs Pattern Mapping"
    },
    {
      "identity": "rx-dispense-rmim",
      "uri": "http://www.hl7.org/v3/PORX_RM020070UV",
      "name": "V3 Pharmacy Dispense RMIM"
    },
    {
      "identity": "v2",
      "uri": "http://hl7.org/v2",
      "name": "HL7 v2 Mapping"
    }
  ],
  "kind": "resource",
  "abstract": false,
  "type": "MedicationDispense",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/MedicationDispense",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "MedicationDispense",
        "path": "MedicationDispense",
        "short": "The dispensation line"
      },
      {
        "id": "MedicationDispense.id",
        "path": "MedicationDispense.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": "MedicationDispense.meta",
        "path": "MedicationDispense.meta",
        "min": 1
      },
      {
        "id": "MedicationDispense.meta.id",
        "path": "MedicationDispense.meta.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.meta.versionId",
        "path": "MedicationDispense.meta.versionId",
        "max": "0"
      },
      {
        "id": "MedicationDispense.meta.lastUpdated",
        "path": "MedicationDispense.meta.lastUpdated",
        "max": "0"
      },
      {
        "id": "MedicationDispense.meta.source",
        "path": "MedicationDispense.meta.source",
        "max": "0"
      },
      {
        "id": "MedicationDispense.meta.profile",
        "path": "MedicationDispense.meta.profile",
        "min": 1,
        "max": "1",
        "fixedCanonical": "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseLine"
      },
      {
        "id": "MedicationDispense.meta.security",
        "path": "MedicationDispense.meta.security",
        "max": "0"
      },
      {
        "id": "MedicationDispense.meta.tag",
        "path": "MedicationDispense.meta.tag",
        "max": "0"
      },
      {
        "id": "MedicationDispense.implicitRules",
        "path": "MedicationDispense.implicitRules",
        "max": "0"
      },
      {
        "id": "MedicationDispense.language",
        "path": "MedicationDispense.language",
        "max": "0"
      },
      {
        "id": "MedicationDispense.text",
        "path": "MedicationDispense.text",
        "max": "0"
      },
      {
        "id": "MedicationDispense.contained",
        "path": "MedicationDispense.contained",
        "max": "0"
      },
      {
        "id": "MedicationDispense.identifier",
        "path": "MedicationDispense.identifier",
        "short": "Identifier for the dispense line",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Identifier",
            "profile": [
              "https://www.esante.lu/fhir-spec/StructureDefinition/EPSimpleIdentifier"
            ]
          }
        ]
      },
      {
        "id": "MedicationDispense.partOf",
        "path": "MedicationDispense.partOf",
        "max": "0"
      },
      {
        "id": "MedicationDispense.status",
        "path": "MedicationDispense.status",
        "definition": "Constant because the dispense line itself is completed, even though the prescription line may still be open",
        "fixedCode": "completed"
      },
      {
        "id": "MedicationDispense.statusReason[x]",
        "path": "MedicationDispense.statusReason[x]",
        "max": "0"
      },
      {
        "id": "MedicationDispense.category",
        "path": "MedicationDispense.category",
        "definition": "Constant",
        "min": 1
      },
      {
        "id": "MedicationDispense.category.id",
        "path": "MedicationDispense.category.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.category.coding",
        "path": "MedicationDispense.category.coding",
        "min": 1,
        "max": "1",
        "fixedCoding": {
          "code": "MED_DISPLINE",
          "system": "urn:oid:1.3.182.5.56"
        }
      },
      {
        "id": "MedicationDispense.category.coding.id",
        "path": "MedicationDispense.category.coding.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.category.coding.system",
        "path": "MedicationDispense.category.coding.system",
        "min": 1
      },
      {
        "id": "MedicationDispense.category.coding.version",
        "path": "MedicationDispense.category.coding.version",
        "max": "0"
      },
      {
        "id": "MedicationDispense.category.coding.code",
        "path": "MedicationDispense.category.coding.code",
        "min": 1
      },
      {
        "id": "MedicationDispense.category.coding.display",
        "path": "MedicationDispense.category.coding.display",
        "max": "0"
      },
      {
        "id": "MedicationDispense.category.coding.userSelected",
        "path": "MedicationDispense.category.coding.userSelected",
        "max": "0"
      },
      {
        "id": "MedicationDispense.category.text",
        "path": "MedicationDispense.category.text",
        "max": "0"
      },
      {
        "id": "MedicationDispense.medication[x]",
        "path": "MedicationDispense.medication[x]",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedicationDispensation",
              "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedicationNoRef"
            ],
            "aggregation": [
              "referenced",
              "bundled"
            ]
          }
        ]
      },
      {
        "id": "MedicationDispense.medication[x].id",
        "path": "MedicationDispense.medication[x].id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.medication[x].reference",
        "path": "MedicationDispense.medication[x].reference",
        "short": "The dispensed medication",
        "definition": "See examples:\r\nIf the medication is in the referential, simply link to it through the dispensation code\r\nIf the medication is not in the referential, you have to create it, put it in the Bundle and link to it through its fullURL",
        "min": 1,
        "example": [
          {
            "label": "Known medication",
            "valueString": "Medication?identifier=urn:oid:1.3.182.5.48|0277072"
          },
          {
            "label": "Medication not in the referential",
            "valueString": "Medication/urn:uuid:595bbd26-b841-4028-817d-adbcc4cdad3b"
          }
        ],
        "condition": [
          "val-medicationByFullURLOrLocal"
        ],
        "constraint": [
          {
            "key": "val-medicationByFullURLOrLocal",
            "severity": "error",
            "human": "SHALL reference a dispensable medication by its identifier or by its fullURL",
            "expression": "(startsWith('Medication?identifier=urn:oid:1.3.182.5.48|') and length()=50) or (startsWith('Medication/urn:uuid:') and length()=56)",
            "source": "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseLine"
          }
        ]
      },
      {
        "id": "MedicationDispense.medication[x].type",
        "path": "MedicationDispense.medication[x].type",
        "max": "0"
      },
      {
        "id": "MedicationDispense.medication[x].identifier",
        "path": "MedicationDispense.medication[x].identifier",
        "max": "0"
      },
      {
        "id": "MedicationDispense.medication[x].display",
        "path": "MedicationDispense.medication[x].display",
        "max": "0"
      },
      {
        "id": "MedicationDispense.subject",
        "path": "MedicationDispense.subject",
        "short": "The patient",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://www.esante.lu/fhir-spec/StructureDefinition/EPPatient"
            ],
            "aggregation": [
              "referenced"
            ]
          }
        ]
      },
      {
        "id": "MedicationDispense.subject.id",
        "path": "MedicationDispense.subject.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.subject.reference",
        "path": "MedicationDispense.subject.reference",
        "short": "The patient referenced by its matricule",
        "min": 1,
        "example": [
          {
            "label": "Example",
            "valueString": "Patient?identifier=urn:oid:1.3.182.4.4|1904112000166"
          }
        ],
        "constraint": [
          {
            "key": "val-patByMatricule",
            "severity": "error",
            "human": "The Patient SHALL be referenced by its matricule",
            "expression": "startsWith('Patient?identifier=urn:oid:1.3.182.4.4|') and length()=52",
            "source": "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseLine"
          }
        ]
      },
      {
        "id": "MedicationDispense.subject.type",
        "path": "MedicationDispense.subject.type",
        "max": "0"
      },
      {
        "id": "MedicationDispense.subject.identifier",
        "path": "MedicationDispense.subject.identifier",
        "max": "0"
      },
      {
        "id": "MedicationDispense.subject.display",
        "path": "MedicationDispense.subject.display",
        "max": "0"
      },
      {
        "id": "MedicationDispense.context",
        "path": "MedicationDispense.context",
        "short": "The dispense containing this dispense line",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispense"
            ]
          }
        ]
      },
      {
        "id": "MedicationDispense.context.id",
        "path": "MedicationDispense.context.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.context.reference",
        "path": "MedicationDispense.context.reference",
        "short": "The dispensation document (Encounter) referenced bi its fullUrl",
        "min": 1,
        "example": [
          {
            "label": "Example",
            "valueString": "Encounter/urn:uuid:20215b63-6b42-4d1d-970f-ffcc08426a9a"
          }
        ],
        "condition": [
          "val-encounterLocal"
        ],
        "constraint": [
          {
            "key": "val-encounterLocal",
            "severity": "error",
            "human": "SHALL reference the Encounter by its fullURL",
            "expression": "startsWith('Encounter/urn:uuid:') and length()=55",
            "source": "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseLine"
          }
        ]
      },
      {
        "id": "MedicationDispense.context.type",
        "path": "MedicationDispense.context.type",
        "max": "0"
      },
      {
        "id": "MedicationDispense.context.identifier",
        "path": "MedicationDispense.context.identifier",
        "max": "0"
      },
      {
        "id": "MedicationDispense.context.display",
        "path": "MedicationDispense.context.display",
        "max": "0"
      },
      {
        "id": "MedicationDispense.supportingInformation",
        "path": "MedicationDispense.supportingInformation",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer",
        "path": "MedicationDispense.performer",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "actor.type"
            }
          ],
          "rules": "closed"
        },
        "short": "Who dispensed: the parmacist and the pharmacy",
        "min": 2,
        "max": "2"
      },
      {
        "id": "MedicationDispense.performer:Pharmacist",
        "path": "MedicationDispense.performer",
        "sliceName": "Pharmacist",
        "short": "The pharmacist",
        "min": 1,
        "max": "1"
      },
      {
        "id": "MedicationDispense.performer:Pharmacist.id",
        "path": "MedicationDispense.performer.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer:Pharmacist.function",
        "path": "MedicationDispense.performer.function",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer:Pharmacist.actor",
        "path": "MedicationDispense.performer.actor",
        "short": "The pharmacist",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://www.esante.lu/fhir-spec/StructureDefinition/EPPractitioner"
            ],
            "aggregation": [
              "referenced"
            ]
          }
        ]
      },
      {
        "id": "MedicationDispense.performer:Pharmacist.actor.id",
        "path": "MedicationDispense.performer.actor.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer:Pharmacist.actor.reference",
        "path": "MedicationDispense.performer.actor.reference",
        "short": "The health professional referenced by its eHealthID",
        "min": 1,
        "example": [
          {
            "label": "Example",
            "valueString": "Practitioner?identifier=urn:oid:1.3.182.4.1|2999254871"
          }
        ],
        "condition": [
          "val-1"
        ],
        "constraint": [
          {
            "key": "val-1",
            "severity": "error",
            "human": "A Practitioner SHALL be referenced by its eHealthID",
            "expression": "startsWith('Practitioner?identifier=urn:oid:1.3.182.4.1|2') and length()=54",
            "source": "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseLine"
          }
        ]
      },
      {
        "id": "MedicationDispense.performer:Pharmacist.actor.type",
        "path": "MedicationDispense.performer.actor.type",
        "min": 1,
        "fixedUri": "Practitioner"
      },
      {
        "id": "MedicationDispense.performer:Pharmacist.actor.identifier",
        "path": "MedicationDispense.performer.actor.identifier",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer:Pharmacist.actor.display",
        "path": "MedicationDispense.performer.actor.display",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer:Pharmacy",
        "path": "MedicationDispense.performer",
        "sliceName": "Pharmacy",
        "short": "The pharmacy",
        "min": 1,
        "max": "1"
      },
      {
        "id": "MedicationDispense.performer:Pharmacy.id",
        "path": "MedicationDispense.performer.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer:Pharmacy.function",
        "path": "MedicationDispense.performer.function",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer:Pharmacy.actor",
        "path": "MedicationDispense.performer.actor",
        "short": "The pharmacy",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Organization"
            ],
            "aggregation": [
              "referenced"
            ]
          }
        ]
      },
      {
        "id": "MedicationDispense.performer:Pharmacy.actor.id",
        "path": "MedicationDispense.performer.actor.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer:Pharmacy.actor.reference",
        "path": "MedicationDispense.performer.actor.reference",
        "short": "The pharmacy referenced by its eHealthID",
        "min": 1,
        "example": [
          {
            "label": "Example",
            "valueString": "Organization?identifier=urn:oid:1.3.182.4.1|1000180763"
          }
        ],
        "condition": [
          "val-orgByEhealthID"
        ],
        "constraint": [
          {
            "key": "val-orgByEhealthID",
            "severity": "error",
            "human": "SHALL reference an organization by its eHealthID",
            "expression": "startsWith('Organization?identifier=urn:oid:1.3.182.4.1|1') and length()=54",
            "source": "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedDispenseLine"
          }
        ]
      },
      {
        "id": "MedicationDispense.performer:Pharmacy.actor.type",
        "path": "MedicationDispense.performer.actor.type",
        "min": 1,
        "fixedUri": "Organization"
      },
      {
        "id": "MedicationDispense.performer:Pharmacy.actor.identifier",
        "path": "MedicationDispense.performer.actor.identifier",
        "max": "0"
      },
      {
        "id": "MedicationDispense.performer:Pharmacy.actor.display",
        "path": "MedicationDispense.performer.actor.display",
        "max": "0"
      },
      {
        "id": "MedicationDispense.location",
        "path": "MedicationDispense.location",
        "max": "0"
      },
      {
        "id": "MedicationDispense.authorizingPrescription",
        "path": "MedicationDispense.authorizingPrescription",
        "short": "The corresponding prescription line",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://www.esante.lu/fhir-spec/StructureDefinition/EPMedPrescriptionLine"
            ],
            "aggregation": [
              "referenced"
            ]
          }
        ]
      },
      {
        "id": "MedicationDispense.authorizingPrescription.id",
        "path": "MedicationDispense.authorizingPrescription.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.authorizingPrescription.reference",
        "path": "MedicationDispense.authorizingPrescription.reference",
        "short": "The prescriptoin line identifier by its identifier",
        "min": 1,
        "example": [
          {
            "label": "Example",
            "valueString": "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/EPMedDispenseLine"
          }
        ]
      },
      {
        "id": "MedicationDispense.authorizingPrescription.type",
        "path": "MedicationDispense.authorizingPrescription.type",
        "max": "0"
      },
      {
        "id": "MedicationDispense.authorizingPrescription.identifier",
        "path": "MedicationDispense.authorizingPrescription.identifier",
        "max": "0"
      },
      {
        "id": "MedicationDispense.authorizingPrescription.display",
        "path": "MedicationDispense.authorizingPrescription.display",
        "max": "0"
      },
      {
        "id": "MedicationDispense.type",
        "path": "MedicationDispense.type",
        "max": "0"
      },
      {
        "id": "MedicationDispense.quantity",
        "path": "MedicationDispense.quantity",
        "min": 1
      },
      {
        "id": "MedicationDispense.quantity.id",
        "path": "MedicationDispense.quantity.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.quantity.code",
        "path": "MedicationDispense.quantity.code",
        "comment": "The preferred system is UCUM."
      },
      {
        "id": "MedicationDispense.daysSupply",
        "path": "MedicationDispense.daysSupply",
        "max": "0"
      },
      {
        "id": "MedicationDispense.whenPrepared",
        "path": "MedicationDispense.whenPrepared",
        "max": "0"
      },
      {
        "id": "MedicationDispense.whenHandedOver",
        "path": "MedicationDispense.whenHandedOver",
        "short": "Dispensation date",
        "min": 1
      },
      {
        "id": "MedicationDispense.destination",
        "path": "MedicationDispense.destination",
        "max": "0"
      },
      {
        "id": "MedicationDispense.receiver",
        "path": "MedicationDispense.receiver",
        "max": "0"
      },
      {
        "id": "MedicationDispense.note",
        "path": "MedicationDispense.note",
        "max": "0"
      },
      {
        "id": "MedicationDispense.note.author[x]",
        "path": "MedicationDispense.note.author[x]",
        "max": "0"
      },
      {
        "id": "MedicationDispense.note.time",
        "path": "MedicationDispense.note.time",
        "max": "0"
      },
      {
        "id": "MedicationDispense.dosageInstruction",
        "path": "MedicationDispense.dosageInstruction",
        "max": "0"
      },
      {
        "id": "MedicationDispense.substitution",
        "path": "MedicationDispense.substitution",
        "short": "Indicates that a substitution was don",
        "definition": "Only use if there actually was a substitution."
      },
      {
        "id": "MedicationDispense.substitution.id",
        "path": "MedicationDispense.substitution.id",
        "max": "0"
      },
      {
        "id": "MedicationDispense.substitution.wasSubstituted",
        "path": "MedicationDispense.substitution.wasSubstituted",
        "short": "A substitution was done",
        "definition": "As the substitution element is only present when a substitution is done, this element can only be true.",
        "fixedBoolean": true
      },
      {
        "id": "MedicationDispense.substitution.type",
        "path": "MedicationDispense.substitution.type",
        "max": "0"
      },
      {
        "id": "MedicationDispense.substitution.reason",
        "path": "MedicationDispense.substitution.reason",
        "max": "0"
      },
      {
        "id": "MedicationDispense.substitution.responsibleParty",
        "path": "MedicationDispense.substitution.responsibleParty",
        "max": "0"
      },
      {
        "id": "MedicationDispense.detectedIssue",
        "path": "MedicationDispense.detectedIssue",
        "max": "0"
      },
      {
        "id": "MedicationDispense.eventHistory",
        "path": "MedicationDispense.eventHistory",
        "max": "0"
      }
    ]
  }
}