{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-17 Emergency Access and Break Glass",
    "version": "1.1.0",
    "description": "Base path /api/ohn/v1. Every POST requires Idempotency-Key; mutations use expected_version. Routes default-deny on role AND purpose (emergency_access). Break glass is fail closed: without a configured jurisdiction policy, or with an unreachable licence or patient check, nothing is granted. Pre-hospital break-glass (1.1.0, owner decision 2026-11-23): an ambulance crew's token carries purpose prehospital_emergency_access; its requests are refused with 403 prehospital_break_glass_disabled unless the jurisdiction's setting prehospital_break_glass_enabled is on (off by default in every jurisdiction). Only role jurisdiction_policy_steward with purpose jurisdiction_emergency_policy switches it (POST /emergency-access/jurisdiction-settings, legal basis reference required to switch on); every change is audited and recorded append-only. When on, the normal rules apply unchanged (reason, time limit, disclosure log, events, mandatory retrospective review); the case carries access_context prehospital."
  },
  "servers": [
    {
      "url": "/api/ohn/v1"
    }
  ],
  "paths": {
    "/emergency-access": {
      "post": {
        "operationId": "requestAccess",
        "summary": "Request emergency access (API-001; F001)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (denied_by_policy) or clinician_mismatch; prehospital_break_glass_disabled when an ambulance crew asks and the jurisdiction has not switched pre-hospital break-glass on"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "domain_validation_failed; policy_not_configured, patient_context_missing, or a denied case (clinician_license_inactive, clinician_membership_expired, sections_outside_policy, duration_exceeds_policy; details.case_id)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "dependency_unavailable: OHN-06 clinician standing or OHN-03 patient lookup is unconfigured or down; nothing is granted"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true,
                "description": "Strict command (unknown fields are refused with 422); validated in code against components.schemas.EmergencyRequest",
                "x-command-schema": "#/components/schemas/EmergencyRequest"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listCases",
        "summary": "Review queue / own cases (review_state, status, cursor)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "review_state",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/emergency-access/active": {
      "get": {
        "operationId": "activeGrants",
        "summary": "Active grants",
        "tags": [
          "OHN-17"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/emergency-access/{id}": {
      "get": {
        "operationId": "getCase",
        "summary": "Case with history, review and escalations (API-002)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "A value that is not a UUID is 404 not_found"
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/emergency-access/{id}/disclosures": {
      "post": {
        "operationId": "recordDisclosure",
        "summary": "Record a section read under the grant (denied if out of scope or expired)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "section_not_in_scope, grant_terminated or grant_expired (each denied attempt is recorded)"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true,
                "description": "Strict command (unknown fields are refused with 422); validated in code against components.schemas.Disclosure",
                "x-command-schema": "#/components/schemas/Disclosure"
              }
            }
          }
        }
      }
    },
    "/emergency-access/{id}/terminate": {
      "post": {
        "operationId": "terminateGrant",
        "summary": "Terminate a grant (F003)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "version_conflict (details.current_version) or illegal_transition (already terminated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true,
                "description": "Strict command (unknown fields are refused with 422); validated in code against components.schemas.Terminate",
                "x-command-schema": "#/components/schemas/Terminate"
              }
            }
          }
        }
      }
    },
    "/emergency-access/{id}/review": {
      "post": {
        "operationId": "reviewCase",
        "summary": "Retrospective review (API-003; F002)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "separation_of_duties: a clinician cannot review their own access"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "version_conflict, illegal_transition (not awaiting review) or grant_still_active",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true,
                "description": "Strict command (unknown fields are refused with 422); validated in code against components.schemas.Review",
                "x-command-schema": "#/components/schemas/Review"
              }
            }
          }
        }
      }
    },
    "/emergency-access/{id}/remediate": {
      "post": {
        "operationId": "remediateCase",
        "summary": "Remediate a violation and close",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "version_conflict or illegal_transition (only a recorded violation can be remediated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true,
                "description": "Strict command (unknown fields are refused with 422); validated in code against components.schemas.Remediate",
                "x-command-schema": "#/components/schemas/Remediate"
              }
            }
          }
        }
      }
    },
    "/emergency-access/maintenance/expire-sweep": {
      "post": {
        "operationId": "expireSweep",
        "summary": "Terminate grants past their time limit",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/emergency-access/maintenance/drain-outbox": {
      "post": {
        "operationId": "drainOutbox",
        "summary": "Drain outbox (no sink => nothing marked delivered)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/emergency-access/request-options": {
      "get": {
        "operationId": "readRequestOptions",
        "summary": "What a clinician may request under the current rules (allowed sections, maximum duration; no approval reference)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "configured, allowed_sections, max_duration_minutes (null until the jurisdiction policy is configured; never the approval reference)"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/emergency-access/policy": {
      "get": {
        "operationId": "readPolicy",
        "summary": "Read policy (unconfigured = fail closed)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      },
      "post": {
        "operationId": "writePolicy",
        "summary": "Write policy",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true,
                "description": "Strict command (unknown fields are refused with 422); validated in code against components.schemas.Policy",
                "x-command-schema": "#/components/schemas/Policy"
              }
            }
          }
        }
      }
    },
    "/emergency-access/jurisdiction-settings": {
      "get": {
        "operationId": "readJurisdictionSettings",
        "summary": "Per-jurisdiction settings: pre-hospital break-glass switch (no setting = off). Steward and emergency reviewer",
        "tags": [
          "OHN-17"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      },
      "post": {
        "operationId": "writeJurisdictionSettings",
        "summary": "Switch pre-hospital break-glass on or off (jurisdiction_policy_steward only; audited)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true,
                "description": "Strict command (unknown fields are refused with 422); validated in code against components.schemas.JurisdictionSettings",
                "x-command-schema": "#/components/schemas/JurisdictionSettings"
              }
            }
          }
        }
      }
    },
    "/emergency-access/report-catalog": {
      "get": {
        "operationId": "reportCatalog",
        "summary": "Report catalog",
        "tags": [
          "OHN-17"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/emergency-access/reports/{reportId}": {
      "get": {
        "operationId": "runReport",
        "summary": "Run report",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-17-R001",
                "OHN-17-R002",
                "OHN-17-R003"
              ]
            }
          },
          {
            "name": "facility",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "uuid"
          },
          {
            "name": "reviewer",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "uuid"
          },
          {
            "name": "actor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "uuid"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "pending|reviewed|justified|violation|remediated|closed"
          },
          {
            "name": "period_from",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "YYYY-MM-DD"
          },
          {
            "name": "period_to",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "YYYY-MM-DD"
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Report (components.schemas.Report: report_id, title, columns, rows, summary, state, generated_at) plus next_cursor"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/emergency-access/reports/{reportId}/export": {
      "post": {
        "operationId": "createExport",
        "summary": "Create signed single-use export",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-17-R001",
                "OHN-17-R002",
                "OHN-17-R003"
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true,
                "description": "Strict command (unknown fields are refused with 422); validated in code against components.schemas.ExportCommand",
                "x-command-schema": "#/components/schemas/ExportCommand"
              }
            }
          }
        }
      }
    },
    "/emergency-access/exports/{token}": {
      "get": {
        "operationId": "fetchExport",
        "summary": "Download export (owner only, single use, 5 min)",
        "tags": [
          "OHN-17"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK: the export file as an attachment (Content-Type text/csv; charset=utf-8 or application/pdf; single use, 5 minutes, owner only)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Not JSON: the file bytes, see Content-Type"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) or domain denial"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "410": {
            "description": "export_expired or export_consumed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "export_integrity_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/health/ohn-17": {
      "get": {
        "operationId": "health",
        "summary": "Liveness incl. DB and dependency modes",
        "security": [],
        "responses": {
          "200": {
            "description": "ok: {status, module, dependencies: {ohn06, ohn20}} with the mode of each dependency (synthetic, unconfigured or live)"
          },
          "503": {
            "description": "unavailable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {}
        }
      },
      "EmergencyRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "patient_id",
          "facility_id",
          "clinician_id",
          "clinical_emergency",
          "requested_sections",
          "requested_duration_minutes"
        ],
        "properties": {
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "facility_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid",
            "description": "Must equal the authenticated clinician"
          },
          "clinical_emergency": {
            "type": "string",
            "minLength": 10,
            "maxLength": 8192
          },
          "requested_sections": {
            "type": "array",
            "minItems": 1,
            "maxItems": 32,
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            }
          },
          "requested_duration_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000
          }
        }
      },
      "Review": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "review_outcome",
          "justification_adequacy",
          "evidence_refs",
          "expected_version"
        ],
        "properties": {
          "review_outcome": {
            "enum": [
              "justified",
              "violation"
            ]
          },
          "justification_adequacy": {
            "enum": [
              "adequate",
              "inadequate"
            ]
          },
          "evidence_refs": {
            "type": "string",
            "format": "uuid"
          },
          "remediation": {
            "type": "string",
            "minLength": 10,
            "maxLength": 8192,
            "description": "Optional narrative, trimmed, 10..8192 characters"
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Remediate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "remediation",
          "expected_version"
        ],
        "properties": {
          "remediation": {
            "type": "string",
            "minLength": 10,
            "maxLength": 8192
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Terminate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "termination_reason",
          "expected_version"
        ],
        "properties": {
          "termination_reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1,
            "description": "Grant version"
          }
        }
      },
      "Disclosure": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "section"
        ],
        "properties": {
          "section": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          }
        }
      },
      "Policy": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "max_duration_minutes",
          "review_deadline_hours",
          "allowed_sections",
          "approval_reference"
        ],
        "properties": {
          "max_duration_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 100000
          },
          "review_deadline_hours": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8760
          },
          "allowed_sections": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            },
            "maxItems": 200
          },
          "approval_reference": {
            "type": "string",
            "minLength": 3,
            "maxLength": 256
          }
        }
      },
      "JurisdictionSettings": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "prehospital_break_glass_enabled",
          "expected_version"
        ],
        "properties": {
          "prehospital_break_glass_enabled": {
            "type": "boolean",
            "description": "Ambulance crews may use break-glass before reaching hospital in this jurisdiction. Default false."
          },
          "legal_basis_reference": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 3,
            "maxLength": 256,
            "description": "Reference of the jurisdiction's legal decision; required when switching on."
          },
          "expected_version": {
            "type": "integer",
            "minimum": 0,
            "description": "0 when the jurisdiction has no setting yet."
          }
        }
      },
      "ExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "format"
        ],
        "properties": {
          "format": {
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "$ref": "#/components/schemas/ReportFilters"
          }
        }
      },
      "Report": {
        "type": "object",
        "properties": {
          "report_id": {
            "enum": [
              "OHN-17-R001",
              "OHN-17-R002",
              "OHN-17-R003"
            ]
          },
          "title": {
            "type": "string"
          },
          "columns": {
            "type": "array"
          },
          "rows": {
            "type": "array"
          },
          "summary": {
            "type": "object"
          },
          "state": {
            "enum": [
              "rendered",
              "no_authorized_data"
            ]
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "description": "Tabular report; at most 100 rows per page, next_cursor continues. Identifiers and codes only: no clinical narrative."
      },
      "ReportFilters": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "facility": {
            "type": "string",
            "format": "uuid"
          },
          "reviewer": {
            "type": "string",
            "format": "uuid"
          },
          "actor": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "enum": [
              "pending",
              "reviewed",
              "justified",
              "violation",
              "remediated",
              "closed"
            ]
          },
          "period_from": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "period_to": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          }
        }
      }
    }
  }
}