Risk Indicator
StableA risk score that cannot be displayed without its date, its drivers, and the fact that it is not a diagnosis.
Why it exists
Risk scores are the most casually rendered artefact in healthcare software: a number, a colour, a tooltip nobody reads.
Three things go wrong. The score is stale — computed nightly, shown at noon, after the admission that would have changed it. The score is unattributed, so the clinician cannot see that 70% of it is driven by one ED visit eighteen months ago. And the score is read as a diagnosis, which is how an externally validated sepsis model with an AUC of 0.63 came to be trusted by clinicians who were never shown its performance. Each needs a shape rather than a caveat: the validity window is data because a 24-hour deterioration model and a 12-month readmission model expire differently, drivers are part of the value type rather than an optional extra, and the framing sentence is a required prop because every product that made it optional shipped without it.
- RiskAssessment
- prediction[].probabilityDecimal and qualitativeRisk, whenPeriod.end as the validity window, basis[] as unweighted drivers, occurrenceDateTime and method. Pairs with a DSI source-attribute record for the model itself.
Playground
Change a prop and watch the component and its code change with it.
- onOpenModel, onRecompute — nothing yet
import { RiskIndicator } from "@/components/zoblocks/risk-indicator";export default function Example() { return ( <RiskIndicator assessment={assessment} density="default" driverCount={4} /> );}Examples
The cases worth copying. Open one in StackBlitz to run it with its dependencies installed.
DatapatientRoutineobservationPotassiumCriticalencounterRoutine
The date, the drivers and the framing
patientRoutineAll three are structural. `validUntil` comes from the model's own window rather than a shared constant, drivers are part of the value type, and the framing is a required prop — because every product that made it optional shipped without it.
import { RiskIndicator, type RiskAssessment } from "@/components/zoblocks/risk-indicator";import { NOT_A_DIAGNOSIS } from "./_shared/shared";const now = "2026-08-12T10:00:00Z";const assessment: RiskAssessment = { id: "readmit-30", outcome: "30-day readmission", band: "high", probability: 0.31, percentile: 94, cohort: "adult medicine", computedAt: "2026-08-12T04:12:00Z", validUntil: "2026-08-13T04:12:00Z", drivers: [ { label: "3 admissions / 6 mo", weight: 11.2 }, { label: "Lives alone", weight: 4.8 }, { label: "No PCP visit < 90 d", weight: 3.9 }, { label: "Adherent to statin", weight: -2.1 }, ], model: { name: "Readmit-v4", auc: 0.71 },};export default function TheDateDriversAndFraming() { return ( <section style={{ display: "grid", gap: 8 }}> <RiskIndicator assessment={assessment} now={now} notADiagnosis={NOT_A_DIAGNOSIS} /> </section> );}Expired, not old
encounterRoutinePast its validity window the score stops being stale and starts being something the model no longer stands behind. There are two ways out and no third: a dismiss action would leave a waved-away score on the panel looking current.
import { useState } from "react";import { RiskIndicator, type RiskAssessment } from "@/components/zoblocks/risk-indicator";import { NOT_A_DIAGNOSIS } from "./_shared/shared";const now = "2026-08-14T09:00:00Z";const assessment: RiskAssessment = { id: "deterioration-24h", outcome: "Deterioration within 24 h", band: "high", probability: 0.42, computedAt: "2026-08-12T04:12:00Z", validUntil: "2026-08-13T04:12:00Z", drivers: [ { label: "Rising respiratory rate", weight: 6.1 }, { label: "Lactate trending up", weight: 3.4 }, ], model: { name: "Deteriorate-v2", auc: 0.74 },};export default function ExpiredNotOld() { const [feedback, setFeedback] = useState<string | null>(null); return ( <section style={{ display: "grid", gap: 8 }}> <RiskIndicator assessment={assessment} now={now} notADiagnosis={NOT_A_DIAGNOSIS} onRecompute={() => setFeedback("Recompute requested")} onAcknowledge={() => setFeedback("Acknowledged as expired")} /> {feedback ? <span aria-live="polite">{feedback}</span> : null} </section> );}Not scored is not low
patientRoutineMissing features, outside the training population, a service that timed out — all produce a fact, and it is not "low". Rendering it as the bottom band is how a patient the model cannot see becomes a patient the panel does not call.
import { RiskIndicator, type RiskAssessment } from "@/components/zoblocks/risk-indicator";import { NOT_A_DIAGNOSIS } from "./_shared/shared";const now = "2026-08-12T10:00:00Z";const assessment: RiskAssessment = { id: "readmit-30-unscored", outcome: "30-day readmission", band: "unknown", computedAt: "2026-08-12T04:12:00Z",};export default function NotScoredIsNotLow() { return ( <section style={{ display: "grid", gap: 8 }}> <RiskIndicator assessment={assessment} now={now} notADiagnosis={NOT_A_DIAGNOSIS} /> </section> );}When one factor is most of the score
observationPotassiumCriticalA model whose top driver carries most of the total attribution is not modelling a patient; it is reporting one event. The component says so, because a clinician who knows that reads the number correctly and one who does not treats it as a synthesis.
import { RiskIndicator, type RiskAssessment } from "@/components/zoblocks/risk-indicator";import { NOT_A_DIAGNOSIS } from "./_shared/shared";const now = "2026-08-12T10:00:00Z";const assessment: RiskAssessment = { id: "readmit-30-concentration", outcome: "30-day readmission", band: "high", probability: 0.28, computedAt: "2026-08-12T04:12:00Z", drivers: [ { label: "ED visit, 18 months ago", weight: 14.0 }, { label: "Lives alone", weight: 2.1 }, { label: "No PCP visit < 90 d", weight: 1.8 }, ], model: { name: "Readmit-v4", auc: 0.71 },};export default function WhenOneFactorIsMostOfTheScore() { return ( <section style={{ display: "grid", gap: 8 }}> <RiskIndicator assessment={assessment} now={now} notADiagnosis={NOT_A_DIAGNOSIS} /> </section> );}Variants
Every variant is the same accessibility contract and the same keyboard model. Pick by what the surface needs.
Default
Band, numeral, percentile, drivers, staleness and framing.
density="default"
Compact
For a panel list. The staleness signal never collapses.
density="compact"
Installation
npx @zoblocks/cli add risk-indicatorFirst install? Run zoblocks init once to say where your @/ alias points. The source is copied into your repository, along with anything it depends on.
clsxtailwind-mergeUsage
Props are the FHIR resource.
import { RiskIndicator } from "@/components/zoblocks/risk-indicator";import "@/styles/zoblocks-risk.css";<RiskIndicator assessment={readmission} now={serverTime} notADiagnosis="A statistical estimate from historical patterns. Not a diagnosis, and not a substitute for assessment."/>Use it when
- Readmission, deterioration, no-show and care-gap models — anywhere a score drives who gets called first.
- In a care-manager panel with density="compact", where forty of these are read in a sitting and the staleness signal is the one that has to survive.
- Alongside a structured assessment rather than in place of one. A suicide-risk model output is not a C-SSRS, and the two belong on the same screen.
- With onRecompute wired wherever recomputation is possible, so an expired score has somewhere to go other than being ignored.
Avoid it when
- Without drivers when the model can produce them. An unattributed score is the second of the three failures, and the component cannot fix it for you.
- As the only risk signal on a screen. It is an estimate; the assessment, the history and the clinician are the rest.
- With a generic framing sentence copied between models. What a score is not depends on what it is, and a shared sentence is wrong for both.
API
Every prop is typed. Props not listed are forwarded to the root element.
RiskIndicator
8 propsassessmentrequiredRiskAssessment- Default
— - The RiskAssessment, with its drivers and the date it was computed. A score cannot render without them — it is a statistical estimate, not a diagnosis, and undated it is not even that.
notADiagnosisrequiredstring- Default
— - The framing, and it is required. Not a default string either: what a score is not depends on what it is — a readmission model and a suicide-risk model need different sentences, and a shared one would be wrong for both.
nowrequiredstring- Default
— - ISO 8601, supplied by the host. The component never reads a clock.
density'compact' | 'default'- Default
"default" - Row height and type scale. Inherited from the nearest density provider when omitted.
driverCountnumber- Default
4 - How many drivers to show on the face. The rest live in the explanation.
onAcknowledge((assessment: RiskAssessment) => void)- Default
— - Acknowledges an expired score. A stale score cannot be dismissed — only recomputed or acknowledged — and the acknowledgement is the host's to record.
onOpenModel((assessment: RiskAssessment) => void)- Default
— - Opens the model card. See the DSI source-attribute record.
onRecompute((assessment: RiskAssessment) => void)- Default
— - Fired when the reader asks for a fresh score. Without it a stale score says it is stale and offers nothing to do about it.
Accessibility
Screen readers and semantics
- Never colour alone. The band is a ClinicalStatus chip, so it carries a shape and a word. Driver direction is a signed number before it is a fill colour, and the sign is what reaches the accessible name. Removing every hue leaves the band word, the sign and the sentence.
- The name ends with the framing. The whole score is one spoken statement — outcome, band, percentage, cohort, age, drivers, model — and the not-a-diagnosis clause is last. Put first it is boilerplate a listener skips; put last it is the sentence they are left with.
- Staleness is content, not a tooltip. An expired score renders the words on the face, in the reading order, before the drivers. A tooltip is invisible to anyone who did not hover, and the population that most needs this signal is the one scanning a panel of forty.
- A percentile is never spoken without its cohort. "94th percentile" of an unnamed population is routinely read as "94th percentile of people like this patient". The two are supplied together or not at all, and the type enforces it.
- Unscored is not a low score. A patient the model could not score gets its own band, its own dashed edge and its own sentence. Rendering it as the bottom band is how somebody the model cannot see becomes somebody the panel does not call.
Conformance · WCAG 2.2 AA · 7 of 8 pass
| Criterion | Status | How | Evidence |
|---|---|---|---|
| 1.3.1Info and relationships | pass | One labelled group carrying the whole statement in reading order, with every inner node aria-hidden. The relationship between score, age and framing is in the sentence rather than in visual adjacency. | risk-indicator.test.tsx |
| 1.4.1Use of colour | pass | The band routes through ClinicalStatus for its shape and word; driver direction is a signed number. A test asserts the sign reaches the accessible name and that unknown is not styled as low. | risk-indicator.test.tsx |
| 4.1.2Name, role, value | pass | role="group" with a composed label. The model link, recompute and acknowledge affordances are all native buttons, present only when the host supplies a handler. | risk-indicator.test.tsx |
| 2.1.1Keyboard | pass | Every affordance is a native button reached and activated by keyboard, with no handler of the component's own. | risk-indicator.test.tsx |
| 2.5.8Target size | pass | Recompute and acknowledge hold a 24px minimum at both densities. | risk-indicator.test.tsx |
| 1.4.10Reflow | pass | Below 420px the driver bars drop and the rows become label and weight; the staleness signal never collapses. | risk-indicator.test.tsx |
| 1.4.12Text spacing | pass | A grid with no fixed heights; increased line-height and letter-spacing grow the card rather than clipping it. | risk-indicator.test.tsx |
| 2.2.1Timing adjustable | n/a | No timing. Staleness is computed against a `now` the host supplies, never a clock the component reads. | — |
Clinical
Panel triage and in-chart display for readmission, deterioration, no-show and rising-risk models. Suicide-risk models are the highest-stakes and the least well-calibrated, which is why the calibration is on the face and the component pairs the score with a structured assessment rather than standing in for one.
- Industries
- healthcare, behavioral-health, payer
- Workflows
- assessment, care-coordination, scheduling
- Terminology
- FHIR, SNOMED CT
- Permissions
- risk.read
- Audit
- Emits AuditEvent
Protected health information
Handles PHI
Renders a model's estimate about a person and the factors driving it. The drivers are the disclosive part — 'lives alone', 'no PCP visit' — and they are on the face by design, because an unattributed score is the failure this component exists to prevent.
Source
Exactly what lands in your repository, read from the published registry so it can never drift from what the CLI installs.
Show sourceHide source307 lines
/** * RiskIndicator — a risk score that cannot be displayed without its date, its * drivers, and the fact that it is not a diagnosis. * * <RiskIndicator * assessment={readmission} * now={serverTime} * notADiagnosis="A statistical estimate, not a diagnosis." * /> * * The band leads and the numeral is demoted: two decimal places imply a * precision the model does not have. Staleness is on the face rather than in a * tooltip, because a score computed nightly and read at noon — after the * admission that would have changed it — is the failure nobody sees. * * `notADiagnosis` is a required prop rather than a convention. Every product * that made it optional shipped without it. * * Styling lives in `styles/zoblocks-risk.css`, installed alongside. */import * as React from "react";import { cn } from "@/lib/utils";import { ClinicalStatus } from "@/components/zoblocks/clinical-status";import { BAND_STEP, concentration, describeAge, describeRisk, driverDirection, freshness, ordinal, topDrivers, type RiskAssessment, type RiskDriver,} from "@/lib/zoblocks-risk";export { BAND_LABEL, BAND_STEP, concentration, describeAge, describeRisk, driverDirection, freshness, fromRiskAssessment, ordinal, toBand, topDrivers, type Freshness, type RiskAssessment, type RiskAssessmentInput, type RiskBand, type RiskDriver,} from "@/lib/zoblocks-risk";export interface RiskIndicatorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> { /** * The RiskAssessment, with its drivers and the date it was computed. A score cannot render * without them — it is a statistical estimate, not a diagnosis, and undated it is not even * that. */ assessment: RiskAssessment; /** ISO 8601, supplied by the host. The component never reads a clock. */ now: string; /** * The framing, and it is required. * * Not a default string either: what a score is not depends on what it is — * a readmission model and a suicide-risk model need different sentences, and * a shared one would be wrong for both. */ notADiagnosis: string; /** How many drivers to show on the face. The rest live in the explanation. */ driverCount?: number; /** Row height and type scale. Inherited from the nearest density provider when omitted. */ density?: "compact" | "default"; /** Opens the model card. See the DSI source-attribute record. */ onOpenModel?: (assessment: RiskAssessment) => void; /** * Acknowledges an expired score. * * A stale score cannot be dismissed — only recomputed or acknowledged — and * the acknowledgement is the host's to record. */ onAcknowledge?: (assessment: RiskAssessment) => void; /** * Fired when the reader asks for a fresh score. Without it a stale score says it is stale * and offers nothing to do about it. */ onRecompute?: (assessment: RiskAssessment) => void;}export const RiskIndicator = React.forwardRef<HTMLDivElement, RiskIndicatorProps>( function RiskIndicator( { assessment, now, notADiagnosis, driverCount = 4, density = "default", onOpenModel, onAcknowledge, onRecompute, className, ...rest }, ref, ) { const fresh = freshness(assessment, now); const drivers = topDrivers(assessment.drivers ?? [], driverCount); const dominant = concentration(assessment.drivers ?? []); const scored = assessment.band !== "unknown"; return ( <div {...rest} ref={ref} className={cn("zb-risk", className)} data-zb-risk="" data-zb-band={assessment.band} data-zb-freshness={fresh.state} data-zb-density={density} role="group" aria-label={describeRisk(assessment, now, notADiagnosis, driverCount)} > <div className="zb-risk__head" aria-hidden="true"> <span className="zb-risk__outcome">{assessment.outcome}</span> <ClinicalStatus scale="risk" step={BAND_STEP[assessment.band]} density="compact" aria-hidden="true" /> </div> {scored ? ( <div className="zb-risk__figures" aria-hidden="true"> {/* The numeral is demoted, not hidden. Two decimal places imply a precision the model does not have, so it is rounded to a whole per cent and set below the band rather than beside it. */} {typeof assessment.probability === "number" ? ( <span className="zb-risk__probability"> {Math.round(assessment.probability * 100)} <span className="zb-risk__unit">%</span> </span> ) : null} {/* A percentile is never rendered without the cohort it is a percentile of. "94th percentile" of an unnamed population reads as "94th percentile of people like this patient", which is a claim nobody made. */} {typeof assessment.percentile === "number" && assessment.cohort ? ( <span className="zb-risk__percentile"> {ordinal(assessment.percentile)} pct · {assessment.cohort} </span> ) : null} </div> ) : ( <p className="zb-risk__unscored" aria-hidden="true"> The model could not score this patient. This is not a low score. </p> )} {drivers.length ? <Drivers drivers={drivers} dominant={dominant} /> : null} {/* Staleness on the face, never in a tooltip. Computed nightly, read at noon, after the admission that would have changed it — and nobody hovered. */} {/* Not aria-hidden as a whole: it holds the model button. Hiding a container hides everything focusable inside it, which is both an axe violation and a button nobody can reach. */} <div className="zb-risk__foot"> <span className="zb-risk__age" data-zb-freshness={fresh.state} aria-hidden="true"> {fresh.state === "expired" ? `Expired ${describeAge(fresh.expiredForMs)} ago` : `Computed ${describeAge(fresh.ageMs)} ago`} </span> {assessment.model ? ( onOpenModel ? ( <button type="button" className="zb-risk__model" onClick={() => onOpenModel(assessment)} > {assessment.model.name} {typeof assessment.model.auc === "number" ? ` · AUC ${assessment.model.auc}` : ""} </button> ) : ( <span className="zb-risk__model" data-zb-static=""> {assessment.model.name} {typeof assessment.model.auc === "number" ? ` · AUC ${assessment.model.auc}` : ""} </span> ) ) : null} </div> {/* An expired score offers two ways out and no third. Dismissal is not one of them: a score somebody waved away is a score that stays on the panel looking current. */} {fresh.state === "expired" && (onRecompute || onAcknowledge) ? ( <div className="zb-risk__expired"> {onRecompute ? ( <button type="button" className="zb-risk__action" onClick={() => onRecompute(assessment)} > Recompute </button> ) : null} {onAcknowledge ? ( <button type="button" className="zb-risk__action" data-zb-secondary="" onClick={() => onAcknowledge(assessment)} > Acknowledge as expired </button> ) : null} </div> ) : null} {/* Last on the face and last in the spoken sentence: put first it is boilerplate a reader skips. */} <p className="zb-risk__framing" aria-hidden="true"> {notADiagnosis} </p> </div> ); },);/** * The drivers, with direction and weight. * * Weights are the model's own units and are never normalised across models — * rescaling somebody else's attributions to fit a bar is how a driver * contributing 11.2 and one contributing 0.4 end up looking comparable. The * bar is scaled within *this* set only, which is a comparison the data * supports. */function Drivers({ drivers, dominant }: { drivers: RiskDriver[]; dominant: number | null }) { const widest = Math.max(...drivers.map((d) => Math.abs(d.weight)), 1); const weighted = drivers.some((d) => d.weight !== 0); return ( <div className="zb-risk__drivers" aria-hidden="true"> <p className="zb-risk__drivers-title">Top drivers</p> <ul className="zb-risk__driver-list"> {drivers.map((driver) => ( <li key={driver.label} className="zb-risk__driver" data-zb-direction={driverDirection(driver)} > <span className="zb-risk__driver-label">{driver.label}</span> {weighted ? ( <> <span className="zb-risk__driver-bar"> <span className="zb-risk__driver-fill" style={{ inlineSize: `${(Math.abs(driver.weight) / widest) * 100}%` }} /> </span> <span className="zb-risk__driver-weight"> {driver.weight > 0 ? "+" : ""} {driver.weight} </span> </> ) : ( // `basis` from a FHIR RiskAssessment names references with no // weights. Drawing a bar for them would be inventing one. <span className="zb-risk__driver-weight" data-zb-unweighted=""> contributing </span> )} </li> ))} </ul> {/* The number that says whether this is a synthesis or a proxy. A model whose top driver is most of the total is not modelling a patient; it is reporting one event, and the clinician should know which. */} {dominant !== null && dominant >= 0.5 ? ( <p className="zb-risk__concentration"> {Math.round(dominant * 100)}% of this score comes from one factor. </p> ) : null} </div> );}