{
  "resourceType": "StructureDefinition",
  "id": "profile-MedicationDispense",
  "url": "https://bpcs.exchange/fhir/StructureDefinition/profile-MedicationDispense",
  "name": "MedicationDispense",
  "title": "Medication Dispense",
  "status": "active",
  "experimental": false,
  "description": "Information about the dispense action associated with a claim receipt",
  "fhirVersion": "5.0.0",
  "mapping": [
    {
      "identity": "BPCS",
      "name": "Internal BPCS API"
    }
  ],
  "kind": "resource",
  "abstract": false,
  "type": "MedicationDispense",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/MedicationDispense",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "MedicationDispense.id",
        "path": "MedicationDispense.id",
        "comment": "This will typically be 'dispense' plus the receipt sequence number",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.extension:prescriberLicense",
        "path": "MedicationDispense.extension",
        "sliceName": "prescriberLicense",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "https://bpcs.exchange/fhir/StructureDefinition/ext-MedicationDispense-PrescriberLicense"
            ]
          }
        ],
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.identifier",
        "path": "MedicationDispense.identifier",
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.identifier.value",
        "path": "MedicationDispense.identifier.value",
        "short": "Pharmacy Rx number",
        "definition": "Id assigned by the pharmacy to this specific dispense",
        "min": 1,
        "mustSupport": true,
        "mapping": [
          {
            "identity": "BPCS",
            "map": "ReceiptDTO.rxNum, DuplicateReceiptDTO.rxNo"
          }
        ]
      },
      {
        "id": "MedicationDispense.status",
        "path": "MedicationDispense.status",
        "patternCode": "completed",
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.medication",
        "path": "MedicationDispense.medication",
        "mustSupport": true,
        "binding": {
          "strength": "required",
          "valueSet": "https://bpcs.exchange/fhir/ValueSet/vs-DinPin"
        }
      },
      {
        "id": "MedicationDispense.medication.concept",
        "path": "MedicationDispense.medication.concept",
        "min": 1,
        "constraint": [
          {
            "key": "bpcs-dispense-1",
            "severity": "error",
            "human": "Must have text for Extemporaneous Mixture (9853359) and Unknown Product (9853448)",
            "expression": "coding.exists(system='http://hl7.org/fhir/NamingSystem/ca-hc-din' and (code='9853359' or code='9853448')) implies text.exists()"
          }
        ],
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.medication.concept.coding",
        "path": "MedicationDispense.medication.concept.coding",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "system"
            }
          ],
          "rules": "open"
        },
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.medication.concept.coding:receiptDinPin",
        "path": "MedicationDispense.medication.concept.coding",
        "sliceName": "receiptDinPin",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.medication.concept.coding:receiptDinPin.system",
        "path": "MedicationDispense.medication.concept.coding.system",
        "comment": "Clients and BPCS system are required to differentiate whether drug is a DIN or PIN",
        "min": 1,
        "mustSupport": true,
        "binding": {
          "strength": "required",
          "valueSet": "https://bpcs.exchange/fhir/ValueSet/vs-DinPinSystem"
        }
      },
      {
        "id": "MedicationDispense.medication.concept.coding:receiptDinPin.code",
        "path": "MedicationDispense.medication.concept.coding.code",
        "min": 1,
        "mustSupport": true,
        "mapping": [
          {
            "identity": "BPCS",
            "map": "DrugDTO.receiptDinPin, DuplicateClaimDTO.dinPin"
          }
        ]
      },
      {
        "id": "MedicationDispense.medication.concept.text",
        "path": "MedicationDispense.medication.concept.text",
        "condition": [
          "bpcs-dispense-1"
        ],
        "mustSupport": true,
        "mapping": [
          {
            "identity": "BPCS",
            "map": "DrugDTO.receiptDrugName, DuplicateClaimDTO.dinDesc"
          }
        ]
      },
      {
        "id": "MedicationDispense.medication.reference",
        "path": "MedicationDispense.medication.reference",
        "type": [
          {
            "code": "Reference",
            "profile": [
              "https://bpcs.exchange/fhir/StructureDefinition/profile-Reference-rest"
            ],
            "targetProfile": [
              "https://bpcs.exchange/fhir/StructureDefinition/profile-Medication"
            ],
            "aggregation": [
              "contained"
            ]
          }
        ],
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.subject",
        "path": "MedicationDispense.subject",
        "type": [
          {
            "code": "Reference",
            "profile": [
              "https://bpcs.exchange/fhir/StructureDefinition/profile-Reference-rest"
            ],
            "targetProfile": [
              "https://bpcs.exchange/fhir/StructureDefinition/profile-Patient-create"
            ]
          }
        ],
        "mustSupport": true,
        "mapping": [
          {
            "identity": "BPCS",
            "map": "ReceiptDTO.odbNum"
          }
        ]
      },
      {
        "id": "MedicationDispense.performer",
        "path": "MedicationDispense.performer",
        "comment": "Ministry assigned code to identify a pharmacy, hospital outpatient dispensary, clinic, dispensing physician or allergen supplier.",
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.performer.actor",
        "path": "MedicationDispense.performer.actor",
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.performer.actor.identifier",
        "path": "MedicationDispense.performer.actor.identifier",
        "patternIdentifier": {
          "system": "https://bpcs.exchange/fhir/NamingSystem/agency-id"
        },
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.performer.actor.identifier.value",
        "path": "MedicationDispense.performer.actor.identifier.value",
        "min": 1,
        "mustSupport": true,
        "mapping": [
          {
            "identity": "BPCS",
            "map": "ClaimDetailDTO.agencyId"
          }
        ]
      },
      {
        "id": "MedicationDispense.quantity",
        "path": "MedicationDispense.quantity",
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.quantity.value",
        "path": "MedicationDispense.quantity.value",
        "min": 1,
        "mustSupport": true,
        "mapping": [
          {
            "identity": "BPCS",
            "map": "ReceiptDTO.quantity"
          }
        ]
      },
      {
        "id": "MedicationDispense.daysSupply",
        "path": "MedicationDispense.daysSupply",
        "patternQuantity": {
          "system": "http://unitsofmeasure.org",
          "code": "d"
        },
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.daysSupply.value",
        "path": "MedicationDispense.daysSupply.value",
        "min": 1,
        "mustSupport": true,
        "mapping": [
          {
            "identity": "BPCS",
            "map": "ReceiptDTO.daysSupply"
          }
        ]
      },
      {
        "id": "MedicationDispense.whenHandedOver",
        "path": "MedicationDispense.whenHandedOver",
        "min": 1,
        "mustSupport": true,
        "mapping": [
          {
            "identity": "BPCS",
            "map": "ReceiptDTO.serviceDate"
          }
        ]
      },
      {
        "id": "MedicationDispense.substitution",
        "path": "MedicationDispense.substitution",
        "mustSupport": true
      },
      {
        "id": "MedicationDispense.substitution.reason",
        "path": "MedicationDispense.substitution.reason",
        "type": [
          {
            "code": "Coding",
            "profile": [
              "https://bpcs.exchange/fhir/StructureDefinition/profile-Coding-simple"
            ]
          }
        ],
        "mustSupport": true,
        "binding": {
          "strength": "required",
          "valueSet": "https://bpcs.exchange/fhir/ValueSet/vs-SubstitutionReason"
        },
        "mapping": [
          {
            "identity": "BPCS",
            "map": "ReceiptDTO.prodSel"
          }
        ]
      }
    ]
  }
}