Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

FerroEHR Viewer

ferroehr-viewer is a standalone web UI for managing an ITS-REST-1.1.0 CDR, this server or any other. It is a pure REST client: everything it does goes through the CDR’s public API (never the database), so what you see in the viewer is exactly what the API serves. The whole application is Rust, drawn on the server as plain HTML with FerroUI, the component library the FerroHEALTH consoles share; the only scripts are FerroUI’s own small modules, and there is no hand-written JavaScript anywhere, including its browser tests.

Running it

The quickstart compose ships the viewer as the ferroehr-viewer service on port 3000, behind the viewer profile, so it is opt-in and does not start with a plain docker compose up:

docker compose --profile viewer up
# → http://localhost:3000  (log in with the quickstart user ferroehr/ferroehr)

Standalone, point it at any CDR:

docker run -p 3000:3000 \
  -e FERROEHR_VIEWER__CDR__BASE_URL=https://cdr.example.org \
  ghcr.io/ferrohealth/ferroehr-viewer

On Kubernetes

The Helm chart deploys the viewer as its own Deployment, Service and ServiceAccount, with an optional Ingress and a NetworkPolicy that confines its egress to the CDR and DNS: the viewer is a REST client of the CDR by mandate, so the chart enforces that rather than trusting it. Off by default, and off renders nothing:

# values.yaml
viewer:
  enabled: true
  ingress:
    enabled: true
    hosts:
      - host: viewer.example.org
        paths:
          - path: /
            pathType: Prefix
  auth:
    oidc:
      enabled: true
      issuer: https://keycloak.example/realms/ferroehr
      clientId: ferroehr-viewer
      publicBaseUrl: https://viewer.example.org
  # the OIDC client secret is MOUNTED from a Secret you create, never env-borne
  existingSecret: viewer-oidc

It needs no database credential and never reaches the database. Before you enable OIDC: a registered client whose redirect URI matches publicBaseUrl, and a Secret holding its client secret. To turn the viewer off, set viewer.enabled: false and upgrade; every viewer object is removed and the CDR is untouched.

Note

The viewer is a demonstration of the CDR, not an EHR for production use: you build your own EHR on the CDR. It runs as one instance and keeps its sessions in that process, so a restart signs everyone out. If you run more than one replica anyway, route each visitor to the same replica (sticky sessions at the ingress), or a reroute signs the visitor out.

Signing in

The sign-in page offers exactly the methods that can actually work: the viewer’s configured login modes intersected with the authentication schemes the CDR advertises (its WWW-Authenticate challenge). A Basic form is never shown against a bearer-only CDR, and vice versa. If the CDR cannot be reached at all, the page falls back to the viewer’s own configuration and renders anyway, and the outage then surfaces on the login attempt instead of hiding the page. A username or password the CDR refuses brings you back to the sign-in card with the refusal under the password.

The sign-in form posts to /sign-in, and like every post to the viewer it must show that it comes from the viewer’s own pages, the defence against cross-site request forgery (OWASP Cross-Site Request Forgery Prevention Cheat Sheet). A browser shows it with Sec-Fetch-Site: same-origin (W3C Fetch Metadata Request Headers §2.4). The viewer answers with Referrer-Policy: no-referrer, so a browser’s plain form post carries Origin: null and no Referer, and Sec-Fetch-Site is what lets it pass. A scripted client, such as a deployment test or a probe, sends no fetch metadata of its own, so it must send the header itself, or an Origin that names auth.public_base_url when that is set. A post that shows neither is refused 403 before the sign-in runs:

curl -c jar -b jar -H 'Sec-Fetch-Site: same-origin' \
  --data-urlencode username=alice --data-urlencode password=secret \
  --data-urlencode next=/ https://viewer.example.org/sign-in

The viewer verifies the CDR and the OIDC issuer against the platform trust store and the extra certificate authorities its configuration names: a CDR or an identity provider whose certificate comes from a private CA is trusted once cdr.tls.trust_roots_file or oidc.tls.trust_roots_file names a PEM bundle holding that CA, on Linux and macOS alike, and a connection opens only once a revocation check of the chain’s CRL or OCSP sources cleared it. A private CA that publishes no revocation service goes in cdr.tls.trust_roots_without_revocation_file or oidc.tls.trust_roots_without_revocation_file, trusted with no check and named at the start. A file that cannot be read, or holds no certificate, refuses the start (How an outbound TLS table verifies a peer).

