{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vetdatastandards.com/schemas/v0.1/consultation.schema.json",
  "title": "Consultation",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "practiceId", "patientId", "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" },
    "clientId": { "$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" },
    "staffId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "status": {
      "type": "string",
      "enum": ["draft", "final", "amended", "entered_in_error", "other"]
    },
    "statusRaw": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/rawText" },
    "startedAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "endedAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "reason": { "type": "string", "minLength": 1, "maxLength": 512 },
    "noteText": { "type": "string", "maxLength": 65536 },
    "soap": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "subjective": { "type": "string", "maxLength": 32768 },
        "objective": { "type": "string", "maxLength": 32768 },
        "assessment": { "type": "string", "maxLength": 32768 },
        "plan": { "type": "string", "maxLength": 32768 }
      }
    }
  },
  "if": {
    "properties": { "status": { "const": "other" } },
    "required": ["status"]
  },
  "then": {
    "required": ["statusRaw"]
  }
}
