openapi: 3.1.0
info:
  title: OHN-50 e-Prescribing and Dispensing
  version: 1.3.0
  description: |
    Bearer tokens issued by the platform gateway: ES256, iss ohn-platform-gateway, aud ohn-50; claims sub, role, jurisdiction, organization_id (uuids), purpose. The TypeScript baseline accepted HS256 tokens
    (iss ohn-50-erx, aud ohn-50-api) and had a synthetic POST .../auth/token route; the Java service has neither (see docs/program/java/ohn-50-contract-changes.md).
    Refusal order: 401 unauthenticated (no, invalid or expired token, unknown role, ids that are not uuids) -> 403 denied_by_policy (purpose not permitted for the role) -> 404 not_found (route outside the permission table) ->
    403 denied_by_policy (role not listed on the route; a denied write is audited) -> rate limit 429 -> kill switch 503 not_configured -> idempotency.
    Every write needs an Idempotency-Key header (1-255 characters, not blank; 400 missing_idempotency_key; a different body under the same key is 409 idempotency_conflict; a replay answers the first response with Idempotent-Replay: true).
    Bodies are application/json up to 128 kB (415 unsupported_media_type, 413 payload_too_large, 400 malformed_json) and strict: an unknown field is refused 422.
    Errors use { error, message, details?, guard?, receipt?, setting?, dependency? }; validation errors are 422 domain_validation_failed with details = { field: [messages] }.
    Who may prescribe what (owner decision 2026-11-23, contract 1.2.0): create, sign and an amendment of medication_code ask OHN-06 for the prescriber's profession.
    A physiotherapist or other allied health professional (OHN-06 profession physiotherapist | allied_health) never prescribes: 403 profession_not_permitted_to_prescribe.
    A dentist prescribes only a medication_code on the jurisdiction's dental formulary (POST /admin/dental-formulary): 403 outside_dental_formulary otherwise. The
    formulary is empty by default, so a dentist prescribes nothing until the jurisdiction loads its list (fail closed). Each refusal is audited (decision refused,
    reason = the guard) and nothing is stored. The OHN-06 good-standing check at signing is unchanged.
    503 not_configured / dependency_unavailable means nothing was recorded.
    Connected pharmacy systems (owner order 2026-11-29, contract 1.3.0, additive): role pharmacy_system, purpose dispensing, a platform service token from the
    external-token exchange (token_use service, client_id ohn-ext-..., organization_id = the pharmacy; any other token carrying the role is 401). It may read a
    prescription, look up by code, claim, release, dispense and record a FHIR MedicationDispense, nothing else. When it dispenses it names the accountable
    pharmacist (accountable_pharmacist_id), who must be registered and in good standing at that pharmacy in OHN-06 (422 pharmacist_not_in_good_standing).
    Dispensations carry recorded_via (staff | pharmacy_system), accountable_pharmacist_id, external_system / external_id (the MedicationDispense identifier)
    and handed_over_at. Prescriptions, their dispensations and medication-history items carry prescriber_display: the prescriber's registered name, resolved
    by OHN-50 from OHN-06 (null when it cannot be read; a label, never a decision).
