The Claim Settlement System reconciles what a medical aid agreed to pay, what it said it paid in its remittance advice, and what reached the bank. This specifies the first of those: what the system needs from the pharmacy system, and how it arrives.
Nothing here requires access to a pharmacy's network. Each site's own installation sends its data outward over HTTPS. No inbound connection, no VPN, no fixed IP address, and no database credential leaves the site.
Nothing is written back. The system does not write to the pharmacy system and is not asking to.
Section 4 is the part that matters. A feed that satisfies sections 2 and 3 but gets section 4 wrong produces figures that look right and are not.
Seven feeds. The first four are sent through a rolling window; the last three are small and sent whole.
One row per dispensing event. The anchor for everything else.
| Field | Type | Required | Notes |
|---|---|---|---|
scriptId |
integer (64-bit) | yes | Unique per dispensing event. Not stable for a script over time — §4.1 |
scriptNumber |
integer (32-bit) | yes | The number a human quotes. Stable. One number maps to many scriptId |
medicalAidCode |
string(100) | yes | Joins to §2.6 |
dispensedAt |
timestamp | yes | Also what the delivery window filters on |
scriptState |
string(40) | preferred | How a rewrite is identified — §4.1 |
claimDate |
timestamp | optional |
One row per attempt to claim a script. A script routinely produces several, and most are not the answer.
| Field | Type | Required | Notes |
|---|---|---|---|
claimId |
integer (64-bit) | yes | |
scriptId |
integer (64-bit) | yes | Joins to §2.1 |
status |
string(8) | yes | §4.2 |
medicalAidCode |
string(100) | yes | May differ between attempts on one script |
ramsNumber |
string(15) | yes, may be empty | §4.3 |
amountClaimed |
decimal(12,2) | yes | What was asked for |
paymentExcl |
decimal(12,2) | yes | What was agreed, excluding VAT |
paymentVat |
decimal(12,2) | yes | Agreed amount is paymentExcl + paymentVat |
authorization |
string(20) | optional | |
claimedAt |
timestamp or string | yes | §4.4 |
switchRef |
string(20) | optional |
One row per product on an attempt. Remittances match at this level, so this is what reconciliation runs on.
| Field | Type | Required | Notes |
|---|---|---|---|
claimLineId |
integer (64-bit) | yes | |
claimId |
integer (64-bit) | yes | Joins to §2.2 |
nappiCode |
string(15) | yes | Send exactly as held — §4.3 |
description |
string(100) | yes | Shown to staff resolving an unmatched line |
paymentExcl |
decimal(12,2) | yes | |
paymentVat |
decimal(12,2) | yes | |
lineNumber |
integer | optional | |
externalStatus |
string(8) | optional |
Claim lines may carry no date of their own. Select them through the attempts already in the window rather than by date:
SELECT l.* FROM <claim lines> l
JOIN <claim attempts> h ON h.<id> = l.<attempt id>
WHERE h.<claim date> >= <thirty days ago>
A line without its attempt is unusable, and an attempt without its lines cannot be matched, so the two must agree on what is in scope.
Postings to the medical aid control account. The system runs without this feed — matching, exceptions and bank reconciliation are unaffected and only outstanding totals go dark — so a site whose accounting sits elsewhere is not blocked.
| Field | Type | Required | Notes |
|---|---|---|---|
postingId |
integer (64-bit) | yes | |
scriptId |
integer (64-bit) | yes | A number, not text — §4.5 |
transactionType |
string(4) | yes | RX and RS only — §4.5 |
amount |
decimal(15,2) | yes | Signed; negatives are reversals |
postedAt |
timestamp | yes | |
controlAccountId |
integer | yes | The medical aid account — §2.5 |
reversed |
boolean | preferred |
Its current balance. Sent whole each time, because a balance is cumulative and a rolling window cannot reconstruct one.
| Field | Type | Required | Notes |
|---|---|---|---|
controlAccountId |
integer | yes | |
name |
string(200) | yes | Shown beside the figure |
accountBalance |
decimal(15,2) | yes | |
modifiedAt |
timestamp | preferred | When the pharmacy system last changed it, so a stale figure is distinguishable from a quiet account |
One row: the medical aid control account.
A site has more than one control account — a medical aid one and a levy one. The choice has to be made at the sending end, because nothing in the delivered data distinguishes them and every obvious rule can pick wrongly: the levy account may carry more postings, a larger balance and a lower account number. Sending the wrong one reports a figure that looks entirely plausible and is not what the pharmacy is owed.
The same applies to §2.4 — send postings for that account only.
| Field | Type | Required | Notes |
|---|---|---|---|
code |
string(20) | yes | Not treated as unique — §4.6 |
name |
string(255) | yes | |
active |
boolean | optional |
| Field | Type | Required |
|---|---|---|
pharmacyName |
string(100) | yes |
branchCode |
string(20) | optional |
The design goal is that the sending side holds no delivery state — no outbox, no queue, no retry logic, nothing to remember and nothing to get wrong.
Every hour, send every row from the last 30 days. We deduplicate.
That is the whole of it. A scheduled job, one query per feed with a date filter, one HTTPS POST carrying the rows and the site's API key. Feeds may be sent together or separately.
There is deliberately no "what have I already sent?" bookkeeping, because that is where this kind of integration usually fails — a queue that fills, a delivered-flag written before the response arrives, a retry storm after an outage.
It is self-healing. If a delivery fails — the line drops, our endpoint restarts, the server is off overnight — nothing is lost, because the next run covers the same ground. A site offline for three days catches up on its next successful delivery, with no code anywhere that knows it was behind.
It catches updates. "Everything after ID 12345" misses changes to rows that already exist, and a claim's status changing is precisely what this system exists to notice.
It costs almost nothing. A busy dispensary moves a few hundred rows a day, so a 30-day window is a few thousand rows. The receiving end is sized well beyond that. The headroom is better spent making the integration impossible to break than on sending fewer bytes.
Reference data (§2.5, §2.6, §2.7) has no useful date filter and is small. Send it whole each time, or daily.
So the window is safe to rely on:
One API key per pharmacy, in the X-Api-Key header. The key identifies the site, so the payload
need not say which pharmacy it is for — and therefore cannot say the wrong one.
Keys are stored hashed: we can verify one and cannot reproduce it. Several can be valid at once, so a key is replaced without a gap — issue the new one, update the installation, retire the old. A key is scoped to exactly one pharmacy.
No request signing and no fixed IP address: authentication is the API key over TLS.
The endpoint is versioned in its path (/v1/...). Sites will not all be upgraded on the same day,
so an older installation keeps working against a newer service. Additive changes will not require
a version change; anything that would break an existing sender will.
Each of these changes what the system reports if the feed gets it wrong, and in every case the wrong answer looks like a right one.
A script that is reversed and resubmitted gets a new scriptId under the same scriptNumber,
and a script number can accumulate a great many over its life. Every one of them can post to the
control account.
The feed must carry every scriptId and the scriptNumber that owns it. If a script is
flattened to a single record the rest is unrecoverable at our end, and this is the requirement
that decides whether the integration works at all.
Totals are grouped by scriptNumber; joins to the ledger go by scriptId. Grouping by scriptId
splits one script's balance across rows and understates it — silently.
Only some attempts carry a payment. The rest are the record of what the switch refused and why, and they are what a staff member reads when a pharmacy asks why a script was never paid: submitted twice, rejected once, accepted on the third attempt. That answer exists only if the failed attempts were sent.
Send every attempt. A failed one sits beside an accepted one on the same script, carrying zero; choose the wrong row and a script the medical aid paid in full reports as owing nothing.
Status is not a safe filter in either direction — an accepted claim can carry zero, and a status that normally carries nothing can occasionally carry a value. Send them all and let the value decide.
NAPPI codes differ in leading zeros between what a switch returns and what the pharmacy system holds — on the same script, for the same product. RAMS numbers are frequently empty, including on accepted claims; nothing in our matching requires them.
Do not normalise, pad or trim. We compare on numeric value and compensate for the inconsistency; a tidied value removes the evidence the matching depends on.
If a claim date is held as text rather than a timestamp — YYYYMMDD with the time in a separate
field, say — send it exactly as recorded. We keep the raw value and parse it only where it is
unambiguous; one we cannot read is left empty and flagged rather than guessed at, because a date
misread files a claim under the wrong month silently.
Preferred: ISO-8601 with an explicit offset throughout. If the storage cannot supply that we will keep treating the value as opaque text, but we need to know which it is, per field.
A posting ties to a script by scriptId. Send it as a number, not as text containing one — a
string-to-number comparison on that join is fragile and unindexable.
Send RX and RS only. Debtor-payment rows must not be included: their reference is
free-typed by whoever posts the payment, so nothing can be concluded from it, and a value reaching
a control-account total produces a figure nobody can explain.
A payer code can appear under more than one scheme name, so the code alone is not a key. Duplicates are expected; code and name together identify a row.
The scheme is currently derived from the first word of the name (Discovery Priority Saver + Core
→ Discovery), which is not a good way to group schemes.
scriptId under a scriptNumber can be sent (§4.1). This is the
one that decides whether the integration is viable; everything else is detail.Z and CFR statuses. We treat them as terminal non-payments, which
works, but we would rather know than infer.One constraint from our side: the sending queries need to run on MySQL 5.6 or later, so no common table expressions and no window functions.
Settled, recorded so they are not re-opened: