{
 "openapi": "3.1.0",
 "info": {
  "title": "OHN-28 Clinical Notification and Alert Routing",
  "version": "1.0.1",
  "description": "Safety-critical alert routing with verified receipt, escalation and retry. Default-deny; every POST needs an Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-]); mutations use expected_version. Alert text and events carry codes and identifiers only. Authentication: a platform-gateway bearer token (Java: ES256, iss ohn-platform-gateway, aud ohn-28; the TypeScript baseline also accepts its own HS256 development token, iss ohn-28-notification, aud ohn-28-api) whose sub, jurisdiction and organization_id are UUIDs; role licensed_clinician or on_call_supervisor and purpose clinical_notification are both required (an unknown role or another purpose is an audited 403). The TypeScript-only development sign-in POST /clinical-notifications/synthetic-token is not part of this contract. Errors are JSON {error, message, details?} (Java: application/problem+json with the same fields plus type, title, status, detail, trace_id); a body that is not JSON is 400 malformed_request, one that is not application/json is 415 unsupported_media_type. Fail-closed rules: an alert is stored before it is routed and is never dropped; an unavailable dependency (OHN-06 standing, OHN-16 access decision, the delivery channel) leaves the alert open and pending (routing_blocked_reason) and the sweep retries it; an alert nobody can be paged for is needs_supervisor and raises clinical-notification.needs-supervisor."
 },
 "servers": [
  {
   "url": "/api/ohn/v1"
  }
 ],
 "paths": {
  "/health/ohn-28": {
   "servers": [
    {
     "url": "/"
    }
   ],
   "get": {
    "summary": "Health (public, served at /health/ohn-28 outside the /api/ohn/v1 prefix)",
    "responses": {
     "200": {
      "description": "ok",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Health"
        }
       }
      }
     },
     "503": {
      "description": "database unavailable",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "const": "unavailable"
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/clinical-notifications": {
   "post": {
    "summary": "OHN-28-API-001 Route a clinical alert (W001)",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/NotificationResult"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/NotificationCommand"
       }
      }
     }
    }
   },
   "get": {
    "summary": "OHN-28-API-002 List alerts visible to the caller",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/NotificationList"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     }
    },
    "parameters": [
     {
      "name": "state",
      "in": "query",
      "schema": {
       "type": "string",
       "maxLength": 32
      }
     },
     {
      "name": "severity",
      "in": "query",
      "schema": {
       "type": "string",
       "maxLength": 64
      }
     },
     {
      "name": "needs_supervisor",
      "in": "query",
      "schema": {
       "enum": [
        "true",
        "false"
       ]
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "description": "Opaque; pages of 50. An unreadable cursor restarts at the first page.",
      "schema": {
       "type": "string",
       "maxLength": 64
      }
     }
    ]
   }
  },
  "/clinical-notifications/policies": {
   "get": {
    "summary": "List routing policies",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PolicyList"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     }
    },
    "parameters": []
   },
   "post": {
    "summary": "OHN-28-F001 Create a routing policy",
    "x-roles": [
     "on_call_supervisor"
    ],
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PolicyResult"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PolicyCommand"
       }
      }
     }
    }
   }
  },
  "/clinical-notifications/policies/{id}/update": {
   "post": {
    "summary": "Update a routing policy (expected_version)",
    "x-roles": [
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PolicyResult"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PolicyUpdateCommand"
       }
      }
     }
    }
   }
  },
  "/clinical-notifications/code-lists/{list}": {
   "get": {
    "summary": "Read a controlled code list",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/CodeList"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     }
    },
    "parameters": [
     {
      "name": "list",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "trigger_type",
        "severity",
        "target_role",
        "channel"
       ]
      }
     }
    ]
   },
   "post": {
    "summary": "Upsert code list entries",
    "x-roles": [
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/CodeListUpsertResult"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "list",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "trigger_type",
        "severity",
        "target_role",
        "channel"
       ]
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/CodeListCommand"
       }
      }
     }
    }
   }
  },
  "/clinical-notifications/maintenance/escalation-sweep": {
   "post": {
    "summary": "OHN-28-W002 Run the escalation sweep (schedule every minute)",
    "x-roles": [
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/SweepResult"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ]
   }
  },
  "/clinical-notifications/maintenance/drain-outbox": {
   "post": {
    "summary": "Relay outbox events to OHN-24 (stay pending without a sink)",
    "x-roles": [
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OutboxResult"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ]
   }
  },
  "/clinical-notifications/report-catalog": {
   "get": {
    "summary": "List reports",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ReportCatalog"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     }
    },
    "parameters": []
   }
  },
  "/clinical-notifications/reports/{reportId}": {
   "get": {
    "summary": "Run OHN-28-R001..R003",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Report"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed: message \"Report filter is not valid.\" (details keep the LAST issue per field) or \"period_from is after period_to.\" (details.period_from after_period_to)"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     }
    },
    "parameters": [
     {
      "name": "reportId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^OHN-28-R00[123]$"
      }
     },
     {
      "name": "facility",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "organization",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "period_from",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      }
     },
     {
      "name": "period_to",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      }
     },
     {
      "name": "severity",
      "in": "query",
      "schema": {
       "type": "string",
       "pattern": "^[a-z][a-z0-9_]{0,63}$"
      }
     },
     {
      "name": "channel",
      "in": "query",
      "schema": {
       "type": "string",
       "pattern": "^[a-z][a-z0-9_]{0,63}$"
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string",
       "description": "Opaque; pages of 100 rows."
      }
     }
    ]
   }
  },
  "/clinical-notifications/reports/{reportId}/export": {
   "post": {
    "summary": "Create a signed, single-use, 5-minute export (supervisors)",
    "x-roles": [
     "on_call_supervisor"
    ],
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ExportReceipt"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "dependency_unavailable: the export signing key is not configured (or shorter than 32 characters)"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "reportId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^OHN-28-R00[123]$"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ExportCommand"
       }
      }
     }
    }
   }
  },
  "/clinical-notifications/exports/{token}": {
   "get": {
    "summary": "Download an export once",
    "x-roles": [
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "The export once (CSV or PDF); the link is single use, bound to the requesting principal, expires after five minutes and is checked against its HMAC-SHA256 signature",
      "content": {
       "text/csv": {
        "schema": {
         "type": "string"
        }
       },
       "application/pdf": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "410": {
      "description": "export_expired or export_consumed"
     },
     "500": {
      "description": "export_integrity_failed: the stored export no longer matches its signature"
     }
    },
    "parameters": [
     {
      "name": "token",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[A-Za-z0-9_-]{20,64}$"
      }
     }
    ]
   }
  },
  "/clinical-notifications/{id}": {
   "get": {
    "summary": "Alert detail with provenance, deliveries, overrides and acknowledgment",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/NotificationDetail"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     }
    ]
   }
  },
  "/clinical-notifications/{id}/history": {
   "get": {
    "summary": "Workflow history (append-only)",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/HistoryList"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     }
    ]
   }
  },
  "/clinical-notifications/{id}/deliveries": {
   "get": {
    "summary": "Delivery attempts",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DeliveryList"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     }
    ]
   }
  },
  "/clinical-notifications/{id}/ack": {
   "post": {
    "summary": "OHN-28-API-003 Acknowledge with read-back (F002)",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AckResult"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/AckCommand"
       }
      }
     }
    }
   }
  },
  "/clinical-notifications/{id}/override": {
   "post": {
    "summary": "OHN-28-F003 Supervisor escalation override",
    "x-roles": [
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AckResult"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OverrideCommand"
       }
      }
     }
    }
   }
  },
  "/clinical-notifications/{id}/close": {
   "post": {
    "summary": "OHN-28-W003 Close an acknowledged alert",
    "x-roles": [
     "licensed_clinician",
     "on_call_supervisor"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AckResult"
        }
       }
      }
     },
     "401": {
      "description": "Unauthenticated"
     },
     "403": {
      "description": "Denied by policy (audited)"
     },
     "404": {
      "description": "Not found or not visible"
     },
     "422": {
      "description": "Validation failed"
     },
     "429": {
      "description": "Rate limited"
     },
     "503": {
      "description": "Dependency unavailable"
     },
     "400": {
      "description": "Idempotency-Key missing or malformed (idempotency_key_required), or the body is not valid JSON (malformed_request)"
     },
     "409": {
      "description": "version_conflict (details.current_version), idempotency_key_reused, request_in_progress, illegal_transition, already_acknowledged, not_acknowledgeable, duplicate_event, conflict"
     },
     "415": {
      "description": "unsupported_media_type: send application/json"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 8,
       "maxLength": 128
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/CloseCommand"
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "NotificationCommand": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "patient_ref",
     "trigger_type",
     "severity",
     "target_role",
     "source_ref"
    ],
    "properties": {
     "patient_ref": {
      "type": "string",
      "format": "uuid"
     },
     "trigger_type": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "severity": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "target_role": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "source_ref": {
      "type": "string",
      "format": "uuid"
     }
    }
   },
   "PolicyCommand": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "trigger_type",
     "severity",
     "target_role",
     "channel",
     "ack_deadline_minutes",
     "escalation_chain"
    ],
    "properties": {
     "trigger_type": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "severity": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "target_role": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "channel": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "ack_deadline_minutes": {
      "type": "integer",
      "minimum": 1,
      "maximum": 10080
     },
     "escalation_chain": {
      "type": "array",
      "items": {
       "type": "string",
       "format": "uuid"
      },
      "minItems": 1,
      "maxItems": 10,
      "uniqueItems": true
     }
    }
   },
   "PolicyUpdateCommand": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "channel",
     "ack_deadline_minutes",
     "escalation_chain",
     "expected_version",
     "reason"
    ],
    "properties": {
     "channel": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "ack_deadline_minutes": {
      "type": "integer",
      "minimum": 1,
      "maximum": 10080
     },
     "escalation_chain": {
      "type": "array",
      "items": {
       "type": "string",
       "format": "uuid"
      },
      "minItems": 1,
      "maxItems": 10
     },
     "expected_version": {
      "type": "integer",
      "minimum": 1
     },
     "reason": {
      "type": "string",
      "minLength": 10,
      "maxLength": 4096
     }
    }
   },
   "AckCommand": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "recipient_id",
     "readback_confirmation",
     "acknowledged_at",
     "notes",
     "expected_version"
    ],
    "properties": {
     "recipient_id": {
      "type": "string",
      "format": "uuid"
     },
     "readback_confirmation": {
      "type": "boolean"
     },
     "acknowledged_at": {
      "type": "string",
      "format": "date-time"
     },
     "notes": {
      "type": "string",
      "minLength": 1,
      "maxLength": 8192
     },
     "expected_version": {
      "type": "integer",
      "minimum": 1
     }
    }
   },
   "OverrideCommand": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "reason",
     "alternate_recipient",
     "expiration",
     "expected_version"
    ],
    "properties": {
     "reason": {
      "type": "string",
      "minLength": 10,
      "maxLength": 4096
     },
     "alternate_recipient": {
      "type": "string",
      "format": "uuid"
     },
     "expiration": {
      "type": "string",
      "format": "date-time"
     },
     "expected_version": {
      "type": "integer",
      "minimum": 1
     }
    }
   },
   "CloseCommand": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "reason",
     "expected_version"
    ],
    "properties": {
     "reason": {
      "type": "string",
      "minLength": 10,
      "maxLength": 4096
     },
     "expected_version": {
      "type": "integer",
      "minimum": 1
     }
    }
   },
   "CodeListCommand": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "entries"
    ],
    "properties": {
     "entries": {
      "type": "array",
      "minItems": 1,
      "maxItems": 200,
      "items": {
       "type": "object",
       "additionalProperties": false,
       "required": [
        "code",
        "label_en",
        "label_fr"
       ],
       "properties": {
        "code": {
         "type": "string",
         "pattern": "^[a-z][a-z0-9_]{0,63}$"
        },
        "label_en": {
         "type": "string",
         "minLength": 1,
         "maxLength": 128
        },
        "label_fr": {
         "type": "string",
         "minLength": 1,
         "maxLength": 128
        },
        "active": {
         "type": "boolean",
         "default": true
        },
        "critical": {
         "type": "boolean",
         "default": false,
         "description": "a severity flagged critical needs read-back to be acknowledged"
        }
       }
      }
     }
    }
   },
   "ExportCommand": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "format"
    ],
    "properties": {
     "format": {
      "enum": [
       "csv",
       "pdf"
      ]
     },
     "filters": {
      "$ref": "#/components/schemas/ReportFilters"
     }
    }
   },
   "Receipt": {
    "type": "object",
    "properties": {
     "receipt_id": {
      "type": "string",
      "format": "uuid"
     },
     "committed_at": {
      "type": "string",
      "format": "date-time"
     },
     "aggregate_id": {
      "type": "string",
      "format": "uuid"
     },
     "version": {
      "type": "integer"
     },
     "status": {
      "enum": [
       "committed",
       "denied"
      ]
     }
    }
   },
   "Notification": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "state": {
      "enum": [
       "received",
       "target_resolved",
       "sent",
       "acknowledged",
       "escalated",
       "escalation_exhausted",
       "unroutable",
       "closed"
      ]
     },
     "severity": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "trigger_type": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "target_role": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "channel": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "critical": {
      "type": "boolean"
     },
     "level": {
      "type": "integer"
     },
     "ack_deadline_minutes": {
      "type": "integer"
     },
     "current_recipient": {
      "type": [
       "string",
       "null"
      ],
      "format": "uuid"
     },
     "deadline_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "first_sent_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "acked_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "acked_by": {
      "type": [
       "string",
       "null"
      ],
      "format": "uuid"
     },
     "closed_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "source_ref": {
      "type": "string",
      "format": "uuid"
     },
     "version": {
      "type": "integer"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     },
     "jurisdiction_id": {
      "type": "string",
      "format": "uuid"
     },
     "organization_id": {
      "type": "string",
      "format": "uuid"
     },
     "pending_reconciliation": {
      "type": "boolean",
      "description": "true while the alert has not reached a recipient (received, target_resolved) or its next page is blocked by a dependency outage"
     },
     "routing_blocked_reason": {
      "type": [
       "string",
       "null"
      ],
      "description": "1.0.1: dependency_unavailable:OHN-06 | OHN-16 | channel while a dependency outage blocks routing or escalation; null otherwise. An alert somebody holds keeps its state, level and holder during the outage."
     },
     "needs_supervisor": {
      "type": "boolean",
      "description": "escalation_exhausted or unroutable: nobody could be paged; supervisors must act"
     },
     "patient_ref_masked": {
      "type": "string",
      "description": "present in lists, intake and mutation answers and in the detail view; the detail view adds patient_ref only when OHN-16 permits"
     },
     "provenance": {
      "type": "object",
      "properties": {
       "source_system_id": {
        "type": "string",
        "format": "uuid"
       },
       "provenance_ref": {
        "type": "string",
        "format": "uuid"
       },
       "source_version": {
        "type": "integer"
       },
       "as_of": {
        "type": "string",
        "format": "date-time"
       }
      }
     }
    }
   },
   "NotificationResult": {
    "type": "object",
    "properties": {
     "notification": {
      "$ref": "#/components/schemas/Notification"
     },
     "delivery_attempts": {
      "type": "integer"
     },
     "skipped_recipients": {
      "type": "integer"
     },
     "receipt": {
      "$ref": "#/components/schemas/Receipt"
     }
    }
   },
   "NotificationList": {
    "type": "object",
    "properties": {
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Notification"
      }
     },
     "next_cursor": {
      "type": [
       "string",
       "null"
      ]
     },
     "as_of": {
      "type": "string"
     }
    }
   },
   "NotificationDetail": {
    "allOf": [
     {
      "$ref": "#/components/schemas/Notification"
     },
     {
      "type": "object",
      "properties": {
       "patient_ref": {
        "type": [
         "string",
         "null"
        ],
        "format": "uuid"
       },
       "patient_access": {
        "enum": [
         "permitted",
         "withheld",
         "unavailable"
        ]
       },
       "readback_required": {
        "type": "boolean"
       },
       "recipients_chain": {
        "type": "array",
        "items": {
         "type": "string",
         "format": "uuid"
        }
       },
       "deliveries": {
        "type": "array",
        "items": {
         "$ref": "#/components/schemas/Delivery"
        }
       },
       "overrides": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "id": {
           "type": "string",
           "format": "uuid"
          },
          "alternate_recipient": {
           "type": "string",
           "format": "uuid"
          },
          "expiration": {
           "type": "string",
           "format": "date-time"
          },
          "created_by": {
           "type": "string",
           "format": "uuid"
          },
          "created_at": {
           "type": "string",
           "format": "date-time"
          }
         }
        }
       },
       "acknowledgement": {
        "type": [
         "object",
         "null"
        ],
        "properties": {
         "recipient_id": {
          "type": "string",
          "format": "uuid"
         },
         "readback_confirmation": {
          "type": "boolean"
         },
         "acknowledged_at": {
          "type": "string",
          "format": "date-time"
         },
         "notes": {
          "type": [
           "string",
           "null"
          ],
          "description": "only for the acknowledger and supervisors"
         }
        }
       }
      }
     }
    ]
   },
   "AckResult": {
    "type": "object",
    "properties": {
     "notification": {
      "$ref": "#/components/schemas/Notification"
     },
     "receipt": {
      "$ref": "#/components/schemas/Receipt"
     }
    }
   },
   "Policy": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "trigger_type": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "severity": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "target_role": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "channel": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "ack_deadline_minutes": {
      "type": "integer"
     },
     "escalation_chain": {
      "type": "array",
      "items": {
       "type": "string",
       "format": "uuid"
      }
     },
     "version": {
      "type": "integer"
     },
     "updated_by": {
      "type": "string",
      "format": "uuid"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     },
     "jurisdiction_id": {
      "type": "string",
      "format": "uuid"
     },
     "organization_id": {
      "type": "string",
      "format": "uuid"
     }
    }
   },
   "PolicyResult": {
    "type": "object",
    "properties": {
     "policy": {
      "$ref": "#/components/schemas/Policy"
     },
     "receipt": {
      "$ref": "#/components/schemas/Receipt"
     }
    }
   },
   "PolicyList": {
    "type": "object",
    "properties": {
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Policy"
      }
     }
    }
   },
   "CodeList": {
    "type": "object",
    "properties": {
     "list": {
      "type": "string"
     },
     "items": {
      "type": "array",
      "items": {
       "type": "object"
      }
     }
    }
   },
   "CodeListUpsertResult": {
    "type": "object",
    "properties": {
     "list": {
      "type": "string"
     },
     "upserted": {
      "type": "integer"
     },
     "receipt": {
      "$ref": "#/components/schemas/Receipt"
     }
    }
   },
   "SweepResult": {
    "type": "object",
    "properties": {
     "examined": {
      "type": "integer"
     },
     "escalated": {
      "type": "integer"
     },
     "retried": {
      "type": "integer"
     },
     "exhausted": {
      "type": "integer"
     },
     "skipped_conflict": {
      "type": "integer"
     },
     "still_pending": {
      "type": "integer"
     }
    },
    "description": "still_pending counts alerts the sweep could not route because a dependency is unavailable (or could not process); they stay open and are retried"
   },
   "OutboxResult": {
    "type": "object",
    "properties": {
     "delivered": {
      "type": "integer"
     },
     "pending": {
      "type": "integer"
     }
    }
   },
   "HistoryList": {
    "type": "object",
    "properties": {
     "items": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "workflow": {
         "enum": [
          "OHN-28-W001",
          "OHN-28-W002",
          "OHN-28-W003"
         ]
        },
        "from_state": {
         "type": [
          "string",
          "null"
         ]
        },
        "to_state": {
         "type": "string"
        },
        "version": {
         "type": "integer"
        },
        "actor_id": {
         "type": "string",
         "format": "uuid"
        },
        "reason": {
         "type": "string"
        },
        "at": {
         "type": "string",
         "format": "date-time"
        }
       }
      }
     }
    }
   },
   "DeliveryList": {
    "type": "object",
    "properties": {
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Delivery"
      }
     }
    }
   },
   "ReportCatalog": {
    "type": "object",
    "properties": {
     "reports": {
      "type": "array",
      "items": {
       "type": "object"
      }
     }
    }
   },
   "Report": {
    "type": "object",
    "properties": {
     "report_id": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "columns": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "rows": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "summary": {
      "type": "object"
     },
     "state": {
      "enum": [
       "rendered",
       "no_authorized_data"
      ]
     },
     "generated_at": {
      "type": "string"
     },
     "next_cursor": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "ExportReceipt": {
    "type": "object",
    "properties": {
     "export_id": {
      "type": "string",
      "format": "uuid"
     },
     "report_id": {
      "type": "string"
     },
     "format": {
      "type": "string"
     },
     "rows": {
      "type": "integer"
     },
     "expires_at": {
      "type": "string"
     },
     "single_use": {
      "type": "boolean"
     },
     "download_path": {
      "type": "string"
     }
    }
   },
   "ExportFile": {
    "type": "string",
    "format": "binary"
   },
   "Delivery": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "recipient_id": {
      "type": "string",
      "format": "uuid"
     },
     "channel": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "level": {
      "type": "integer"
     },
     "status": {
      "enum": [
       "sent",
       "failed",
       "undeliverable",
       "stale_contact"
      ]
     },
     "error_code": {
      "type": [
       "string",
       "null"
      ]
     },
     "transport_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "ReportFilters": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
     "facility": {
      "type": "string",
      "format": "uuid"
     },
     "organization": {
      "type": "string",
      "format": "uuid"
     },
     "period_from": {
      "type": "string",
      "format": "date"
     },
     "period_to": {
      "type": "string",
      "format": "date"
     },
     "severity": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     },
     "channel": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
     }
    }
   },
   "Health": {
    "type": "object",
    "properties": {
     "status": {
      "const": "ok"
     },
     "module": {
      "const": "OHN-28"
     },
     "dependencies": {
      "type": "object",
      "properties": {
       "worker": {
        "enum": [
         "live",
         "unconfigured",
         "synthetic"
        ]
       },
       "access": {
        "enum": [
         "live",
         "unconfigured",
         "synthetic"
        ]
       },
       "channel": {
        "enum": [
         "live",
         "unconfigured",
         "synthetic"
        ]
       }
      }
     },
     "overdue_unswept": {
      "type": "integer",
      "description": "1.0.1 (Java): open alerts whose deadline passed more than sweep_grace_minutes ago without the sweep reaching them; above zero means the sweep scheduler has stopped"
     },
     "sweep_grace_minutes": {
      "type": "integer"
     }
    }
   },
   "Error": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "string"
     },
     "message": {
      "type": "string"
     },
     "details": {
      "type": "object",
      "description": "validation: {field: zod issue code} (first issue per field; a refinement reports its message; unknown keys under \"_\"); version_conflict: {current_version}; duplicate_event: {notification_id}"
     }
    }
   }
  },
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer"
   }
  }
 },
 "security": [
  {
   "bearer": []
  }
 ]
}
