Chart Header
StablePersistent patient context that collapses to a safety bar rather than to a name, and never renders administrative gender beside a dose.
Why it exists
The chart header is the most-read eighty pixels in healthcare software and it is almost always built as a heading.
Three consequences follow. It scrolls away, so the clinician acts with no identity on screen. It shows Patient.gender, which is the wrong field for every clinical decision — the right one is the Sex Parameter for Clinical Use, which is context-specific and can legitimately differ between a medication order and a reference range. And it treats the encounter as a subtitle, when which encounter am I documenting into is the single most common cause of a misfiled note. A subtitle cannot be wrong on purpose; a control can say nothing is selected and mean it.
- Patient
- Identity through PatientBanner. patient-sexParameterForClinicalUse is read with its comment and period; Patient.gender is never read, not even as a fallback.
- Encounter
- Each open encounter becomes one option. Nothing is auto-selected when more than one is open.
- EpisodeOfCare
- status and type give the program; period.start gives the week, and an episode with no start gets no week rather than a guessed one.
Playground
Change a prop and watch the component and its code change with it.
- Penicillin — anaphylaxisconfirmed
- DNR
- Contact precautionsMRSA
- Involuntary holdexpired 09:00
No encounter selected. 3 encounters are open — choose one before documenting.
- onSelectEncounter — nothing yet
import { ChartHeader } from "@/components/zoblocks/chart-header";export default function Example() { return ( <ChartHeader patient={patient} identifiers={[{ kind: "mrn" }, { kind: "nhs" }]} now="2026-08-24T10:00:00Z" safety={safety} encounters={encounters} surface="overview" collapsed={false} /> );}Examples
The cases worth copying. Open one in StackBlitz to run it with its dependencies installed.
DatapatientRoutineencounterRoutineallergyHighRisk
It collapses to the strip, not to the name
patientRoutineForty-four pixels carrying allergies, code status, isolation, fall risk, legal status and alerts. The detail moves behind a disclosure rather than out of the DOM, so a screen-reader user is never worse off than a sighted one.
import { useState } from "react";import { ChartHeader, type SafetyInput } from "@/components/zoblocks/chart-header";import { NOW, patient } from "./_shared/patient";const safety: SafetyInput = { allergies: { label: "Penicillin — anaphylaxis", tone: "critical", detail: "confirmed" }, codeStatus: { label: "DNR" },};export default function CollapseExample() { const [collapsed, setCollapsed] = useState(false); return ( <ChartHeader patient={patient} identifiers={[{ kind: "mrn" }, { kind: "nhs" }]} now={NOW} collapsed={collapsed} onCollapsedChange={setCollapsed} safety={safety} /> );}The sex parameter, with its context — and never the gender
patientRoutineOn an order screen it is shown with what it applies to. On an overview screen it is not shown at all, because out of context it is a demographic wearing a clinical name. Where the surface calls for it and nothing is recorded, the header says so rather than leaving the space that invites somebody to reach for Patient.gender.
import { useState } from "react";import { ChartHeader, resolveSpcu } from "@/components/zoblocks/chart-header";import { NOW, patientWithSpcu as patient } from "./_shared/patient";type Surface = "orders" | "overview";export default function SpcuExample() { const [surface, setSurface] = useState<Surface>("orders"); // "orders" → { value: "female", context: "for medication dosing", recorded: true } // "overview" → null — not a demographic const reading = resolveSpcu(patient, surface); return ( <div className="grid gap-2.5"> <div className="flex gap-2 text-[13px]"> {(["orders", "overview"] as const).map((s) => ( <button key={s} type="button" onClick={() => setSurface(s)} aria-pressed={surface === s} className={surface === s ? "font-semibold" : undefined} > {s === "orders" ? "Orders" : "Overview"} </button> ))} </div> <ChartHeader key={surface} patient={patient} identifiers={[{ kind: "mrn" }, { kind: "nhs" }]} now={NOW} surface={surface} /> <span className="text-xs opacity-60"> {reading ? "Orders: the sex parameter shows, with what it applies to." : "Overview: the same patient, the same field — not shown at all."} </span> </div> );}No encounter selected is a state, not a default
encounterRoutineOne open encounter is chosen, because there is nothing to choose between. Three open encounters are not, because a note filed into an encounter nobody read is the most common misfiling in the building — and a selection that no longer matches an open encounter reverts to none rather than sliding to the first.
import { ChartHeader, type EncounterOption } from "@/components/zoblocks/chart-header";import { NOW, patient } from "./_shared/patient";// Three open encounters: none is chosen for you.// resolveEncounterContext(three)// → { kind: "none", reason: "3 encounters are open — choose one before documenting" }const three: EncounterOption[] = [ { id: "enc-1", label: "Inpatient — Ward 4B", type: "inpatient" }, { id: "enc-2", label: "Outpatient — 24 Aug, 09:00", type: "ambulatory" }, { id: "enc-3", label: "Telehealth — 24 Aug, 14:00", type: "virtual" },];export default function EncounterExample() { return ( <ChartHeader patient={patient} identifiers={[{ kind: "mrn" }, { kind: "nhs" }]} now={NOW} encounters={three} /> );}Two facts are always on the strip, recorded or not
allergyHighRiskAllergy status and code status appear whether or not the host supplied them, because their absence is the finding. Everything else appears only when it exists — an isolation chip on every chart in the hospital is noise, and noise here is what makes the two rows that matter invisible.
import { ChartHeader } from "@/components/zoblocks/chart-header";import { NOW, patient } from "./_shared/patient";// No `safety` supplied. The strip still shows the two facts whose absence is the finding:// safetyStrip({})// → [{ kind: "allergy", label: "Allergies not asked", tone: "absent" },// { kind: "code-status", label: "Code status not recorded", tone: "absent" }]export default function AbsenceExample() { return ( <ChartHeader patient={patient} identifiers={[{ kind: "mrn" }, { kind: "nhs" }]} now={NOW} /> );}Variants
Every variant is the same accessibility contract and the same keyboard model. Pick by what the surface needs.
Expanded
Banner, encounter control, program and the safety strip.
collapsed=false
Collapsed
The 44px strip a clinician must not act without. Everything else is behind a disclosure, not gone.
collapsed=true
Installation
npx @zoblocks/cli add chart-headerFirst 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-merge@zoblocks/identityUsage
Props are the FHIR resource.
import { ChartHeader } from "@/components/zoblocks/chart-header";import "@/styles/zoblocks-chart-header.css";<ChartHeader patient={patient} identifiers={[{ kind: "mrn" }, { kind: "nhs" }]} surface="orders" now={serverTime} encounters={open} selectedEncounterId={encounterId} onSelectEncounter={setEncounterId} safety={{ allergies: { label: "Penicillin — anaphylaxis", tone: "critical" }, codeStatus: { label: "DNR" }, }}> <OrderForm /></ChartHeader>Use it when
- On every chart screen, for the whole session. It is chrome, not a section.
- Wrapping the screen rather than sitting above it — the children render inside the patient context the banner establishes, which is what lets PatientGuard compare a form against the chart on screen.
- With `surface` set to what is actually in view. That is what decides whether the Sex Parameter for Clinical Use appears at all.
- With the safety facts resolved upstream, so the strip states an answer rather than a count.
Avoid it when
- As a page title. A heading scrolls away; this is the thing that must not.
- With `Patient.gender` mapped into the SPCU slot. They are different fields and the whole point of the second one is that the first was being misused.
- With an encounter auto-selected when several are open. Picking one for the user is picking where the note lands.
- Collapsed by default. The first render of a chart is the one where identity matters most.
API
Every prop is typed. Props not listed are forwarded to the root element.
ChartHeader
15 props15 props
identifiersrequiredTwoOrMore<IdentifierSpec>- Default
— - Two, enforced by the type — this is NPSG.01.01.01 in the signature rather than in a review comment.
patientrequiredPatient- Default
— - The patient this chart belongs to. `Patient.gender` is deliberately not rendered — it is administrative gender, and a bare “M” beside a dose is a prescriber reading the wrong reference range.
actionsReact.ReactNode- Default
— - Rendered at the end of the expanded row. Actions belong to the application.
childrenReact.ReactNode- Default
— - The screen, rendered inside the patient context the banner establishes. This is what lets `PatientGuard` compare a form against the chart on screen — the header is not a decoration above the content, it is the statement the content is made under.
classNamestring- Default
— - Applied to the header element.
collapsedboolean- Default
false - Start collapsed. Uncontrolled by design: the host owns the scroll sentinel because only the host knows what its scroll container is, and an IntersectionObserver wired to the wrong ancestor is worse than none.
encountersreadonly EncounterOption[]- Default
[] - Every encounter open for this patient. One is selected by the caller.
nowstring- Default
— - ISO 8601, supplied by the host. Decides whether a dated fact has lapsed.
onCollapsedChange((collapsed: boolean) => void)- Default
— - Fired when the header collapses to its safety strip or expands again. Content moves behind a disclosure rather than out of the DOM.
onSelectEncounter((id: string | undefined) => void)- Default
— - Switching encounter is a deliberate act, and the host re-guards every open form on the far side of it.
Page 1 of 2
Accessibility
Screen readers and semantics
- Collapse hides nothing from the accessibility tree. The expanded content moves behind a disclosure rather than out of the DOM, so a screen-reader user is never worse off than a sighted one. A test asserts the toggle's aria-expanded and aria-controls agree with the region's hidden state in both heights.
- Focus never lands behind the sticky bar. Everything below the header carries a scroll margin the height of the expanded bar (WCAG 2.4.11). A focus ring hidden under sticky chrome is the most common way a keyboard user loses their place in a long chart.
- The strip is one spoken statement. The banner landmark's accessible name is the whole safety strip in reading order, so a screen-reader user hears the six facts as a sentence rather than as six unlabelled chips.
- Absence is drawn as well as spoken. "Allergies not asked" is a dashed border and an italic label, not a missing chip. A blank space where an allergy status should be is the state that gets prescribed against, and it is the only one with no visual weight at all.
- Tone never carries a fact on its own. Each fact is a word plus a 3px bar. Remove the colour and the strip is unchanged in content — which matters here more than on most components, because this is the row read at a glance from two metres away.
- The encounter control keeps its place in the tab order. A header with no change handler renders the encounter as static text rather than as a disabled select. A disabled control leaves the tab order, so a keyboard user could not reach the one fact that says where their note is going.
Conformance · WCAG 2.2 AA · 8 of 8 pass
| Criterion | Status | How | Evidence |
|---|---|---|---|
| 1.3.1Info and relationships | pass | The strip is a list with an accessible name, each fact is a list item, and the disclosure is a button with aria-expanded and aria-controls pointing at the region it governs. | chart-header.test.tsx |
| 2.4.11Focus not obscured (minimum) | pass | Content below the sticky header carries a scroll margin the height of the expanded bar, so a focused element is never rendered behind it. | chart-header.test.tsx |
| 4.1.2Name, role, value | pass | role="banner" carrying the safety strip as its name; the encounter is a labelled select, or static text when the host supplies no handler rather than a disabled control. | chart-header.test.tsx |
| 1.4.1Use of colour | pass | Every safety fact is a word before it is a tone, and the tone is a 3px bar rather than a fill. A test asserts the collapsed and expanded strips carry identical text — they differ in how they fit, never in what they say. | chart-header.test.tsx |
| 4.1.3Status messages | pass | The "no encounter selected" reason is role="status", because it changes as encounters open and close and the difference decides what the clinician does next. | chart-header.test.tsx |
| 2.1.1Keyboard | pass | The disclosure is a native button and the encounter is a native select. Nothing is a div with a click handler and nothing traps focus. | chart-header.test.tsx |
| 2.5.8Target size (minimum) | pass | The toggle and the encounter select both carry a 28px minimum block size, above the 24px floor. | chart-header.test.tsx |
| 1.4.10Reflow | pass | Expanded, the strip wraps, so a patient with four alerts has none of them clipped. Collapsed, it scrolls behind a visible fade instead, because a second line there would move the content underneath at the moment the alerts are being read. | chart-header.test.tsx |
Clinical
Carries the fields behavioral health needs in a header and nowhere else: the program and the week (IOP, week 3 of 8), the legal status with its expiry, and the safety facts that must survive a collapse. The week is what decides whether today's session is a mid-course review or a discharge plan.
- Industries
- healthcare, behavioral-health
- Workflows
- documentation, medication, care-coordination, intake
- Terminology
- FHIR, SNOMED CT
- Permissions
- patient.read, encounter.read
- Audit
- Emits no AuditEvent
Protected health information
Handles PHI
The most PHI-dense element on any chart screen, and the one most likely to be in a screenshot. It is also sticky, so it is on screen during every screen share.
Source
Exactly what lands in your repository, read from the published registry so it can never drift from what the CLI installs.
Show sourceHide source379 lines
"use client";/** * ChartHeader — patient context that collapses to a safety bar, not to a name. * * <ChartHeader * patient={patient} * identifiers={[{ kind: "mrn" }, { kind: "nhs" }]} * surface="orders" * encounters={open} * selectedEncounterId={encounterId} * onSelectEncounter={setEncounterId} * safety={{ allergies: { label: "Penicillin — anaphylaxis", tone: "critical" } }} * > * <OrderForm /> * </ChartHeader> * * The workspace chrome over `PatientBanner`, which is the safety control: two * identifiers before a care action, enforced by the type. This adds the three * things a header needs that a banner does not — it is always there, it knows * which encounter you are documenting into, and it degrades to the strip you * must not act without rather than to a heading. * * Three rules are load-bearing. * * Collapse hides nothing. The expanded content moves behind a disclosure * rather than out of the DOM, so a screen-reader user is never worse off * than a sighted one, and focus never lands behind the sticky element. * * The encounter is a control, not a subtitle. "No encounter selected" is a * state it will sit in rather than pick for you, because a note filed into * an encounter nobody chose is the most common misfiling in the building. * * `Patient.gender` never appears. On an order or a result screen the header * shows the Sex Parameter for Clinical Use with the context it applies to, * and says "not recorded" when there is none. * * Styling lives in `styles/zoblocks-chart-header.css`, installed alongside. */import * as React from "react";import { PatientBanner, type IdentifierSpec, type PatientBannerProps, type TwoOrMore,} from "@zoblocks/identity";import { cn } from "@/lib/utils";import { clockTime } from "@/lib/zoblocks-clock";import { SAFETY_ORDER, describeEncounterContext, describeProgram, describeSafety, describeSpcu, hasExpired, resolveEncounterContext, resolveSpcu, safetyStrip, type ChartSurface, type EncounterOption, type Program, type SafetyInput,} from "@/lib/zoblocks-chart-header";export { EXT_SPCU, SAFETY_ORDER, SPCU_SURFACES, describeEncounterContext, describeProgram, describeSafety, describeSpcu, hasExpired, programFromEpisode, resolveEncounterContext, resolveSpcu, safetyStrip, type ChartSurface, type EncounterContext, type EncounterOption, type Program, type SafetyFact, type SafetyInput, type SafetyKind, type SafetyTone, type SpcuReading,} from "@/lib/zoblocks-chart-header";/** * The FHIR `Patient` the banner accepts, taken from the banner rather than * re-declared. A registry component that redeclares a resource shape is one * upstream field away from disagreeing with the thing it renders. */type BannerPatient = NonNullable<PatientBannerProps["patient"]>;export interface ChartHeaderProps { /** * The patient this chart belongs to. `Patient.gender` is deliberately not rendered — it is * administrative gender, and a bare “M” beside a dose is a prescriber reading the wrong * reference range. */ patient: BannerPatient; /** * Two, enforced by the type — this is NPSG.01.01.01 in the signature rather * than in a review comment. */ identifiers: TwoOrMore<IdentifierSpec>; /** * What the clinician has in view. Decides whether the Sex Parameter for * Clinical Use appears at all. */ surface?: ChartSurface; /** ISO 8601, supplied by the host. Decides whether a dated fact has lapsed. */ now?: string; /** Every encounter open for this patient. One is selected by the caller. */ encounters?: readonly EncounterOption[]; /** Which encounter is in view, controlled. */ selectedEncounterId?: string; /** * Switching encounter is a deliberate act, and the host re-guards every open * form on the far side of it. */ onSelectEncounter?: (id: string | undefined) => void; /** * The banner facts, in the fixed house order: allergies, code status, isolation, legal * status. Same order on every chart in the building, because a reader scans position before * words. */ safety?: SafetyInput; /** The care programme and where the patient is in it, e.g. IOP week 3 of 8. */ program?: Program; /** Where the patient physically is. Shown because the answer changes who can act. */ ward?: string; /** Rendered at the end of the expanded row. Actions belong to the application. */ actions?: React.ReactNode; /** * Start collapsed. * * Uncontrolled by design: the host owns the scroll sentinel because only the * host knows what its scroll container is, and an IntersectionObserver wired * to the wrong ancestor is worse than none. */ collapsed?: boolean; /** * Fired when the header collapses to its safety strip or expands again. Content moves behind * a disclosure rather than out of the DOM. */ onCollapsedChange?: (collapsed: boolean) => void; /** Applied to the header element. */ className?: string; /** * The screen, rendered inside the patient context the banner establishes. * * This is what lets `PatientGuard` compare a form against the chart on * screen — the header is not a decoration above the content, it is the * statement the content is made under. */ children?: React.ReactNode;}/* ------------------------------------------------------------------ *//* The strip *//* ------------------------------------------------------------------ *//** * The 44px bar. * * Memoised on its own inputs. A chart header re-renders whenever anything on * the page changes, and this is the part that must not: it is read * continuously and re-rendering it moves nothing but costs a frame on every * vitals refresh. */const SafetyStrip = React.memo(function SafetyStrip({ safety, now, scrollable,}: { safety: SafetyInput; now?: string; /** * True when the strip is the collapsed one, which scrolls sideways. * * A scrollable region has to be reachable by keyboard or its content is * unreachable to anyone not using a pointer — WCAG 2.1.1, and axe's * `scrollable-region-focusable` caught it on the first audit after this * component landed. The expanded strip wraps instead of scrolling, so it * needs no tab stop and does not get one: an extra stop on the most-read * eighty pixels of the screen is a cost, and paying it twice buys nothing. */ scrollable: boolean;}) { const facts = React.useMemo(() => safetyStrip(safety), [safety]); return ( <ul className="zb-chart-header__strip" aria-label="Safety" {...(scrollable ? { tabIndex: 0 } : {})} > {facts .slice() .sort((a, b) => SAFETY_ORDER.indexOf(a.kind) - SAFETY_ORDER.indexOf(b.kind)) .map((fact, index) => { const expired = hasExpired(fact, now); return ( <li key={`${fact.kind}-${index}`} className="zb-chart-header__fact" data-zb-kind={fact.kind} data-zb-tone={expired ? "critical" : fact.tone} data-zb-expired={expired ? "" : undefined} > <span className="zb-chart-header__fact-label">{fact.label}</span> {fact.detail ? ( <span className="zb-chart-header__fact-detail">{fact.detail}</span> ) : null} {/* An expired hold is shown as expired rather than removed. Dropping it the moment it lapses is how somebody finds out at 02:00 that the legal basis for an admission ended at 20:00. */} {fact.until ? ( <span className="zb-chart-header__fact-until"> {expired ? "expired" : "until"} {clockTime(fact.until, now)} </span> ) : null} </li> ); })} </ul> );});/* ------------------------------------------------------------------ *//* The header *//* ------------------------------------------------------------------ */export function ChartHeader({ patient, identifiers, surface = "overview", now, encounters = [], selectedEncounterId, onSelectEncounter, safety = {}, program, ward, actions, collapsed = false, onCollapsedChange, className, children,}: ChartHeaderProps) { const detailId = React.useId(); const context = resolveEncounterContext(encounters, selectedEncounterId); const spcu = resolveSpcu(patient, surface, now); const facts = React.useMemo(() => safetyStrip(safety), [safety]); return ( <div className={cn("zb-chart-header", className)} data-zb-chart-header=""> <header className="zb-chart-header__bar" data-zb-collapsed={collapsed ? "" : undefined} data-zb-surface={surface} // A banner landmark, so "skip to the patient" is a thing a screen // reader can offer without the application inventing it. role="banner" aria-label={describeSafety(facts, now)} > {/* The strip is outside the disclosure on purpose. It is the one part that must be readable in both heights, and moving it in and out of the tree at 44px would be the exact failure the collapse exists to avoid. */} <div className="zb-chart-header__persistent"> <button type="button" className="zb-chart-header__toggle" aria-expanded={!collapsed} aria-controls={detailId} onClick={() => onCollapsedChange?.(!collapsed)} > {collapsed ? "Show patient details" : "Collapse"} </button> <SafetyStrip safety={safety} now={now} scrollable={collapsed} /> </div> {/* Hidden with `hidden`, not unmounted. Collapse moves content behind a disclosure so a screen-reader user is never worse off than a sighted one — and, just as importantly, focus can never land on something scrolled behind the sticky bar. */} <div id={detailId} className="zb-chart-header__detail" hidden={collapsed}> <PatientBanner context="action" patient={patient} identifiers={identifiers} {...(ward ? { ward } : {})} {...(actions ? { actions } : {})} /> <div className="zb-chart-header__context"> {/* The encounter is a control. A subtitle cannot be wrong on purpose, and this one has to be able to say "nothing is selected" and mean it. */} {onSelectEncounter ? ( <label className="zb-chart-header__encounter"> <span className="zb-chart-header__encounter-label">Documenting into</span> <select className="zb-chart-header__encounter-select" data-zb-encounter={context.kind} value={context.kind === "selected" ? context.encounter.id : ""} onChange={(event) => onSelectEncounter(event.target.value || undefined)} > <option value="">No encounter selected</option> {encounters.map((encounter) => ( <option key={encounter.id} value={encounter.id}> {encounter.label} </option> ))} </select> </label> ) : ( // Read-only rather than a disabled control: a disabled select // leaves the tab order, so a keyboard user cannot reach the one // fact that says where their note is going. <p className="zb-chart-header__encounter" data-zb-encounter={context.kind}> <span className="zb-chart-header__encounter-label">Documenting into</span> <span className="zb-chart-header__encounter-value"> {context.kind === "selected" ? context.encounter.label : "No encounter selected"} </span> </p> )} {/* Announced, because the reason changes as encounters open and close and the difference between "none open" and "three open, choose one" decides what the clinician does next. */} {context.kind === "none" ? ( <p className="zb-chart-header__encounter-reason" role="status"> {describeEncounterContext(context)} </p> ) : null} {program ? ( <p className="zb-chart-header__program">{describeProgram(program)}</p> ) : null} {/* Only on an order or a result screen, and always with its context. Everywhere else this field is a demographic wearing a clinical name, which is what it was invented to replace. */} {spcu ? ( <p className="zb-chart-header__spcu" data-zb-recorded={spcu.recorded ? "" : undefined} > {describeSpcu(spcu)} </p> ) : null} </div> </div> </header> {children} </div> );}ChartHeader.displayName = "ChartHeader";