openapi: 3.1.0
info:
  title: OHN-41 FHIR Repository and Profile Registry
  version: 1.1.0
  description: >-
    Governed FHIR R4 persistence with immutable version history, profile release governance (W001), optimistic
    versioned storage (W002) and quarantine of invalid resources (W003). Every POST requires an Idempotency-Key.
    Errors use {error, message, details}. 401 unauthenticated, 403 policy_denied, 404 not disclosed, 409 stale_version /
    invalid_transition / idempotency_key_reused, 422 domain_validation_failed and domain refusals, 429 with Retry-After,
    503 jurisdiction_unavailable / dependency_unavailable (the body also names the `dependency`, e.g. OHN-16).
    Also: 400 malformed_request and idempotency_key_required, 413 payload_too_large (body over 512 KB), 410 export_expired.
    The Java service answers problem+json that adds type, title, status, detail and trace_id to {error, message, details};
    validation details are zod's flatten() shape {formErrors, fieldErrors}. Tokens come from the platform gateway (ES256,
    audience ohn-41); /synthetic-token exists only in the TypeScript baseline.
servers:
  - url: https://opeshealthnetwork.com
security:
  - bearerAuth: []
tags:
  - name: Health
  - name: Synthetic
  - name: Repository
  - name: Profiles
  - name: Pins
  - name: Partitions
  - name: Resources
  - name: Quarantine
  - name: Reports
