{
    "$schema": "https://json-schema.org/draft/2020-12/schema#",
    "$vocabulary": {
        "https://json-schema.org/draft/2020-12/vocab/core": true,
        "https://json-schema.org/draft/2020-12/vocab/applicator": true,
        "https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
        "https://json-schema.org/draft/2020-12/vocab/validation": true,
        "https://json-schema.org/draft/2020-12/vocab/meta-data": true,
        "https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
        "https://json-schema.org/draft/2020-12/vocab/content": true
    },
    "$id": "https://www.medbiq.org/standards/virtual-patient",
    "title": "Activity Model",
    "description": "Schema for MedBiq Medical Activity Model",
    "type": "object",
    "$defs": {
        "NonNullStringType": {
            "$ref": "http://medbiq.pixelbytellc.com/common.schema.json#/$defs/NonNullStringType"
        },
        "RelationsType": {
            "type": "string",
            "enum": ["eq", "neq", "leq", "lt", "geq", "gt"]
        },
        "RuleFunctionType": {
            "type": "string",
            "enum": ["stop", "showMessageOnly", "restart"]
        },
        "OnOffType": {
            "type": "string",
            "enum": ["on", "off"]
        },
        "TimerDirectionType": {
            "type": "string",
            "enum": ["up", "down"]
        },
        "CounterOperatorType": {
            "type": "string",
            "enum": ["+", "-", "="]
        },
        "WeightingType": {
            "type": "integer",
            "maximum": 100
        },
        "ContentType": {
            "type": "string",
            "pattern": "^\\s*/DataAvailabilityModel/DAMNode\\[@id\\s?=\\s?'[^']+\\'\\]\\s*$"
        },
        "ActivityNodeXpathType": {
            "type": "string",
            "pattern": "^\\s*/ActivityModel/ActivityNodes/NodeSection/ActivityNode\\[@id\\s?=\\s?'[^']+\\'\\]\\s*$"
        },
        "CounterPathType": {
            "type": "string",
            "pattern": "^\\s*/ActivityModel/Properties/Counters/Counter\\[@id\\s?=\\s?'[^']+\\'\\]\\s*$"
        },
        "ActivityModelType": {
            "type": "object",
            "properties": {
                "Properties": {
                    "$ref": "#/$defs/PropertiesType"
                },
                "ActivityNodes": {
                    "$ref": "#/$defs/ActivityNodesType"
                },
                "Links": {
                    "$ref": "#/$defs/LinksType"
                },
                "XtensibleInfo": {
                    "$ref": "#/$defs/XtensibleInfoType"
                }
            },
            "Required": ["ActivityModes"]
        },
        "PropertiesType": {
            "type": "object",
            "properties": {
                "Counters": {
                    "$ref": "#/$defs/CountersType"
                },
                "Timer": {
                    "$ref": "#/$defs/TimerType"
                }
            }
        },
        "ActivityNodesType": {
            "type": "object",
            "properties": {
                "NodeSection": {
                    "type": "array",
                    "$ref": "#/$defs/NodeSectionType"
                }
            },
            "required": ["NodeSection"]
        },
        "LinksType": {
            "type": "object",
            "properties": {
                "Link": {
                    "type": "object",
                    "allOf": [
                        {
                            "$ref": "#/$defs/LinkType"
                        }
                    ]
                }
            }
        },
        "CountersType": {
            "type": "object",
            "properties": {
                "Counter": {
                    "type": "array",
                    "$ref": "#/$defs/CounterType"
                }
            }
        },
        "CounterType": {
            "type": "object",
            "properties": {
                "CounterLabel": {
                    "$ref": "#/$defs/NonNullStringType"
                },
                "CounterUnitsSuffix": {
                    "$ref": "#/$defs/NonNullStringType"
                },
                "CounterUnitsPrefix": {
                    "$ref": "#/$defs/NonNullStringType"
                },
                "CounterInitValue": {
                    "type": "integer"
                },
                "CounterRules": {
                    "$ref": "#/$defs/CounterRulesType"
                },
                "id": {
                    "type": "string"
                },
                "isVisible": {
                    "type": "boolean",
                    "default": true
                }
            },
            "required": ["CounterLabel", "CounterInitValue", "id", "isVisible"]
        },
        "CounterRulesType": {
            "type": "object",
            "properties": {
                "Rule": {
                    "type": "array",
                    "$ref": "#/$defs/RuleType"
                }
            }
        },
        "RuleType": {
            "type": "object",
            "properties": {
                "Relation": {
                    "$ref": "#/$defs/RelationsType"
                },
                "Value": {
                    "type": "integer"
                },
                "RuleRedirect": {
                    "$ref": "#/$defs/ActivityNodeXpathType"
                },
                "RuleMessage": {
                    "$ref": "#/$defs/NonNullStringType"
                }
            },
            "required": ["Relation", "Value"]
        },
        "TimerType": {
            "type": "object",
            "properties": {
                "TimerDeltaSeconds": {
                    "type": "integer"
                },
                "TimerDirection": {
                    "$ref": "#/$defs/TimerDirectionType"
                },
                "TimerRules": {
                    "$ref": "#/$defs/CounterRulesType"
                },
                "isVisible": {
                    "type": "boolean",
                    "default": true
                }
            },
            "required": ["TimerDeltaSeconds", "TimerDirection"]
        },
        "ActivityNodeType": {
            "type": "object",
            "properties": {
                "Content": {
                    "$ref": "#/$defs/ContentType"
                },
                "Rules": {
                    "$ref": "#/$defs/RulesType"
                },
                "Services": {
                    "$ref": "#/$defs/ServicesType"
                },
                "id": {
                    "type": "string"
                },
                "label": {
                    "type": "string"
                }
            },
            "required": ["Content", "id", "label"]
        },
        "NodeSectionType": {
            "type": "object",
            "properties": {
                "choice": {
                    "oneOf": [
                        {
                            "type": "array",
                            "$ref": "#/$defs/NodeSectionType"
                        },
                        {
                            "type": "array",
                            "$ref": "#/$defs/ActivityNodeType"
                        }
                    ]
                },
                "id": {
                    "type": "string"
                },
                "label": {
                    "type": "string"
                }
            },
            "required": ["id", "label"]
        },
        "RulesType": {
            "type": "object",
            "properties": {
                "CounterActionRule": {
                    "type": "array",
                    "$ref": "#/$defs/CounterActionRuleType"
                },
                "Probability": {
                    "$ref": "#/$defs/OnOffType"
                },
                "ConditionalRule": {
                    "$ref": "#/$defs/ConditionalRuleType"
                },
                "NavigateGlobal": {
                    "$ref": "#/$defs/OnOffType"
                }
            }
        },
        "CounterActionRuleType": {
            "type": "object",
            "properties": {
                "CounterOperator": {
                    "$ref": "#/$defs/CounterOperatorType"
                },
                "CounterRuleValue": {
                    "type": "integer"
                },
                "CounterPath": {
                    "$ref": "#/$defs/CounterPathType"
                },
                "CounterRuleEnabled": {
                    "$ref": "#/$defs/OnOffType"
                }
            }
        },
        "ServicesType": {
            "type": "object",
            "properties": {
                "Timer": {
                    "$ref": "#/$defs/TimerType"
                }
            }
        },
        "LinkType": {
            "type": "object",
            "properties": {
                "ActivityNodeA": {
                    "$ref": "#/$defs/ActivityNodeXpathType"
                },
                "ActivityNodeB": {
                    "$ref": "#/$defs/ActivityNodeXpathType"
                },
                "Weighting": {
                    "$ref": "#/$defs/WeightingType"
                },
                "CounterActionRule": {
                    "$ref": "#/$defs/CounterActionRuleType",
                    "type": "array"
                },
                "label": {
                    "type": "string"
                },
                "display": {
                    "type": "boolean",
                    "default": true
                }
            },
            "required": ["ActivityNodeA", "ActivityNodeB", "label", "display"]
        },
        "XtensibleInfoType": {
            "type": "object",
            "properties": {
                "other": {
                    "type": "array",
                    "items": {
                        "type": "object"
                    },
                    "additionalProperties": true
                }
            }
        },
        "ConditionalRuleType": {
            "type": "object",
            "properties": {
                "Operator": {
                    "$ref": "#/$defs/OperatorType"
                },
                "RuleRedirect": {
                    "$ref": "#/$defs/ActivityNodeXpathType"
                },
                "RuleMessage": {
                    "$ref": "#/$defs/NonNullStringType"
                }
            },
            "required": ["Operator"]
        },
        "OperatorType": {
            "type": "object",
            "oneOf": [
                {
                    "type": "object",
                    "properties": {
                        "And": { "$ref": "#/$defs/ConditionType" }
                    },
                    "required": []
                },
                {
                    "type": "object",
                    "properties": {
                        "Or": { "$ref": "#/$defs/ConditionType" }
                    },
                    "required": []
                },
                {
                    "type": "object",
                    "properties": {
                        "Nand": { "$ref": "#/$defs/ConditionType" }
                    },
                    "required": []
                },
                {
                    "type": "object",
                    "properties": {
                        "Nor": { "$ref": "#/$defs/ConditionType" }
                    },
                    "required": []
                }
            ]
        },
        "ConditionType": {
            "type": "object",
            "properties": {
                "Operand": {
                    "type": "array",
                    "$ref": "#/$defs/NonNullStringType"
                },
                "And": {
                    "type": "array",
                    "$ref": "#/$defs/NonNullStringType"
                },
                "Or": {
                    "type": "array",
                    "$ref": "#/$defs/NonNullStringType"
                },
                "Nand": {
                    "type": "array",
                    "$ref": "#/$defs/NonNullStringType"
                },
                "Nor": {
                    "type": "array",
                    "$ref": "#/$defs/NonNullStringType"
                }
            }
        }
    },
    "properties": {
        "ActivityModel": {
            "$ref": "#/$defs/ActivityModelType"
        }
    }
}
