Conditions and combinations
Conditions make a form react to answers.
They let you say:
If this is true, ask that next.
When to use them
- Show follow-up questions only when they matter.
- Require extra fields when a previous answer is yes.
- Keep the form shorter for doctors.
The simplest mental model
if / then / else
"medications": {
"title": "Medications",
"type": "object",
"properties": {
"takes-medications": {
"title": "Patient currently takes medications",
"type": "boolean",
"description": "Confirm if the patient is actively taking any medication"
}
},
"allOf": [
{
"if": {
"properties": { "takes-medications": { "const": true } },
"required": ["takes-medications"]
},
"then": {
"properties": {
"medication-list": {
"title": "List medications",
"type": "array",
"items": {
"title": "Medication",
"type": "string",
"description": "Name and dose"
},
"minItems": 1
}
},
"required": ["medication-list"]
},
"else": {
"properties": {
"no-medication-reason": {
"title": "Reason for no medications",
"type": "string",
"description": "Explain why the patient is not taking medications"
}
}
}
}
]
}
This checks takes-medications.
If it is true, medication-list is required.
allOf: stack rules
allOf means every rule must pass.
"blood-pressure": {
"title": "Blood pressure (mmHg)",
"type": "string",
"description": "Systolic/diastolic like 120/80",
"allOf": [
{ "pattern": "^\d{2,3}/\d{2,3}$" },
{ "maxLength": 7 }
]
}
Both rules must pass.
oneOf: choose exactly one shape
oneOf means exactly one option should match.
"follow-up": {
"title": "Follow-up plan",
"type": "object",
"oneOf": [
{
"title": "Clinic visit",
"properties": {
"visit-date": { "title": "Visit date", "type": "string", "format": "date" }
},
"required": ["visit-date"]
},
{
"title": "Virtual check-in",
"properties": {
"contact-method": {
"title": "Contact method",
"type": "string",
"oneOf": [
{ "const": "PHONE", "title": "Phone" },
{ "const": "VIDEO", "title": "Video" }
]
}
},
"required": ["contact-method"]
}
]
}
Use it when the doctor must choose one path.
anyOf: allow one or more shapes
anyOf means one or more rules can match.
"pain-documentation": {
"title": "Pain documentation",
"type": "string",
"description": "Record either a numeric score or a narrative",
"anyOf": [
{ "pattern": "^[0-9]|10$" },
{ "minLength": 15 }
]
}
Use it when several answer shapes are acceptable.
Simple rule
Start simple. Too many conditions make forms hard to maintain. Use conditions only when they make the doctor's job easier.