openapi: 3.1.0
info:
  title: OHN-58 Certificates, Medicines Supply and Payments
  version: 1.1.0
  description: |
    Synthetic data only. Reconciled with the observed TypeScript behaviour (see docs/program/java/ohn-58-contract-changes.md); served by the Java module `server/modules/ohn-58` in the portals deployable.

    Authentication: a gateway token (ES256, issuer `ohn-platform-gateway`, audience `ohn-58`) with the claims `sub`, `jurisdiction`, `organization_id` (all UUIDs), `role` and `purpose`. Each role has exactly one purpose
    (clinician `certification`, patient `patient_access`, pharmacist `medicine_supply`, ministry_officer `supply_oversight`, regulator `pharmacovigilance`, mutuelle_officer `mutuelle_administration`,
    payments_officer `payments`, services_admin `services_administration`, cashier `facility_payments`, distributor `medicine_distribution`). A bad token or claim is 401; a role used with another purpose is 403; an unknown route (after sign-in) is 404 `not_found`; a route the role
    is not listed for is 403 `denied_by_policy` (audited). The only unauthenticated routes are the health check and the employer's certificate check by code.

    Every write needs an `Idempotency-Key` header (1 to 255 characters; 400 `missing_idempotency_key`); the same key and body replays the first answer (`Idempotent-Replay: true`); the same key with another body is 409
    `idempotency_conflict`; a key still in flight is 409 `request_in_progress`. Request bodies are strict: an unknown field (for example a `diagnosis` on a certificate) is refused with 422 `domain_validation_failed`.

    Errors are `{error, message, ...}` (problem+json superset: `type`, `title`, `status`, `detail`, `trace_id`). Configuration is never invented: with no certificate limit, signing key, payer-hash key or dependency the operation
    is refused with 503 `not_configured` (names the `setting`; nothing is stored). There is no live payment provider: only the sandbox moves no money.

    1.1.0 (2026-11-23, owner decision on the #88 questions 4 and 5): role `cashier` (a facility's cashier) may list providers and create, list, read, check and complete
    (sandbox) payments of its own organisation only; a payment of another organisation is 404. It may not name a mutuelle member or take a `mutuelle_contribution`
    (403 `denied_by_policy`), and the mutuelle schemes, members, eligibility, provider balance, certificates and medicines routes are 403. Role `distributor` (a
    medicine distributor) has only the three `/medicines/distributor/...` routes: the batches whose `supplier_org_id` is its organisation, their recalls, and one
    acknowledgement per recall; every other route, including all patient routes, is 403. The registry import accepts the optional `supplier_org_id` per row.
servers: [{ url: https://opeshealthnetwork.com }]
security: [{ bearer: [] }]
components:
  securitySchemes:
    bearer: { type: http, scheme: bearer, bearerFormat: "JWT (ES256, iss ohn-platform-gateway, aud ohn-58)" }
  parameters:
    IdempotencyKey: { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 1, maxLength: 255 } }
    Id: { name: id, in: path, required: true, schema: { type: string, format: uuid } }
  responses:
    Invalid: { description: "422 domain_validation_failed: a strict body or query check failed. `details` maps each failing top-level field to a zod issue code (invalid_type, too_small, too_big, invalid_string, invalid_enum_value); unknown keys are reported under `_`.", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Denied: { description: "401 unauthenticated, or 403 denied_by_policy (role not listed or purpose not the role's)", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Unavailable: { description: "503 not_configured (names `setting`, and `dependency` for OHN-45 and OHN-23) or dependency_unavailable; nothing was stored", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
  schemas:
    Error:
      type: object
      required: [error, message]
      properties:
        error: { type: string, description: "machine code, for example not_found, denied_by_policy, domain_validation_failed, version_conflict, invalid_transition, validity_too_long, backdated_too_far, unknown_product, amount_mismatch, provider_unavailable, not_configured, dependency_unavailable, duplicate, rate_limited" }
        message: { type: string }
        setting: { type: string, description: "the configuration property that is missing (503 not_configured)" }
        dependency: { type: string, enum: [OHN-45, OHN-23] }
        current_version: { type: integer, description: "version_conflict" }
        code: { type: string, description: "unknown_product: the product code" }
        provider: { type: string, description: "provider_unavailable" }
        details: { type: object, additionalProperties: { type: string } }
        type: { type: string }
        title: { type: string }
        status: { type: integer }
        detail: { type: string }
        trace_id: { type: string }
    Day:
      type: string
      pattern: '^\d{4}-\d{2}-\d{2}$'
      description: "yyyy-MM-dd with month 01 to 12 and day 01 to 31. A day the calendar lacks (2030-02-31) passes the check and is then refused as 422 domain_validation_failed (an integrity failure); nothing is stored."
    IssueCertificate:
      oneOf:
        - type: object
          additionalProperties: false
          required: [kind, patient_id, outcome, valid_from, valid_to]
          properties: { kind: { const: fitness }, patient_id: { type: string, format: uuid }, outcome: { enum: [fit, not_fit] }, valid_from: { $ref: '#/components/schemas/Day' }, valid_to: { $ref: '#/components/schemas/Day' } }
        - type: object
          additionalProperties: false
          required: [kind, patient_id, valid_from, valid_to]
          properties: { kind: { const: sick_leave }, patient_id: { type: string, format: uuid }, valid_from: { $ref: '#/components/schemas/Day' }, valid_to: { $ref: '#/components/schemas/Day' } }
    RevokeCertificate:
      type: object
      additionalProperties: false
      required: [reason, expected_version]
      properties: { reason: { type: string, minLength: 10, maxLength: 500, description: trimmed }, expected_version: { type: integer, minimum: 1 } }
    Certificate:
      type: object
      properties:
        id: { type: string, format: uuid }
        kind: { enum: [fitness, sick_leave] }
        patient_id: { type: string, format: uuid }
        issued_by: { type: string, format: uuid }
        organization_id: { type: string, format: uuid }
        outcome: { enum: [fit, not_fit, null] }
        valid_from: { $ref: '#/components/schemas/Day' }
        valid_to: { $ref: '#/components/schemas/Day' }
        verify_code: { type: string, pattern: '^[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$' }
        status: { enum: [active, revoked] }
        standing: { enum: [valid, revoked, expired, not_yet_valid] }
        revoked_at: { type: [string, 'null'], format: date-time }
        revoke_reason: { type: [string, 'null'] }
        version: { type: integer }
        issued_at: { type: string, format: date-time }
        ohn45_artifact_ref: { type: string, format: uuid }
        ohn45_signature_ref: { type: string, format: uuid }
        verify_path: { type: string }
        receipt: { type: string, format: uuid, description: "issue and revoke answers only" }
    PublicVerification:
      type: object
      description: "Only these members. A certificate whose signature, stored columns or OHN-45 verification do not agree answers {code, result: invalid_signature, message} and no certificate data."
      additionalProperties: false
      properties:
        code: { type: string }
        result: { enum: [valid, revoked, expired, not_yet_valid, invalid_signature] }
        kind: { enum: [fitness, sick_leave] }
        answer: { enum: [fit, not_fit, unfit_for_work] }
        valid_from: { $ref: '#/components/schemas/Day' }
        valid_to: { $ref: '#/components/schemas/Day' }
        revoked_on: { oneOf: [{ $ref: '#/components/schemas/Day' }, { type: 'null' }] }
        signature: { const: verified_by_ohn45 }
        message: { type: string }
    PharmacyProfile:
      type: object
      additionalProperties: false
      required: [name, district, latitude, longitude, phone]
      properties:
        name: { type: string, minLength: 1, maxLength: 160 }
        district: { type: string, minLength: 1, maxLength: 120 }
        latitude: { type: [number, 'null'], minimum: -90, maximum: 90 }
        longitude: { type: [number, 'null'], minimum: -180, maximum: 180 }
        phone: { type: [string, 'null'], maxLength: 32 }
    StockReport:
      type: object
      additionalProperties: false
      required: [items]
      properties:
        items:
          type: array
          minItems: 1
          maxItems: 200
          items:
            type: object
            additionalProperties: false
            required: [code_system, code, quantity, unit]
            properties:
              code_system: { type: string, minLength: 1, maxLength: 200 }
              code: { type: string, minLength: 1, maxLength: 64 }
              quantity: { type: integer, minimum: 0, maximum: 10000000 }
              reorder_level: { type: integer, minimum: 0, maximum: 10000000, default: 0 }
              unit: { type: string, minLength: 1, maxLength: 32 }
    BatchRow:
      type: object
      additionalProperties: false
      required: [manufacturer, product_code, product_name, batch_number, expiry_date]
      properties:
        manufacturer: { type: string, minLength: 1, maxLength: 160 }
        product_code: { type: string, minLength: 1, maxLength: 64 }
        product_name: { type: string, minLength: 1, maxLength: 200 }
        batch_number: { type: string, minLength: 1, maxLength: 64 }
        expiry_date: { $ref: '#/components/schemas/Day' }
        status: { enum: [active, recalled], default: active }
        recall_reason: { type: [string, 'null'], maxLength: 500, description: "required (non-empty) when status is recalled" }
        serials: { type: array, maxItems: 5000, items: { type: string, minLength: 1, maxLength: 64 }, default: [] }
        supplier_org_id: { type: [string, 'null'], format: uuid, description: "the distributor organisation that supplied the batch; only it sees the batch and its recall on the distributor routes (1.1.0)" }
    RecallAcknowledgement:
      type: object
      additionalProperties: false
      properties:
        note: { type: string, minLength: 1, maxLength: 500 }
    BatchImport:
      type: object
      additionalProperties: false
      required: [source, rows]
      properties:
        source: { type: string, minLength: 1, maxLength: 200 }
        rows: { type: array, minItems: 1, maxItems: 2000, items: {}, description: "each element is validated against BatchRow on its own; a bad row is reported in `errors` (row number from 1, message in the form `field: Required`) and the others are imported" }
    Recall:
      type: object
      additionalProperties: false
      required: [reason]
      properties: { reason: { type: string, minLength: 10, maxLength: 500 } }
    Scan:
      type: object
      additionalProperties: false
      required: [product_code, batch_number]
      properties:
        product_code: { type: string, minLength: 1, maxLength: 64 }
        batch_number: { type: string, minLength: 1, maxLength: 64 }
        serial: { type: [string, 'null'], minLength: 1, maxLength: 64, default: null }
        note: { type: [string, 'null'], maxLength: 500, default: null }
    ScanResult:
      type: object
      properties:
        id: { type: string, format: uuid }
        result: { enum: [genuine, unknown, recalled, duplicate_scan, expired] }
        message: { type: string }
        product_code: { type: string }
        batch_number: { type: string }
        serial: { type: [string, 'null'] }
        product_name: { type: [string, 'null'] }
        manufacturer: { type: [string, 'null'] }
        expiry_date: { type: [string, 'null'] }
        recall_reason: { type: [string, 'null'] }
        previous_scans_here: { type: integer, description: "genuine and expired only" }
        regulator_report_id: { type: [string, 'null'], format: uuid }
        scanned_at: { type: string, format: date-time }
        receipt: { type: string, format: uuid }
    ReportTransition:
      type: object
      additionalProperties: false
      required: [to_state, expected_version]
      properties:
        to_state: { enum: [investigating, closed] }
        expected_version: { type: integer, minimum: 1 }
        outcome: { enum: [substantiated, unsubstantiated] }
        resolution: { type: string, minLength: 10, maxLength: 1000 }
      description: "closing needs an outcome and a resolution (422 otherwise); open -> investigating | closed, investigating -> closed, closed is final (409 invalid_transition)"
    Scheme:
      type: object
      additionalProperties: false
      required: [name, contribution_minor, currency, period_months, waiting_days]
      properties:
        name: { type: string, minLength: 1, maxLength: 160 }
        contribution_minor: { type: integer, minimum: 1, maximum: 1000000000, description: "whole minor units; the scheme's own configuration, never computed here" }
        currency: { type: string, pattern: '^[A-Z]{3}$' }
        period_months: { type: integer, minimum: 1, maximum: 24 }
        waiting_days: { type: integer, minimum: 0, maximum: 365 }
    Enrol:
      type: object
      additionalProperties: false
      required: [scheme_id, patient_id, enrolled_on]
      properties:
        scheme_id: { type: string, format: uuid }
        patient_id: { type: string, format: uuid }
        household_ref: { type: [string, 'null'], maxLength: 64, default: null }
        enrolled_on: { $ref: '#/components/schemas/Day' }
    Payment:
      type: object
      additionalProperties: false
      required: [provider, purpose, amount_minor, currency, payer_msisdn, reference]
      properties:
        provider: { type: string, minLength: 1, maxLength: 32, description: "sandbox, mtn_momo or orange_money; any other value is 422 unknown_provider" }
        purpose: { enum: [mutuelle_contribution, service_fee, medicine_purchase] }
        amount_minor: { type: integer, minimum: 1, maximum: 1000000000, description: "whole minor units; a contribution must equal the scheme's contribution_minor and currency exactly (422 amount_mismatch)" }
        currency: { type: string, pattern: '^[A-Z]{3}$' }
        payer_msisdn: { type: string, pattern: '^\+?[0-9]{8,15}$', description: "stored only as the last four digits and a keyed hash; never returned" }
        member_id: { type: [string, 'null'], format: uuid, default: null, description: "required for mutuelle_contribution" }
        reference: { type: string, minLength: 1, maxLength: 64 }
    SandboxCallback:
      type: object
      additionalProperties: false
      required: [expected_version]
      properties: { expected_version: { type: integer, minimum: 1 } }
    Eligibility:
      type: object
      properties:
        patient_id: { type: string, format: uuid }
        on: { $ref: '#/components/schemas/Day' }
        eligible: { type: boolean }
        memberships: { type: array, items: { type: object, properties: { member_id: { type: string }, scheme: { type: string }, scheme_org_id: { type: string }, enrolled_on: { $ref: '#/components/schemas/Day' }, waiting_ends: { $ref: '#/components/schemas/Day' }, paid_until: { type: [string, 'null'] }, eligible: { type: boolean }, reasons: { type: array, items: { enum: [membership_suspended, membership_ended, waiting_period, no_paid_contribution] } } } } }
        reasons: { type: array, items: { const: no_membership }, description: "present only when there is no membership" }
paths:
  /api/ohn/v1/payment-callbacks/{provider}/{paymentId}/{signature}:
    description: |
      Operator payment notification (MTN MoMo Collections callback, Orange Money notification). No gateway token: the path carries a per-payment HMAC-SHA256 signature under the
      callback secret (Orange webpay also matches the stored notif_token). The body is only a signal; the operator's own status call decides. See docs/program/java/ohn-58-mobile-money.md.
    parameters:
      - { name: provider, in: path, required: true, schema: { type: string, enum: [mtn_momo, orange_money] } }
      - { name: paymentId, in: path, required: true, schema: { type: string, format: uuid } }
      - { name: signature, in: path, required: true, schema: { type: string } }
    put: &cb
      operationId: paymentCallback
      security: []
      requestBody: { required: false, content: { application/json: { schema: { type: object } } } }
      responses:
        '200': { description: Already final; no change }
        '202': { description: Accepted; the operator could not be reached and reconciliation will decide }
        '400': { description: Malformed }
        '401': { description: Signature or notification token does not match }
        '404': { description: Unknown payment }
        '503': { description: Provider not configured }
    post: *cb
  /health/ohn-58:
    get:
      security: []
      summary: Health. Public. Database ping, dependency modes (live or unconfigured), whether the signing key, the certificate limits and the payer-hash key are configured, the providers and whether writes are enabled.
      responses:
        '200': { description: "{status: ok, module: OHN-58, dependencies: {OHN-45, OHN-23}, signing_key_configured, auth_configured, synthetic_auth (always false), certificate_policy_configured, payments_configured, payment_providers: [{id, sandbox, available}], writes_enabled}" }
        '503': { description: "{status: unavailable, ...} the database does not answer" }
  /api/ohn/v1/certificates/verify/{code}:
    get:
      security: []
      summary: Public verification by code (the employer's check). Case and separators are ignored. Rate-limited per client address (429). Fails closed (503) when OHN-45 cannot answer.
      parameters: [{ name: code, in: path, required: true, schema: { type: string } }]
      responses:
        '200': { description: result, content: { application/json: { schema: { $ref: '#/components/schemas/PublicVerification' } } } }
        '404': { description: unknown or malformed code }
        '429': { description: rate limited }
        '503': { description: OHN-45 unavailable or not configured }
  /api/ohn/v1/certificates/context:
    get:
      summary: Role, purpose, organisation, today, signing readiness and the configured limits (all roles). A limit that is not configured is null.
      responses:
        '200': { description: "{role, purpose, organization_id, today, signing_ready, policy: {fitness_max_days, sick_leave_max_days, fitness_max_backdate_days, sick_leave_max_backdate_days}}" }
        '401': { $ref: '#/components/responses/Denied' }
  /api/ohn/v1/certificates:
    post:
      summary: Issue (clinician). Signed with the Ed25519 key and registered with OHN-45 before it is stored. Contains no diagnosis.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/IssueCertificate' } } } }
      responses:
        '201': { description: issued, content: { application/json: { schema: { $ref: '#/components/schemas/Certificate' } } } }
        '403': { $ref: '#/components/responses/Denied' }
        '422': { description: "domain_validation_failed (bad input, end before start, or a day not on the calendar), validity_too_long, backdated_too_far", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
        '503': { $ref: '#/components/responses/Unavailable' }
    get:
      summary: List (clinician own organisation; patient own certificates), newest first, at most 200.
      parameters: [{ name: kind, in: query, schema: { enum: [fitness, sick_leave] } }, { name: status, in: query, schema: { enum: [active, revoked] } }]
      responses:
        '200': { description: '{items}' }
        '422': { $ref: '#/components/responses/Invalid' }
  /api/ohn/v1/certificates/{id}:
    get:
      summary: Read (clinician of the issuing organisation, the patient). Another organisation, patient or jurisdiction is 404.
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses: { '200': { description: ok, content: { application/json: { schema: { $ref: '#/components/schemas/Certificate' } } } }, '404': { description: not found or out of scope } }
  /api/ohn/v1/certificates/{id}/revoke:
    post:
      summary: Revoke (clinician of the issuing organisation), with optimistic concurrency.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/RevokeCertificate' } } } }
      responses: { '200': { description: revoked }, '404': { description: not found }, '409': { description: version_conflict (with current_version) or already_revoked }, '422': { $ref: '#/components/responses/Invalid' } }
  /api/ohn/v1/certificates/reports/summary:
    get:
      summary: "OHN-58-R01 certificates issued and verified (clinician: own organisation; services_admin: the jurisdiction)."
      responses: { '200': { description: "{id, title, certificates: [{kind, status, n}], verifications_30_days: [{result, n}], generated_at}" } }
  /api/ohn/v1/medicines/pharmacy:
    get: { summary: Own pharmacy profile (pharmacist), responses: { '200': { description: ok }, '404': { description: none yet } } }
    put:
      summary: Set own pharmacy profile (pharmacist).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/PharmacyProfile' } } } }
      responses: { '200': { description: saved }, '404': { description: the organisation belongs to another jurisdiction }, '422': { $ref: '#/components/responses/Invalid' } }
  /api/ohn/v1/medicines/stock:
    post:
      summary: Report stock (pharmacist). Every product is validated by OHN-23 before anything is saved.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/StockReport' } } } }
      responses: { '201': { description: "{items, new_stock_outs, receipt}" }, '404': { description: pharmacy profile missing }, '422': { description: "unknown_product (names `code`) or invalid", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }, '503': { $ref: '#/components/responses/Unavailable' } }
    get: { summary: "Own stock (pharmacist), with `level` (in_stock, low, out_of_stock)", responses: { '200': { description: ok } } }
  /api/ohn/v1/medicines/availability:
    get:
      summary: Search pharmacies (clinician, patient, pharmacist, ministry). Needs q (2 to 100 characters) or code. Patients get availability without quantity or unit.
      parameters:
        - { name: q, in: query, schema: { type: string, minLength: 2, maxLength: 100 } }
        - { name: code, in: query, schema: { type: string, maxLength: 64 } }
        - { name: code_system, in: query, schema: { type: string, maxLength: 200 } }
        - { name: district, in: query, schema: { type: string, maxLength: 120 } }
        - { name: lat, in: query, schema: { type: number, minimum: -90, maximum: 90 }, description: "needs lon" }
        - { name: lon, in: query, schema: { type: number, minimum: -180, maximum: 180 }, description: "needs lat" }
        - { name: radius_km, in: query, schema: { type: number, minimum: 1, maximum: 500, default: 25 } }
        - { name: include_out, in: query, schema: { enum: ['true', 'false'], default: 'false' } }
      responses: { '200': { description: "{items: [{id, pharmacy_id, pharmacy, district, phone, product, code_system, code, availability, quantity?, unit?, distance_km, reported_at, stale}]}, at most 100" }, '422': { $ref: '#/components/responses/Invalid' } }
  /api/ohn/v1/medicines/stock-outs:
    get: { summary: OHN-58-R02 (ministry_officer, services_admin), responses: { '200': { description: "{id, title, items, by_product, generated_at}" } } }
  /api/ohn/v1/medicines/stock-outs/export:
    get: { summary: OHN-58-R02 as CSV (formula-injection guarded; audited), responses: { '200': { description: "text/csv; charset=utf-8, attachment ohn58-stock-outs-yyyy-MM-dd.csv" } } }
  /api/ohn/v1/medicines/batches:
    get: { summary: Registry (regulator), parameters: [{ name: q, in: query, schema: { type: string, maxLength: 100 } }], responses: { '200': { description: ok }, '422': { $ref: '#/components/responses/Invalid' } } }
  /api/ohn/v1/medicines/batches/import:
    post:
      summary: Import registry rows (regulator); rows are validated one by one.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/BatchImport' } } } }
      responses: { '201': { description: '{import_id, rows_accepted, rows_rejected, errors: [{row, message}], receipt}' }, '422': { description: "invalid body, or a day the date check accepts but the calendar lacks (the whole import is refused and nothing is stored)" } }
  /api/ohn/v1/medicines/batches/{id}/recall:
    post:
      summary: Recall (regulator)
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Recall' } } } }
      responses: { '200': { description: recalled }, '404': { description: not found }, '409': { description: already_recalled } }
  /api/ohn/v1/medicines/distributor/batches:
    get: { summary: "Own supply list (distributor): batches whose supplier_org_id is the token organisation, with this distributor's acknowledgement. No patient, pharmacy or stock data.", responses: { '200': { description: "{items: [{id, manufacturer, product_code, product_name, batch_number, expiry_date, status, recall_reason, updated_at, acknowledged_at}]}" }, '403': { $ref: '#/components/responses/Denied' } } }
  /api/ohn/v1/medicines/distributor/recalls:
    get: { summary: "Recalls of batches this distributor supplied (distributor); never another supplier's", responses: { '200': { description: "{items: [... as distributor/batches, status recalled]}" }, '403': { $ref: '#/components/responses/Denied' } } }
  /api/ohn/v1/medicines/distributor/recalls/{id}/acknowledge:
    post:
      summary: Acknowledge a recall of a batch this distributor supplied (distributor; audited, event medicine.recall_acknowledged)
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: false, content: { application/json: { schema: { $ref: '#/components/schemas/RecallAcknowledgement' } } } }
      responses: { '201': { description: "{id, batch_id, acknowledged_at, receipt}" }, '403': { $ref: '#/components/responses/Denied' }, '404': { description: "not a recalled batch this distributor supplied (another supplier's, active or unknown)" }, '409': { description: already_acknowledged }, '422': { $ref: '#/components/responses/Invalid' } }
  /api/ohn/v1/medicines/authenticity/scans:
    post:
      summary: Check a pack (pharmacist, clinician). Unknown, recalled and duplicate_scan results open a regulator report.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Scan' } } } }
      responses: { '201': { description: result, content: { application/json: { schema: { $ref: '#/components/schemas/ScanResult' } } } } }
    get: { summary: Recent scans (own organisation; regulator all), at most 200, responses: { '200': { description: ok } } }
  /api/ohn/v1/medicines/regulator/reports:
    get: { summary: Regulator queue (regulator), parameters: [{ name: state, in: query, schema: { enum: [open, investigating, closed] } }], responses: { '200': { description: ok }, '422': { $ref: '#/components/responses/Invalid' } } }
  /api/ohn/v1/medicines/regulator/reports/{id}/transition:
    post:
      summary: Move a report along its workflow (regulator), with optimistic concurrency.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ReportTransition' } } } }
      responses: { '200': { description: "{id, state, outcome, resolution, version, receipt}" }, '404': { description: not found }, '409': { description: version_conflict or invalid_transition }, '422': { $ref: '#/components/responses/Invalid' } }
  /api/ohn/v1/payments/providers:
    get: { summary: "Providers and availability (payments_officer, mutuelle_officer, pharmacist, services_admin). Only the sandbox can be available.", responses: { '200': { description: "{items: [{id, label, sandbox, available, reason}]}" } } }
  /api/ohn/v1/payments/mutuelle/schemes:
    get: { summary: Own organisation's schemes (mutuelle_officer, payments_officer), responses: { '200': { description: ok } } }
    post:
      summary: Create a scheme (mutuelle_officer)
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Scheme' } } } }
      responses: { '201': { description: created }, '409': { description: duplicate (same name in the organisation) }, '422': { $ref: '#/components/responses/Invalid' } }
  /api/ohn/v1/payments/mutuelle/members:
    get: { summary: Members of own schemes (mutuelle_officer, payments_officer; never cashier), responses: { '200': { description: ok } } }
    post:
      summary: Enrol (mutuelle_officer)
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Enrol' } } } }
      responses: { '201': { description: enrolled }, '404': { description: scheme not found }, '409': { description: duplicate or scheme_inactive }, '422': { $ref: '#/components/responses/Invalid' } }
  /api/ohn/v1/payments/mutuelle/members/{patientId}/eligibility:
    get:
      summary: "Cover on a day (mutuelle_officer and payments_officer: own schemes; clinician: all schemes)"
      parameters: [{ name: patientId, in: path, required: true, schema: { type: string, format: uuid } }, { name: on, in: query, schema: { $ref: '#/components/schemas/Day' }, description: "default today (UTC); a day not on the calendar is 422" }]
      responses: { '200': { description: ok, content: { application/json: { schema: { $ref: '#/components/schemas/Eligibility' } } } }, '422': { $ref: '#/components/responses/Invalid' } }
  /api/ohn/v1/payments/mutuelle/me:
    get: { summary: "Patient's own cover today and contributions", responses: { '200': { description: "Eligibility plus {contributions: [{id, amount_minor, currency, period_start, period_end, created_at}]}" } } }
  /api/ohn/v1/payments:
    post:
      summary: Request a payment. Only the sandbox is available (records a simulated collection; no money moves). A live provider is 503 provider_unavailable.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Payment' } } } }
      responses: { '201': { description: pending }, '404': { description: member not found in your scheme }, '409': { description: member_not_active }, '422': { description: "invalid, unknown_provider or amount_mismatch", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }, '503': { description: "provider_unavailable (the sandbox is off in production; a live provider has no adapter) or not_configured (payer-hash key)" } }
    get: { summary: Own organisation's payments, parameters: [{ name: status, in: query, schema: { enum: [pending, succeeded, failed, cancelled] } }], responses: { '200': { description: ok }, '422': { $ref: '#/components/responses/Invalid' } } }
  /api/ohn/v1/payments/{id}:
    get: { summary: Read (own organisation), parameters: [{ $ref: '#/components/parameters/Id' }], responses: { '200': { description: ok }, '404': { description: not found } } }
  /api/ohn/v1/payments/{id}/sandbox/{outcome}:
    post:
      summary: Sandbox approve (complete) or decline (fail), with optimistic concurrency
      parameters: [{ $ref: '#/components/parameters/Id' }, { name: outcome, in: path, required: true, schema: { enum: [complete, fail] } }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/SandboxCallback' } } } }
      responses: { '200': { description: "the payment plus {contribution: {id, period_start, period_end} | null, receipt}" }, '404': { description: not found }, '409': { description: not_sandbox, version_conflict or invalid_transition }, '422': { $ref: '#/components/responses/Invalid' } }
  /api/ohn/v1/payments/audit:
    get: { summary: Audit trail of the jurisdiction (services_admin), newest first, at most 200, responses: { '200': { description: "{items: [{receipt_id, at, actor_role, action, resource_type, resource_id, decision, reason}]}" } } }
