{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-09 Encounter and Care Timeline",
    "version": "1.0.0",
    "description": "Server paths are under /api/ohn/v1/encounter-timeline. Default deny: role AND purpose must match. Inventory paths OHN-09-API-001..003 are mapped to this disjoint prefix (see ADR-0001)."
  },
  "servers": [
    {
      "url": "/api/ohn/v1/encounter-timeline"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/patients/{id}/encounters": {
      "get": {
        "operationId": "getPatientTimeline",
        "summary": "Latest cross-facility timeline projection for a patient (stale flag included)",
        "x-inventory-id": "OHN-09-API-001",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/patients/{id}/episodes": {
      "get": {
        "operationId": "getPatientEpisodes",
        "summary": "Episodes of care with derived boundaries",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/patients/{id}/patient-view": {
      "get": {
        "operationId": "patientEncounterView",
        "summary": "The patient's own current, indexed encounters for the OHN-31 patient chart (role patient under purpose patient_access; own record only, otherwise 404; OHN-16 decision read_own_encounters; every read audited)",
        "x-roles": [
          "patient"
        ],
        "x-purpose": "patient_access",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The patient's own OHN-03 id (must equal the token subject)"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/encounters": {
      "post": {
        "operationId": "registerEncounter",
        "summary": "Register a source encounter (F001, W001)",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EncounterCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      },
      "get": {
        "operationId": "listEncounters",
        "summary": "Ingest worklist and exception queue",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "facility",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "patient_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "current_only",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/encounters/project": {
      "post": {
        "operationId": "projectTimeline",
        "summary": "Build and store a cross-facility timeline (W003)",
        "x-inventory-id": "OHN-09-API-003",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/encounters/compare": {
      "get": {
        "operationId": "compareEncounters",
        "summary": "Field-by-field comparison of two encounters of one patient",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "left",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "required": true
          },
          {
            "name": "right",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/encounters/{id}": {
      "get": {
        "operationId": "getEncounter",
        "summary": "Encounter with versions, corrections, episodes and handovers",
        "x-inventory-id": "OHN-09-API-002",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/encounters/{id}/transitions": {
      "post": {
        "operationId": "stepEncounter",
        "summary": "Advance ingestion (W001)",
        "x-roles": [
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EncounterStepCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/corrections": {
      "post": {
        "operationId": "openCorrection",
        "summary": "Open an encounter correction (F002, W002)",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CorrectionCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      },
      "get": {
        "operationId": "listCorrections",
        "summary": "Corrections and provenance",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "facility",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/corrections/{id}/transitions": {
      "post": {
        "operationId": "stepCorrection",
        "summary": "Advance a correction; an amendment creates a new encounter version",
        "x-roles": [
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CorrectionStepCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/episode-links": {
      "post": {
        "operationId": "linkEpisode",
        "summary": "Link an encounter to an episode of care (F003)",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EpisodeLinkCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/handovers": {
      "post": {
        "operationId": "createHandover",
        "summary": "Record a care transition between two encounters",
        "x-roles": [
          "licensed_clinician"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HandoverCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      },
      "get": {
        "operationId": "listHandovers",
        "summary": "Care transitions",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "acknowledged",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/handovers/{id}/acknowledge": {
      "post": {
        "operationId": "acknowledgeHandover",
        "summary": "Acknowledge a handover (not by its recorder)",
        "x-roles": [
          "licensed_clinician"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HandoverAckCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/code-lists/{list}": {
      "get": {
        "operationId": "getCodeList",
        "summary": "Controlled list (encounter_type, care_setting, transfer_type)",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "encounter_type",
                "care_setting",
                "transfer_type"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      },
      "post": {
        "operationId": "upsertCodeList",
        "summary": "Upsert controlled list entries",
        "x-roles": [
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "encounter_type",
                "care_setting",
                "transfer_type"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeListBody"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/policy": {
      "get": {
        "operationId": "getPolicy",
        "summary": "Timeline policy",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      },
      "post": {
        "operationId": "setPolicy",
        "summary": "Set the timeline policy",
        "x-roles": [
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PolicyCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/maintenance/drain-outbox": {
      "post": {
        "operationId": "drainOutbox",
        "summary": "Report pending outbox events (no sink: nothing claimed delivered)",
        "x-roles": [
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/report-catalog": {
      "get": {
        "operationId": "reportCatalog",
        "summary": "Available reports",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/reports/{reportId}": {
      "get": {
        "operationId": "runReport",
        "summary": "Run report R001..R003",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "OHN-09-R001",
                "OHN-09-R002",
                "OHN-09-R003"
              ]
            }
          },
          {
            "name": "region",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "facility",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "jurisdiction",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "period_from",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 10
            }
          },
          {
            "name": "period_to",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 10
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/reports/{reportId}/export": {
      "post": {
        "operationId": "exportReport",
        "summary": "Create a signed single-use report export",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "OHN-09-R001",
                "OHN-09-R002",
                "OHN-09-R003"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/report-exports/{token}": {
      "get": {
        "operationId": "downloadReportExport",
        "summary": "Download a report export once",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "encounter_timeline",
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{20,64}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed)"
          }
        },
        "tags": [
          "OHN-09"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "minLength": 8,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9_.:-]+$"
        }
      }
    },
    "schemas": {
      "EncounterCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "source_facility_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "encounter_source_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "encounter_type": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "start_at": {
            "type": "string",
            "x-format": "date-time"
          },
          "end_at": {
            "type": "string",
            "x-format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": [
              "planned",
              "in_progress",
              "finished",
              "cancelled",
              "entered_in_error"
            ]
          }
        },
        "required": [
          "patient_id",
          "source_facility_id",
          "encounter_source_id",
          "encounter_type",
          "start_at",
          "status"
        ]
      },
      "EncounterStepCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "to_state": {
            "type": "string",
            "enum": [
              "schema_validated",
              "identity_matched",
              "source_linked",
              "indexed",
              "rejected"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ]
      },
      "CorrectionCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "encounter_ref": {
            "type": "string",
            "x-format": "uuid"
          },
          "field_disputed": {
            "type": "string",
            "enum": [
              "encounter_type",
              "start_at",
              "end_at",
              "status"
            ]
          },
          "correct_value": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "supporting_evidence": {
            "type": "string",
            "x-format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "encounter_ref",
          "field_disputed",
          "correct_value",
          "supporting_evidence",
          "reason"
        ]
      },
      "CorrectionStepCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "to_state": {
            "type": "string",
            "enum": [
              "source_contacted",
              "amended_by_source",
              "projection_refreshed",
              "resolved"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          },
          "source_response": {
            "type": "string",
            "enum": [
              "amended",
              "declined"
            ]
          }
        },
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ]
      },
      "EpisodeLinkCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "encounter_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "episode_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "care_setting": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "link_reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          },
          "effective_at": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          }
        },
        "required": [
          "encounter_id",
          "episode_id",
          "care_setting",
          "link_reason",
          "effective_at"
        ]
      },
      "HandoverCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "from_encounter_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "to_encounter_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "transfer_type": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          }
        },
        "required": [
          "from_encounter_id",
          "to_encounter_id",
          "transfer_type"
        ]
      },
      "HandoverAckCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "expected_version"
        ]
      },
      "ProjectCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient_id": {
            "type": "string",
            "x-format": "uuid"
          }
        },
        "required": [
          "patient_id"
        ]
      },
      "CodeListBody": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "entries": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "code": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,63}$"
                },
                "label": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "active": {
                  "type": "boolean"
                }
              },
              "required": [
                "code",
                "label"
              ]
            },
            "minItems": 1,
            "maxItems": 200
          }
        },
        "required": [
          "entries"
        ]
      },
      "PolicyCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "duplicate_window_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10080
          },
          "late_arrival_hours": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8760
          },
          "approval_reference": {
            "type": "string",
            "minLength": 3,
            "maxLength": 256
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "duplicate_window_minutes",
          "late_arrival_hours",
          "approval_reference"
        ]
      },
      "ExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "format": {
            "type": "string",
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "type": "object",
            "description": "Open object validated by the report filter rules (region, facility, type, status, jurisdiction, period_from, period_to); unknown keys 422"
          }
        },
        "required": [
          "format"
        ]
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {}
        }
      }
    }
  }
}
