openapi: 3.1.0
info:
  title: OHN-51 Claims and Pre-authorisation
  version: 1.0.1
  description: |
    Providers request pre-authorisation and submit claims; insurers review, adjudicate line by line, pay and decide appeals.
    Every write requires `Idempotency-Key` (same key + same body replays the first answer with `Idempotent-Replay: true`;
    same key + different body = 409 idempotency_conflict). Mutating commands carry `expected_version` (409 version_conflict).
    Authorisation: bearer token of the OHN gateway (Java service: ES256, iss `ohn-platform-gateway`, aud `ohn-51`; the TypeScript baseline: HS256, iss `ohn-51-claims`, aud `ohn-51-api`), claims sub, role, jurisdiction, organization_id, purpose (subject, jurisdiction and organization must be RFC-4122 uuids, else 401),
    default-deny route permission table, organisation scope (provider roles: own provider organisation; payer roles: claims addressed to them).
    Money is integer minor units of the payer's configured currency.
    Refusals: a route outside the permission table is 404 not_found; a purpose that is not the role's bound purpose or does not cover the action is 403 denied_by_policy; a role without the action is 403 forbidden.
    claims_oversight (network staff) is jurisdiction-wide, read-only, bound to purpose claims_oversight, sees no clinical or free-text content (`withheld`), and every read and refusal is audited before data is read.
    1.0.1: the TypeScript-only synthetic `POST /api/ohn/v1/claims/auth/token` is not served (tokens come from the gateway); a non-JSON content type is 415 unsupported_media_type; a JSON body that is not an object or array is 400 malformed_json.
servers:
  - url: https://opeshealthnetwork.com
security:
  - bearer: []
tags:
  - name: preauthorizations
  - name: claims
  - name: payer
  - name: reports
  - name: operations