paths:
  /health/ohn-41:
    get:
      operationId: ohn41_health
      summary: Liveness and database check
      tags: [Health]
      security: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '404': { $ref: '#/components/responses/E404' }
  /api/ohn/v1/fhir/synthetic-token:
    post:
      operationId: ohn41_syntheticToken
      summary: Issue a synthetic token (TypeScript baseline in synthetic mode only; not served by the Java service, tokens come from the gateway)
      tags: [Synthetic]
      security: []
      parameters:
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SyntheticToken' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '404': { $ref: '#/components/responses/E404' }
  /api/ohn/v1/fhir/capabilities:
    get:
      operationId: ohn41_capabilities
      x-inventory-id: OHN-41-API-001
      summary: FHIR R4 CapabilityStatement for the caller partition
      tags: [Repository]
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CapabilityStatement' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/repository/status:
    get:
      operationId: ohn41_repositoryStatus
      x-inventory-id: OHN-41-API-004
      summary: Repository configuration, counts and guidance
      tags: [Repository]
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/context:
    get:
      operationId: ohn41_context
      summary: Caller principal and permitted actions
      tags: [Repository]
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/vocabulary:
    get:
      operationId: ohn41_vocabulary
      summary: Controlled vocabularies used by forms
      tags: [Repository]
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/profiles:
    get:
      operationId: ohn41_listProfiles
      summary: List profile releases in the jurisdiction
      tags: [Profiles]
      parameters:
        - name: state
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: resource_type
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: package_id
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: cursor
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
    post:
      operationId: ohn41_createProfile
      x-inventory-id: OHN-41-API-002
      summary: Submit a profile release (F001)
      tags: [Profiles]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ReleaseCreate' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/profiles/{id}:
    get:
      operationId: ohn41_getProfile
      x-inventory-id: OHN-41-API-003
      summary: Profile release with history and compatibility runs
      tags: [Profiles]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/profiles/{id}/compatibility:
    get:
      operationId: ohn41_profileCompatibility
      summary: Breaking changes versus the release in force
      tags: [Profiles]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/profiles/{id}/resolve-dependencies:
    post:
      operationId: ohn41_resolveDependencies
      summary: candidate -> dependency_resolved (dependencies approved, bindings licensed)
      tags: [Profiles]
      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: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/profiles/{id}/validate:
    post:
      operationId: ohn41_validateProfile
      summary: dependency_resolved -> validated (compatibility run)
      tags: [Profiles]
      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: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/profiles/{id}/approve:
    post:
      operationId: ohn41_approveProfile
      summary: validated -> approved (independent reviewer)
      tags: [Profiles]
      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/Approve' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/profiles/{id}/activate:
    post:
      operationId: ohn41_activateProfile
      summary: approved -> active; emits fhir.profile.published
      tags: [Profiles]
      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: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/profiles/{id}/reject:
    post:
      operationId: ohn41_rejectProfile
      summary: Reject a release before activation
      tags: [Profiles]
      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
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/profiles/{id}/retire:
    post:
      operationId: ohn41_retireProfile
      summary: Retire an active, unpinned release
      tags: [Profiles]
      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
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/pins:
    get:
      operationId: ohn41_listPins
      summary: Package pins in the jurisdiction
      tags: [Pins]
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
    post:
      operationId: ohn41_pinRelease
      summary: Pin an active release for its resource type
      tags: [Pins]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Pin' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/pins/{id}/unpin:
    post:
      operationId: ohn41_unpin
      summary: Remove a pin
      tags: [Pins]
      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
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/partitions:
    get:
      operationId: ohn41_listPartitions
      summary: Partition of the caller organization
      tags: [Partitions]
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
    post:
      operationId: ohn41_createPartition
      summary: Create the organization partition
      tags: [Partitions]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Partition' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/partitions/{id}/suspend:
    post:
      operationId: ohn41_suspendPartition
      summary: Suspend writes to a partition
      tags: [Partitions]
      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
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/partitions/{id}/purge-expired:
    post:
      operationId: ohn41_purgeExpired
      summary: Delete superseded versions older than the partition retention period (current versions are kept)
      tags: [Partitions]
      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: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/resources:
    get:
      operationId: ohn41_listResources
      summary: Resource heads (metadata only)
      tags: [Resources]
      parameters:
        - name: resource_type
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: logical_id
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: cursor
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
    post:
      operationId: ohn41_writeResource
      summary: Create or update a resource (W002); invalid input is quarantined (W003)
      tags: [Resources]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ResourceWrite' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/resources/{id}/history:
    get:
      operationId: ohn41_resourceHistory
      summary: Version history metadata, no bodies
      tags: [Resources]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/resources/inspect:
    post:
      operationId: ohn41_inspectVersion
      summary: Read one version (F002); patient-linked bodies need an OHN-16 permit
      tags: [Resources]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Inspect' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/profile-packs:
    get:
      operationId: ohn41_getProfilePack
      summary: (v1.1, ADR-0005) Profile pack by reference - "package_id", "package_id|version" or the id of any active release in the pack
      tags: [Profiles]
      parameters:
        - { name: ref, in: query, required: true, schema: { type: string, maxLength: 600 } }
      responses:
        '200':
          description: All active releases of one package version in the caller's jurisdiction
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ProfilePack' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
  /api/ohn/v1/fhir/transactions:
    post:
      operationId: ohn41_commitTransaction
      summary: (v1.1, ADR-0005) Atomic multi-resource commit - every entry is stored or none is
      description: Each entry passes the full W002 pipeline inside one database transaction. Intra-bundle references to an entry full_url are resolved to Type/id. A refusal answers 422 with outcome rolled_back, the failing entry index and reason, and is not stored as an idempotent response so the same bundle can be retried after the cause is fixed. A dependency outage answers 503 and nothing is written.
      tags: [Resources]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Transaction' }
      responses:
        '201':
          description: Committed; one result per entry, in entry order
          content:
            application/json:
              schema: { $ref: '#/components/schemas/TransactionCommitted' }
        '422':
          description: Rolled back (outcome rolled_back) or request validation failed (error domain_validation_failed); nothing was stored
          content:
            application/json:
              schema: { oneOf: [{ $ref: '#/components/schemas/TransactionRolledBack' }, { $ref: '#/components/schemas/Error' }] }
        '400': { $ref: '#/components/responses/E400' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '409': { $ref: '#/components/responses/E409' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/resources/read:
    post:
      operationId: ohn41_readCurrent
      summary: (v1.1, ADR-0005) Read the current version of one resource; same checks as inspect
      tags: [Resources]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ReadCurrent' }
      responses:
        '200':
          description: Current version with freshness and an audit receipt
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '400': { $ref: '#/components/responses/E400' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '409': { $ref: '#/components/responses/E409' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/resources/compare:
    post:
      operationId: ohn41_compareVersions
      summary: Diff two versions
      tags: [Resources]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Compare' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/outcomes:
    get:
      operationId: ohn41_listOutcomes
      summary: Quarantine records
      tags: [Quarantine]
      parameters:
        - name: state
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: resource_type
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: cursor
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/outcomes/{id}:
    get:
      operationId: ohn41_getOutcome
      summary: Quarantine record with history and appeals
      tags: [Quarantine]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/outcomes/{id}/notify-source:
    post:
      operationId: ohn41_notifySource
      summary: quarantined -> source_notified
      tags: [Quarantine]
      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: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/outcomes/{id}/correct:
    post:
      operationId: ohn41_correctOutcome
      summary: Submitter supplies a corrected body
      tags: [Quarantine]
      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/Correction' }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/outcomes/{id}/revalidate:
    post:
      operationId: ohn41_revalidateOutcome
      summary: corrected -> revalidated (commits) or back to quarantined
      tags: [Quarantine]
      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: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/outcomes/{id}/discard:
    post:
      operationId: ohn41_discardOutcome
      summary: Close a quarantine record without storing
      tags: [Quarantine]
      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
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/appeals:
    get:
      operationId: ohn41_listAppeals
      summary: Validation failure appeals
      tags: [Quarantine]
      parameters:
        - name: state
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: cursor
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
    post:
      operationId: ohn41_createAppeal
      summary: Appeal a failed rule (F003)
      tags: [Quarantine]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Appeal' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/appeals/{id}/decide:
    post:
      operationId: ohn41_decideAppeal
      summary: Assigned reviewer upholds or overturns
      tags: [Quarantine]
      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: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/reports/{reportId}:
    get:
      operationId: ohn41_runReport
      summary: Run OHN-41-R001..R003
      tags: [Reports]
      parameters:
        - name: reportId
          in: path
          required: true
          schema: { type: string, enum: [OHN-41-R001, OHN-41-R002, OHN-41-R003] }
        - name: jurisdiction
          in: query
          required: false
          schema: { type: string, format: uuid }
        - name: country
          in: query
          required: false
          schema: { type: string, format: uuid }
        - name: source
          in: query
          required: false
          schema: { type: string, format: uuid }
        - 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: package
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: resource_type
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: review_state
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
        - name: cursor
          in: query
          required: false
          schema: { type: string, maxLength: 512 }
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Document' }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/reports/{reportId}/export:
    post:
      operationId: ohn41_exportReport
      summary: Create a signed, 5-minute, owner-only CSV or PDF export
      tags: [Reports]
      parameters:
        - name: reportId
          in: path
          required: true
          schema: { type: string, enum: [OHN-41-R001, OHN-41-R002, OHN-41-R003] }
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Export' }
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CommandResult' }
        '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/fhir/exports/{token}:
    get:
      operationId: ohn41_downloadExport
      summary: Download an export (audited)
      tags: [Reports]
      parameters:
        - name: token
          in: path
          required: true
          schema: { type: string, pattern: "^[A-Za-z0-9_-]{20,64}$" }
      responses:
        '200':
          description: Success
          content:
            text/csv: { schema: { type: string } }
            application/pdf: { schema: { type: string, format: binary } }
        '401': { $ref: '#/components/responses/E401' }
        '403': { $ref: '#/components/responses/E403' }
        '404': { $ref: '#/components/responses/E404' }
        '422': { $ref: '#/components/responses/E422' }
        '429': { $ref: '#/components/responses/E429' }
        '503': { $ref: '#/components/responses/E503' }
  /api/ohn/v1/fhir/synthetic/setup:
    post:
      operationId: ohn41_syntheticSetup
      summary: Configure the synthetic upstream fakes (synthetic mode only)
      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: { $ref: '#/components/schemas/CommandResult' }
        '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' }
    E422:
      description: Validation failure, domain refusal or quarantined resource
      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-41/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' }
        delivery: { type: string, enum: [committed, pending_downstream_confirmation] }
      additionalProperties: true
    CapabilityStatement:
      type: object
      required: [resourceType, status, kind, fhirVersion, rest]
      properties:
        resourceType: { const: CapabilityStatement }
        status: { const: active }
        kind: { const: instance }
        fhirVersion: { const: '4.0.1' }
        implementationGuide: { type: array, items: { type: string } }
        rest: { type: array, items: { type: object } }
    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: 1, maxLength: 2000 }
    Approve:
      type: object
      additionalProperties: false
      required: [expected_version]
      properties:
        expected_version: { type: integer, minimum: 1 }
        acknowledge_breaking_changes: { type: boolean, default: false }
    Rules:
      type: object
      additionalProperties: false
      properties:
        required: { type: array, maxItems: 50, items: { type: string, pattern: "^[a-z][A-Za-z0-9]*(\\.[a-z][A-Za-z0-9]*){0,5}$" } }
        fixed:
          type: array
          maxItems: 50
          items:
            type: object
            additionalProperties: false
            required: [path, values]
            properties: { path: { type: string, pattern: "^[a-z][A-Za-z0-9]*(\\.[a-z][A-Za-z0-9]*){0,5}$" }, values: { type: array, minItems: 1, items: { type: string, maxLength: 256 } } }
        bindings:
          type: array
          maxItems: 50
          items:
            type: object
            additionalProperties: false
            required: [path, system]
            properties: { path: { type: string, pattern: "^[a-z][A-Za-z0-9]*(\\.[a-z][A-Za-z0-9]*){0,5}$" }, system: { type: string, format: uri, maxLength: 2048 } }
    ReleaseCreate:
      type: object
      description: OHN-41-F001 FHIR profile release
      additionalProperties: false
      required: [profile_canonical, package_id, package_version, resource_type, country_scope, release_evidence, rules]
      properties:
        profile_canonical: { type: string, format: uri, maxLength: 2048, description: "http(s)://<base>/StructureDefinition/<name>" }
        package_id: { type: string, maxLength: 512, pattern: "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$" }
        package_version: { type: string, maxLength: 512, pattern: "^\\d+\\.\\d+\\.\\d+(-[A-Za-z0-9.]+)?$" }
        resource_type: { type: string, enum: [Patient, Observation, Condition, AllergyIntolerance, MedicationStatement, Immunization, Encounter, DiagnosticReport, Organization, Practitioner, Location] }
        country_scope: { type: string, minLength: 1, maxLength: 8192 }
        release_evidence: { type: string, format: uuid }
        rules: { $ref: '#/components/schemas/Rules' }
        dependencies:
          type: array
          maxItems: 20
          items: { type: object, additionalProperties: false, required: [package_id, version], properties: { package_id: { type: string, maxLength: 512, pattern: "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$" }, version: { type: string, maxLength: 512, pattern: "^\\d+\\.\\d+\\.\\d+(-[A-Za-z0-9.]+)?$" } } }
    Pin:
      type: object
      additionalProperties: false
      required: [release_id, reason]
      properties:
        release_id: { type: string, format: uuid }
        reason: { type: string, minLength: 1, maxLength: 2000 }
    Partition:
      type: object
      additionalProperties: false
      required: [name, resource_types, retention_days]
      properties:
        name: { type: string, minLength: 1, maxLength: 200 }
        resource_types: { type: array, minItems: 1, maxItems: 20, items: { type: string, enum: [Patient, Observation, Condition, AllergyIntolerance, MedicationStatement, Immunization, Encounter, DiagnosticReport, Organization, Practitioner, Location] } }
        retention_days: { type: integer, minimum: 1, maximum: 36500 }
    ResourceWrite:
      type: object
      additionalProperties: false
      required: [resource_type, logical_id, resource]
      properties:
        resource_type: { type: string, enum: [Patient, Observation, Condition, AllergyIntolerance, MedicationStatement, Immunization, Encounter, DiagnosticReport, Organization, Practitioner, Location] }
        logical_id: { type: string, pattern: "^[A-Za-z0-9.-]{1,64}$" }
        resource: { type: object, description: FHIR R4 JSON resource }
        patient_ref: { type: string, format: uuid, description: Required for patient-linked types }
        expected_version_id: { type: integer, minimum: 1, description: Omit to create; current version id to update }
    ProfilePack:
      type: object
      required: [api_version, ref, id, name, version, profiles]
      properties:
        api_version: { type: string, const: 1.1.0 }
        ref: { type: string }
        id: { type: string, description: 'package_id|version' }
        name: { type: string }
        version: { type: string }
        profiles:
          type: array
          items:
            type: object
            required: [resource_type, canonical, required, release_id]
            properties:
              resource_type: { type: string }
              canonical: { type: string, format: uri }
              required: { type: array, items: { type: string } }
              release_id: { type: string, format: uuid }
    Transaction:
      type: object
      additionalProperties: false
      required: [transaction_id, entries]
      properties:
        transaction_id: { type: string, pattern: '^[A-Za-z0-9._:-]{1,128}$' }
        patient_ref: { type: string, format: uuid, description: Required when any entry is patient-linked }
        entries:
          type: array
          minItems: 1
          maxItems: 100
          items:
            type: object
            additionalProperties: false
            required: [full_url, method, resource_type, resource]
            properties:
              full_url: { type: string, minLength: 1, maxLength: 2048 }
              method: { type: string, enum: [POST, PUT] }
              resource_type: { type: string, enum: [Patient, Observation, Condition, AllergyIntolerance, MedicationStatement, Immunization, Encounter, DiagnosticReport, Organization, Practitioner, Location] }
              logical_id: { type: string, pattern: '^[A-Za-z0-9.-]{1,64}$', description: PUT only; POST ids are assigned by the server }
              resource: { type: object }
    TransactionCommitted:
      type: object
      required: [api_version, outcome, transaction_id, results, receipt]
      properties:
        api_version: { type: string, const: 1.1.0 }
        outcome: { type: string, const: committed }
        transaction_id: { type: string }
        results:
          type: array
          items:
            type: object
            required: [full_url, status, location, resource_type, logical_id, version_id, etag, last_modified]
            properties:
              full_url: { type: string }
              status: { type: string, enum: ['201 Created', '200 OK'] }
              location: { type: string }
              resource_type: { type: string }
              logical_id: { type: string }
              version_id: { type: string }
              etag: { type: string }
              last_modified: { type: string, format: date-time }
              provenance_ref: { type: [string, 'null'] }
        receipt: { $ref: '#/components/schemas/Receipt' }
    TransactionRolledBack:
      type: object
      required: [api_version, outcome, transaction_id, failed_index, reason, issues, entries_committed, receipt]
      properties:
        api_version: { type: string, const: 1.1.0 }
        outcome: { type: string, const: rolled_back }
        transaction_id: { type: string }
        failed_index: { type: integer, minimum: 0 }
        reason: { type: string, description: 'A validator rule code, partition_not_configured, profile_not_pinned, policy_denied, patient_context_missing, resource_exists, stale_version, duplicate_full_url, put_requires_logical_id, post_must_not_name_logical_id or duplicate_resource_in_transaction' }
        issues: { type: array, items: { type: object } }
        entries_committed: { type: integer, const: 0 }
        receipt: { $ref: '#/components/schemas/Receipt' }
    ReadCurrent:
      type: object
      additionalProperties: false
      required: [resource_type, logical_id, jurisdiction_id, access_purpose]
      properties:
        resource_type: { type: string, enum: [Patient, Observation, Condition, AllergyIntolerance, MedicationStatement, Immunization, Encounter, DiagnosticReport, Organization, Practitioner, Location] }
        logical_id: { type: string, pattern: '^[A-Za-z0-9.-]{1,64}$' }
        jurisdiction_id: { type: string, format: uuid }
        access_purpose: { type: string, maxLength: 64 }
    Inspect:
      type: object
      description: OHN-41-F002 FHIR resource version inspection
      additionalProperties: false
      required: [resource_type, logical_id, version_id, jurisdiction_id, access_purpose]
      properties:
        resource_type: { type: string, enum: [Patient, Observation, Condition, AllergyIntolerance, MedicationStatement, Immunization, Encounter, DiagnosticReport, Organization, Practitioner, Location] }
        logical_id: { type: string, pattern: "^[A-Za-z0-9.-]{1,64}$" }
        jurisdiction_id: { type: string, format: uuid }
        access_purpose: { type: string, enum: [repository_administration, conformance_review, treatment, care_coordination, public_health] }
        version_id: { type: string, pattern: "^[1-9][0-9]{0,8}$" }
    Compare:
      type: object
      additionalProperties: false
      required: [resource_type, logical_id, from_version_id, to_version_id, jurisdiction_id, access_purpose]
      properties:
        resource_type: { type: string, enum: [Patient, Observation, Condition, AllergyIntolerance, MedicationStatement, Immunization, Encounter, DiagnosticReport, Organization, Practitioner, Location] }
        logical_id: { type: string, pattern: "^[A-Za-z0-9.-]{1,64}$" }
        jurisdiction_id: { type: string, format: uuid }
        access_purpose: { type: string, enum: [repository_administration, conformance_review, treatment, care_coordination, public_health] }
        from_version_id: { type: string, pattern: "^[1-9][0-9]{0,8}$" }
        to_version_id: { type: string, pattern: "^[1-9][0-9]{0,8}$" }
    Correction:
      type: object
      additionalProperties: false
      required: [expected_version, resource]
      properties:
        expected_version: { type: integer, minimum: 1 }
        resource: { type: object }
    Appeal:
      type: object
      description: OHN-41-F003 FHIR validation failure appeal
      additionalProperties: false
      required: [resource_ref, profile_ref, rule_code, source_evidence, reviewer]
      properties:
        resource_ref: { type: string, format: uuid, description: Quarantine record id }
        profile_ref: { type: string, format: uuid }
        rule_code: { type: string, maxLength: 128, pattern: "^[A-Za-z0-9._:/-]+$" }
        source_evidence: { type: string, format: uuid }
        reviewer: { type: string, format: uuid }
    AppealDecision:
      type: object
      additionalProperties: false
      required: [expected_version, decision, reason]
      properties:
        expected_version: { type: integer, minimum: 1 }
        decision: { type: string, enum: [upheld, overturned] }
        reason: { type: string, minLength: 1, maxLength: 2000 }
    Export:
      type: object
      additionalProperties: false
      required: [format]
      properties:
        format: { type: string, enum: [csv, pdf] }
        filters: { type: object, additionalProperties: { type: string, maxLength: 512 } }
    SyntheticToken:
      type: object
      additionalProperties: false
      required: [principal_id, role, jurisdiction, organization_id, purpose]
      properties:
        principal_id: { type: string, format: uuid }
        role: { type: string, enum: [fhir_administrator, conformance_reviewer, fhir_source_system, unauthorized_viewer] }
        jurisdiction: { type: string, format: uuid }
        organization_id: { type: string, format: uuid }
        purpose: { type: string, enum: [repository_administration, conformance_review, treatment, care_coordination, public_health] }
    SyntheticSetup:
      type: object
      additionalProperties: false
      properties:
        deny_patients: { type: array, items: { type: string, format: uuid } }
        unlicensed_systems: { type: array, items: { type: string, format: uri } }
        inactive_jurisdictions: { type: array, items: { type: string, format: uuid } }
        down: { type: array, items: { type: string, enum: [OHN-01, OHN-16, OHN-23, OHN-18] } }
        reset: { type: boolean }
