Skip to main content

Afiax FHIR and Afiax Billing Contract

This page defines the live integration contract between Afiax FHIR and Afiax Billing.

Use it to implement billing adapters, reconciliation workers, bot-driven handoff, and ERP-facing event handlers without turning Afiax Billing into a second clinical record.

Contract model

The integration exposes four contract surfaces:

  1. outbound billing events from Afiax FHIR to Afiax Billing
  2. inbound financial events from Afiax Billing to Afiax FHIR
  3. pharmacy operational events between prescription and stock workflows
  4. shared identifiers and reconciliation metadata

The contract remains event-driven and API-backed.

Afiax FHIR publishes canonical clinical and reimbursement state.

Afiax Billing publishes financial and operational state.

Contract status in this repo

Today, this repo provides:

  • the documentation contract
  • Kenya claim submit and claim-status bot handoff points
  • the clinical and reimbursement ledger where normalized financial outcomes will be recorded

This repo does not yet provide:

  • direct ERPNext document creation
  • inbound Afiax Billing event consumers
  • finance reconciliation workers

That means these contract docs are the implementation target for external integration services, not proof that the ERP integration is already running in this repo.

Producer and consumer rule

Afiax FHIR as producer

Afiax FHIR is the producer when the event starts from:

  • clinical billable state
  • coverage context
  • claim submission
  • claim adjudication
  • invoice-ready clinical workflow state

Afiax Billing as producer

Afiax Billing is the producer when the event starts from:

  • invoice posting
  • payment posting
  • partial settlement
  • write-off or adjustment
  • pharmacy operational completion

Afiax FHIR as consumer

Afiax FHIR consumes only the normalized outcome needed for:

  • claim-financial visibility
  • patient-liability visibility
  • pharmacy dispense write-back
  • audit and reconciliation linkage

Outbound events from Afiax FHIR

These events originate from Afiax FHIR and drive finance, receivables, and ERP workflows.

EventTrigger in Afiax FHIRPrimary resourcesAfiax Billing result
billing.billable-event.createdbillable care activity is recordedEncounter, ChargeItem, Accountcreates or updates a billing work item
billing.coverage.context.updatedpayer or coverage context changesCoverage, Organization, Patientupdates payer/account linkage
billing.claim.submitteda country-pack claim leaves Afiax FHIRClaim, Task, AuditEventcreates reimbursement-linked receivable context
billing.claim.adjudicatedclaim outcome enters canonical workflow stateClaimResponse, Taskupdates expected settlement path
billing.invoice.readyinvoice-ready encounter or account closes to billingAccount, Invoice, ChargeItemcreates draft invoice or receivable workflow

Inbound events from Afiax Billing

These events originate from Afiax Billing and update the Afiax FHIR reimbursement ledger.

EventTrigger in Afiax BillingAfiax FHIR write-back
billing.invoice.issuedinvoice is postedupdates billing status and links invoice reference
billing.payment.postedpayment is collected and postedupdates patient- or payer-facing settlement state
billing.payment.partialpartial payment is postedrecords partial settlement outcome
billing.settlement.completedreceivable is fully settledmarks reimbursement workflow as financially complete
billing.adjustment.appliedwrite-off, refund, or adjustment postsrecords normalized financial adjustment outcome

Pharmacy contract

The pharmacy contract preserves the split between clinical medication state and operational inventory state.

Outbound pharmacy events from Afiax FHIR

EventTrigger in Afiax FHIRPrimary resourcesAfiax Billing result
pharmacy.order.createdprescription enters fulfillment workflowMedicationRequest, Encounter, Patientcreates fulfillment or dispensing work item
pharmacy.dispense.record-requireddispense must return to the clinical recordMedicationRequest, Taskreserves write-back path for dispense result

Inbound pharmacy events from Afiax Billing

EventTrigger in Afiax BillingAfiax FHIR write-back
pharmacy.dispense.completeddispense is completedcreates or updates MedicationDispense
pharmacy.dispense.cancelleddispense is cancelled or voidedupdates fulfillment status
pharmacy.stock.exceptionstock issue blocks dispensingrecords operational blocker on the workflow task

Shared identifiers

Every contract payload carries stable identifiers that allow both systems to reconcile state without shared tables.

IdentifierSource systemPurpose
projectIdAfiax FHIRtenant boundary
countryPackAfiax FHIRpack-aware routing and settlement logic
correlationIdevent producertrace across retries and write-backs
patientIdAfiax FHIRpatient-linked financial context
organizationIdAfiax FHIRfacility or billing entity context
encounterIdAfiax FHIRbillable care grouping
claimIdAfiax FHIRreimbursement correlation
invoiceIdorigin systeminvoice correlation
paymentIdAfiax Billingpayment correlation
externalReferenceorigin systemcross-system lookup key

Delivery guarantees

The contract supports idempotent processing and replay-safe reconciliation.

Each event includes:

  • eventId
  • eventType
  • occurredAt
  • correlationId
  • idempotencyKey
  • projectId
  • countryPack
  • sourceSystem
  • targetSystem

These fields let integration workers retry without duplicating invoices, payments, or dispense write-backs.

Handoff sequence

Use this sequence when implementing the integration:

  1. Afiax FHIR records the clinical or reimbursement state
  2. Afiax FHIR emits the normalized outbound event
  3. Afiax Billing processes the ERP-side workflow
  4. Afiax Billing emits the normalized financial outcome
  5. Afiax FHIR records the normalized write-back in the clinical workflow ledger

In Kenya, the current bot handoff points sit after:

  • successful claim submission
  • successful claim status refresh

Those are the correct first async boundaries for downstream finance continuation.

Canonical write-back behavior

Afiax FHIR records only the financial outcomes that affect clinical or reimbursement workflows.

That includes:

  • normalized billing status
  • normalized payment status
  • claim outcome state
  • dispense completion state when it belongs in the patient record
  • linked Task, AuditEvent, and Provenance

Afiax Billing retains ownership of:

  • finance ledger state
  • ERP document numbering
  • collections workflow internals
  • inventory bookkeeping

Payload and mapping rule

Use the contract this way:

  • the event name captures the workflow boundary
  • the payload body carries only the data the receiver needs
  • normalized status values use the shared status model
  • raw ERP or payer codes travel as references, not as the primary application state

For the full field-level examples, use:

What not to do

  • do not send raw ERP document internals as the primary workflow state
  • do not make Afiax Billing responsible for clinical truth
  • do not make Afiax FHIR responsible for full ERP execution
  • do not let a payment or billing event bypass Afiax FHIR when care or reimbursement visibility depends on it