The viewer manages no accounts of its own: it authenticates you against the CDR (Basic) or your identity provider (OIDC), and there are no user, role, or password screens to find; those live in the CDR’s configuration and in your IdP.

The button with your name at the end of the top bar opens the user menu: who is signed in and how, Your preferences, Your access, the theme, Keyboard shortcuts and Sign out.

Your access

Your access (/access) answers what may this session do, and who says so: the principal and how it signed in (a Basic session replays its CDR account and carries no SMART scopes; an OIDC session carries an access token whose scopes are listed), every scope on the session read as its parsed grant (the compartment, the resource family and id pattern, and which of create, read, update, delete and search it permits, with a broad access marker on a bare *; an identity or launch scope such as openid, profile or launch/patient reads as the request it makes), and a previewer: paste any scope or a whole claim, press Read it, and read the same rendering. A malformed scope says what the grammar expected. The user menu and Server’s SMART tab link here.

The reading parses with the same grammar the CDR’s SMART on openEHR enforcement reads, so the two cannot drift. Scopes narrow access and never grant it; the CDR remains the enforcer.

When your session ends

A session ends when you sign out, when its idle window (session.idle_timeout, an hour by default) passes with no request from your browser, when its lifetime (session.absolute_timeout, 12 hours after you signed in by default) runs out whatever you do, or when the CDR stops accepting the credential behind it (an expired or revoked token). The pairing of an idle timeout with an absolute one follows the OWASP Session Management Cheat Sheet.

Each signed-in page watches its session. Two minutes before the idle window ends, a dialog says when the session ends and offers Stay signed in or Sign out; typing or clicking on the page also keeps the session going, at most once a minute. Nothing extends the lifetime, so near its end the page gives no warning and leaves when it runs out. When the session has ended, the page leaves for the sign-in page, which says the session ended, and signing in again (Basic or OIDC) returns you to the page you were on. Every other tab of the viewer in the same browser leaves with it, and signing out in one tab ends the others.

The idle window slides on each request your browser makes for a page or a post. The watch’s own reads of the session do not slide it, so a tab left open and untouched idles out after session.idle_timeout_s like a closed one. With FerroUI’s scripts refused, the next page you ask for is where the viewer notices.

The deployment profile

The status pill at the end of the top bar says whether the CDR answers. A deployment that declares the sandbox profile (deployment.profile in its configuration, reported on GET /rest/status) raises a band under the top bar on every signed-in page: this deployment must not hold real patient data, with the number of production separations the server reported as open (a shared database credential, a shared cluster, no subject pseudonym namespace, no durable audit trail, schema preparation on the runtime credential). Its Details opens Server’s Overview, which names each one. A production deployment raises no band. The quickstart and the composed stacks run as sandbox; a CDR older than the profile reports none and the viewer claims nothing. See the deployment profile in the server configuration.

Configuration

One TOML file (ferroehr-viewer.toml, read from the path --config or FERROEHR_VIEWER_CONFIG names; with none named, no file is read), with FERROEHR_VIEWER__<SECTION>__<KEY> environment overrides and --set key=value pairs over both. Unknown keys and unknown FERROEHR_VIEWER_ variables are refused at startup. The CDR refuses only an unknown FERROEHR__ override, because the viewer’s variables share its prefix:

