{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vetdatastandards.com/schemas/v0.1/prescription.schema.json",
  "title": "Prescription",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "practiceId", "patientId", "medicationName", "prescribedAt", "source"],
  "properties": {
    "id": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "source": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/source" },
    "matchKeys": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/matchKeys" },
    "createdAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "updatedAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "deletedAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "active": { "type": "boolean" },
    "extensions": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/extensions" },
    "practiceId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "patientId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "consultationId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "appointmentId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "productId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "staffId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "medicationName": { "type": "string", "minLength": 1, "maxLength": 255 },
    "prescribedAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "dosage": { "type": "string", "minLength": 1, "maxLength": 128 },
    "frequency": { "type": "string", "minLength": 1, "maxLength": 128 },
    "quantity": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/decimal" },
    "quantityUnit": { "type": "string", "minLength": 1, "maxLength": 32 },
    "instructions": { "type": "string", "maxLength": 4096 },
    "status": {
      "type": "string",
      "enum": ["active", "completed", "cancelled", "expired", "other"]
    },
    "statusRaw": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/rawText" },
    "batchNumber": { "type": "string", "minLength": 1, "maxLength": 64 },
    "startDate": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/date" },
    "endDate": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/date" },
    "withdrawal": {
      "type": "string",
      "maxLength": 512,
      "description": "Free-text withdrawal information. v0.1 does not model a structured withdrawal period."
    }
  },
  "if": {
    "properties": { "status": { "const": "other" } },
    "required": ["status"]
  },
  "then": {
    "required": ["statusRaw"]
  }
}
