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.
/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: [...] } }with422for 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_state | Means | restrictions |
|---|---|---|
none | No subscription yet | — |
trial | In trial; full plan features | — |
ok | Paid up | — |
past_due | An invoice is overdue | billing_banner |
grace | Overdue past the grace threshold | billing_banner, admin_warning |
restricted | Overdue past the restriction threshold | billing_banner, admin_warning, premium_features_suspended |
cancelled | Subscription ended | billing_banner |
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
| restriction | Suggested UI |
|---|---|
billing_banner | Dismissible banner for facility admins and the accounts office: amount due and how to pay. |
admin_warning | Persistent warning on admin pages, with the date premium features will pause. |
premium_features_suspended | Paused 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.