openapi: 3.1.0
info:
  title: OHN-43 Patient Rights and Record Correction
  version: 1.1.0
  description: >-
    Patient rights requests (W001), clinical correction disputes that preserve the original (W002) and independent
    appeals (W003). Every POST requires an Idempotency-Key. Patients act only on their own cases; packages are one-time.
    1.1.0 (2026-11-23): a facility's data protection officer works as rights_caseworker with purpose facility_rights_administration
    or privacy_officer with purpose facility_privacy_oversight. With these purposes every request, correction, appeal and package is
    scoped to the token's organisation_id (the organisation the request is addressed to): another organisation's is 404 and is not
    listed; reports and exports (jurisdiction-wide) are 403. The network privacy office keeps its purposes and network scope.
servers:
  - url: https://opeshealthnetwork.com
security:
  - bearerAuth: []
tags:
  - name: Health
  - name: Synthetic
  - name: Requests
  - name: Corrections
  - name: Appeals
  - name: Reports
paths:
  /health/ohn-43:
    get:
      operationId: ohn43_health
      summary: Liveness and database check
      tags: [Health]
      security: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '404': { $ref: '#/components/responses/E404' }
  /api/ohn/v1/rights-requests/synthetic-token:
    post:
      operationId: ohn43_syntheticToken
      summary: Issue a synthetic token (TypeScript baseline, synthetic mode only; the Java module never issues tokens and answers 404)
      tags: [Synthetic]
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SyntheticToken' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '404': { $ref: '#/components/responses/E404' }
  /api/ohn/v1/rights-requests:
    get:
      operationId: ohn43_listRequests
      summary: Rights requests (patients see only their own)
      tags: [Requests]
      parameters:
        - name: state
          in: query
          required: false
          schema: { type: string, maxLength: 64 }
        - name: request_type
          in: query
          required: false
          schema: { type: string, maxLength: 64 }
        - name: overdue
          in: query
          required: false
          description: 'true or false; any other value is 422. Unknown query keys are refused with 422.'
          schema: { type: string, maxLength: 5 }
        - name: cursor
          in: query
          required: false
          schema: { type: string, maxLength: 64 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
    post:
      operationId: ohn43_fileRequest
      x-inventory-id: OHN-43-API-001
      summary: File a rights request (F001)
      tags: [Requests]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/RightsRequest' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/context:
    get:
      operationId: ohn43_context
      summary: Caller principal and permitted actions
      tags: [Requests]
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/vocabulary:
    get:
      operationId: ohn43_vocabulary
      summary: Controlled vocabularies
      tags: [Requests]
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/corrections:
    get:
      operationId: ohn43_listCorrections
      summary: Correction disputes
      tags: [Corrections]
      parameters:
        - name: state
          in: query
          required: false
          schema: { type: string, maxLength: 64 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
    post:
      operationId: ohn43_proposeCorrection
      summary: Dispute a clinical assertion (F002)
      tags: [Corrections]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Correction' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/corrections/{id}:
    get:
      operationId: ohn43_getCorrection
      summary: Correction with history
      tags: [Corrections]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/corrections/{id}/identify-source:
    post:
      operationId: ohn43_identifySource
      summary: patient_dispute -> source_identified
      tags: [Corrections]
      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
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/corrections/{id}/send-to-source:
    post:
      operationId: ohn43_sendToSource
      summary: source_identified -> source_review
      tags: [Corrections]
      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
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/corrections/{id}/respond:
    post:
      operationId: ohn43_sourceRespond
      summary: Named source amends or attaches the patient statement
      tags: [Corrections]
      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/SourceResponse' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/corrections/{id}/close:
    post:
      operationId: ohn43_closeCorrection
      summary: amendment_or_statement -> closed
      tags: [Corrections]
      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
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/appeals:
    get:
      operationId: ohn43_listAppeals
      summary: Appeals
      tags: [Appeals]
      parameters:
        - name: state
          in: query
          required: false
          schema: { type: string, maxLength: 64 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
    post:
      operationId: ohn43_submitAppeal
      summary: Appeal a denial or partial approval (F004)
      tags: [Appeals]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Appeal' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/appeals/{id}:
    get:
      operationId: ohn43_getAppeal
      summary: Appeal with history
      tags: [Appeals]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/appeals/{id}/start-review:
    post:
      operationId: ohn43_startReview
      summary: Named independent reviewer starts the review
      tags: [Appeals]
      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
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/appeals/{id}/decide:
    post:
      operationId: ohn43_decideAppeal
      summary: Uphold or overturn (overturn reopens fulfillment)
      tags: [Appeals]
      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/AppealDecision' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/packages/{token}:
    get:
      operationId: ohn43_downloadPackage
      summary: One-time access package download (secure portal, the patient; other channels, a caseworker)
      tags: [Requests]
      parameters:
        - name: token
          in: path
          required: true
          schema: { type: string, pattern: "^[A-Za-z0-9_-]{20,64}$" }
      responses:
        '200':
          description: Success; headers Content-Disposition (attachment) and X-Content-SHA256 (digest of the body)
          content:
            application/json: { schema: { type: string, format: binary } }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/reports/{reportId}:
    get:
      operationId: ohn43_runReport
      summary: Run OHN-43-R001..R003
      tags: [Reports]
      parameters:
        - name: reportId
          in: path
          required: true
          schema: { type: string, enum: [OHN-43-R001, OHN-43-R002, OHN-43-R003] }
        - name: from
          in: query
          required: false
          description: 'ISO 8601 date-time with offset. Declared as a string: a malformed filter is 422 invalid_filter (not a binding error).'
          schema: { type: string, maxLength: 64 }
        - name: to
          in: query
          required: false
          description: 'ISO 8601 date-time with offset (see from).'
          schema: { type: string, maxLength: 64 }
        - name: country
          in: query
          required: false
          description: 'uuid; another jurisdiction answers an empty no_authorized_data report.'
          schema: { type: string, maxLength: 64 }
        - name: jurisdiction
          in: query
          required: false
          description: 'uuid; same as country.'
          schema: { type: string, maxLength: 64 }
        - name: request_type
          in: query
          required: false
          schema: { type: string, maxLength: 64 }
        - name: source
          in: query
          required: false
          description: 'uuid of a source contact (R002).'
          schema: { type: string, maxLength: 64 }
        - name: status
          in: query
          required: false
          schema: { type: string, maxLength: 64 }
        - name: cursor
          in: query
          required: false
          schema: { type: string, maxLength: 64 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/reports/{reportId}/export:
    post:
      operationId: ohn43_exportReport
      summary: Signed, 5-minute, owner-only CSV or PDF export
      tags: [Reports]
      parameters:
        - name: reportId
          in: path
          required: true
          schema: { type: string, enum: [OHN-43-R001, OHN-43-R002, OHN-43-R003] }
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Export' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/exports/{token}:
    get:
      operationId: ohn43_downloadExport
      summary: Download an export (audited; requester only; valid 5 minutes)
      tags: [Reports]
      parameters:
        - name: token
          in: path
          required: true
          schema: { type: string, pattern: "^[A-Za-z0-9_-]{20,64}$" }
      responses:
        '200':
          description: Success; Content-Disposition attachment with the report id as file name
          content:
            text/csv: { schema: { type: string, format: binary } }
            application/pdf: { schema: { type: string, format: binary } }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/{id}:
    get:
      operationId: ohn43_getRequest
      x-inventory-id: OHN-43-API-002
      summary: Request with decisions, corrections, appeals and history
      tags: [Requests]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '410': { $ref: '#/components/responses/E410' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/{id}/package:
    post:
      operationId: ohn43_issuePackage
      summary: Issue a one-time link for the access package to its rightful recipient
      tags: [Requests]
      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/Empty' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/{id}/verify-identity:
    post:
      operationId: ohn43_verifyIdentity
      summary: request_received -> identity_verified (OHN-37 assurance)
      tags: [Requests]
      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/Identity' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/{id}/decide:
    post:
      operationId: ohn43_decide
      x-inventory-id: OHN-43-API-003
      summary: 'Adjudicate (F003): identity_verified -> eligibility_evaluated'
      tags: [Requests]
      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/Decide' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/{id}/fulfill:
    post:
      operationId: ohn43_fulfill
      summary: fulfilled or denied; issues the access package
      tags: [Requests]
      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
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/{id}/notify:
    post:
      operationId: ohn43_notify
      summary: notified; emits rights.request.closed
      tags: [Requests]
      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/Notify' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/rights-requests/synthetic/setup:
    post:
      operationId: ohn43_syntheticSetup
      summary: Configure synthetic upstream doubles (404 unless synthetic mode; not for production)
      tags: [Synthetic]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SyntheticSetup' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '400': { $ref: '#/components/responses/E400' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
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:
    E400:
      description: Malformed request or missing Idempotency-Key
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    E401:
      description: Unauthenticated
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    E403:
      description: Denied by policy (audited)
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    E404:
      description: Not found or not disclosed
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    E409:
      description: Stale version, invalid transition, conflict or reused idempotency key
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    E410:
      description: 'Gone: link expired or already used'
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    E422:
      description: Validation failure or domain refusal
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    E429:
      description: Rate limited; see Retry-After
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    E503:
      description: Jurisdiction service or another dependency unavailable; nothing changed
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
  schemas:
    Error:
      type: object
      required: [error]
      properties:
        error: { type: string }
        message: { type: string }
        details: {}
    Document:
      type: object
      description: JSON document; shapes are listed in modules/OHN-43/data/schema.md
      additionalProperties: true
    Receipt:
      type: object
      required: [receipt_id, committed_at, aggregate_id, aggregate_type, version, status]
      properties:
        receipt_id: { type: string, format: uuid }
        committed_at: { type: string, format: date-time }
        aggregate_id: { type: string, format: uuid }
        aggregate_type: { type: string }
        version: { type: integer, minimum: 1 }
        status: { type: string, enum: [committed, denied, pending] }
    CommandResult:
      type: object
      properties:
        receipt: { $ref: '#/components/schemas/Receipt' }
      additionalProperties: true
    Empty:
      type: object
      additionalProperties: false
    Versioned:
      type: object
      additionalProperties: false
      required: [expected_version]
      properties:
        expected_version: { type: integer, minimum: 1 }
    Export:
      type: object
      additionalProperties: false
      required: [format]
      properties:
        format: { type: string, enum: [csv, pdf] }
        filters: { type: object, additionalProperties: { type: string, maxLength: 512 } }
    RightsRequest:
      type: object
      description: OHN-43-F001 Patient rights request
      additionalProperties: false
      required: [patient_ref, request_type, request_scope, preferred_response_channel]
      properties:
        patient_ref: { type: string, format: uuid, description: A patient may only use their own reference }
        request_type: { type: string, enum: [access_copy, correction, restriction, erasure, portability, accounting_of_disclosures] }
        request_scope: { type: string, minLength: 1, maxLength: 8192 }
        preferred_response_channel: { type: string, enum: [secure_portal, postal_mail, in_person] }
        supporting_evidence_ref: { type: string, format: uuid }
    Identity:
      type: object
      additionalProperties: false
      required: [expected_version, method, evidence_ref]
      properties:
        expected_version: { type: integer, minimum: 1 }
        method: { type: string, enum: [in_person_document_check, national_eid, verified_portal_account] }
        evidence_ref: { type: string, format: uuid }
    Decide:
      type: object
      additionalProperties: false
      required: [expected_version, legal_basis, decision, explanation, reviewer, due_date]
      properties:
        expected_version: { type: integer, minimum: 1 }
        legal_basis: { type: string, enum: [patient_right_of_access, clinical_retention_obligation, third_party_information, risk_of_serious_harm, legal_proceedings, manifestly_unfounded] }
        decision: { type: string, enum: [approved, partially_approved, denied] }
        explanation: { type: string, minLength: 1, maxLength: 8192 }
        reviewer: { type: string, format: uuid, description: Must be the caller }
        due_date: { type: string, format: date }
    Notify:
      type: object
      additionalProperties: false
      required: [expected_version, channel]
      properties:
        expected_version: { type: integer, minimum: 1 }
        channel: { type: string, enum: [secure_portal, postal_mail, in_person] }
    Correction:
      type: object
      description: OHN-43-F002 Record correction proposal
      additionalProperties: false
      required: [request_id, source_record_ref, patient_statement, requested_change, supporting_document_ref, source_contact]
      properties:
        request_id: { type: string, format: uuid }
        source_record_ref: { type: string, format: uuid }
        patient_statement: { type: string, minLength: 1, maxLength: 8192 }
        requested_change: { type: string, minLength: 1, maxLength: 8192 }
        supporting_document_ref: { type: string, format: uuid }
        source_contact: { type: string, format: uuid }
    SourceResponse:
      type: object
      additionalProperties: false
      required: [expected_version, outcome, response]
      properties:
        expected_version: { type: integer, minimum: 1 }
        outcome: { type: string, enum: [amended, statement_attached] }
        response: { type: string, minLength: 1, maxLength: 8192 }
        amendment_ref: { type: string, format: uuid, description: Required when amended }
    Appeal:
      type: object
      description: OHN-43-F004 Rights appeal
      additionalProperties: false
      required: [original_request, appeal_reason, new_evidence, reviewer]
      properties:
        original_request: { type: string, format: uuid }
        appeal_reason: { type: string, minLength: 10, maxLength: 4096 }
        new_evidence: { type: string, format: uuid }
        reviewer: { type: string, format: uuid, description: Must differ from the first reviewer }
    AppealDecision:
      type: object
      additionalProperties: false
      required: [expected_version, outcome, response]
      properties:
        expected_version: { type: integer, minimum: 1 }
        outcome: { type: string, enum: [upheld, overturned] }
        response: { type: string, minLength: 1, maxLength: 8192 }
    SyntheticToken:
      type: object
      additionalProperties: false
      required: [principal_id, role, jurisdiction, organization_id, purpose]
      properties:
        principal_id: { type: string, format: uuid }
        role: { type: string, enum: [rights_caseworker, privacy_officer, patient, records_source, unauthorized_viewer] }
        jurisdiction: { type: string, format: uuid }
        organization_id: { type: string, format: uuid }
        purpose: { type: string, enum: [rights_administration, privacy_oversight, patient_self_service, record_correction, facility_rights_administration, facility_privacy_oversight] }
    SyntheticSetup:
      type: object
      additionalProperties: false
      properties:
        low_assurance_evidence: { type: array, items: { type: string, format: uuid } }
        down: { type: array, items: { type: string, enum: [OHN-01, OHN-37] } }
        reset: { type: boolean }