paths:
  /health/ohn-51:
    get:
      tags: [operations]
      security: []
      operationId: health
      responses:
        '200': { description: Database reachable, content: { application/json: { schema: { $ref: '#/components/schemas/Health' } } } }
        '503': { description: Database unavailable, content: { application/json: { schema: { $ref: '#/components/schemas/Health' } } } }
  /api/ohn/v1/preauthorizations:
    post:
      tags: [preauthorizations]
      operationId: createPreauthorization
      description: provider_billing. Checks payer policy, active tariff, OHN-05 facility (published), OHN-03 patient, OHN-30 inquiry (eligible, same patient and payer), OHN-23 code, OHN-13 attachments (indexed).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/PreauthCreate' } } } }
      responses:
        '201': { description: Created, content: { application/json: { schema: { type: object, properties: { preauthorization: { $ref: '#/components/schemas/Preauthorization' }, receipt: { $ref: '#/components/schemas/Receipt' }, event: { $ref: '#/components/schemas/EventRef' } } } } } }
        '400': { $ref: '#/components/responses/Error' }
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
    get:
      tags: [preauthorizations]
      operationId: listPreauthorizations
      parameters: [{ name: state, in: query, schema: { $ref: '#/components/schemas/PreauthState' } }]
      responses:
        '200': { description: Latest 200 in scope, content: { application/json: { schema: { type: object, properties: { data: { type: array, items: { $ref: '#/components/schemas/Preauthorization' } } } } } } }
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/preauthorizations/{id}:
    get:
      tags: [preauthorizations]
      operationId: getPreauthorization
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses:
        '200': { description: Detail with decisions, history, appeals, units used/remaining, content: { application/json: { schema: { $ref: '#/components/schemas/PreauthorizationDetail' } } } }
        '404': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/preauthorizations/{id}/respond:
    post:
      tags: [preauthorizations]
      operationId: respondPreauthorization
      description: provider_billing; pended -> submitted.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [expected_version, provider_response], additionalProperties: false, properties: { expected_version: { type: integer }, provider_response: { type: string, minLength: 10, maxLength: 8000 }, attachment_refs: { $ref: '#/components/schemas/Attachments' } } } } } }
      responses: { '200': { $ref: '#/components/responses/PreauthCommand' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/preauthorizations/{id}/pend:
    post:
      tags: [preauthorizations]
      operationId: pendPreauthorization
      description: claims_adjudicator or medical_reviewer; submitted -> pended; reason code in category `pend`.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [expected_version, reason_code, info_request], additionalProperties: false, properties: { expected_version: { type: integer }, reason_code: { type: string }, info_request: { type: string, minLength: 10, maxLength: 4000 } } } } } }
      responses: { '200': { $ref: '#/components/responses/PreauthCommand' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' }, '503': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/preauthorizations/{id}/decision:
    post:
      tags: [preauthorizations]
      operationId: decidePreauthorization
      description: medical_reviewer only. approve = all requested units; partial = fewer units + preauth_partial reason; deny = preauth_deny reason. Validity <= preauth_max_validity_days.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/PreauthDecision' } } } }
      responses: { '200': { $ref: '#/components/responses/PreauthCommand' }, '403': { $ref: '#/components/responses/Error' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' }, '503': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/preauthorizations/{id}/appeal:
    post:
      tags: [preauthorizations]
      operationId: appealPreauthorization
      description: provider_billing; denied or partially_approved -> appealed; once; within appeal_window_days of the decision.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/AppealCreate' } } } }
      responses: { '201': { $ref: '#/components/responses/AppealCreated' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' }, '503': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims:
    post:
      tags: [claims]
      operationId: createClaim
      description: provider_billing; creates a draft. Nothing is checked against other services until submit.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ClaimCreate' } } } }
      responses: { '201': { $ref: '#/components/responses/ClaimCommand' }, '422': { $ref: '#/components/responses/Error' } }
    get:
      tags: [claims]
      operationId: listClaims
      description: Payer roles never see drafts.
      parameters: [{ name: state, in: query, schema: { $ref: '#/components/schemas/ClaimState' } }]
      responses: { '200': { description: Latest 200 in scope, content: { application/json: { schema: { type: object, properties: { data: { type: array, items: { $ref: '#/components/schemas/Claim' } } } } } } } }
  /api/ohn/v1/claims/{id}:
    get:
      tags: [claims]
      operationId: getClaim
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses: { '200': { description: Detail, content: { application/json: { schema: { $ref: '#/components/schemas/ClaimDetail' } } } }, '404': { $ref: '#/components/responses/Error' } }
    put:
      tags: [claims]
      operationId: updateClaimDraft
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ClaimLinesCommand' } } } }
      responses: { '200': { $ref: '#/components/responses/ClaimCommand' }, '409': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/{id}/submit:
    post:
      tags: [claims]
      operationId: submitClaim
      description: |
        draft -> submitted. Order: payer policy (currency, duplicate_window_days); exact duplicate (409 duplicate_claim, duplicate_of);
        per line tariff (422 tariff_not_configured), units_exceed_tariff, preauth_required / preauth_not_found / preauth_not_approved /
        preauth_code_mismatch / preauth_out_of_validity / preauth_units_exhausted; then OHN-05, OHN-03, OHN-30, OHN-23, OHN-13.
        Near duplicates are accepted and flagged duplicate_suspect_of.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/VersionOnly' } } } }
      responses: { '200': { $ref: '#/components/responses/ClaimCommand' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' }, '503': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/{id}/resubmit:
    post:
      tags: [claims]
      operationId: resubmitClaim
      description: provider_billing; denied -> resubmitted; returns the new corrected draft (replaces_claim_id).
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ClaimLinesCommand' } } } }
      responses: { '201': { $ref: '#/components/responses/ClaimCommand' }, '409': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/{id}/acknowledge:
    post:
      tags: [claims]
      operationId: acknowledgeClaim
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/VersionOnly' } } } }
      responses: { '200': { $ref: '#/components/responses/ClaimCommand' }, '409': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/{id}/adjudications:
    post:
      tags: [claims]
      operationId: adjudicateClaimLines
      description: acknowledged claims only. Lines billed >= medical_review_threshold_minor need medical_reviewer (403 medical_review_required). accept = ceiling min(billed, qty x tariff); adjust < ceiling with claim_line_adjust reason; deny with claim_line_deny reason.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/LineAdjudication' } } } }
      responses: { '200': { $ref: '#/components/responses/ClaimCommand' }, '403': { $ref: '#/components/responses/Error' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' }, '503': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/{id}/finalize:
    post:
      tags: [claims]
      operationId: finalizeClaim
      description: All lines decided -> adjudicated (allowed total) or denied (every line denied); else 422 lines_not_adjudicated.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/VersionOnly' } } } }
      responses: { '200': { $ref: '#/components/responses/ClaimCommand' }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/{id}/appeal:
    post:
      tags: [claims]
      operationId: appealClaim
      description: provider_billing; adjudicated, denied or paid -> appealed; once; within appeal_window_days of adjudication.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/AppealCreate' } } } }
      responses: { '201': { $ref: '#/components/responses/AppealCreated' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/appeals:
    get:
      tags: [claims]
      operationId: listAppeals
      parameters: [{ name: state, in: query, schema: { enum: [open, upheld, overturned] } }]
      responses: { '200': { description: Appeals in scope with their decision, content: { application/json: { schema: { type: object, properties: { data: { type: array, items: { $ref: '#/components/schemas/Appeal' } } } } } } } }
  /api/ohn/v1/claims/appeals/{id}/decision:
    post:
      tags: [claims]
      operationId: decideAppeal
      description: claims_adjudicator or medical_reviewer (pre-auth appeals medical_reviewer only); the filer may not decide; reason code category appeal. Overturning a pre-auth requires approved_units, valid_from, valid_to.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/AppealDecision' } } } }
      responses: { '200': { description: Decided, content: { application/json: { schema: { type: object, properties: { appeal: { $ref: '#/components/schemas/Appeal' }, receipt: { $ref: '#/components/schemas/Receipt' }, event: { $ref: '#/components/schemas/EventRef' } } } } } }, '403': { $ref: '#/components/responses/Error' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/config:
    get:
      tags: [payer]
      operationId: getPayerConfig
      description: Payer roles read their own organisation's configuration; provider_billing passes payer_org_id.
      parameters: [{ name: payer_org_id, in: query, schema: { type: string, format: uuid } }]
      responses: { '200': { description: Configuration, content: { application/json: { schema: { $ref: '#/components/schemas/PayerConfig' } } } }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/config/policy:
    put:
      tags: [payer]
      operationId: putPayerPolicy
      description: claims_admin; expected_version required when a policy exists.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/PayerPolicy' } } } }
      responses: { '200': { description: Saved }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/config/reason-codes:
    post:
      tags: [payer]
      operationId: upsertReasonCode
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ReasonCode' } } } }
      responses: { '201': { description: Upserted } }
  /api/ohn/v1/claims/config/tariffs:
    post:
      tags: [payer]
      operationId: upsertTariff
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Tariff' } } } }
      responses: { '201': { description: Upserted }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/payment-batches:
    get:
      tags: [payer]
      operationId: listPaymentBatches
      responses: { '200': { description: Batches of the payer } }
    post:
      tags: [payer]
      operationId: createPaymentBatch
      description: payer_finance; adjudicated claims of this payer, one currency, not in another open batch, outstanding amount > 0.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [claim_ids], additionalProperties: false, properties: { claim_ids: { type: array, minItems: 1, maxItems: 500, items: { type: string, format: uuid } } } } } } }
      responses: { '201': { description: Created }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/payment-batches/{id}:
    get:
      tags: [payer]
      operationId: getPaymentBatch
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses: { '200': { description: Batch with items }, '404': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/payment-batches/{id}/release:
    post:
      tags: [payer]
      operationId: releasePaymentBatch
      description: payer_finance other than the batch creator (403 separation_of_duties). Writes remittances, marks claims paid, emits claims.claim.paid.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [expected_version, payment_reference], additionalProperties: false, properties: { expected_version: { type: integer }, payment_reference: { type: string, minLength: 3, maxLength: 128 } } } } } }
      responses: { '200': { description: Released }, '403': { $ref: '#/components/responses/Error' }, '409': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/remittances:
    get:
      tags: [payer]
      operationId: listRemittances
      description: provider_billing sees remittances to its organisation; payer roles see what they paid.
      responses: { '200': { description: Remittances with line breakdown, content: { application/json: { schema: { type: object, properties: { data: { type: array, items: { $ref: '#/components/schemas/Remittance' } } } } } } } }
  /api/ohn/v1/claims/reports/{reportId}:
    get:
      tags: [reports]
      operationId: runReport
      parameters: [{ $ref: '#/components/parameters/ReportId' }, { name: from, in: query, schema: { type: string, format: date } }, { name: to, in: query, schema: { type: string, format: date } }]
      responses: { '200': { description: Rows, content: { application/json: { schema: { $ref: '#/components/schemas/Report' } } } }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/claims/reports/{reportId}/export:
    get:
      tags: [reports]
      operationId: exportReport
      parameters: [{ $ref: '#/components/parameters/ReportId' }, { name: from, in: query, schema: { type: string, format: date } }, { name: to, in: query, schema: { type: string, format: date } }]
      responses:
        '200':
          description: CSV; X-OHN51-Signature = sha256=HMAC-SHA256(OHN51_EXPORT_SIGNING_KEY, body)
          headers: { X-OHN51-Signature: { schema: { type: string } }, X-OHN51-Signed-At: { schema: { type: string, format: date-time } } }
          content: { text/csv: { schema: { type: string } } }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/claims/maintenance/relay-outbox:
    post:
      tags: [operations]
      operationId: relayOutbox
      description: claims_admin; delivers pending outbox rows of the caller's jurisdiction to OHN-24.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      responses: { '200': { description: Result, content: { application/json: { schema: { type: object, properties: { delivered: { type: integer }, failed: { type: integer }, pending_after: { type: integer } } } } } } }
components:
  securitySchemes:
    bearer: { type: http, scheme: bearer, bearerFormat: JWT }
  parameters:
    Id: { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    IdempotencyKey: { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 1, maxLength: 255 } }
    ReportId: { name: reportId, in: path, required: true, schema: { enum: [OHN-51-R001, OHN-51-R002, OHN-51-R003] } }
  responses:
    Error: { description: Error, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    PreauthCommand: { description: Committed, content: { application/json: { schema: { type: object, properties: { preauthorization: { $ref: '#/components/schemas/PreauthorizationDetail' }, receipt: { $ref: '#/components/schemas/Receipt' }, event: { $ref: '#/components/schemas/EventRef' } } } } } }
    ClaimCommand: { description: Committed, content: { application/json: { schema: { type: object, properties: { claim: { $ref: '#/components/schemas/ClaimDetail' }, receipt: { $ref: '#/components/schemas/Receipt' }, event: { $ref: '#/components/schemas/EventRef' } } } } } }
    AppealCreated: { description: Filed, content: { application/json: { schema: { type: object, properties: { appeal: { $ref: '#/components/schemas/Appeal' }, receipt: { $ref: '#/components/schemas/Receipt' }, event: { $ref: '#/components/schemas/EventRef' } } } } } }
  schemas:
    Error:
      type: object
      required: [error]
      properties:
        error: { type: string, description: 'unauthenticated, forbidden, denied_by_policy, not_found, missing_idempotency_key, idempotency_conflict, version_conflict, invalid_transition, duplicate_claim, domain_validation_failed, not_configured, dependency_unavailable, rate_limited, and the named rule codes' }
        message: { type: string }
        details: { type: object, additionalProperties: { type: array, items: { type: string } } }
        setting: { type: string }
        dependency: { enum: [OHN-03, OHN-05, OHN-13, OHN-23, OHN-24, OHN-30] }
        configured: { type: boolean }
        duplicate_of: { type: string, format: uuid }
        line_no: { type: integer }
    Health:
      type: object
      properties:
        status: { enum: [ok, unavailable] }
        module: { const: OHN-51 }
        database: { enum: [ok, unavailable] }
        dependencies: { type: object, additionalProperties: { enum: [live, unconfigured, test_fake, test_failing] } }
        writes_enabled: { type: boolean }
        export_signing_configured: { type: boolean }
        synthetic_auth: { type: boolean }
        jwt_configured: { type: boolean }
    Role: { enum: [provider_billing, claims_adjudicator, medical_reviewer, payer_finance, claims_admin, claims_oversight] }
    PreauthState: { enum: [submitted, pended, approved, partially_approved, denied, appealed, final] }
    ClaimState: { enum: [draft, submitted, acknowledged, adjudicated, denied, paid, appealed, resubmitted, final] }
    Attachments: { type: array, maxItems: 20, items: { type: string, format: uuid }, description: OHN-13 document ids (must be indexed) }
    Receipt: { type: object, properties: { receipt_id: { type: string, format: uuid }, committed_at: { type: string, format: date-time }, aggregate_id: { type: [string, 'null'] }, aggregate_type: { type: string }, version: { type: integer }, status: { enum: [committed, refused] } } }
    EventRef: { type: object, properties: { event_id: { type: string, format: uuid }, event_type: { type: string }, delivery: { const: pending_downstream_confirmation } } }
    VersionOnly: { type: object, required: [expected_version], additionalProperties: false, properties: { expected_version: { type: integer, minimum: 1 } } }
    PreauthCreate:
      type: object
      additionalProperties: false
      required: [payer_org_id, facility_id, patient_ref, eligibility_inquiry_ref, code_system, service_code, requested_units, clinical_justification]
      properties:
        payer_org_id: { type: string, format: uuid }
        facility_id: { type: string, format: uuid }
        patient_ref: { type: string, format: uuid }
        eligibility_inquiry_ref: { type: string, format: uuid }
        code_system: { type: string, maxLength: 512 }
        service_code: { type: string, pattern: '^[A-Za-z0-9._:/-]+$', maxLength: 128 }
        requested_units: { type: integer, minimum: 1, maximum: 10000 }
        requested_amount_minor: { type: integer, minimum: 0 }
        clinical_justification: { type: string, minLength: 20, maxLength: 8000 }
        attachment_refs: { $ref: '#/components/schemas/Attachments' }
    PreauthDecision:
      type: object
      additionalProperties: false
      required: [expected_version, decision, note]
      properties:
        expected_version: { type: integer }
        decision: { enum: [approve, partial, deny] }
        reason_code: { type: string }
        note: { type: string, minLength: 10, maxLength: 4000 }
        approved_units: { type: integer, minimum: 1 }
        approved_amount_minor: { type: integer, minimum: 0 }
        valid_from: { type: string, format: date }
        valid_to: { type: string, format: date }
    Preauthorization:
      type: object
      properties:
        id: { type: string, format: uuid }
        reference_number: { type: string }
        provider_org_id: { type: string, format: uuid }
        payer_org_id: { type: string, format: uuid }
        facility_id: { type: string, format: uuid }
        patient_ref: { type: string, format: uuid }
        eligibility_inquiry_ref: { type: string, format: uuid }
        eligibility_outcome: { type: string }
        code_system: { type: string }
        service_code: { type: string }
        service_display: { type: [string, 'null'] }
        requested_units: { type: integer }
        requested_amount_minor: { type: [integer, 'null'] }
        clinical_justification: { type: string }
        attachment_refs: { $ref: '#/components/schemas/Attachments' }
        state: { $ref: '#/components/schemas/PreauthState' }
        pend_reason_code: { type: [string, 'null'] }
        info_request: { type: [string, 'null'] }
        provider_response: { type: [string, 'null'] }
        approved_units: { type: [integer, 'null'] }
        approved_amount_minor: { type: [integer, 'null'] }
        valid_from: { type: [string, 'null'], format: date }
        valid_to: { type: [string, 'null'], format: date }
        decision_reason_code: { type: [string, 'null'] }
        final_outcome: { type: [string, 'null'] }
        appeal_count: { type: integer }
        version: { type: integer }
        next_actions: { type: array, items: { type: string }, description: Transitions the caller's role may take now }
    PreauthorizationDetail:
      allOf:
        - $ref: '#/components/schemas/Preauthorization'
        - type: object
          properties:
            units_used: { type: integer }
            units_remaining: { type: [integer, 'null'] }
            decisions: { type: array, items: { type: object } }
            history: { type: array, items: { $ref: '#/components/schemas/HistoryEntry' } }
            appeals: { type: array, items: { $ref: '#/components/schemas/Appeal' } }
    ClaimLineInput:
      type: object
      additionalProperties: false
      required: [code_system, service_code, quantity, unit_price_minor]
      properties:
        code_system: { type: string }
        service_code: { type: string, pattern: '^[A-Za-z0-9._:/-]+$' }
        quantity: { type: integer, minimum: 1, maximum: 10000 }
        unit_price_minor: { type: integer, minimum: 0 }
        preauth_id: { type: string, format: uuid }
    ClaimCreate:
      type: object
      additionalProperties: false
      required: [payer_org_id, facility_id, patient_ref, encounter_ref, eligibility_inquiry_ref, service_date, lines]
      properties:
        payer_org_id: { type: string, format: uuid }
        facility_id: { type: string, format: uuid }
        patient_ref: { type: string, format: uuid }
        encounter_ref: { type: string, format: uuid }
        eligibility_inquiry_ref: { type: string, format: uuid }
        service_date: { type: string, format: date }
        lines: { type: array, minItems: 1, maxItems: 99, items: { $ref: '#/components/schemas/ClaimLineInput' } }
        attachment_refs: { $ref: '#/components/schemas/Attachments' }
    ClaimLinesCommand:
      type: object
      additionalProperties: false
      required: [expected_version, lines]
      properties:
        expected_version: { type: integer }
        lines: { type: array, minItems: 1, maxItems: 99, items: { $ref: '#/components/schemas/ClaimLineInput' } }
        attachment_refs: { $ref: '#/components/schemas/Attachments' }
    LineAdjudication:
      type: object
      additionalProperties: false
      required: [expected_version, decisions]
      properties:
        expected_version: { type: integer }
        decisions:
          type: array
          minItems: 1
          items:
            type: object
            additionalProperties: false
            required: [line_id, decision]
            properties:
              line_id: { type: string, format: uuid }
              decision: { enum: [accept, adjust, deny] }
              allowed_amount_minor: { type: integer, minimum: 0 }
              reason_code: { type: string }
              note: { type: string, maxLength: 2000 }
    Claim:
      type: object
      properties:
        id: { type: string, format: uuid }
        claim_number: { type: string }
        provider_org_id: { type: string, format: uuid }
        payer_org_id: { type: string, format: uuid }
        facility_id: { type: string, format: uuid }
        patient_ref: { type: string, format: uuid }
        encounter_ref: { type: string, format: uuid }
        eligibility_inquiry_ref: { type: string, format: uuid }
        eligibility_outcome: { type: [string, 'null'] }
        service_date: { type: string, format: date }
        currency: { type: [string, 'null'] }
        billed_total_minor: { type: integer }
        allowed_total_minor: { type: [integer, 'null'] }
        paid_total_minor: { type: integer }
        state: { $ref: '#/components/schemas/ClaimState' }
        duplicate_suspect_of: { type: [string, 'null'], format: uuid }
        replaces_claim_id: { type: [string, 'null'], format: uuid }
        replaced_by_claim_id: { type: [string, 'null'], format: uuid }
        adjudication_round: { type: integer }
        submitted_at: { type: [string, 'null'], format: date-time }
        acknowledged_at: { type: [string, 'null'], format: date-time }
        adjudicated_at: { type: [string, 'null'], format: date-time }
        paid_at: { type: [string, 'null'], format: date-time }
        appeal_count: { type: integer }
        version: { type: integer }
        next_actions: { type: array, items: { type: string } }
    ClaimDetail:
      allOf:
        - $ref: '#/components/schemas/Claim'
        - type: object
          properties:
            lines: { type: array, items: { type: object, properties: { id: { type: string }, line_no: { type: integer }, code_system: { type: string }, service_code: { type: string }, service_display: { type: [string, 'null'] }, quantity: { type: integer }, unit_price_minor: { type: integer }, billed_amount_minor: { type: integer }, preauth_id: { type: [string, 'null'] }, decision: { type: [string, 'null'] }, allowed_amount_minor: { type: [integer, 'null'] }, reason_code: { type: [string, 'null'] }, requires_medical_review: { type: [boolean, 'null'] } } } }
            adjudications: { type: array, items: { type: object } }
            timeline: { type: array, items: { $ref: '#/components/schemas/HistoryEntry' } }
            appeals: { type: array, items: { $ref: '#/components/schemas/Appeal' } }
            remittances: { type: array, items: { $ref: '#/components/schemas/Remittance' } }
            medical_review_threshold_minor: { type: [integer, 'null'] }
    HistoryEntry: { type: object, properties: { id: { type: string }, from_state: { type: [string, 'null'] }, to_state: { type: string }, action: { type: string }, version: { type: integer }, actor_role: { type: string }, reason: { type: [string, 'null'] }, created_at: { type: string, format: date-time } } }
    AppealCreate: { type: object, additionalProperties: false, required: [expected_version, reason], properties: { expected_version: { type: integer }, reason: { type: string, minLength: 20, maxLength: 8000 }, attachment_refs: { $ref: '#/components/schemas/Attachments' } } }
    AppealDecision: { type: object, additionalProperties: false, required: [expected_version, outcome, reason_code, note], properties: { expected_version: { type: integer }, outcome: { enum: [upheld, overturned] }, reason_code: { type: string }, note: { type: string, minLength: 10 }, approved_units: { type: integer }, approved_amount_minor: { type: integer }, valid_from: { type: string, format: date }, valid_to: { type: string, format: date } } }
    Appeal: { type: object, properties: { id: { type: string }, subject_type: { enum: [claim, preauth] }, subject_id: { type: string }, provider_org_id: { type: string }, payer_org_id: { type: string }, prior_state: { type: string }, reason: { type: string }, attachment_refs: { $ref: '#/components/schemas/Attachments' }, state: { enum: [open, upheld, overturned] }, version: { type: integer }, decision: { type: [object, 'null'] } } }
    PayerPolicy:
      type: object
      additionalProperties: false
      required: [currency, medical_review_threshold_minor, duplicate_window_days, appeal_window_days, preauth_max_validity_days]
      properties:
        currency: { type: string, pattern: '^[A-Z]{3}$' }
        medical_review_threshold_minor: { type: [integer, 'null'] }
        duplicate_window_days: { type: [integer, 'null'], minimum: 1 }
        appeal_window_days: { type: [integer, 'null'], minimum: 1 }
        preauth_max_validity_days: { type: [integer, 'null'], minimum: 1 }
        expected_version: { type: integer }
    ReasonCode: { type: object, additionalProperties: false, required: [category, code, label_en, label_fr], properties: { category: { enum: [claim_line_adjust, claim_line_deny, preauth_partial, preauth_deny, pend, appeal] }, code: { type: string, pattern: '^[A-Za-z0-9._-]{1,64}$' }, label_en: { type: string }, label_fr: { type: string }, active: { type: boolean, default: true } } }
    Tariff: { type: object, additionalProperties: false, required: [code_system, service_code, unit_price_minor, requires_preauth, max_units_per_line, effective_from, effective_to], properties: { code_system: { type: string }, service_code: { type: string }, unit_price_minor: { type: integer, minimum: 0 }, requires_preauth: { type: boolean }, max_units_per_line: { type: [integer, 'null'] }, effective_from: { type: string, format: date }, effective_to: { type: [string, 'null'], format: date }, active: { type: boolean, default: true } } }
    PayerConfig: { type: object, properties: { payer_org_id: { type: string }, configured: { type: boolean }, policy: { oneOf: [{ $ref: '#/components/schemas/PayerPolicy' }, { type: 'null' }] }, reason_codes: { type: array, items: { $ref: '#/components/schemas/ReasonCode' } }, tariffs: { type: array, items: { $ref: '#/components/schemas/Tariff' } } } }
    Remittance: { type: object, properties: { id: { type: string }, batch_id: { type: string }, claim_id: { type: string }, claim_number: { type: string }, provider_org_id: { type: string }, payer_org_id: { type: string }, amount_minor: { type: integer }, currency: { type: string }, payment_reference: { type: string }, lines: { type: array, items: { type: object } }, created_at: { type: string, format: date-time } } }
    Report: { type: object, properties: { report_id: { type: string }, title: { type: string }, columns: { type: array, items: { type: string } }, rows: { type: array, items: { type: object } }, period: { type: object, properties: { from: { type: string, format: date }, to: { type: string, format: date } } }, generated_at: { type: string, format: date-time } } }
