{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-10 Clinical Summary",
    "version": "1.1.0",
    "description": "Server paths are under /api/ohn/v1/clinical-summary. Default deny: role AND purpose must match. Inventory paths OHN-10-API-001..002 are mapped to this disjoint prefix (see ADR-0001)."
  },
  "servers": [
    {
      "url": "/api/ohn/v1/clinical-summary"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/patients/{id}/summary": {
      "get": {
        "operationId": "getCurrentSummary",
        "summary": "Current clinical summary with staleness and warnings",
        "x-inventory-id": "OHN-10-API-001",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "max_staleness_minutes",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 525600
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/patients/{id}/critical-info": {
      "get": {
        "operationId": "getCriticalInfo",
        "summary": "Critical health information: blood group (LOINC 883-9), Rh (LOINC 10331-7) and configured haemoglobin genotype from OHN-11 verified results with provenance and conflicts, plus active allergies and problems",
        "x-inventory-id": "OHN-10-API-005",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/patients/{id}/entries": {
      "get": {
        "operationId": "getPatientEntries",
        "summary": "Current problems, allergies and medication statements of one patient with their verification state (also patient self-access for OHN-31; audited)",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/patients/{id}/summary/generate": {
      "post": {
        "operationId": "generateSummary",
        "summary": "Project a new summary version (F001, W001)",
        "x-roles": [
          "licensed_clinician"
        ],
        "x-purpose": "clinical_summary",
        "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/GenerateCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/summaries": {
      "get": {
        "operationId": "listSummaries",
        "summary": "Summary versions",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "patient_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/summaries/{id}": {
      "get": {
        "operationId": "getSummary",
        "summary": "Summary version with section-level provenance",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/summaries/{id}/reconcile": {
      "post": {
        "operationId": "reconcileSummaryCase",
        "summary": "Decide a discrepancy of the summary's patient",
        "x-inventory-id": "OHN-10-API-002",
        "x-roles": [
          "licensed_clinician"
        ],
        "x-purpose": "clinical_summary",
        "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/ReconcileCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/assertions": {
      "post": {
        "operationId": "addAssertion",
        "summary": "Record a source claim: problem, allergy review (F003) or medication reconciliation (F002)",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssertionCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK",
            "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)"
          }
        }
      },
      "get": {
        "operationId": "listAssertions",
        "summary": "Claims for a patient",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "patient_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "required": true
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "problem",
                "allergy",
                "medication"
              ]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/cases": {
      "get": {
        "operationId": "listCases",
        "summary": "Exceptions queue",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "problem",
                "allergy",
                "medication"
              ]
            }
          },
          {
            "name": "patient_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/cases/{id}": {
      "get": {
        "operationId": "getCase",
        "summary": "Case with both claims",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/cases/{id}/transitions": {
      "post": {
        "operationId": "stepCase",
        "summary": "Advance reconciliation (W002)",
        "x-roles": [
          "licensed_clinician"
        ],
        "x-purpose": "clinical_summary",
        "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/CaseStepCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/revocations": {
      "post": {
        "operationId": "openRevocation",
        "summary": "Record a consent revocation (W003)",
        "x-roles": [
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RevocationOpenCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK",
            "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)"
          }
        }
      },
      "get": {
        "operationId": "listRevocations",
        "summary": "Revocation cases",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/revocations/{id}/transitions": {
      "post": {
        "operationId": "stepRevocation",
        "summary": "Advance a revocation case",
        "x-roles": [
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "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/RevocationStepCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/policy": {
      "get": {
        "operationId": "getPolicy",
        "summary": "Jurisdiction summary policy",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      },
      "post": {
        "operationId": "setPolicy",
        "summary": "Set the jurisdiction summary policy",
        "x-roles": [
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PolicyCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/maintenance/drain-outbox": {
      "post": {
        "operationId": "drainOutbox",
        "summary": "Report pending outbox events (no sink: nothing claimed delivered)",
        "x-roles": [
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/report-catalog": {
      "get": {
        "operationId": "reportCatalog",
        "summary": "Available reports",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/reports/{reportId}": {
      "get": {
        "operationId": "runReport",
        "summary": "Run report R001..R003",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "OHN-10-R001",
                "OHN-10-R002",
                "OHN-10-R003"
              ]
            }
          },
          {
            "name": "facility",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cohort",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "section",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "problems",
                "allergies",
                "medications"
              ]
            }
          },
          {
            "name": "severity",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "low",
                "moderate",
                "high"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "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": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Report (report_id, title, columns, rows, summary, state, generated_at) plus next_cursor"
                }
              }
            }
          },
          "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)"
          }
        }
      }
    },
    "/reports/{reportId}/export": {
      "post": {
        "operationId": "exportReport",
        "summary": "Create a signed single-use report export",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "OHN-10-R001",
                "OHN-10-R002",
                "OHN-10-R003"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/report-exports/{token}": {
      "get": {
        "operationId": "downloadReportExport",
        "summary": "Download a report export once",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{20,64}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "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)"
          }
        }
      }
    },
    "/observations": {
      "post": {
        "operationId": "recordObservations",
        "summary": "Record vital-sign observations (LOINC codes, UCUM units) from a source such as OHN-61 triage (F004, contract 1.1.0)",
        "x-roles": [
          "licensed_clinician"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ObservationBatchCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "ObservationBatchResult"
                }
              }
            }
          },
          "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)"
          }
        },
        "description": "Every code is validated with OHN-23 (system LOINC); the caller must be permitted by OHN-16 for the patient and the source facility must hold consent (OHN-15). One call is one batch measured together: append-only, never updated (a correction is a new batch that supersedes the earlier one). 503 when a dependency is unavailable (fail closed)."
      }
    },
    "/patients/{patient_id}/observations": {
      "get": {
        "operationId": "listObservations",
        "summary": "Vital-sign observations of a patient, newest first (contract 1.1.0)",
        "x-roles": [
          "licensed_clinician",
          "clinical_data_steward",
          "patient"
        ],
        "x-purpose": "clinical_summary",
        "parameters": [
          {
            "name": "patient_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "code",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{1,7}-[0-9]$"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "ObservationPage"
                }
              }
            }
          },
          "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)"
          }
        }
      }
    }
  },
  "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": {
      "GenerateCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "purpose": {
            "type": "string",
            "enum": [
              "continuity_of_care",
              "emergency",
              "referral",
              "discharge"
            ]
          },
          "encounter_context": {
            "type": "string",
            "format": "uuid"
          },
          "sections": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "problems",
                "allergies",
                "medications"
              ]
            },
            "minItems": 1,
            "description": "Distinct sections (duplicates are refused with 422 duplicate_sections)"
          },
          "maximum_staleness_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 525600
          }
        },
        "required": [
          "purpose",
          "encounter_context",
          "sections"
        ]
      },
      "AssertionCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "problem",
              "allergy",
              "medication"
            ]
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "code_system": {
            "type": "string",
            "enum": [
              "snomed_ct",
              "rxnorm",
              "atc",
              "local"
            ]
          },
          "code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "display": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "inactive",
              "resolved",
              "stopped",
              "on_hold",
              "unknown"
            ]
          },
          "verification_state": {
            "type": "string",
            "enum": [
              "unconfirmed",
              "confirmed",
              "refuted",
              "entered_in_error"
            ]
          },
          "reaction": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "source_facility": {
            "type": "string",
            "format": "uuid"
          },
          "evidence_ref": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          },
          "supersedes": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "kind",
          "patient_id",
          "code_system",
          "code",
          "display",
          "status",
          "verification_state",
          "source_facility",
          "evidence_ref"
        ]
      },
      "CaseStepCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "to_state": {
            "type": "string",
            "enum": [
              "clinician_review",
              "source_update_requested",
              "acknowledged"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          },
          "risk": {
            "type": "string",
            "enum": [
              "low",
              "moderate",
              "high"
            ]
          },
          "resolution": {
            "type": "string",
            "enum": [
              "accept_a",
              "accept_b",
              "both_valid",
              "source_update"
            ]
          }
        },
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ]
      },
      "ReconcileCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "case_id": {
            "type": "string",
            "format": "uuid"
          },
          "resolution": {
            "type": "string",
            "enum": [
              "accept_a",
              "accept_b",
              "both_valid",
              "source_update"
            ]
          },
          "risk": {
            "type": "string",
            "enum": [
              "low",
              "moderate",
              "high"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "case_id",
          "resolution",
          "risk",
          "reason",
          "expected_version"
        ]
      },
      "RevocationOpenCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "consent_ref": {
            "type": "string",
            "format": "uuid"
          },
          "revoked_facility": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "patient_id",
          "consent_ref",
          "revoked_facility"
        ]
      },
      "RevocationStepCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "to_state": {
            "type": "string",
            "enum": [
              "invalidated",
              "recomputed",
              "redaction_verified"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ]
      },
      "PolicyCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "required_sections": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "problems",
                "allergies",
                "medications"
              ]
            },
            "minItems": 1,
            "description": "Distinct sections (duplicates are refused with 422 duplicate_sections)"
          },
          "default_max_staleness_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 525600
          },
          "approval_reference": {
            "type": "string",
            "minLength": 3,
            "maxLength": 256
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "required_sections",
          "default_max_staleness_minutes",
          "approval_reference"
        ]
      },
      "ExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "format": {
            "type": "string",
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "type": "object",
            "description": "Report filters (facility, cohort, section, severity, status, jurisdiction, period_from, period_to); unknown keys and invalid values are refused with 422"
          }
        },
        "required": [
          "format"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": [
          "error"
        ]
      },
      "ObservationValue": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code_system": {
            "type": "string",
            "enum": [
              "loinc"
            ]
          },
          "code": {
            "type": "string",
            "pattern": "^[0-9]{1,7}-[0-9]$",
            "description": "LOINC code, validated with OHN-23"
          },
          "value": {
            "type": "number"
          },
          "unit": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32,
            "pattern": "^[A-Za-z0-9%\\[\\]/.*^{}()'-]+$",
            "description": "UCUM unit, e.g. Cel, /min, mm[Hg], %, kg, cm, mmol/L, {score}"
          }
        },
        "required": [
          "code_system",
          "code",
          "value",
          "unit"
        ]
      },
      "ObservationBatchCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "encounter_id": {
            "type": "string",
            "format": "uuid",
            "description": "OHN-09 encounter the measurements belong to (the triage encounter for OHN-61)"
          },
          "effective_at": {
            "type": "string",
            "format": "date-time",
            "description": "when measured; not in the future"
          },
          "performer": {
            "type": "string",
            "format": "uuid",
            "description": "who measured"
          },
          "source_facility": {
            "type": "string",
            "format": "uuid"
          },
          "source": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]{1,31}$",
            "description": "the sending system, e.g. ohn-61"
          },
          "source_ref": {
            "type": "string",
            "format": "uuid",
            "description": "the sender's own record id (OHN-61 vital set id); a second batch with the same source and source_ref is 409"
          },
          "supersedes": {
            "type": "string",
            "format": "uuid",
            "description": "an earlier batch of the same patient and source that this one corrects"
          },
          "observations": {
            "type": "array",
            "minItems": 1,
            "maxItems": 30,
            "items": {
              "$ref": "#/components/schemas/ObservationValue"
            }
          }
        },
        "required": [
          "patient_id",
          "effective_at",
          "performer",
          "source_facility",
          "source",
          "observations"
        ]
      },
      "Observation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "batch_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "encounter_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "final"
            ]
          },
          "category": {
            "type": "string",
            "enum": [
              "vital-signs"
            ]
          },
          "code_system": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "display": {
            "type": [
              "string",
              "null"
            ]
          },
          "value": {
            "type": "number"
          },
          "unit": {
            "type": "string"
          },
          "effective_at": {
            "type": "string",
            "format": "date-time"
          },
          "performer": {
            "type": "string",
            "format": "uuid"
          },
          "source_facility": {
            "type": "string",
            "format": "uuid"
          },
          "source": {
            "type": "string"
          },
          "source_ref": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "superseded": {
            "type": "boolean"
          },
          "terminology_version": {
            "type": [
              "string",
              "null"
            ]
          },
          "recorded_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ObservationBatchResult": {
        "type": "object",
        "properties": {
          "batch_id": {
            "type": "string",
            "format": "uuid"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Observation"
            }
          },
          "receipt": {
            "type": "object"
          }
        },
        "required": [
          "batch_id",
          "items",
          "receipt"
        ]
      },
      "ObservationPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Observation"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "items"
        ]
      }
    }
  }
}
