{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/nextgen-healthcare/main/json-schema/nextgen-healthcare-medication-dispense-bundled-schema.json",
  "title": "MedicationDispenseBundled",
  "description": "A FHIR Bundle of MedicationDispense resources",
  "x-generated": "2026-10-12",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/nextgen-healthcare-medicationdispense-api-openapi.yml#/components/schemas/MedicationDispenseBundled",
  "type": "object",
  "properties": {
    "resourceType": {
      "type": "string",
      "description": "Always 'Bundle'"
    },
    "id": {
      "type": "string",
      "description": "Persistent identifier for the bundle"
    },
    "meta": {
      "type": "object",
      "description": "Metadata about the resource",
      "properties": {
        "lastUpdated": {
          "type": "string",
          "format": "date-time",
          "description": "When the bundle was last updated"
        }
      },
      "required": [
        "lastUpdated"
      ]
    },
    "type": {
      "type": "string",
      "description": "document | message | transaction | transaction-response | batch | batch-response | history | searchset | collection"
    },
    "total": {
      "type": "integer",
      "description": "Number of MedicationDispense in entry field"
    },
    "link": {
      "type": "array",
      "description": "Links related to this bundle",
      "items": {
        "type": "object",
        "properties": {
          "relation": {
            "type": "string",
            "description": "Relation type (e.g., self, next, previous)"
          },
          "url": {
            "type": "string",
            "minLength": 1,
            "description": "Reference details for the link"
          }
        },
        "required": [
          "relation",
          "url"
        ]
      }
    },
    "entry": {
      "type": "array",
      "description": "Entries in the bundle (each is a MedicationDispense resource)",
      "items": {
        "type": "object",
        "properties": {
          "fullUrl": {
            "type": "string",
            "minLength": 1,
            "description": "URI for resource (Absolute URL server address or URI for UUID/OID)"
          },
          "resource": {
            "$ref": "#/$defs/MedicationDispense"
          }
        },
        "required": [
          "fullUrl",
          "resource"
        ]
      }
    }
  },
  "required": [
    "resourceType",
    "type",
    "entry"
  ],
  "$defs": {
    "MedicationDispense": {
      "type": "object",
      "description": "Dispensing a medication to a named patient",
      "properties": {
        "resourceType": {
          "type": "string",
          "minLength": 1,
          "description": "The type of the FHIR resource (should be 'MedicationDispense')"
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "The id of the resource with prefix values HX | VS | LR with hyphen.Example HX-123"
        },
        "meta": {
          "type": "object",
          "description": "Metadata about the resource",
          "properties": {
            "profile": {
              "description": "Profiles this resource claims to conform to",
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "profile"
          ]
        },
        "status": {
          "type": "string",
          "minLength": 1,
          "description": "preparation | in-progress | cancelled | on-hold | completed | entered-in-error | stopped | declined | unknown"
        },
        "medicationCodeableConcept": {
          "type": "object",
          "description": "Coded form of the medication being dispensed (e.g., RxNorm)",
          "properties": {
            "coding": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "system": {
                    "type": "string",
                    "minLength": 1,
                    "description": "The identification of the code system (e.g., RxNorm)"
                  },
                  "code": {
                    "type": "string",
                    "minLength": 1,
                    "description": "The code itself from the code system"
                  },
                  "display": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Representation defined by the system"
                  }
                },
                "required": [
                  "system",
                  "code",
                  "display"
                ]
              }
            },
            "text": {
              "type": "string",
              "minLength": 1,
              "description": "Plain text representation of the concept"
            }
          },
          "required": [
            "coding"
          ]
        },
        "subject": {
          "type": "object",
          "properties": {
            "reference": {
              "type": "string",
              "minLength": 1,
              "description": "The patient for whom the medication is dispensed"
            }
          },
          "required": [
            "reference"
          ]
        },
        "performer": {
          "type": "array",
          "description": "Who performed the dispense",
          "items": {
            "type": "object",
            "properties": {
              "actor": {
                "type": "object",
                "properties": {
                  "reference": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Reference to the performer resource"
                  }
                },
                "required": [
                  "reference"
                ]
              }
            },
            "required": [
              "actor"
            ]
          }
        },
        "type": {
          "type": "object",
          "properties": {
            "coding": {
              "type": "array",
              "items": {
                "type": "object",
                "description": "Type of medication dispense (e.g. Trial fill, partial fill, emergency fill, etc.)",
                "properties": {
                  "system": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Code system for the type (e.g., http://terminology.hl7.org/CodeSystem/v3-ActCode)"
                  },
                  "code": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Code for the type of dispense"
                  },
                  "display": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Representation defined by the system"
                  }
                },
                "required": [
                  "system",
                  "code",
                  "display"
                ]
              }
            },
            "text": {
              "type": "string",
              "minLength": 1,
              "description": "Plain text representation of the concept"
            }
          },
          "required": [
            "coding"
          ]
        },
        "quantity": {
          "type": "object",
          "properties": {
            "value": {
              "type": "number",
              "description": "Amount dispensed"
            },
            "unit": {
              "type": "string",
              "minLength": 1,
              "description": "Unit defined by the system"
            },
            "system": {
              "type": "string",
              "minLength": 1,
              "description": "Code system for the unit(e.g. http://unitsofmeasure.org)"
            },
            "code": {
              "type": "string",
              "minLength": 1,
              "description": "UCUM code for the unit"
            }
          },
          "required": [
            "value",
            "unit",
            "system",
            "code"
          ]
        },
        "whenHandedOver": {
          "type": "string",
          "format": "date-time",
          "description": "When product was given out or mailed"
        },
        "dosageInstruction": {
          "type": "array",
          "items": {
            "type": "object",
            "description": "How the medication is to be used by the patient or administered by the caregiver",
            "properties": {
              "text": {
                "type": "string",
                "description": "Free text dosage instructions e.g. SIG"
              },
              "timing": {
                "type": "object",
                "description": "When medication should be administered",
                "properties": {
                  "code": {
                    "type": "object",
                    "description": "Timing code for when medication should be administered",
                    "properties": {
                      "coding": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "system": {
                              "type": "string",
                              "minLength": 1,
                              "description": "Symbol in syntax defined by the system"
                            },
                            "code": {
                              "type": "string",
                              "minLength": 1,
                              "description": "Symbol in syntax defined by the system"
                            },
                            "display": {
                              "type": "string",
                              "minLength": 1,
                              "description": "Representation defined by the system"
                            }
                          }
                        }
                      },
                      "text": {
                        "type": "string",
                        "minLength": 1,
                        "description": "TimingAbbreviation defined by system (e.g. - BID | TID | QID | AM | PM | QD | QOD)"
                      }
                    },
                    "required": [
                      "coding"
                    ]
                  }
                }
              },
              "doseAndRate": {
                "type": "array",
                "items": {
                  "type": "object",
                  "description": "Amount of medication administered",
                  "properties": {
                    "doseQuantity": {
                      "type": "object",
                      "properties": {
                        "value": {
                          "type": "number",
                          "minimum": 1,
                          "description": "Amount of medication per dose"
                        },
                        "unit": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Unit defined by the system"
                        },
                        "system": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Code system for the unit (e.g. http://unitsofmeasure.org)"
                        },
                        "code": {
                          "type": "string",
                          "minLength": 1,
                          "description": "UCUM code for the unit"
                        }
                      }
                    }
                  },
                  "required": [
                    "doseQuantity"
                  ]
                }
              }
            },
            "required": [
              "text",
              "timing",
              "doseAndRate"
            ]
          }
        }
      },
      "required": [
        "resourceType",
        "id",
        "meta",
        "status",
        "medicationCodeableConcept",
        "subject",
        "performer",
        "type",
        "quantity",
        "whenHandedOver",
        "dosageInstruction"
      ]
    }
  }
}