KeyDefaultMeaning
server.listen127.0.0.1:3000 (0.0.0.0:3000 in the image)The socket address the viewer listens on.
server.tlsunsetThe listener’s certificate and key, as the CDR’s [server.tls] table; unset, the viewer speaks plain HTTP behind a terminating proxy.
server.request_timeout / body_limit"1min" / "16MiB"How long one request may take, and the largest body it may post (a template or composition posts whole).
server.drain_delay / shutdown_timeout"0s" / "10s"On SIGTERM the viewer withdraws readiness, waits the drain delay, then gives the requests in flight the shutdown bound.
server.*as the CDR’sThe other keys of the CDR’s [server] table (header_read_timeout, idle_timeout, max_concurrent_requests, retry_after, trusted_proxies, forwarded_header, compression, compression_min_size) apply as they do there. base_path and caller_rate are refused: the viewer’s pages are served at /, and it mounts no per-caller limit.
telemetry.*as the CDR’sThe CDR’s [telemetry] section: format (auto, json or pretty), filter (default info,hyper=warn,tower=warn,h2=warn, refused at startup when it does not parse; RUST_LOG is a lower-priority fallback, as on the CDR), logged_query_parameters, environment and the [telemetry.otlp] export. A viewer request line has the CDR’s fields, and a panic writes the CDR’s one fixed line. The service.name is ferroehr-viewer; the viewer serves no Prometheus surface, so its http.server.request.duration histogram leaves only over OTLP with otlp.metrics.
cdr.base_urlhttp://localhost:8080The CDR origin (cdr.base_path is appended).
cdr.base_path/ferroehr/rest/openehr/v1The CDR’s ITS-REST base path. Mirror of the CDR’s own api.base_path: set the same value here when a deployment shortens it, or the viewer calls paths the CDR does not serve. The status document, the OpenAPI documents and the SMART discovery document are derived from it by the same rule the CDR uses.
cdr.timeout"30s"How long one request to the CDR may take.
cdr.purpose_of_useunsetThe purpose of use the viewer declares when the reader chose none on Preferences. It must be a code the CDR’s GET {extensions}/access/purposes lists: an unlisted code stops the first request after sign-in with an error naming it, and is never sent. Unset declares nothing until the reader chooses.
cdr.basic_issuerlocalhostThe issuer the CDR names a Basic user’s login by, its [api] basic_issuer (which defaults to its [api] system_id). The viewer names a Basic session’s user under it in the placeholder committer of every commit, so set it to the CDR’s value; localhost is the CDR’s own in a sandbox with neither system_id nor public_base_url.
cdr.tls.trust_roots_fileunsetA PEM bundle of certificate authorities trusted for the CDR beside the platform’s roots, for a CDR behind a private PKI; the CDR’s chain must be cleared by a revocation check.
cdr.tls.trust_roots_without_revocation_fileunsetThe same for a private PKI that publishes no revocation service, trusted with no revocation check.
cdr.tls.client_identity (_file)unsetThe client certificate chain and its private key, in one PEM, presented to a CDR that asks for mutual TLS.
cdr.tls.min_version"1.3"The oldest TLS version the CDR client speaks; "1.2" lowers it.
cdr.management_base_urlderived from cdr.base_urlThe CDR’s management surface, base path included; set it when the CDR serves management on its own internal listener (management.listen) or under a renamed base path. Drives Server’s management tabs.
auth.basic_enabledtrueOffer the username/password form (validated against the CDR; held server-side).
auth.oidc_enabledfalseOffer the OpenID Connect sign-in (authorization code + PKCE) at the provider [oidc] names.
auth.post_quantum_onlyfalseAccept an ID Token of the OpenID Connect sign-in signed with ML-DSA-44, ML-DSA-65 or ML-DSA-87 (RFC 9964) alone. Off, the viewer accepts those and the classical RS256 to PS512, ES256, ES384 and EdDSA.
auth.public_base_url—The viewer’s externally visible origin: the origin the same-origin check compares a post with, the base of oidc.redirect_uri (<public_base_url>/auth/callback) when that is not set, and the base of oidc.post_logout_redirect_uri (<public_base_url>/sign-in?signed-out=1, the signed-out page) when that is not set.
oidc.issuer / client_id / client_secret (_file) / redirect_uri / post_logout_redirect_uri / scopes—The viewer’s client at its OpenID Provider (ferrohealth-session’s [oidc]). The provider must allow the redirect URI <public_base_url>/auth/callback and the post-logout redirect URI <public_base_url>/sign-in?signed-out=1 (OpenID Connect RP-Initiated Logout 1.0 §3). With auth.oidc_enabled, an issuer that is not https off loopback, a missing client id or redirect URI, and scopes without openid are startup errors, and the provider’s metadata is discovered at the start.
oidc.resolveemptyhost=ip:port entries for split-horizon DNS: the viewer reaches each provider host at its address, while browsers and tokens keep the canonical URL.
oidc.tls.trust_roots_file / trust_roots_without_revocation_file / client_identity (_file) / min_versionunset / unset / unset / "1.3"The family’s outbound TLS table for the provider: a PEM bundle of certificate authorities trusted beside the platform’s roots, for a provider behind a private PKI, checked for revocation; the same for a private PKI that publishes no revocation service, with no check; the client certificate chain and its private key in one PEM, for mutual TLS (RFC 8705 §2); and the oldest TLS version of the provider connection ("1.2" lowers it).
login.noticeemptyInformational text on the sign-in card, line breaks preserved. A demo or evaluation deployment states its public credentials and usage expectations here.
login.linksemptyLinks under the sign-in card, each { label, href } — an API reference, a documentation page.
session.storememoryWhere sessions are kept (ferrohealth-session’s [session]): memory, in the one viewer process, is the only store. sealed, session.key and session.key_file are removed and refuse the start.
session.idle_timeout"1h"Session idle expiry: the window slides on each page or post the browser asks for and on Stay signed in, never on the session watch’s own reads.
session.absolute_timeout"12h"The session’s lifetime from sign-in, which no activity extends. Zero, or a value below session.idle_timeout, is a startup error.
session.secure_cookietrueThe cookies carry Secure and with it the __Host- prefix; set false only for plain-HTTP local development.
launch.issueremptyFerroSMART’s issuer identifier. Set, an EHR’s More menu offers a Launch item per [[launch.app]] (Launching a SMART app); empty, it offers none. An issuer that is not https off loopback is a startup error.
launch.client_id / private_key_file / kid— / — / emptyThe viewer’s client at FerroSMART, registered with private_key_jwt and system/launch.c in its scope, and the PEM private key its client assertion is signed with: ML-DSA-44, ML-DSA-65 or ML-DSA-87 (signed with its parameter set, RFC 9964), RSA (signed RS384) or P-384 (signed ES384); RS384 and ES384 are the two algorithms SMART App Launch 2.2.0 has a server support, and FerroSMART also takes ML-DSA. A key of any other kind is a startup error. kid is the key id FerroSMART’s registered JWK Set names; empty, the key’s RFC 7638 thumbprint. Required when launch.issuer is set.
launch.resource—The base an app receives as iss: the CDR’s public openEHR REST base, one of FerroSMART’s [[ferrosmart.resource]] tables. Required when launch.issuer is set.
launch.patient_namespacesemptyThe EHR subject namespaces whose subject id is a FHIR Patient id, sent as patient beside ehrId.
launch.fhir_baseemptyThe FHIR facade’s base. Set, the page of an EHR whose subject namespace is one of launch.patient_namespaces lists the patient’s SMART launch Tasks read at that base with your own token, and launches the app of one (Launch Tasks); an EHR of any other namespace lists none. Empty, no Task is read. A value that is no absolute http or https URL is a startup error.
launch.timeout / launch.tls.*"10s" / unsetHow long one request to FerroSMART may take, and the family’s outbound TLS table for it.
launch.appemptyThe apps, each { name, client_id, launch_url }: the name the menu draws, the app’s client_id at FerroSMART and its registered launch URL. Two apps with one client_id are a startup error.
ui.localeenThe language a page renders in when the browser’s Accept-Language names none the viewer ships. English is the one language that ships today. A language is added as a catalog file under app/ferroehr-viewer/locales/<tag>/ (the viewer’s words) beside FerroUI’s (the components’ words) with no code change; the catalogs are embedded when the viewer is built, so a new one reaches a deployment in a rebuilt image, never at run time. A value that is no BCP 47 language tag is a startup error.

