{
  "resourceType": "StructureDefinition",
  "url": "http://electronichealth.se/fhir/StructureDefinition/NLLDetachedDispense",
  "name": "NLLDetachedDispense",
  "status": "draft",
  "fhirVersion": "4.0.0",
  "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"
    },
    {
      "identity": "EHM",
      "uri": "http://ehalsomyndigheten.se",
      "name": "E-hälsomyndighetens internal model"
    }
  ],
  "kind": "resource",
  "abstract": false,
  "type": "MedicationDispense",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/MedicationDispense",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "MedicationDispense.extension",
        "path": "MedicationDispense.extension",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "url"
            }
          ],
          "rules": "open"
        }
      },
      {
        "id": "MedicationDispense.extension:nllDispatchId",
        "path": "MedicationDispense.extension",
        "sliceName": "nllDispatchId",
        "short": "The identifier of the dispatch in which the dispense was made",
        "min": 1,
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://electronichealth.se/fhir/StructureDefinition/NLLDispatchId"
            ]
          }
        ],
        "mapping": [
          {
            "identity": "EHM",
            "map": "Expedition.Expeditions-id"
          }
        ]
      },
      {
        "id": "MedicationDispense.extension:nllNumberOfPackagesDispensed",
        "path": "MedicationDispense.extension",
        "sliceName": "nllNumberOfPackagesDispensed",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://electronichealth.se/fhir/StructureDefinition/NLLNumberOfPackagesDispensed"
            ]
          }
        ],
        "mapping": [
          {
            "identity": "EHM",
            "map": "Antal expedierade förpackningar"
          }
        ]
      },
      {
        "id": "MedicationDispense.extension:nllActorDispatchId",
        "path": "MedicationDispense.extension",
        "sliceName": "nllActorDispatchId",
        "short": "The identifier of the actors dispatch in which the dispense was made",
        "definition": "The identifier of the actors dispatch in which the dispense was made",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://electronichealtb.se/fhir/StructureDefinition/NLLActorDispatchId"
            ]
          }
        ],
        "mapping": [
          {
            "identity": "EHM",
            "map": "Expedition.Aktörens expeditions-id"
          }
        ]
      },
      {
        "id": "MedicationDispense.extension:nllNPLid",
        "path": "MedicationDispense.extension",
        "sliceName": "nllNPLid",
        "short": "NPL id of the dispensed product",
        "definition": "NPL id of the dispensed product, if the dispensed product is a medication.",
        "max": "1",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://electronichealth.se/fhir/StructureDefinition/NLLNplId"
            ]
          }
        ]
      },
      {
        "id": "MedicationDispense.extension:nllNPLid.value[x]",
        "path": "MedicationDispense.extension.value[x]",
        "binding": {
          "strength": "required",
          "description": "NPL id as available in VARA product catalogue.",
          "valueSet": "https://npl.mpa.se/"
        },
        "mapping": [
          {
            "identity": "EHM",
            "map": "NPL-id"
          }
        ]
      },
      {
        "id": "MedicationDispense.extension:nllPrescriptionDetails",
        "path": "MedicationDispense.extension",
        "sliceName": "nllPrescriptionDetails",
        "short": "Information from the authorizing prescription",
        "definition": "Information from the authorizing prescription",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://electronichealth.se/fhir/StructureDefinition/NLLPrescriptionDetails"
            ]
          }
        ]
      },
      {
        "id": "MedicationDispense.status",
        "path": "MedicationDispense.status",
        "short": "in-progress | cancelled",
        "definition": "Note! Used in NLL when a dispense is cancelled (sv: uttaget backat). If the dispense should be cancelled and credited the status cancelled is used to show that this dispense is no longer used. TODO, kolla vilka övriga statusar som används. Completed?",
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.medication[x]",
        "path": "MedicationDispense.medication[x]",
        "mustSupport": true,
        "binding": {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName",
              "valueString": "MedicationCode"
            }
          ],
          "strength": "required",
          "description": "Swedish medicine packages and reimbursed consumables.",
          "valueSet": "http://electronichealth.se/fhir/ValueSet/medicines-consumables"
        },
        "mapping": [
          {
            "identity": "EHM",
            "map": "Artikel.Läkemedelsartikel.NPL Pack id"
          },
          {
            "identity": "EHM",
            "map": "Artikel.Handelsvaruartikel.Varunummer"
          }
        ]
      },
      {
        "id": "MedicationDispense.subject",
        "path": "MedicationDispense.subject",
        "short": "Which patient the dispense is for",
        "definition": "A patient with swedish national identification number (sv: personnummer) should be referenced, other cases should be handled by containing the patient resource.",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://electronichealth.se/fhir/StructureDefinition/NLLPatient"
            ],
            "aggregation": [
              "contained",
              "referenced"
            ]
          }
        ],
        "mustSupport": true,
        "mapping": [
          {
            "identity": "EHM",
            "map": "Patient"
          }
        ]
      },
      {
        "id": "MedicationDispense.authorizingPrescription",
        "path": "MedicationDispense.authorizingPrescription",
        "definition": "Indicates the medication order that is being dispensed against. In this profile, the authorizing prescription is always in paper form (current format)  and/or there is no electronic presecription in NLL to refer to (sv: uttag där underlaget är ett papper eller ett utländskt e-recept)",
        "max": "0"
      },
      {
        "id": "MedicationDispense.authorizingPrescription.reference",
        "path": "MedicationDispense.authorizingPrescription.reference",
        "max": "0"
      },
      {
        "id": "MedicationDispense.authorizingPrescription.identifier",
        "path": "MedicationDispense.authorizingPrescription.identifier",
        "max": "0"
      },
      {
        "id": "MedicationDispense.type",
        "path": "MedicationDispense.type",
        "short": "Only used for Trial Fill (Startförpacking)",
        "definition": "Type is only used for \"Trial fill\" (startförpackning) in the Swedish National Medication List. May not be set for dose dispensed dispenses.",
        "mustSupport": true,
        "binding": {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName",
              "valueString": "MedicationDispenseType"
            }
          ],
          "strength": "required",
          "description": "Indicates the type of dispensing event that is performed. Only used for Trial Fill (Startförpacking)",
          "valueSet": "http://electronichealth.se/fhir/ValueSet/dispense-types"
        },
        "mapping": [
          {
            "identity": "EHM",
            "map": "Startförpackning"
          }
        ]
      },
      {
        "id": "MedicationDispense.quantity",
        "path": "MedicationDispense.quantity",
        "binding": {
          "strength": "required",
          "valueSet": "http://electronichealth.se/fhir/ValueSet/dose-quantity-units"
        },
        "mapping": [
          {
            "identity": "EHM",
            "map": "Expedierad mängd"
          }
        ]
      },
      {
        "id": "MedicationDispense.whenHandedOver",
        "path": "MedicationDispense.whenHandedOver",
        "mustSupport": true,
        "mapping": [
          {
            "identity": "EHM",
            "map": "Expediering.Expedieringstidpunkt"
          }
        ]
      },
      {
        "id": "MedicationDispense.dosageInstruction",
        "path": "MedicationDispense.dosageInstruction",
        "max": "1"
      },
      {
        "id": "MedicationDispense.dosageInstruction.text",
        "path": "MedicationDispense.dosageInstruction.text",
        "short": "Free text dosage instructions",
        "definition": "Free text dosage instructions",
        "min": 1,
        "mustSupport": true,
        "mapping": [
          {
            "identity": "EHM",
            "map": "Doseringstext"
          }
        ]
      },
      {
        "id": "MedicationDispense.substitution.extension",
        "path": "MedicationDispense.substitution.extension",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "url"
            }
          ],
          "rules": "open"
        }
      },
      {
        "id": "MedicationDispense.substitution.extension:nllSubstitutionAllowed",
        "path": "MedicationDispense.substitution.extension",
        "sliceName": "nllSubstitutionAllowed",
        "short": "Indicates if medication may be substituted",
        "definition": "Indicates if medication may be substituted (sv: generisk substotution tillåten)",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://electronichealth.se/fhir/StructureDefinition/NLLSubstitutionAllowed"
            ]
          }
        ],
        "mapping": [
          {
            "identity": "EHM",
            "map": "Substitution ej tillåten",
            "comment": "Detta element motsvarar substitution TILLÅTEN då detta harmonierar med FHIRs definition av substitution."
          }
        ]
      }
    ]
  }
}