openapi: 3.1.0
info:
  title: OHN-26 Offline Synchronization and Edge Integration
  version: 1.0.0
  description: Default-deny, tenant-scoped edge sync API. Every POST requires Idempotency-Key. Errors use the Error schema; 401/403/404/409/422/429/503 map to UI states.
servers:
  - url: https://opeshealthnetwork.com
security:
  - bearerAuth: []
paths:
  /health/ohn-26:
    get:
      operationId: ohn26_health
      summary: "Module health"
      security: []
      responses:
        '200':
          description: Success; commands return an audit receipt
        '404': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/synthetic-token:
    post:
      operationId: ohn26_syntheticToken
      summary: "Synthetic sign-in of the TypeScript baseline (404 unless NODE_ENV!=production and OHN26_SYNTHETIC_AUTH=true). NOT SERVED by the Java service: tokens come from the platform gateway (ES256, issuer ohn-platform-gateway, audience ohn-26)"
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SyntheticToken' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '404': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/context:
    get:
      operationId: ohn26_context
      summary: "Caller context, permissions and policy configuration"
      x-authorization-action: read
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/vocabulary:
    get:
      operationId: ohn26_vocabulary
      summary: "Controlled vocabularies"
      x-authorization-action: read
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/dashboard:
    get:
      operationId: ohn26_fleetDashboard
      summary: "Edge fleet dashboard (P001)"
      x-authorization-action: read
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/expiration:
    get:
      operationId: ohn26_expirationDashboard
      summary: "Offline data expiration dashboard (P006)"
      x-authorization-action: read
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/nodes:
    get:
      operationId: ohn26_listNodes
      summary: "List edge nodes"
      x-authorization-action: read
      parameters:
        - { name: state, in: query, required: false, schema: { $ref: "#/components/schemas/NodeState" } }
        - { name: facility, in: query, required: false, schema: { type: string, format: uuid } }
        - { name: cursor, in: query, required: false, schema: { type: string, maxLength: 64 } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
    post:
      operationId: ohn26_registerNode
      x-form-submit: OHN-26-F001-SUBMIT
      summary: "Register an edge node (OHN-26-F001-SUBMIT)"
      x-authorization-action: enroll
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/NodeRegistration' }
      responses:
        '201':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/nodes/{id}:
    get:
      operationId: ohn26_getNode
      summary: "Edge node with cursor, grants, cases and history"
      x-authorization-action: read
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/nodes/{id}/transitions:
    post:
      operationId: ohn26_transitionNode
      summary: "Advance enrollment (W001) or retire"
      x-authorization-action: enroll
      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/NodeTransition' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/nodes/{id}/compromise:
    post:
      operationId: ohn26_reportCompromise
      summary: "Report device compromise (W003)"
      x-authorization-action: contain
      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/Compromise' }
      responses:
        '201':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/nodes/{id}/wipe-confirmation:
    post:
      operationId: ohn26_confirmWipe
      summary: "Device confirms remote wipe"
      x-authorization-action: sync
      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/WipeConfirmation' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/sync:
    post:
      operationId: ohn26_submitSyncBatch
      x-inventory-id: OHN-26-API-001
      summary: "Submit a signed offline delta batch (W002)"
      x-authorization-action: sync
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SyncBatch' }
      responses:
        '201':
          description: Success; commands return an audit receipt
        '200':
          description: "A resend of an already accepted batch with identical content (same digest): the stored answer with duplicate true; nothing new is written."
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/cursors:
    get:
      operationId: ohn26_listCursors
      x-inventory-id: OHN-26-API-002
      summary: "List sync cursors"
      x-authorization-action: read
      parameters:
        - { name: node, in: query, required: false, schema: { type: string, format: uuid } }
        - { name: cursor, in: query, required: false, schema: { type: string, maxLength: 64 } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/batches:
    get:
      operationId: ohn26_listBatches
      summary: "Synchronization queue"
      x-authorization-action: read
      parameters:
        - { name: status, in: query, required: false, schema: { $ref: "#/components/schemas/BatchStatus" } }
        - { name: node, in: query, required: false, schema: { type: string, format: uuid } }
        - { name: facility, in: query, required: false, schema: { type: string, format: uuid } }
        - { name: sort, in: query, required: false, schema: { enum: [received_desc, received_asc, seq_desc] } }
        - { name: cursor, in: query, required: false, schema: { type: string, maxLength: 64 } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/batches/{id}:
    get:
      operationId: ohn26_getBatch
      summary: "Batch with item outcomes and history"
      x-authorization-action: read
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/batches/{id}/revalidate:
    post:
      operationId: ohn26_revalidateBatch
      summary: "Re-run revalidation for held items"
      x-authorization-action: revalidate
      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/Versioned' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/maintenance/expire-grants:
    post:
      operationId: ohn26_expireGrants
      summary: "Expire due offline grants"
      x-authorization-action: maintain
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Empty' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/conflicts:
    get:
      operationId: ohn26_listConflicts
      summary: "List conflict cases"
      x-authorization-action: read
      parameters:
        - { name: status, in: query, required: false, schema: { $ref: "#/components/schemas/ConflictStatus" } }
        - { name: entity_class, in: query, required: false, schema: { $ref: "#/components/schemas/EntityClass" } }
        - { name: cursor, in: query, required: false, schema: { type: string, maxLength: 64 } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/conflicts/{id}:
    get:
      operationId: ohn26_getConflict
      summary: "Conflict case with both revisions"
      x-authorization-action: read
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/conflicts/{id}/resolve:
    post:
      operationId: ohn26_resolveConflict
      x-inventory-id: OHN-26-API-003
      x-form-submit: OHN-26-F002-SUBMIT
      summary: "Resolve a conflict explicitly (OHN-26-F002-SUBMIT)"
      x-authorization-action: resolve
      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/ConflictResolution' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/renewals:
    get:
      operationId: ohn26_listRenewals
      summary: "List renewal requests"
      x-authorization-action: read
      parameters:
        - { name: status, in: query, required: false, schema: { enum: [requested, approved, rejected] } }
        - { name: cursor, in: query, required: false, schema: { type: string, maxLength: 64 } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
    post:
      operationId: ohn26_requestRenewal
      x-form-submit: OHN-26-F003-SUBMIT
      summary: "Request offline permission renewal (OHN-26-F003-SUBMIT)"
      x-authorization-action: request_renewal
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Renewal' }
      responses:
        '201':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/renewals/{id}:
    get:
      operationId: ohn26_getRenewal
      summary: "Renewal request"
      x-authorization-action: read
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/renewals/{id}/decide:
    post:
      operationId: ohn26_decideRenewal
      summary: "Approve or reject a renewal (dual control)"
      x-authorization-action: decide_renewal
      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/RenewalDecision' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/device-cases:
    get:
      operationId: ohn26_listDeviceCases
      summary: "List device compromise cases"
      x-authorization-action: read
      parameters:
        - { name: cursor, in: query, required: false, schema: { type: string, maxLength: 64 } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/device-cases/{id}:
    get:
      operationId: ohn26_getDeviceCase
      summary: "Device case with quarantined batches"
      x-authorization-action: read
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/device-cases/{id}/advance:
    post:
      operationId: ohn26_advanceDeviceCase
      summary: "Retry pending key revocation"
      x-authorization-action: contain
      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/Reasoned' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/device-cases/{id}/request-wipe:
    post:
      operationId: ohn26_requestWipe
      summary: "Request remote wipe"
      x-authorization-action: contain
      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/Reasoned' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/alerts:
    get:
      operationId: ohn26_listAlerts
      summary: "Sync-time authorization alerts"
      x-authorization-action: read
      parameters:
        - { name: type, in: query, required: false, schema: { $ref: "#/components/schemas/AlertType" } }
        - { name: status, in: query, required: false, schema: { enum: [open, acknowledged] } }
        - { name: cursor, in: query, required: false, schema: { type: string, maxLength: 64 } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/alerts/{id}/acknowledge:
    post:
      operationId: ohn26_acknowledgeAlert
      summary: "Acknowledge an alert"
      x-authorization-action: acknowledge
      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/Acknowledge' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/reports/{reportId}:
    get:
      operationId: ohn26_runReport
      summary: "Run report R001-R003"
      x-authorization-action: read
      description: "Strict filters per report; any other query key or an invalid value is 422 invalid_filter. R001: jurisdiction (uuid, another jurisdiction yields no rows), facility, status (NodeState); R002: facility, entity_class, status (ConflictStatus); R003: facility, from, to (date-time with offset). cursor (max 64) pages 100 rows."
      parameters:
        - { name: reportId, in: path, required: true, schema: { enum: [OHN-26-R001, OHN-26-R002, OHN-26-R003] } }
        - { name: jurisdiction, in: query, required: false, schema: { type: string, format: uuid } }
        - { name: facility, in: query, required: false, schema: { type: string, format: uuid } }
        - { name: status, in: query, required: false, schema: { type: string, description: "NodeState (R001) or ConflictStatus (R002)" } }
        - { name: entity_class, in: query, required: false, schema: { $ref: "#/components/schemas/EntityClass" } }
        - { name: from, in: query, required: false, schema: { type: string, format: date-time } }
        - { name: to, in: query, required: false, schema: { type: string, format: date-time } }
        - { name: cursor, in: query, required: false, schema: { type: string, maxLength: 64 } }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/reports/{reportId}/export:
    post:
      operationId: ohn26_exportReport
      summary: "Create an audited CSV/PDF export"
      x-authorization-action: export
      parameters:
        - { name: reportId, in: path, required: true, schema: { enum: [OHN-26-R001, OHN-26-R002, OHN-26-R003] } }
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Export' }
      responses:
        '201':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/exports/{token}:
    get:
      operationId: ohn26_downloadExport
      summary: "Download an export (personal, 5 minutes)"
      x-authorization-action: export
      parameters:
        - { name: token, in: path, required: true, schema: { type: string, pattern: "^[A-Za-z0-9_-]{20,64}$" } }
      responses:
        '200':
          description: "The signed export; Content-Disposition names the report and format. The link is personal (the caller who created it, in the same tenant) and lives five minutes; it is not single use."
          content:
            text/csv: { schema: { type: string } }
            application/pdf: { schema: { type: string, format: binary } }
        '410': { $ref: '#/components/responses/Error' }
        '500': { $ref: '#/components/responses/Error' }
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/synthetic/facts:
    post:
      operationId: ohn26_syntheticFact
      summary: "Seed synthetic upstream facts (synthetic mode only: the TypeScript baseline with OHN26_SYNTHETIC_AUTH=true, Java with ohn.m26.synthetic-gateways=true; 404 otherwise)"
      x-authorization-action: seed_synthetic
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SyntheticFact' }
      responses:
        '201':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/edge/synthetic/sign:
    post:
      operationId: ohn26_syntheticSign
      summary: "Sign a batch with the synthetic device key (synthetic mode only)"
      x-authorization-action: seed_synthetic
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SyntheticSign' }
      responses:
        '200':
          description: Success; commands return an audit receipt
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '413': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
components:
  securitySchemes:
    bearerAuth: { type: http, scheme: bearer, bearerFormat: JWT }
  parameters:
    IdempotencyKey: { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 8, maxLength: 128, pattern: "^[A-Za-z0-9_.:-]+$" } }
  responses:
    Error:
      description: Error
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
  schemas:
    NodeState: { enum: [device_claimed, attested, facility_bound, policy_installed, active, blocked, retired] }
    EntityClass: { enum: [observation, encounter, immunization, medication_administration, appointment, demographic_update, stock_level] }
    Operation: { enum: [create, update, identity_merge] }
    ItemPurpose: { enum: [treatment, public_health, operations] }
    BatchStatus: { enum: [applied, partial, held, rejected, quarantined] }
    ItemOutcome: { enum: [accepted, conflict, denied_consent, denied_authorization, denied_scope, rejected_identity_merge, quarantined_identity, held_dependency_unavailable, quarantined_compromise, resolved] }
    ConflictStatus: { enum: [open, resolved, frozen] }
    Resolution: { enum: [keep_server, apply_local, manual_merge] }
    SignalType: { enum: [lost, stolen, tamper_detected, anomalous_sync, operator_report] }
    AlertType: { enum: [stale_consent, expired_grant, revoked_device, authorization_denied, clock_skew, signature_invalid, scope_violation, identity_quarantine] }
    Role: { enum: [edge_operator, clinical_data_steward, sync_auditor, unauthorized_viewer] }
    Error: { type: object, required: [error], properties: { error: { type: string }, message: { type: string }, details: { description: "Validation failures: zod flatten() shape {formErrors: [string], fieldErrors: {field: [string]}}; domain refusals add fieldErrors or codes such as current_version, expected_batch_seq, remote_wipe_required, clock_skew_seconds" }, type: { type: string }, title: { type: string }, status: { type: integer }, detail: { type: string }, trace_id: { type: string } } }
    Empty: { type: object, additionalProperties: false }
    Versioned: { type: object, additionalProperties: false, required: [expected_version], properties: { expected_version: { type: integer, minimum: 1 } } }
    Reasoned: { type: object, additionalProperties: false, required: [expected_version, reason], properties: { expected_version: { type: integer, minimum: 1 }, reason: { type: string, minLength: 10, maxLength: 4096 } } }
    SyntheticToken: { type: object, additionalProperties: false, required: [principal_id, role, jurisdiction, organization_id, purpose], properties: { principal_id: { type: string, format: uuid }, role: { $ref: "#/components/schemas/Role" }, jurisdiction: { type: string, format: uuid }, organization_id: { type: string, format: uuid }, purpose: { enum: [edge_operations, data_stewardship, audit] } } }
    NodeRegistration: { type: object, additionalProperties: false, required: [facility_id, device_attestation_ref, jurisdiction_id, software_version, sync_scope, max_offline_hours], properties: { facility_id: { type: string, format: uuid }, device_attestation_ref: { type: string, format: uuid }, jurisdiction_id: { type: string, format: uuid }, software_version: { type: string, minLength: 1, maxLength: 512 }, sync_scope: { type: string, minLength: 1, maxLength: 8192, description: "Comma-separated EntityClass values" }, max_offline_hours: { type: integer, minimum: 0, maximum: 100000, description: "maximum 100000; must not exceed the jurisdiction cap (ohn.m26.max-offline-hours-cap / OHN26_MAX_OFFLINE_HOURS_CAP) when one is configured" } } }
    NodeTransition: { type: object, additionalProperties: false, required: [to, expected_version, reason], properties: { to: { enum: [attested, facility_bound, policy_installed, active, retired] }, expected_version: { type: integer, minimum: 1 }, reason: { type: string, minLength: 10, maxLength: 4096 }, device_key_ref: { type: string, format: uuid } } }
    Compromise: { type: object, additionalProperties: false, required: [signal_type, reason, expected_version], properties: { signal_type: { $ref: "#/components/schemas/SignalType" }, reason: { type: string, minLength: 10, maxLength: 4096 }, expected_version: { type: integer, minimum: 1 } } }
    WipeConfirmation: { type: object, additionalProperties: false, required: [wipe_receipt_digest], properties: { wipe_receipt_digest: { type: string, pattern: "^[0-9a-f]{64}$" } } }
    SyncItem: { type: object, additionalProperties: false, required: [local_seq, entity_class, entity_ref, patient_ref, operation, purpose, base_revision, local_revision, payload], properties: { local_seq: { type: integer, minimum: 1 }, entity_class: { $ref: "#/components/schemas/EntityClass" }, entity_ref: { type: string, format: uuid }, patient_ref: { type: string, format: uuid }, operation: { $ref: "#/components/schemas/Operation" }, purpose: { $ref: "#/components/schemas/ItemPurpose" }, base_revision: { type: [string, "null"], minLength: 1, maxLength: 512 }, local_revision: { type: string, minLength: 1, maxLength: 512 }, payload: { type: object, description: "At most 16384 characters as JSON" } } }
    SyncBatch: { type: object, additionalProperties: false, required: [edge_node_id, batch_seq, device_clock_at, policy_version, grant_id, signature, items], properties: { edge_node_id: { type: string, format: uuid }, batch_seq: { type: integer, minimum: 1 }, device_clock_at: { type: string, format: date-time }, policy_version: { type: string, minLength: 1, maxLength: 512 }, grant_id: { type: string, format: uuid }, signature: { type: object, required: [key_ref, algorithm, value], properties: { key_ref: { type: string, format: uuid }, algorithm: { const: ES256 }, value: { type: string, minLength: 16, maxLength: 1024 } } }, items: { type: array, minItems: 1, maxItems: 200, items: { $ref: "#/components/schemas/SyncItem" } } } }
    ConflictResolution: { type: object, additionalProperties: false, required: [batch_id, entity_ref, local_revision, server_revision, resolution, reason, expected_version], properties: { batch_id: { type: string, format: uuid }, entity_ref: { type: string, format: uuid }, local_revision: { type: string, minLength: 1, maxLength: 512 }, server_revision: { type: string, minLength: 1, maxLength: 512 }, resolution: { $ref: "#/components/schemas/Resolution" }, clinical_reviewer: { type: string, format: uuid, description: "Required (= caller) for clinical entity classes" }, reason: { type: string, minLength: 10, maxLength: 4096 }, expected_version: { type: integer, minimum: 1 }, merged_payload: { type: object } } }
    Renewal: { type: object, additionalProperties: false, required: [edge_node_id, requested_scope, last_policy_version, last_sync_time, justification], properties: { edge_node_id: { type: string, format: uuid }, requested_scope: { type: string, minLength: 1, maxLength: 8192 }, last_policy_version: { type: string, minLength: 1, maxLength: 512 }, last_sync_time: { type: string, format: date-time }, justification: { type: string, minLength: 10, maxLength: 4096 } } }
    RenewalDecision: { type: object, additionalProperties: false, required: [decision, reason, expected_version], properties: { decision: { enum: [approve, reject] }, reason: { type: string, minLength: 10, maxLength: 4096 }, expected_version: { type: integer, minimum: 1 } } }
    Acknowledge: { type: object, additionalProperties: false, required: [expected_version, note], properties: { expected_version: { type: integer, minimum: 1 }, note: { type: string, minLength: 10, maxLength: 4096 } } }
    Export: { type: object, additionalProperties: false, required: [format], properties: { format: { enum: [csv, pdf] }, filters: { type: object, additionalProperties: { type: string, maxLength: 512 }, default: {}, description: "The report's strict filters (as query parameters); invalid ones are 422 invalid_filter" } } }
    SyntheticFact: { type: object, required: [kind], description: "Discriminated by kind. identity: patient_ref, status (active, merged, under_review, unknown); consent: patient_ref, purpose, status (granted, withdrawn, unknown); authorization: patient_ref, purpose, decision (permit, deny, indeterminate); device_key: key_ref, status (active, revoked); attestation: attestation_ref, status (trusted, unmanaged, untrusted); outage: dependency (OHN-02, OHN-15, OHN-16, OHN-45), down. Each is strict.", properties: { kind: { enum: [identity, consent, authorization, device_key, attestation, outage] } } }
    SyntheticSign: { type: object, required: [batch], description: "batch: a SyncBatch without signature plus key_ref (uuid); the answer carries the digest (SHA-256 of the key-sorted JSON of edge_node_id, batch_seq, device_clock_at, policy_version, grant_id, items) and the stand-in ES256 signature", properties: { batch: { type: object } } }
