{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Ehr_extract/EXTRACT.json",
    "definitions": {
        "EXTRACT": {
            "type": "object",
            "required": [
                "archetype_node_id",
                "name",
                "time_created",
                "system_id",
                "sequence_nr"
            ],
            "properties": {
                "uid": {
                    "allOf": [
                        {
                            "required": [
                                "_type"
                            ],
                            "properties": {
                                "_type": {
                                    "type": "string",
                                    "enum": [
                                        "OBJECT_VERSION_ID",
                                        "HIER_OBJECT_ID"
                                    ]
                                }
                            }
                        },
                        {
                            "if": {
                                "properties": {
                                    "_type": {
                                        "const": "OBJECT_VERSION_ID"
                                    }
                                }
                            },
                            "then": {
                                "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/BASE/Release-1.1.0/Base_types/OBJECT_VERSION_ID.json#/definitions/OBJECT_VERSION_ID"
                            }
                        },
                        {
                            "if": {
                                "properties": {
                                    "_type": {
                                        "const": "HIER_OBJECT_ID"
                                    }
                                }
                            },
                            "then": {
                                "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/BASE/Release-1.1.0/Base_types/HIER_OBJECT_ID.json#/definitions/HIER_OBJECT_ID"
                            }
                        }
                    ]
                },
                "archetype_node_id": {
                    "type": "string"
                },
                "name": {
                    "allOf": [
                        {
                            "properties": {
                                "_type": {
                                    "type": "string",
                                    "enum": [
                                        "DV_CODED_TEXT",
                                        "DV_TEXT"
                                    ]
                                }
                            }
                        },
                        {
                            "if": {
                                "properties": {
                                    "_type": {
                                        "const": "DV_CODED_TEXT"
                                    }
                                },
                                "required": [
                                    "_type"
                                ]
                            },
                            "then": {
                                "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Data_types/DV_CODED_TEXT.json#/definitions/DV_CODED_TEXT"
                            }
                        },
                        {
                            "if": {
                                "properties": {
                                    "_type": {
                                        "const": "DV_TEXT"
                                    }
                                },
                                "required": [
                                    "_type"
                                ]
                            },
                            "then": {
                                "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Data_types/DV_TEXT.json#/definitions/DV_TEXT"
                            }
                        },
                        {
                            "if": {
                                "not": {
                                    "required": [
                                        "_type"
                                    ]
                                }
                            },
                            "then": {
                                "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Data_types/DV_TEXT.json#/definitions/DV_TEXT"
                            }
                        }
                    ]
                },
                "archetype_details": {
                    "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Common/ARCHETYPED.json#/definitions/ARCHETYPED"
                },
                "feeder_audit": {
                    "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Common/FEEDER_AUDIT.json#/definitions/FEEDER_AUDIT"
                },
                "links": {
                    "type": "array",
                    "items": {
                        "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Common/LINK.json#/definitions/LINK"
                    },
                    "minItems": 1
                },
                "request_id": {
                    "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/BASE/Release-1.1.0/Base_types/HIER_OBJECT_ID.json#/definitions/HIER_OBJECT_ID"
                },
                "time_created": {
                    "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Data_types/DV_DATE_TIME.json#/definitions/DV_DATE_TIME"
                },
                "system_id": {
                    "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/BASE/Release-1.1.0/Base_types/HIER_OBJECT_ID.json#/definitions/HIER_OBJECT_ID"
                },
                "sequence_nr": {
                    "type": "integer"
                },
                "specification": {
                    "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Ehr_extract/EXTRACT_SPEC.json#/definitions/EXTRACT_SPEC"
                },
                "chapters": {
                    "type": "array",
                    "items": {
                        "allOf": [
                            {
                                "properties": {
                                    "_type": {
                                        "type": "string",
                                        "enum": [
                                            "EXTRACT_ENTITY_CHAPTER",
                                            "EXTRACT_CHAPTER"
                                        ]
                                    }
                                }
                            },
                            {
                                "if": {
                                    "properties": {
                                        "_type": {
                                            "const": "EXTRACT_ENTITY_CHAPTER"
                                        }
                                    },
                                    "required": [
                                        "_type"
                                    ]
                                },
                                "then": {
                                    "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Ehr_extract/EXTRACT_ENTITY_CHAPTER.json#/definitions/EXTRACT_ENTITY_CHAPTER"
                                }
                            },
                            {
                                "if": {
                                    "properties": {
                                        "_type": {
                                            "const": "EXTRACT_CHAPTER"
                                        }
                                    },
                                    "required": [
                                        "_type"
                                    ]
                                },
                                "then": {
                                    "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Ehr_extract/EXTRACT_CHAPTER.json#/definitions/EXTRACT_CHAPTER"
                                }
                            },
                            {
                                "if": {
                                    "not": {
                                        "required": [
                                            "_type"
                                        ]
                                    }
                                },
                                "then": {
                                    "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Ehr_extract/EXTRACT_CHAPTER.json#/definitions/EXTRACT_CHAPTER"
                                }
                            }
                        ]
                    }
                },
                "participations": {
                    "type": "array",
                    "items": {
                        "$ref": "https://specifications.openehr.org/releases/ITS-JSON/latest/components/RM/Release-1.1.0/Ehr_extract/EXTRACT_PARTICIPATION.json#/definitions/EXTRACT_PARTICIPATION"
                    }
                },
                "_type": {
                    "type": "string",
                    "const": "EXTRACT"
                }
            },
            "additionalProperties": false
        }
    }
}