Commands

ferroehr-viewer (or ferroehr-viewer serve) serves until SIGTERM or SIGINT. ferroehr-viewer config check reads the configuration, checks [oidc] and [session] and builds the CDR client, the session store and, with [launch] set, the launch client and its key, reading every TLS file, without reaching the CDR, the provider or FerroSMART. ferroehr-viewer healthcheck, the image’s HEALTHCHECK, asks the viewer beside it for GET /health/readiness over the loopback (over TLS when server.tls is set) and exits 0 only on 200. The viewer serves the family’s health routes: /health/liveness, /health/readiness and /health.

Every command exits 78 (EX_CONFIG of sysexits(3)) when the viewer refuses its configuration (an unknown or invalid key, a TLS file that does not read, an [oidc] or [session] table it cannot use) and 1 on any other failure, with the whole cause on stderr. A command line clap cannot parse exits 2.

Browser security headers

Every response carries a Content-Security-Policy that admits scripts and styles from the viewer’s own origin alone (script-src 'self'; style-src 'self'), with no nonce and neither 'unsafe-inline' nor 'unsafe-eval', and forms that post to the viewer alone (form-action 'self', beside the origin of each [[launch.app]], since a launch’s answer sends its window on to the app), beside X-Content-Type-Options: nosniff, X-Frame-Options: DENY, Referrer-Policy: no-referrer, Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Resource-Policy: same-site; when the viewer serves TLS itself (server.tls), Strict-Transport-Security: max-age=31536000 as well. Every document is Cache-Control: no-store; FerroUI’s stylesheet, theme and scripts under /ferrohealth-ui/<version>/ are no-cache, so a browser revalidates them. A request that is not a safe method (a form post, the search panel’s answer) is refused 403 unless the browser’s Sec-Fetch-Site says it came from the viewer’s own pages; without that header its Origin or Referer must name auth.public_base_url.

