Connecting an EHR¶
An EHR calls Mendari's CDS Hooks services (GET /cds-services, POST /cds-services/{id} and
its card feedback, POST /cds-services/{id}/feedback) in one of two ways:
- With a Mendari key. An administrator makes a key from the
cds-hookspreset and the EHR sends it asAuthorization: Bearer ohk_…(the presets). This needs sign-in on. - With its own signed token, as CDS Hooks 2.0 describes ("Trusting CDS Clients"). You register the EHR once, and each call carries a short-lived JWT the EHR signs with its own private key. Mendari never holds that key. This page is about this way.
Off until you register a client: with MENDARI_CDS_CLIENTS unset, a JWT on /cds-services is
refused in every mode, open mode included, and everything else works as before. Registered or
not, with sign-in off the CDS services answer this machine only (In open mode).
The decision behind it is
ADR-0014.
The bundled agent's service
The bundled demo agent, mendari/portal-message-agent, offers one CDS Hooks service, the
hook mendari-message-received (a FHIR Communication in, a card and a Task out). What
this page says of standard hooks (patient-view, order-sign), linked reads and code sets
applies to an agent of your own that declares them.
Register the EHR¶
MENDARI_CDS_CLIENTS is a JSON list, one entry per CDS client. It is read at startup, so a
change takes effect at the next restart or redeploy. A sandbox EHR, for example (the names are
fictional):
[
{
"id": "ehr-sandbox",
"title": "EHR sandbox",
"iss": "https://ehr.example.org/fhir/r4",
"org": "default",
"fhir_servers": ["https://ehr.example.org/fhir/r4"],
"jwks_uri": "https://ehr.example.org/.well-known/jwks.json",
"iss_is_fhir_server": true
}
]
| Field | Required | What it is |
|---|---|---|
id |
yes | Lower-case letters, digits and hyphens, at most 63. The client is the principal cds:<id>, and the audit chain names it cds <id>. |
title |
yes | A name for people, at most 100 characters. |
iss |
yes | Exactly what the EHR's tokens carry as iss. Some EHRs send their FHIR base. |
org |
yes | The organization its calls act for, and whose decisions they become. With sign-in off it must be default. In memberships mode it needs a record. |
fhir_servers |
yes | The FHIR bases (1 to 20) the EHR may send as fhirServer. Each must have its origin on MENDARI_FHIR_ALLOWED_SERVERS, and if MENDARI_SMART_EHRS registers the same base for launches, it must be to the same organization. |
jwks or jwks_uri |
one of the two | The EHR's public keys. jwks is a JWK Set by value. jwks_uri is the one URL Mendari fetches them from: https (plain http only for a loopback or single-label host), with its origin on MENDARI_FHIR_ALLOWED_SERVERS. |
sub |
no | When set, every token must carry exactly this sub. |
tenant |
no | When set, every token must carry exactly this tenant. When not set, a token with any tenant is refused: an EHR shared by several organizations is not supported yet. |
iss_is_fhir_server |
no | true: the fhirServer a call sends must also be its iss (which must then be one of fhir_servers). |
origins |
no | The browser origins (https://host[:port], 0 to 20) the EHR's pages call from. A page there may call the CDS services and read their answers (below); a page anywhere else may not use this client's tokens. |
Also set MENDARI_PUBLIC_URL to the address the EHR calls. A token's aud is that URL plus the
path called, so without it the server does not start. It is https, or plain http only for a
loopback address or a single-label host (a compose service, such as the sandbox's
http://engine-signin:8000).
Anything wrong in the list stops the server at startup. The message names the setting, the
entry's position and the field, for example
MENDARI_CDS_CLIENTS entry 2: fhir_servers 1 is not on MENDARI_FHIR_ALLOWED_SERVERS. It never
shows a value or any key material.
The keys¶
Keys are RS384 (RSA of 2048 to 8192 bits) or ES384 (EC P-384) public keys, 1 to 10 in a set,
each with its own kid. A set that holds a private or symmetric key is refused, by value at
startup and from a jwks_uri when it is fetched: treat such a key as exposed.
Keys from a jwks_uri:
- are fetched through the same allow-listed client as every other call to the EHR: no
redirects, a timeout and a size cap, and a JSON answer only (
application/json); - are kept an hour;
- are fetched again, at most once a minute per client, when a token names a
kidthe kept keys do not hold. A key the EHR rotates in is found within a minute of its first use. A flood of made-upkids costs the EHR one request a minute from each running instance of Mendari.
Each instance keeps its own keys (on Vercel, each function instance), so a new instance fetches them at its first token, and the limit above holds per instance: with several running, the EHR sees up to one request a minute from each.
An answer that is not a set of public signing keys, a key of the wrong shape among them, keeps
nothing, and drops what was kept. A failed fetch (no answer, an error, or an answer that is not
JSON or is nested too deep to read) keeps what was kept until it is an hour old. Each is one
cds.jwks.refused line in the security log.
Retiring a key, and trusting its host. Mendari learns that the EHR retired a key only when it
fetches the keys again. A key taken out of the JWK Set still verifies for up to an hour on each
instance that kept it, unless a token under a kid it does not hold makes that instance fetch
sooner. A key given by value verifies until you change MENDARI_CDS_CLIENTS and redeploy, which
is also how to stop a client at once. A key the EHR rotates in is found at the next fetch: on an
instance that fetched in the last minute, its tokens are refused (cds_key) until that minute
has passed. Mendari trusts whatever public keys the jwks_uri serves, so whoever controls that
host, its DNS or a certificate for its name can publish one, and a successful fetch is not
logged. An EHR whose tokens carry no jku can be registered with its keys by value instead,
which takes the host out of the trust; a client registered so refuses any token that names a
jku.
The token¶
The EHR signs one token for each call:
| Part | What Mendari requires |
|---|---|
| Size | At most 8 KiB, three base64url segments. |
| Header | Only alg, kid, typ and jku. alg is RS384 or ES384, typ is JWT, and kid names one of the client's keys of that key type. jku, when sent, must be the registered jwks_uri exactly; a client whose keys are given by value sends none. |
iss |
The registered iss, exactly. |
aud |
One string: MENDARI_PUBLIC_URL and the path called, exactly. Discovery's is https://<mendari>/cds-services, a hook's https://<mendari>/cds-services/<id>. It is never compared with the Host header. |
exp, iat |
Required numbers. iat is not in the future, and exp is at most 330 seconds after iat and after now, with 30 seconds of clock skew. |
jti |
Required, 1 to 256 characters, used once per client. A token is good for one request: discovery and a hook each need their own. |
sub, tenant |
As registered (above). |
Every token that does not pass is the same answer, a 401 with
WWW-Authenticate: Bearer realm="mendari", error="invalid_token". Nothing a refused token
sends is written: its jti is claimed only once every other check has passed, those of the
token, then (in memberships mode) its organization's record, then the route's permission. A
hook call refused for its fhirServer (below) has passed all of them, so its jti is used.
What a client may do¶
A verified token is a principal of kind cds, in the client's registered organization. It may
list the services, call them and send feedback on their cards, and nothing else:
- It reaches
/cds-servicesand its children only. On any other route the token is not a credential: with sign-in on the answer is the same401as for any other credential Mendari did not issue, and in open mode, which reads no credential there, it is ignored. - The
fhirServerit sends must be one of itsfhir_servers(and itsiss, withiss_is_fhir_server). Any other is a403before anything is fetched, charged or decided. - It is rate limited and capped daily like any principal, as
cds:<id>(MENDARI_PRINCIPAL_DAILY_LIMIT). One client carries a whole site's hooks, so measure a pilot's volume before it goes live. - It is never asked to acknowledge the notice: that is for people.
With an Authorization header there is no fallback to a session cookie: the token decides
alone.
From a browser¶
Some CDS clients run in the browser: a page on the EHR's own origin calls the services
directly. For that, list the page's origin in the client's origins. Then, on
/cds-services and its children only:
- The browser's preflight from that origin is answered before anything else, with
204:Access-Control-Allow-Originthat origin,Access-Control-Allow-Methods: GET, POST, OPTIONS,Access-Control-Allow-Headers: authorization, content-type,Access-Control-Max-Age: 600. - Every answer to that origin names it in
Access-Control-Allow-Origin, a refusal included, so the page can read why. Every answer there carriesVary: Origin. Access-Control-Allow-Credentialsis never sent. The page sends the EHR's token, never a cookie, and a call that carries a Mendari cookie is refused as another site's.- A token from a page must come from one of its own client's
origins, or from Mendari's own site. From any other origin, another client's included, the call is a403(this CDS client does not call from this origin) before the token'sjtiis used.
A page on an origin no client registered gets no CORS header, and its calls are refused as before. Nothing else Mendari serves is open to other origins.
In open mode¶
With sign-in off, the CDS services answer this machine only: a call from a loopback address
(127.0.0.1, ::1), to a Host that names this machine (localhost, a .localhost name or a
loopback address), with no forwarding header (Forwarded, X-Forwarded-For,
X-Forwarded-Host, X-Real-IP). From anywhere else every call is a 403, before any
credential is read, a valid token included, and the security log says open_mode_remote. An
EHR on a network calls a server with sign-in on, and so does anything behind a proxy. A proxy
that adds a forwarding header makes every call it forwards look remote. A proxy on this machine
that adds none makes every call it forwards look local, wherever it came from. nginx's default is
one: proxy_pass http://127.0.0.1:8000 sends Host: 127.0.0.1:8000 and no forwarding header.
A synthetic sandbox reached over a network, such as the compose sandbox's open engine, which
Docker reaches from its network's gateway, sets MENDARI_CDS_SANDBOX=1: it then answers from
anywhere, and says so at startup. 0 is off, as unset is. The server refuses to start with any
other value, and with 1 on Vercel or with sign-in on.
On this machine, a JWT on /cds-services is verified too, and without a registry it is
refused. A request with no credential is answered as before, so a local demo that sends no
token still works. Off /cds-services open mode reads no credential, a JWT included. A tool
that always sends its own JWT, such as the public CDS Hooks Sandbox, has to be registered first,
with org set to default, and its page's origin in origins.
Check it¶
- Signed in,
/api/healthlists your organization's clients by id (cds_clients);nullmeans none is registered. - Each refusal is one
auth.credential.refusedline in the security log, with its reason and, once the token'sissnames a registered client,cds:<id>. It never holds the token or a claim.
| Reason | What it means |
|---|---|
cds_unregistered |
A JWT came, and no client is registered here. |
cds_headers |
More than one Authorization header. |
cds_size, cds_format |
Over 8 KiB, or not three base64url segments of JSON. |
cds_header |
A header field other than alg, kid, typ and jku, an algorithm other than RS384 or ES384, typ not JWT, or no kid. |
cds_issuer |
No client is registered with this iss. |
cds_jku |
A jku other than the registered jwks_uri. |
cds_keys_unavailable |
The keys from the jwks_uri could not be fetched or were refused. |
cds_key |
No one key of the client matches the kid and the algorithm's key type. |
cds_signature |
The signature does not verify with that key. |
cds_audience |
aud is not the URL called. |
cds_expired, cds_not_yet_valid, cds_lifetime |
The token's time: expired, not valid yet (nbf or iat more than 30 seconds ahead), or living longer than 330 seconds. |
cds_claims |
A required claim is missing, or of the wrong type: exp or iat not a number (a numeric string included), or jti not a string. |
cds_subject, cds_tenant |
sub or tenant other than registered. |
cds_jti |
A jti that is empty or longer than 256 characters. |
cds_replayed |
The jti was used before by this client. |
cds_no_organization_record |
Memberships mode: the client's organization has no record. |
A fhirServer refused for a cds principal is an auth.permission.refused line, reason
cds_fhir_server_not_registered. A token from a page on an origin that is not its client's is
an auth.origin.refused line, reason cds_origin, with cds:<id>. In open mode, a call from
another machine is an auth.permission.refused line, reason open_mode_remote.
Reading the record¶
A hook decides on its prefetch. A key the request leaves out (or sends empty) is read from
fhirServer with the fhirAuthorization token, only when that server is on
MENDARI_FHIR_ALLOWED_SERVERS; with no fhirServer the request is a 412. A key whose value is
null has no data and is not read. When part of the record cannot be read, the hook still answers
200: the decision is ABSTAIN, its reasons say could not read <key or field>: <reason>, it is
recorded with its data_coverage record, and its card is an info card that names what was not
read.
Linked data¶
An agent can read a note that is only a link to a Binary, and what a reference points to: the
payer behind Coverage.payor, the drug behind medicationReference
(the mapping). When the record does not hold them, Mendari
reads them from the same fhirServer, with the same token:
- one
GETof one resource byType/id, under the server's base URL, withAccept: application/fhir+json. The server must answer a Binary as FHIR JSON (its content indata), not as its raw bytes; - at most 50 note Binaries and, apart from them, 50 followed references a decision, so a chart's
notes never use up what its drugs need; each at most 1 MiB once decoded. A note field stops
reading its notes once their text is longer than the agent's input takes: the decision abstains
(
too_large) whatever the rest hold; - at most 100 reads a request, its decisions together (each draft order of an order hook is a
decision), and 60 seconds spent in them. The decision's deadline (
MENDARI_DECISION_DEADLINE_S) starts before its linked reads and its remote providers share what is left, so an EHR that answers slowly leaves the providers less time (they fail withtimeout, and a person decides); - each link once a request, however it is written (relative, or an absolute URL under the base), so the draft orders of one order hook share what was read;
- never a link to another server, or outside the base;
- nothing a MedicationRequest links to when the agent leaves it out of its list
(
medication_period: one entered in error, a proposal, a plan or an option, and an order not to give the drug).
A fhirServer that is not on MENDARI_FHIR_ALLOWED_SERVERS is configuration, not the patient's
data: for an agent that reads links, the hook is a 422 before anything is decided, with nothing
fetched or recorded, as when a prefetch key is left out. The token must allow reading what the
links name: Binary, and the types the agent follows a reference to. A link that is not read
makes the decision ABSTAIN with its field and one of these reasons:
| Reason | What it means |
|---|---|
off_server |
The link names another server, another scheme, or a path outside the base URL. Nothing was sent. |
cap |
The decision had already read 50 notes, or 50 followed references; or the request had sent 100 reads. Nothing was sent. |
timeout |
The read did not answer in time, or the decision's deadline or the request's 60 seconds of reads had run out (then nothing was sent). |
too_large |
A resource's answer, or a Binary's content once decoded, is over 1 MiB. |
not_fetched |
There was no server to read from (no fhirServer, fhir/decide, $decide), or the link names no Type/id. |
unsupported_type |
The link names another type than the agent reads (a note's url anything but a Binary, relative or absolute; nothing is sent), the Binary holds no content, or the note is of a type Mendari does not read. |
network, unauthorized, http_status, not_json, operation_outcome, not_r4 |
The read failed. not_json is a Binary answered as raw bytes. |
Notes are read as plain text and HTML. RTF, PDF and CDA are not read, and the decision abstains,
unless another rendition of the same note was read: the content of one DocumentReference holds
one document in several formats, so an RTF beside the HTML of a note is not needed, and is not
read. A note none of whose renditions is read counts once, by the reason of its HTML or plain
text rendition (cap, a failed read), else unsupported_type, and the field's data-coverage
record counts the formats of the notes it read as unsupported_type (unread_formats: rtf,
pdf, xml, image, none, other). The record's links section says how many links the
decision read for each budget, and how many reads failed with each HTTP status. An agent that
reads notes by link, the Medication a MedicationRequest names, or the Organization a Coverage's
payor names needs a token that allows Binary, Medication and Organization reads.
The cards¶
Each card is CDS Hooks 2.0's:
- Its
uuidis the id of the decision it shows. Its one suggestion has its ownuuid, and the card saysselectionBehavior: at-most-one. The EHR keeps theuuidbeside the patient it sent, so an export or archive of the audit chain is identifiable beside the EHR's records, after Mendari's retention has removed the inputs too (threat model). - It offers three override reasons, from
https://mendari.co/fhir/CodeSystem/card-override-reasons(served at/fhir/CodeSystem/card-override-reasons):not-relevant,already-addressedandclinical-judgement, each with its display. - The summary uses the agent's display names, under 140 characters. The detail is the agent's status, the notice and one plain sentence for the outcome, and never a percentage: the confidence the card used to show as one is gone.
- Every decision is recorded, but an agent may show a card for some recommendations only (its
cds_hooks.card.show; a decision with no recommendation, an ABSTAIN or a BLOCK, is itsnone, and one that refused its input is itsrefusedwhere the agent names that key). An agent may also show a card for a recommendation it otherwise leaves out when a policy rule of its own matched, in that rule's words (cds_hooks.card.also_show). An input the agent refuses as invalid (BLOCK) gets itsrefusedcard, if the agent names one, saying it was not checked and why, each reason naming where in the input and which rule, never the text; it is in the audit trail, not in the review queue. An ABSTAIN because part of the record could not be read always gets itsinfocard, whatever the agent shows otherwise; a decision whose input is also refused is a BLOCK, and shows the card the agent shows for refused input, if any. - The demo agent's hook,
mendari-message-received, is Mendari's own, not a standard one: the EHR sends the message (aCommunication) and its sender as prefetch, and gets one card.
The links on a card need MENDARI_PUBLIC_URL:
| Link | When | Where it goes |
|---|---|---|
The audit trail (absolute) |
MENDARI_PUBLIC_URL is set |
<public URL>/?agent=<agent id>#audit/<decision>, the decision's record, which needs a Mendari sign-in with read in the organization. The engine's reasons move behind this link, but for a list read without a source your EHR does not offer (<list> may be incomplete: …, below), which stays in the detail, and for an input refused as invalid (an agent's refused card), whose reasons stay in its detail. |
The agent (source.url) |
MENDARI_PUBLIC_URL is set |
<public URL>/?agent=<agent id>#card, the agent's card. |
The launch (smart) |
also SMART is on (MENDARI_SMART_CLIENT_ID), and the request's fhirServer is registered in MENDARI_SMART_EHRS to the caller's own organization |
<public URL>/smart/launch?agent=<agent id> (the launch's own parameter keeps the name it had). The EHR adds iss and launch. |
Without MENDARI_PUBLIC_URL, a card has no links and the reasons stay in its detail, but for
the confidence thresholds' reason (such as confidence 0.94 is below the auto threshold 0.95):
its figures carry no interval, and the outcome's sentence says what it decided. The audit trail
keeps it. A
clinician without a Mendari account sees no reasons behind the link: give pilot clinicians
accounts, or open the agent from the EHR (the launch link).
Card feedback¶
When the clinician acts on a card, the EHR may send CDS Hooks 2.0 feedback to
POST /cds-services/{id}/feedback, with a token for that URL (or the cds-hooks key):
{
"feedback": [
{
"card": "<the card's uuid>",
"outcome": "accepted",
"acceptedSuggestions": [{"id": "<its suggestion's uuid>"}],
"outcomeTimestamp": "2026-10-18T12:00:00-04:00"
},
{
"card": "<another card's uuid>",
"outcome": "overridden",
"overrideReason": {
"reason": {
"system": "https://mendari.co/fhir/CodeSystem/card-override-reasons",
"code": "clinical-judgement"
}
},
"outcomeTimestamp": "2026-10-18T12:01:00-04:00"
}
]
}
- 1 to 50 cards in one request, each once. The answer is
{"recorded": <n>}. acceptednames the card's one suggestion.overriddennames one of the card's reasons, or none. Anything the card did not offer, a field CDS Hooks 2.0 does not define (a Coding issystem,codeanddisplay), or anoutcomeTimestampwith no time in UTC is a422.extension, which CDS Hooks 2.0 reserves for implementations, is accepted on any object of the body and never kept.- Each card must be a decision of that service, in the caller's organization, and, with sign-in
on (or for a CDS client's token), one the same caller asked for. Otherwise the answer is one
404for all of them, whichever it was. - It is all or nothing: a refused request records nothing.
- Each card's feedback is chained on its decision as
card.feedback: the service, the outcome, the suggestion taken, the reason's system and code, the time and who sent it.userCommentis never kept. - It counts against the decide rate limit, as
cds:<id>, and not against the daily cap: it decides nothing.
Try it with the sandbox's client¶
Before an EHR does, the sandbox plays one: a CDS client that signs its own tokens and calls over HTTP, for synthetic cases a FHIR server holds.
The cases. mendari sandbox seed --fhir <FHIR base> loads the bundled demo agent's
synthetic portal messages into a FHIR server, as US Core Patients and Communications tagged
https://mendari.co/fhir/sandbox|synthetic. For an agent of your own that reads a portal
message, name it (--agent, an id or a directory); --dataset gives other cases than its
benchmark dataset.
The client. mendari sandbox cds-client --engine <URL> --fhir <FHIR base>, for the same
agent (--agent; the demo agent unless given):
- makes an EC P-384 key in memory, which it never writes anywhere, and serves its JWK Set at
<iss>/jwks.json(--listen, default127.0.0.1:8300;--iss, the URL the engine reaches it at, defaulthttp://and the listening address); - prints its
MENDARI_CDS_CLIENTSentry, with its keys byjwks_uri(--id, defaultsandbox-client;--org, defaultdefault); - finds the agent's seeded cases on the FHIR server, by the sandbox's tag and the resource
the agent's FHIR mapping decides about, five of them at most (
--limit). With none there, it stops and says to seed first; - reads discovery, then calls the agent's service once for each case. Each call carries a new
ES384 token:
issits own URL,audthe engine's public URL (--audience, default--engine) and the path, five minutes, a newjti, andjkuin the header. The request sends no prefetch and names the FHIR server asfhirServer, so the engine reads the record there. Its context names the patient and, by id, what the service's prefetch reads (the demo agent's message, ascommunicationId); an order hook'sdraftOrdersis the case's order, as a draft.
It prints what each call answered, and exits 1 on any answer other than 200, a hook answer
that is not CDS Hooks' (a cards list, each with a summary, an indicator and a source), or a
card saying part of the record could not be read. Every hook answers 200, so a read of the
FHIR server that failed (for an agent that reads a patient's conditions, could not read
conditions: http_status) shows only there. To run
it against your own engine, register the entry it prints, put its origin and the FHIR server's
on MENDARI_FHIR_ALLOWED_SERVERS, and give the engine's MENDARI_PUBLIC_URL as --audience.
Each run makes a new key, and an engine fetches a client's keys again at most once a minute, so
a second run within the minute is refused (cds_key).
In the compose sandbox, the profile signin's service cds-client seeds the demo agent's
messages and runs the client against both engines, the open one (under MENDARI_CDS_SANDBOX=1)
and the signed-in one (in organization pilot). Both register it at http://cds-client:8300.
CI's sandbox-e2e runs it on every change:
docker compose --profile signin run --rm --use-aliases cds-client
The standard hooks, on data shaped as an EHR returns it. The demo agent's hook is its own
(mendari-message-received). The standard hooks (patient-view, order-sign) are held by
the test suite on what the product does not bundle: the chart-summary test fixture and its
order-sign twin, on a vendor-shaped EHR (tests/support/chart_ehr.py) served inside the test,
with no network. Its synthetic patients follow the shapes an EHR such as Epic returns, and hold
none of its data:
- a note is a DocumentReference whose attachments only link to Binaries, as plain text, HTML or RTF, in one rendition or two (HTML with an RTF twin of the same note);
- a Condition carries the site's own diagnosis code first, beside ICD-10-CM;
- a medication is a MedicationRequest naming a Medication coded in RxNorm by reference, with its
dates in a dosage
boundsPeriod; - no SNOMED CT anywhere.
Each fixture decides through its own hook, as an EHR calls it (no prefetch, the FHIR server and
its token named), the profile's server answering the engine's reads (tests/test_ehr_profile.py).
What an agent cannot read in these shapes. An agent reads a note that is only a link from
the FHIR server (its Binary, as text/plain or text/html, and of a note kept in two renditions
the readable one); an RTF note alone is not read, so the decision abstains for a patient whose
note is RTF (could not read notes: unsupported_type, an info card). And an EHR that keeps
every medication as an active MedicationRequest, its dates in the dosage's bounds, gives a
medication the patient's record ended as active, with the same dates. The test pins both, each
with why.
Site codes¶
An EHR often codes things its own way: a local code system, or another code of a standard one.
An agent names sets of its own codes (code_sets) and reads a field through one
(code_set, the spec). MENDARI_SITE_CODES
says how a site's codes translate into an agent's, one organization at a time. Off until you set
it: unset, no code is translated and every decision is made as before.
It is inline JSON, or the path of a JSON file. For example (every code here is fictional):
{
"default": {
"version": "2026-10-19.1",
"sets": {
"referral_category": [
{"system": "https://ehr.example.org/fhir/CodeSystem/order-types", "code": "REF-7",
"as": "FR101"}
]
}
}
}
| Field | What it is |
|---|---|
<org> |
The organization whose decisions read with this map: one your people sign in to, default with sign-in off (and then the only one). At most 100. |
version |
Your own label for this version of the map, 1 to 64 visible ASCII characters. Every decision records it. |
sets |
By the name of a code set an agent declares, the translations into it. |
system, code |
The site's code: a code system URI (http, https or urn:) and a code in it. |
as |
The agent's code it stands for: one of the codes the set declares. |
At most 10,000 translations in one organization's map, and a site code once in a set. It is read
at startup, so a change takes effect at the next restart or redeploy. It is checked against the
code sets of the agents found on the server, served or not: a set no agent declares, or an as
that is not a code of its set, stops the server. The message names the setting, the
organization, the code set and the translation's position, for example
MENDARI_SITE_CODES organization 'default', code set 'referral_category', translation 1: it
translates into a code the set does not declare. It never shows a system or a code. A
translation applies in an agent whose set of that name lists its as, and only for that set's
fields. It only fills in where the agent's own codes give nothing: a coding in the set's own
system wins over a translated one wherever the field finds it, among one path's codings or on
a later one of its paths. A path that gives a code only through a translation passes to the
next, and the first translated code counts only when no path gives one of the set's own. So a
record whose own codes give a field its value is read the same with the map as without it.
What a decision does with it:
- A FHIR decision the server makes (
fhir/decide, CDS Hooks,$decide, an EHR launch) reads its record with the map of the organization it acts for, never another's. Its record keepssite_codes: the map'sversionandsha256, the SHA-256 of the map's canonical form (mendari.site-codes/1: the organization, the version and each set's translations sorted by system and code). The same map written in another order has the same digest; any change, or one organization's map given to another, has another. Without a map it isnull, as it is on a JSON decision./api/healthshows your organization's. - The command line reads no map.
mendari decide --fhir(with--dbtoo) andmendari bulk datasetread every record as without one: a site's own codes are unknown, the decision recordssite_codes: null, andMENDARI_SITE_CODESis not read or checked. A dataset built from your bulk export is so not read as the server reads your records. - Its data-coverage record is read with the same translations, so it says what the input read. It holds no translation, and a coding a translation matched counts by its system.
- What a linked read fetched (the Medication behind a
medicationReference, say) is read with the same map, as the rest of the record is. A map translates codings only: a payer's identifier (Organization.identifier) is read as it is, never through a map. - A decision whose input took a value through a translation never automates. AUTO becomes
HUMAN_REVIEW, with the reasonsite code translated (<code set>): a person decides. An agent rule's BLOCK, which is final at once, becomesHUMAN_REVIEWtoo, with the reasonsite code translated (<code set>): a person decides instead of its rule's BLOCK. A decision its policy already sends to a person (HUMAN_REVIEW, orABSTAIN: a confidence below the review threshold, no answer) keeps its outcome, with the first reason added; one that abstains because part of the record could not be read asks no provider, and its reasons name only what was not read. Nothing in an agent or a setting lifts this, a governance approval included. It stays until the site's map is validated (launch gate G5-6,site-validation), and lifting it then is the owner's decision.
A map is configuration, not part of an agent: no agent file or digest changes. A site's own SNOMED
CT codes may go in its map under its own licence; Mendari ships none. A map reaches only an
agent that declares code sets: an agent that reads a referral through focus_where and a code
set (referral_category above), say, finds your referrals once the map translates the code
your EHR marks them with. An agent that reads its codes by code system, through no code set, is
not reached by a map. The bundled demo agent declares none.
What your EHR does not offer¶
An agent may read one list from several resource types: an agent may read its medications from
MedicationStatement and MedicationRequest. Some EHRs do not offer one of them at all. Epic offers
no R4 MedicationStatement API (only DSTU2 and STU3), so its read is refused (unauthorized), and,
as for any part of the record that cannot be read, the decision abstains: could not read
medications: unauthorized. That is the safe default. A drug the EHR never gave is not evidence
that the patient does not take it.
MENDARI_EHR_DECLARATIONS lets the site say what its EHR does not offer, one FHIR base and
organization at a time. Off until you set it. It is inline JSON, or the path of a JSON file:
{
"https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4": {
"org": "default",
"version": "2026-11-08",
"attested_by": "<who checked it>",
"reference": "<where that check is recorded>",
"not_offered": ["MedicationStatement"]
}
}
- Checked at startup. The base must be on
MENDARI_FHIR_ALLOWED_SERVERSand registered for launches (MENDARI_SMART_EHRS) or in a CDS client'sfhir_servers, for the same organization (defaultwith sign-in off). Each declared type must be one that an agent found here reads as one of several sources of a list, beside a source not declared. DeclaringDocumentReference,Patient, or every source of a list, stops the server. So does anything else wrong; the refusal names the setting, the base and the field. - What it changes. For a SMART launch from that base, or a CDS hook whose
fhirServeris that base, acting for that organization, a prefetch key of a declared type is not read for an agent that may read its list without it, when another source of that list is read. A CDS client that sends the key with entries has them used; sent null, empty or as a search with no entries, the key is not offered. Nothing changes forfhir/decide,$decide, the command line, another base, another organization, or an agent that reads the type anywhere else. - What the decision records. Its
ehr_declaration(version, SHA-256, who attested it, its reference); in its data-coverage record the source and the list markednot_offered(its 0 is "not read", never "read and empty") and the key underprefetch./api/healthshows your organization's declarations. - It never automates. AUTO, and an agent rule's BLOCK, become
HUMAN_REVIEW, with the reason<list> may be incomplete: read without <Type>, which this EHR does not offer (declared, <attested_by>): a person decides, whatever the outcome (an input refused by the agent's input schema, or underenforceby US Core, is a final BLOCK, and its reason ends at the closing parenthesis). A card the agent shows keeps it in its detail even when its other reasons are behind the audit link (on an unreadable ABSTAIN's card and a refused input's, apart from what was not read or why it was refused). An agent that shows no card for an outcome an incomplete list can give sends such a decision to the review queue only (owner question O6).
Declaring MedicationStatement says more than that Epic lacks the API: it says every medication the agent should see is in Epic's MedicationRequests, so "no insulin among the orders" may read as "off insulin". Check, on your Epic, before you set it:
- whether patient-reported or historical home medications are returned as MedicationRequest,
and with which
intent. An agent that leaves out requests whoseintentisproposal,planoroptionwould not see home medications recorded so; - whether the default MedicationRequest search (no
status, nocategory) returns stopped, completed and inpatient orders, if an agent's criteria look back at recently stopped drugs; - whether
Medication.code.text(or the request'sdisplay) carries the generic name. Criteria that match medications by name read a brand-only name as no such drug.
Setting it on a hosted deployment is a clinical claim as well as a configuration change: the person who attests it is named on every decision it applies to.
Conformance runs¶
Mendari's own repository runs two of Inferno's test kits against an engine, weekly and by hand
(conformance.yml; how to run them yourself, and every known gap with its reason, in
sandbox/inferno/README.md):
the SMART App Launch client suite against an EHR launch, and the Bulk Data client suite against
mendari bulk export. terminology.yml runs the HL7 validator over Mendari's synthetic FHIR
resources with a terminology server (tx.fhir.org). None of them proves your deployment: TLS,
your EHR's keys and their rotation, and your EHR's own requests are yours to check (Check it,
above). For an EHR that launches Mendari, mendari smart check <its FHIR base> also compares the
scopes a launch asks for with the EHR's scopes_supported
(Sign-in and roles).
Before a pilot¶
What Mendari's own tests and runs show, on synthetic data and test keys only, and what they leave to a pilot:
- End to end. An EHR's signed token, a hook over HTTP whose record is read from the EHR's
FHIR server, its card, the clinician's feedback on that card, then
mendari audit verifypassing over the trail, and failing once one of its events is changed, on SQLite and Postgres (tests/test_ehr_pilot_e2e.py). - Not yet shown on a vendor's own EHR. That every agent with a standard hook decides on the
vendor's sandbox patients without a failed hook, and that
mendari smart checkpasses against the vendor, is the pilot's first run (the named vendor is Epic, with Oracle Health as the backup). Until then the path is proven with test keys, the sandbox's client and Inferno only. - Notes the agents may not read. An agent that reads notes reads a note that is only a link
from the FHIR server, but as text only when it is text/plain or text/html: an RTF,
PDF or CDA note abstains (
unsupported_type). So do notes longer than the agent's input allows in all (too_large; the text is never cut) and more notes than a decision reads (50,cap), which a patient with many notes may reach. On an EHR that sends notes that way, or keeps many notes for each patient, the agents that read notes may abstain for most patients with one, each decision going to a person with aninfocard. Read the decisions' data-coverage records (the audit view's "What it read") in the first days. - After the first run. The first SMART launch on Epic's sandbox (2026-11-08) launched, authorized and read the patient; the agent abstained on MedicationStatement's refusal, on one link budget its notes had used, and on RTF twins counted twice. Each decision's "What it read" now says which prefetch reads failed and with which HTTP status, how many links it read for each budget, and the formats of the notes it could not read: read those lines after the first run, and before declaring what your EHR does not offer (above).
- The validation mode. Under
MENDARI_FHIR_VALIDATION=warn, the default, input that is R4 JSON but breaks R4's other rules is decided with its issues recorded;enforceblocks it before any provider runs (Settings at a glance). - What stays a risk with all of this in place: trust in the EHR's key and its rotation, a
compromised
jkuhost, the decision id the EHR keeps, a misconfigured site map, a wrong declaration of what the EHR does not offer, and frequent abstention on records whose notes Mendari cannot read (threat model).