Skip to content

EHR integration

How the EHR at each facility reports usage to the hub and adapts its UI — modules, upgrade prompts, billing banners — to the facility’s plan and standing.

Facility API, not Platform API
These endpoints live under /api/v1/billing and use the facility credential the EHR already holds — not a Platform API key. The facility is always taken from the token; it is never read from the request body.

Facility token

Exchange the facility app key for a 4-hour bearer token (the same token the EHR uses for reference-data sync):

POST https://admin.heka.care/api/v1/auth/token
Content-Type: application/json

{ "app_key": "<facility app key>", "facility_id": "GH-VRH-001" }

→ 200 { "success": true, "data": { "token": "eyJhbGciOi…", "expires_in": 14400,
         "facility": { "name": "Volta Regional Hospital", "tier": "standard", "is_active": true } } }

Cache the token and refresh it a few minutes before expires_in elapses. The exchange is limited to 10 requests per facility per minute.

Reporting usage

POST /api/v1/billing/usage takes up to 500 records. Field names on this endpoint are camelCase (they mirror the EHR’s own types):

POST https://admin.heka.care/api/v1/billing/usage
Authorization: Bearer <facility token>
Content-Type: application/json

{
  "records": [
    { "metric": "nhis_claims_submitted", "quantity": 412, "value": 8240000,
      "occurredAt": "2026-11-30T20:00:00Z", "idempotencyKey": "claims:2026-11:submitted" },
    { "metric": "sms_sent", "quantity": 1830,
      "occurredAt": "2026-11-30T20:00:00Z", "idempotencyKey": "sms:2026-11-30" }
  ]
}

→ 200 { "success": true, "data": { "accepted": 2, "duplicates": 0 } }
  • Idempotent per facility and idempotencyKey: queue reports in an outbox and retry whole batches until they succeed — duplicates are skipped.
  • Report daily or at month end. Usage for month M is invoiced on the M+1 invoice.
  • Errors use the facility API envelope: { "success": false, "error": "…", "errors": { field: [...] } } with 422 for validation.
  • Metric names and rules are on Usage metering.

Reading entitlements

GET https://admin.heka.care/api/v1/billing/entitlements
Authorization: Bearer <facility token>

→ 200 {
  "success": true,
  "data": {
    "facility_id": "GH-VRH-001",
    "plan": { "code": "hospital", "name": "Hospital", "tier": "standard" },
    "subscription_status": "grace",
    "commercial_state": "grace",
    "clinical_access": "full",
    "features": ["billing", "cashier", "dhims2_reporting", "ipd", "laboratory", "nhis_claims_scrubber", "opd", …],
    "suspended_features": [],
    "limits": { "maxBeds": 150, "maxSites": 1, "includedSmsPerMonth": 1000, "storageGb": 100 },
    "restrictions": ["billing_banner", "admin_warning"],
    "message": "Payment is overdue. Please settle to avoid pausing premium features.",
    "trial_ends_at": null,
    "current_period_end": "2026-12-01T00:00:00.000Z",
    "balance_due": 473200,
    "overdue_amount": 473200,
    "currency": "GHS",
    "generated_at": "2026-11-25T09:30:00.000Z"
  }
}

Poll every 15–60 minutes and cache the last good response. If the hub is unreachable, keep using the cached value — never lock users out because the hub is down.

The same data is available to partners through the Platform API at GET /api/platform/v1/facilities/{facility_id}/entitlements, with snake_case limits.

Commercial state

commercial_stateMeansrestrictions
noneNo subscription yet—
trialIn trial; full plan features—
okPaid up—
past_dueAn invoice is overduebilling_banner
graceOverdue past the grace thresholdbilling_banner, admin_warning
restrictedOverdue past the restriction thresholdbilling_banner, admin_warning, premium_features_suspended
cancelledSubscription endedbilling_banner
Invariant: clinical_access is always "full"
Non-payment never blocks patient care. Registration, consultation, prescribing, lab, pharmacy, admission and record access must keep working in every commercial state. The most a facility loses for non-payment is its premium add-ons (listed in suspended_features). Security revocation of a facility is a separate, explicit action taken by hub administrators.

Adapting the UI

Feature gating

  • Show a module when its feature flag is in features. Hide or show an upgrade prompt otherwise.
  • For flags in suspended_features, keep the data visible read-only and explain why the feature is paused, with the balance and how to pay.
  • Never gate clinical workflows on a feature flag absent from the plan — gate only the premium extras.

Restrictions

restrictionSuggested UI
billing_bannerDismissible banner for facility admins and the accounts office: amount due and how to pay.
admin_warningPersistent warning on admin pages, with the date premium features will pause.
premium_features_suspendedPaused add-on screens show a notice and a pay link; clinical screens are untouched.

Limits

limits holds plan allowances such as maxBeds and includedSmsPerMonth. Absent keys mean unlimited. Warn as a facility approaches a limit; do not hard-stop clinical operations at it.