The viewer is stateless: it has no database and keeps no local files of its own. Everything it shows, including how stored queries are grouped, which is derived from the namespace in each query’s qualified name, lives in the CDR and is read over ITS-REST, so nothing here needs backing up. The sign-in and the session are ferrohealth-session’s, kept in the viewer’s process: a restart signs everyone out.

Sign-in and sessions live in the viewer’s server; the browser stores only the session cookie, an opaque id: CDR credentials and bearer tokens never reach it in readable form. The sign-in page is /sign-in, and the sign-in routes are /login (which begins the OpenID Connect sign-in), /auth/callback, /logout and /session.

How the pages work

The viewer draws every page on its server and sends it complete. Every link is a link and every action is a form that posts to the page it sits on, so the whole viewer works with JavaScript off. The browser then loads FerroUI’s small script modules, which add behaviour to a few parts of a page (the code editor, the path trees, the chart legend, the date pickers, the search panel’s suggestions, the user menu’s keyboard handling, the subject reveal and Copy buttons); nothing on a page waits for them. There is no hand-written JavaScript.

An editor (a new EHR, a composition, the EHR status, the directory, a party, a template upload) ends in a bar docked at the foot of the page: what has changed, Discard, and the save. A save that the CDR refuses keeps what you typed on the page beside the CDR’s own words.

The screens are listed in the sidebar; below 48 rem it folds into a drawer behind the menu button.

  • Dashboard: record counts, the compositions committed per day, and the stored queries by namespace. See Queries.
  • EHRs: find, create and delete EHRs; each EHR’s compositions, directory, status, contributions, tags, care relationships, access settings and legal marks. See Templates and EHRs.
  • Parties: the demographic parties, their versions, relationships and tags. See Parties.
  • Templates: upload and read ADL 1.4 and ADL 2 operational templates. See Templates and EHRs.
  • Terminology: the terminologies the CDR serves. See Terminology.
  • Stored queries and Query: build or write AQL, run it, chart and export the rows, save it to the CDR. See Queries.
  • Server: what the CDR is, how it runs and what it serves, and the Audit log. See Server and audit log.
  • Access policy: the controller’s access policy by section, its versions and its editor. See Access control.
  • Roles and grants: the roles holding an openehr_access grant and the system clients. See Access control.
  • Retention: the declared retention periods and what is due. See Access control.
  • Configuration: the CDR’s redacted running configuration, by section.
  • About: the viewer, the CDR and their versions, the manufacturer and the CDR’s conformance manifest.

The top bar’s search takes an EHR id, a composition or party uid, a subject id, a template id or a stored-query name. From the second character a panel under the field shows what matches, five of a kind; the arrow keys move through it, Enter opens a hit and Escape closes it. Submitting the search opens the find page, which lists every match, or the other ways to find a record when nothing does.

The footer under every page names the viewer and its version, the manufacturer (Cadasto B.V.), and an About link.

Paging

A listing that can show patient data (the EHRs, an EHR’s compositions and contributions, the audit log) pages with First, Previous, Next and Last under the table and keeps its page in a cookie for the browser session, never in the address or the history, as FerroUI asks of every family console. A filter stays in the address, so a filtered view is still shareable; the page you were on is not. Each step is a form that posts to /paging and comes back to the listing, so paging works with JavaScript off.

Preferences and the keyboard

Your preferences keeps the viewer’s display choices, each in its own cookie for that browser: the theme, the reading choices, and the keyboard shortcuts. See Preferences and the theme.

Audit log

The audit log has its own section in Server and audit log.

Acknowledgment

The viewer’s feature set (the Template Manager, the point-and-click Query Builder, and saved, grouped and cohort queries) is inspired by EHRServer by Pablo Pazos and CaboLabs Health Informatics (Apache-2.0). The interface is reimplemented in Rust over FerroEHR’s own AQL engine, and no code is copied.