servers: [{ url: https://opeshealthnetwork.com }]
security: [{ bearer: [] }]
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, maxLength: 255 } }
    AccessRequestId: { name: access_request_id, in: query, required: false, description: 'OHN-32 patient-approved access request id (pharmacist only). OHN-50 verifies it with OHN-32 (POST /clinician/patient-access/requests/{id}/use as the caller) and serves the read only for an active grant, purpose dispensing, sections incl. medications, for this patient at this facility. Otherwise 403 patient_access_grant_{invalid|not_permitted|not_found|other_facility|not_active|disabled|out_of_scope|other_patient} (audited); OHN-32 unavailable: 503. Each served read is audited per record with reason patient:<id>;grant:<grant id>.', schema: { type: string, format: uuid } }
  schemas:
    Error:
      type: object
      required: [error]
      properties: { error: { type: string }, message: { type: string }, details: { type: object }, guard: { type: string }, setting: { type: string }, dependency: { type: string }, receipt: { $ref: '#/components/schemas/Receipt' }, warnings: { type: array, items: { $ref: '#/components/schemas/Warning' } } }
    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, denied, refused] } }
    EventRef:
      type: object
      properties: { event_id: { type: string, format: uuid }, event_type: { type: string }, delivery: { const: pending_downstream_confirmation } }
    Warning:
      type: object
      properties: { warning_id: { type: string }, rule_id: { type: string }, kind: { type: string, description: 'local rules: interaction | allergy | duplicate_therapy; OHN-59: its check (allergy, interaction, dose, pregnancy, breastfeeding, duplicate_therapy, lab_contraindication) or not_checked' }, severity: { enum: [info, warning, serious, high, contraindicated] }, medication_code: { type: string }, other_code: { type: string }, message_en: { type: string }, message_fr: { type: string }, check: { type: string }, management_en: { type: [string, 'null'] }, management_fr: { type: [string, 'null'] }, other_display: { type: [string, 'null'] }, reason: { type: string } }
      description: >-
        OHN-59 warnings have warning_id ohn59:<OHN-59 warning id>; items OHN-59 could not check have kind not_checked and warning_id
        ohn59-not-checked:<check>:<rule>:<medication>. Optional fields from OHN-59: check, management_en, management_fr, other_display, reason.
    Override:
      type: object
      required: [warning_id, reason]
      additionalProperties: false
      properties: { warning_id: { type: string }, reason: { type: string, minLength: 10, maxLength: 2000 } }
    State: { enum: [draft, available, routed, claimed, partially_dispensed, completed, expired, cancelled] }
    Prescription:
      type: object
      properties:
        id: { type: string, format: uuid }
        jurisdiction_id: { type: string, format: uuid }
        prescriber_id: { type: string, format: uuid }
        prescriber_org: { type: string, format: uuid }
        prescriber_display: { type: [string, 'null'], description: '1.3.0: the prescriber''s registered name (OHN-06), resolved by OHN-50; also on each dispensation and medication-history item' }
        patient_id: { type: string, format: uuid }
        pickup_code: { type: string, pattern: '^[A-Z2-9]{8}$' }
        state: { $ref: '#/components/schemas/State' }
        routing: { enum: [any_pharmacy, nominated] }
        nominated_pharmacy_id: { type: [string, 'null'], format: uuid }
        claimed_by_pharmacy_id: { type: [string, 'null'], format: uuid }
        medication_system: { type: string }
        medication_code: { type: string }
        medication_display: { type: string }
        controlled_schedule: { type: [string, 'null'] }
        dose: { type: string }
        dose_unit: { type: string }
        route: { type: string }
        frequency: { type: string, description: 'Human-readable direction: free text, or the English label of frequency_code' }
        frequency_code: { oneOf: [{ $ref: '#/components/schemas/FrequencyCode' }, { type: 'null' }], description: null for free-text frequency }
        times_per_day: { type: [integer, 'null'], minimum: 1, maximum: 48, description: 'Computed by the server from frequency_code (every N hours = 24/N); null for free text, as_needed and once_weekly. Sent to OHN-59 as proposed[].frequency.times_per_day for the daily-dose check.' }
        duration_days: { type: integer }
        quantity: { type: integer }
        quantity_unit: { type: string }
        repeats_allowed: { type: integer }
        fills_completed: { type: integer }
        current_fill_dispensed: { type: integer }
        total_fills: { type: integer }
        remaining_in_fill: { type: integer }
        repeats_remaining: { type: integer }
        check_warnings: { type: array, items: { $ref: '#/components/schemas/Warning' }, description: omitted for patients }
        overrides: { type: array, description: omitted for patients }
        last_coverage: { type: [object, 'null'] }
        last_check: { oneOf: [{ $ref: '#/components/schemas/CheckRecord' }, { type: 'null' }], description: omitted for patients }
        safety_context: { $ref: '#/components/schemas/SafetyContext' }
        valid_until: { type: [string, 'null'], format: date-time }
        signed_at: { type: [string, 'null'], format: date-time }
        version: { type: integer }
        controlled: { type: boolean }
        is_expired: { type: boolean }
    CreatePrescription:
      type: object
      additionalProperties: false
      required: [patient_id, medication_code, dose, dose_unit, route, duration_days, quantity, quantity_unit, repeats, routing]
      description: >-
        Frequency: send frequency_code (structured; the server stores its English label as frequency and computes times_per_day) or
        frequency (free text; times_per_day stays null and OHN-59 reports the daily-dose check as not checked unless it can read the text).
        422 errors: unknown_frequency_code; times_per_day_mismatch (client times_per_day differs from the code's value);
        times_per_day_without_code; frequency_conflict (text that is not the code's EN/FR label); domain_validation_failed (neither sent).
      properties:
        patient_id: { type: string, format: uuid }
        medication_code: { type: string, pattern: '^[A-Za-z0-9._:/-]{1,128}$' }
        dose: { type: string, maxLength: 64 }
        dose_unit: { type: string, maxLength: 32 }
        route: { type: string, maxLength: 64 }
        frequency: { type: string, maxLength: 128, description: 'Free text; required when frequency_code is absent or null' }
        frequency_code: { oneOf: [{ $ref: '#/components/schemas/FrequencyCode' }, { type: 'null' }] }
        times_per_day: { type: [number, 'null'], description: 'Optional; only compared with the value computed from frequency_code (never trusted)' }
        duration_days: { type: integer, minimum: 1, maximum: 730 }
        quantity: { type: integer, minimum: 1 }
        quantity_unit: { type: string, maxLength: 32 }
        repeats: { type: integer, minimum: 0, maximum: 24 }
        notes: { type: string, maxLength: 2000 }
        routing: { enum: [any_pharmacy, nominated] }
        nominated_pharmacy_id: { type: string, format: uuid, description: required exactly when routing is nominated }
        known_allergy_codes: { type: array, items: { type: string }, maxItems: 50 }
        safety_context: { $ref: '#/components/schemas/SafetyContext' }
    FrequencyCode:
      enum: [1x_daily, 2x_daily, 3x_daily, 4x_daily, every_4h, every_6h, every_8h, every_12h, once_weekly, as_needed, once]
      description: >-
        Structured schedule (backend/modules/ohn-50/domain/frequency.ts). times_per_day: 1x_daily 1, 2x_daily 2, 3x_daily 3, 4x_daily 4,
        every_4h 6, every_6h 4, every_8h 3, every_12h 2, once 1 (single dose), as_needed null, once_weekly null (no daily averaging).
    SafetyContext:
      type: object
      additionalProperties: false
      description: Optional context forwarded to OHN-59 (medication_safety_source ohn59) so fewer checks are not checked. Stored on the prescription; amendable.
      properties:
        weight_kg: { type: number, exclusiveMinimum: 0, maximum: 500 }
        pregnancy_status: { enum: [pregnant, not_pregnant, unknown] }
        breastfeeding: { enum: ['yes', 'no', unknown] }
    CheckRecord:
      type: object
      description: Last medication safety check, kept on the prescription as last_check and returned as medication_safety by create, amend, sign and a refused sign.
      required: [source, checked_at, ruleset_version]
      properties:
        source: { enum: [local_rules, ohn59] }
        checked_at: { type: string, format: date-time }
        ruleset_version: { type: string, description: 'local: ohn50_settings.check_ruleset_version; ohn59: ohn59:v<knowledge version>' }
        evaluation_id: { type: string, format: uuid, description: OHN-59 evaluation (ohn59 only) }
        knowledge: { type: object, description: 'OHN-59 knowledge version: version_id, version, label, synthetic_demo, notice' }
        complete: { type: boolean }
        not_checked: { type: integer }
    Dispense:
      type: object
      additionalProperties: false
      required: [expected_version, quantity, identity_verification]
      properties:
        expected_version: { type: integer }
        quantity: { type: integer, minimum: 1 }
        identity_verification:
          type: object
          required: [method]
          properties: { method: { enum: [photo_id, pickup_code_and_birth_date, known_to_pharmacy, representative_with_id] }, pickup_code: { type: string }, birth_date: { type: string, format: date } }
        substitution: { type: object, required: [medication_code, reason], properties: { medication_code: { type: string }, reason: { type: string, minLength: 10 } } }
        counsel_note: { type: string, maxLength: 2000 }
        accountable_pharmacist_id: { type: string, format: uuid, description: '1.3.0: required when a pharmacy_system dispenses (the pharmacist accountable for the hand-over); refused for a pharmacist' }
    MedicationDispense:
      description: |
        1.3.0: FHIR R4 MedicationDispense from a connected pharmacy system. Read strictly (fail closed): status completed; identifier[0] {system (absolute URI), value}
        = the dispensation's id in the pharmacy system; authorizingPrescription = exactly one MedicationRequest/{prescription id}; subject = Patient/{the prescription's patient};
        medicationCodeableConcept.coding with the prescription's medication_system (another code than prescribed needs substitution.wasSubstituted = true and
        substitution.reason[0].text, 10-2000); quantity.value (integer 1-100000) with the prescription's quantity_unit as unit; whenHandedOver (dateTime with zone,
        not in the future); performer with a Practitioner/{id} actor = the accountable pharmacist; extension
        https://opeshealthnetwork.com/fhir/StructureDefinition/ohn-identity-verification with sub-extensions method (valueCode, as identity_verification.method),
        pickupCode (valueString), birthDate (valueDate); at most one note (counsel note). Any modifierExtension or element OHN-50 does not know is 422 fhir_invalid.
      type: object
      required: [resourceType, status, identifier, authorizingPrescription, subject, medicationCodeableConcept, quantity, whenHandedOver, performer, extension]
      properties:
        resourceType: { const: MedicationDispense }
        status: { const: completed }
  responses:
    Err: { description: Error, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    RxWrite:
      description: Committed
      content: { application/json: { schema: { type: object, properties: { prescription: { $ref: '#/components/schemas/Prescription' }, receipt: { $ref: '#/components/schemas/Receipt' }, events: { type: array, items: { $ref: '#/components/schemas/EventRef' } } } } } }
paths:
  /health/ohn-50:
    get: { security: [], summary: 'Health: status, module, dependencies (OHN-03, 05, 06, 15, 23, 24, 30, 32, 59: live | unconfigured | test_fake), writes_enabled, export_signing_configured, auth_configured, synthetic_auth (always false on Java)', responses: { '200': { description: ok }, '503': { description: database unavailable } } }
  /api/ohn/v1/prescriptions/health:
    get: { security: [], summary: 'Public liveness: status ok, service OHN-50, version 1.0.0', responses: { '200': { description: ok } } }
  /api/ohn/v1/prescriptions:
    post:
      summary: Create draft (prescriber). Validates OHN-03 patient, OHN-23 code, OHN-05 nominated pharmacy; returns configured check warnings.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/CreatePrescription' } } } }
      description: '403 profession_not_permitted_to_prescribe (physiotherapist, allied_health) or outside_dental_formulary (dentist, code not on the jurisdiction''s dental formulary; the formulary is empty by default).'
      responses: { '201': { description: Draft created with warnings }, '401': { $ref: '#/components/responses/Err' }, '403': { $ref: '#/components/responses/Err' }, '422': { $ref: '#/components/responses/Err' }, '503': { $ref: '#/components/responses/Err' } }
    get:
      summary: List in scope (prescriber own, patient own non-draft, admin jurisdiction)
      parameters: [{ name: state, in: query, schema: { $ref: '#/components/schemas/State' } }, { name: patient_id, in: query, schema: { type: string, format: uuid } }, { name: limit, in: query, schema: { type: integer } }, { name: offset, in: query, schema: { type: integer } }]
      responses: { '200': { description: '{ data: Prescription[] }' } }
  /api/ohn/v1/prescriptions/{id}:
    get: { summary: Detail with timeline, amendments, dispensations, allowed_actions, parameters: [{ $ref: '#/components/parameters/Id' }], responses: { '200': { description: detail }, '404': { $ref: '#/components/responses/Err' } } }
  /api/ohn/v1/prescriptions/{id}/sign:
    post:
      summary: >-
        Sign draft (OHN-06 standing; the checks run again; an override reason of at least 10 characters for every warning, including
        kind not_checked). With medication_safety_source ohn59, 503 not_configured (setting "OHN-59 active knowledge version") or
        503 dependency_unavailable (dependency OHN-59) when OHN-59 has no active version or does not answer; nothing is signed.
        After a sign the outcome is reported to OHN-59 (best effort).
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { content: { application/json: { schema: { type: object, required: [expected_version], properties: { expected_version: { type: integer }, overrides: { type: array, items: { $ref: '#/components/schemas/Override' } } } } } } }
      responses: { '200': { $ref: '#/components/responses/RxWrite' }, '403': { $ref: '#/components/responses/Err' }, '409': { $ref: '#/components/responses/Err' }, '422': { $ref: '#/components/responses/Err' }, '503': { $ref: '#/components/responses/Err' } }
  /api/ohn/v1/prescriptions/{id}/amend:
    post:
      summary: Amend with reason (unclaimed, nothing dispensed)
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      description: 'changes may include frequency_code (a code, or null together with frequency text), frequency (text alone switches to free text and clears frequency_code and times_per_day) and times_per_day (compared only). Same 422 errors as create.'
      requestBody: { content: { application/json: { schema: { type: object, required: [expected_version, reason, changes], properties: { expected_version: { type: integer }, reason: { type: string, minLength: 10 }, changes: { type: object }, overrides: { type: array, items: { $ref: '#/components/schemas/Override' } } } } } } }
      responses: { '200': { $ref: '#/components/responses/RxWrite' }, '409': { $ref: '#/components/responses/Err' }, '422': { $ref: '#/components/responses/Err' } }
  /api/ohn/v1/prescriptions/{id}/cancel:
    post:
      summary: Cancel with reason (prescriber own or erx_admin)
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { content: { application/json: { schema: { type: object, required: [expected_version, reason], properties: { expected_version: { type: integer }, reason: { type: string, minLength: 10 } } } } } }
      responses: { '200': { $ref: '#/components/responses/RxWrite' }, '409': { $ref: '#/components/responses/Err' } }
  /api/ohn/v1/prescriptions/frequency-codes:
    get:
      summary: Structured frequency vocabulary (code, times_per_day, label_en, label_fr, note); any OHN-50 role
      responses:
        '200': { description: 'data: [{ code, times_per_day, label_en, label_fr, note }], free_text_allowed: true' }
  /api/ohn/v1/prescriptions/medication-history/{patientId}:
    get: { summary: 'Medication-dispensed history (patient self; clinicians with OHN-15 consent when configured; 1.1.0: a pharmacist with an active OHN-32 patient-approved dispensing grant, see access_request_id)', parameters: [{ name: patientId, in: path, required: true, schema: { type: string, format: uuid } }, { $ref: '#/components/parameters/AccessRequestId' }], responses: { '200': { description: history }, '403': { $ref: '#/components/responses/Err' }, '404': { $ref: '#/components/responses/Err' } } }
  /api/ohn/v1/prescriptions/admin/config:
    get: { summary: 'Settings, rules, controlled codes, dental_formulary (codes a dentist may prescribe; empty by default), readiness and missing configuration', responses: { '200': { description: config } } }
  /api/ohn/v1/prescriptions/admin/settings:
    post: { summary: 'Create (expected_version 0) or update jurisdiction settings. Optional medication_safety_source (local_rules | ohn59; omitted keeps the stored value, default local_rules)', parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], responses: { '200': { description: saved }, '409': { $ref: '#/components/responses/Err' } } }
  /api/ohn/v1/prescriptions/admin/check-rules:
    post: { summary: Upsert configured check rule, parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], responses: { '201': { description: saved } } }
  /api/ohn/v1/prescriptions/admin/controlled-codes:
    post: { summary: Upsert/remove controlled medication code, parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], responses: { '201': { description: saved } } }
  /api/ohn/v1/prescriptions/admin/dental-formulary:
    post:
      summary: Load (active true, the default) or remove (active false) codes of the jurisdiction's dental formulary (erx_admin)
      description: >-
        The medicines a dentist may prescribe in this jurisdiction. OHN ships the list empty and invents no clinical list: the jurisdiction loads the list its
        regulator approved (runbook "Dental formulary"). One transaction; duplicates in the request count once; one audit record per code
        (config.dental_formulary.add | config.dental_formulary.remove, reason = the code) and one for the request (config.dental_formulary).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { type: object, additionalProperties: false, required: [medication_codes], properties: {
        medication_codes: { type: array, minItems: 1, maxItems: 500, items: { type: string, pattern: '^[A-Za-z0-9._:/-]{1,128}$' } }, active: { type: boolean, default: true } } } } } }
      responses: { '200': { description: '{ dental_formulary: { active, requested, changed, total }, receipt }' }, '403': { $ref: '#/components/responses/Err' }, '422': { $ref: '#/components/responses/Err' } }
  /api/ohn/v1/prescriptions/admin/expire-sweep:
    post: { summary: Expire open prescriptions past valid_until, parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], responses: { '200': { description: '{ examined, expired, receipt }' } } }
  /api/ohn/v1/prescriptions/admin/outbox/relay:
    post: { summary: Relay pending events to OHN-24, parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], responses: { '200': { description: '{ delivered, failed, pending_after, pending_total }' } } }
  /api/ohn/v1/prescriptions/reports:
    get: { summary: Report catalog, responses: { '200': { description: catalog } } }
  /api/ohn/v1/prescriptions/reports/{reportId}:
    get: { summary: Run R001/R002/R003 (from, to, pharmacy_id), parameters: [{ name: reportId, in: path, required: true, schema: { enum: [OHN-50-R001, OHN-50-R002, OHN-50-R003] } }], responses: { '200': { description: report } } }
  /api/ohn/v1/prescriptions/reports/{reportId}/export:
    get: { summary: Signed CSV (X-OHN50-Signature hmac-sha256=...), parameters: [{ name: reportId, in: path, required: true, schema: { type: string } }], responses: { '200': { description: CSV, content: { text/csv: {} } }, '503': { $ref: '#/components/responses/Err' } } }
  /api/ohn/v1/dispensing/queue:
    get: { summary: Pharmacy queue (claimed by us, nominated to us, open to any), responses: { '200': { description: '{ data, counts }' } } }
  /api/ohn/v1/dispensing/lookup:
    get: { summary: 'Lookup by code or patient_id (OHN-15 consent). 1.1.0: patient_id + access_request_id = the patient''s open prescriptions under an active OHN-32 dispensing grant (answer adds access and per item dispensing { allowed, reason }; items not dispensable here are read-only and carry the medicine only)', parameters: [{ name: code, in: query, schema: { type: string } }, { name: patient_id, in: query, schema: { type: string, format: uuid } }, { $ref: '#/components/parameters/AccessRequestId' }], responses: { '200': { description: matches }, '403': { $ref: '#/components/responses/Err' }, '404': { $ref: '#/components/responses/Err' } } }
  /api/ohn/v1/dispensing/history:
    get: { summary: Dispensations by the caller's pharmacy, parameters: [{ name: from, in: query, schema: { type: string, format: date } }, { name: to, in: query, schema: { type: string, format: date } }], responses: { '200': { description: history } } }
  /api/ohn/v1/dispensing/{id}/claim:
    post: { summary: Claim for the caller's pharmacy, parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }], responses: { '200': { $ref: '#/components/responses/RxWrite' }, '403': { $ref: '#/components/responses/Err' }, '409': { $ref: '#/components/responses/Err' } } }
  /api/ohn/v1/dispensing/{id}/release:
    post: { summary: Release claim with reason, parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }], responses: { '200': { $ref: '#/components/responses/RxWrite' }, '409': { $ref: '#/components/responses/Err' } } }
  /api/ohn/v1/dispensing/{id}/coverage-check:
    post: { summary: Advisory OHN-30 coverage check, parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }], responses: { '200': { description: '{ coverage, receipt }' }, '503': { $ref: '#/components/responses/Err' } } }
  /api/ohn/v1/dispensing/{id}/dispense:
    post:
      summary: Dispense (pharmacist, or 1.3.0 a pharmacy_system naming accountable_pharmacist_id)
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Dispense' } } } }
      responses: { '201': { description: '{ prescription, dispensation, label, coverage, receipt, events }' }, '409': { $ref: '#/components/responses/Err' }, '422': { $ref: '#/components/responses/Err' } }
  /api/ohn/v1/dispensing/fhir/MedicationDispense:
    post:
      summary: '1.3.0: a connected pharmacy system records a dispensation (FHIR R4 MedicationDispense; pharmacy_system only)'
      description: |
        Checked against the prescription (patient, product or declared substitution, unit), then recorded through the dispense action: the same dispensation row,
        history, audit record and events (medication.dispensed; prescription.completed when the last fill is done) as a pharmacist's. A prescription open to the
        pharmacy and not yet claimed is claimed first, and released again if the dispensation is refused. Idempotent on (pharmacy, identifier[0]): the same resource
        (the whole JSON body, compared key-sorted: sha256 of its canonical form, every element counts) again answers 200 with the stored one; any other body under the
        same identifier is 409 identifier_conflict. Refusals after the prescription is found are
        audited (action dx.fhir_dispense or dx.dispense). Errors use the Error shape, not OperationOutcome.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/fhir+json: { schema: { $ref: '#/components/schemas/MedicationDispense' } }, application/json: { schema: { $ref: '#/components/schemas/MedicationDispense' } } } }
      responses:
        '201': { description: The stored dispensation as a MedicationDispense (id = dispensation id), application/fhir+json }
        '200': { description: 'A resend of the same resource: the stored MedicationDispense' }
        '404': { $ref: '#/components/responses/Err' }
        '409': { $ref: '#/components/responses/Err' }
        '422': { $ref: '#/components/responses/Err' }
