Skip to content

Provenance Chip

Stable

Where a value came from, how it got here, and how much of it a human has actually looked at.

FHIR R4Provenance
13 states9 props16.0 KB installedsince 0.4.0
npx @zoblocks/cli add provenance-chip
View sourceRegistry JSON ↗

Why it exists

A blood pressure typed by a medical assistant, streamed from a home cuff, pulled from an HIE document of unknown vintage, and extracted by a language model from a scanned fax all render as 128/76.

They are not the same fact and they do not support the same decision. As ambient AI and external exchange both scale, the proportion of chart content that no human ever typed is rising fast, and there is no widely used convention for saying so. Two distinctions carry the component. Observed-at is kept separate from recorded-at, because a C-CDA authored in March may carry a reading measured in January and rendering the document's date as the observation's is how a nine-week-old value is acted on as current. And patient-reported is a source class rather than a caveat: self-report is the primary instrument in behavioral health, so a patient-reported PHQ-9 is the correct provenance and rendering it as second-class is its own error — the same class standing in for a blood-pressure measurement is a different matter, and that judgement belongs to the caller.

Provenance
agent[].type and who, entity[].role, recorded and occurredDateTime as two separate fields, and activity. The adapter will not call an authorship an extraction on the strength of the agent type alone.

Playground

Change a prop and watch the component and its code change with it.

Design language
Props
Events
  • onOpenChain, onOpenSpan — nothing yet
Playground.tsx
import { ProvenanceChip } from "@/components/zoblocks/provenance-chip";export default function Example() {  return (    <ProvenanceChip      record={record}      stalenessPolicy={stalenessPolicy}      glyphOnly={false}    />  );}

Examples

The cases worth copying. Open one in StackBlitz to run it with its dependencies installed.

DataobservationPotassiumCriticalprovenanceLateEntrypractitionerSignerdocumentLateEntry

One value, six provenances

observationPotassiumCritical

The same 128/76, six times. Each supports a different decision, and only the affix says which — the clinic reading is actionable, the HIE row carries a document date rather than an observation date, and the extracted row states that nobody has looked at it.

Document vintage is not observation vintage

documentLateEntry

A C-CDA authored on 11 March may carry a reading measured in January. Rendering the document's date as the observation's is how a nine-week-old value is acted on as current, so the two are separate fields and the age is measured from the first.

One subscription, not two hundred requests

provenanceLateEntry

Components never fetch their own provenance. A chart with two hundred values would make two hundred requests and every chip would settle at a different moment, so the host subscribes once and the chips are pure.

Four days differs by datum

practitionerSigner

Four days is nothing for a problem list and a lot for a blood pressure, so the threshold is injected per datum type. Without a policy the chip says nothing about age rather than assuming one — a wrong threshold is worse than no threshold.

Variants

Every variant is the same accessibility contract and the same keyboard model. Pick by what the surface needs.

Default

Glyph, source word and age. The affix a value carries.

glyphOnly=false

Glyph only

For a dense grid where the column is entirely provenance. The word stays in the accessible name.

glyphOnly=true

Installation

Terminal
npx @zoblocks/cli add provenance-chip

First install? Run zoblocks init once to say where your @/ alias points. The source is copied into your repository, along with anything it depends on.

Dependenciesclsxtailwind-merge

Usage

Props are the FHIR resource.

usage.tsx
import { ProvenanceChip, ledgerFrom } from "@/components/zoblocks/provenance-chip";import "@/styles/zoblocks-provenance.css";const ledger = ledgerFrom(records);<ProvenanceChip  resourceId="obs-bp-1"  ledger={ledger}  now={serverTime}  stalenessPolicy={(r) => (r.source === "device" ? 48 * 3600_000 : null)}/>

Use it when

  • Beside any value whose origin changes what a reader should do with it — vitals, medication lists, problem lists, external documents, anything a model produced.
  • With a ledger rather than a record per call site, so every chip on a screen describes the same snapshot.
  • With onOpenSpan wherever extracted values appear. Jumping to the source span is the single most requested behaviour from clinicians reviewing extraction.
  • With a staleness policy per datum type. A shared threshold either screams about every diagnosis or stays silent about every vital.

Avoid it when

  • As a headline. It is an affix; a provenance that competes with the value it qualifies has inverted the reading order.
  • As a quality score. It says where a value came from, not whether it is right — a clinic measurement can be wrong and a patient-reported PHQ-9 is the instrument.
  • Without `now` when age matters. Omitting it renders no age at all, which is honest; a client clock is not.

API

Every prop is typed. Props not listed are forwarded to the root element.

ProvenanceChip

9 props
glyphOnly
boolean
Defaultfalse
Hides the source word, leaving the glyph and the age. For dense grids.
ledger
ProvenanceLedger
Default—
Read from a ledger instead. Components never fetch their own provenance: a chart with two hundred values would make two hundred requests and every chip would settle at a different moment. The host subscribes once and passes this down.
now
string
Default—
ISO 8601, supplied by the host. No relative age is shown without it.
onOpenChain
((record: ProvenanceRecord) => void)
Default—
Opens the chain: the agents, the device, the document, the versions.
onOpenSpan
((span: NonNullable<ProvenanceRecord['span']>, record: ProvenanceRecord) => void)
Default—
Jumps to the span an extracted value was lifted from. The single most requested behaviour from clinicians reviewing extraction, which is why it is its own handler rather than something folded into the chain.
record
ProvenanceRecord
Default—
The record, or a ledger lookup below. One of the two is required.
resourceId
string
Default—
The resource this provenance is about. Used to link back to the record rather than to re-fetch it.
stalenessPolicy
StalenessPolicy
Default—
How old is too old, per kind of datum. Four days differs by datum.
versionId
string
Default—
Which version was seen. Provenance for a value that has since changed is provenance for a different value.

Accessibility

Screen readers and semantics

  • Six shapes, not six colours. Colour would put the source classes on a scale from better to worse, and they are not one. Each class is a CSS glyph in currentColor, so it survives greyscale and forced colours — where colour would have been the only channel, and where colour was never the right channel anyway.
  • The name is the whole sentence. "Source: device, Omron BP7450, unvalidated cuff size, observed 4 d ago, stale." One string, in a fixed order: what kind of source, then who or what, then when, then whether anybody has looked. The confirmation clause is last because it decides whether to act, and a listener remembers the end of a sentence.
  • A span when there is nothing to open. role="img" with a label by default; a real button only when the host supplies a chain. There is one of these beside every value on a chart, so a focusable element with no action is worse here than almost anywhere.
  • Staleness is on the chip, not in the chain. A device reading from four days ago and one from four minutes ago carry different weight, and a reader who has to hover to learn which is a reader who will not. The threshold is injected per datum type: four days is nothing for a problem list and a lot for a blood pressure.
  • Unreviewed is a word, not a dot. An unconfirmed extraction says so in text and in the accessible name. It is not a confidence score — a model can be very confident and wrong — and the fact a reader needs is whether a human has been involved at all.

Conformance · WCAG 2.2 AA · 7 of 8 pass

CriterionStatusHowEvidence
1.4.1Use of colourpassSix CSS glyphs in currentColor rather than six hues, and a test asserts every source class renders a distinct glyph. Staleness and the unreviewed state carry words as well as backgrounds.provenance-chip.test.tsx
1.3.1Info and relationshipspassThe whole provenance is one composed name in a fixed order, with every inner node aria-hidden — so a screen reader hears a sentence rather than five fragments beside a value.provenance-chip.test.tsx
4.1.2Name, role, valuepassrole="img" with a label when static, a real button when a chain is supplied, and the span affordance is its own labelled button.provenance-chip.test.tsx
2.1.1KeyboardpassBoth affordances are native buttons reached and activated by keyboard, with no handler of the component's own.provenance-chip.test.tsx
2.5.8Target sizepassThe chip and the span button hold a 20px box inside a 24px line, and the interactive form is padded to reach the floor without shifting the value beside it.provenance-chip.test.tsx
1.4.11Non-text contrastpassThe glyph is drawn in the inherited text colour, so it meets whatever the surrounding text meets; the two tinted states route through gated status tokens.contrast.gate
1.4.12Text spacingpassAn inline-flex row with no fixed height; increased line-height and letter-spacing grow the chip rather than clipping it.provenance-chip.test.tsx
2.2.1Timing adjustablen/aNo timing. Staleness is computed against a `now` the host supplies.—

Clinical

Every surface where a value's origin changes the decision. Self-report is the primary instrument in behavioral health, so the component distinguishes self-report as the instrument from self-report standing in for a measurement — the same class, two different weights, and the caller's judgement rather than the component's.

Industries
healthcare, behavioral-health
Workflows
documentation, assessment, care-coordination, medication
Terminology
FHIR
Permissions
provenance.read
Audit
Emits AuditEvent

Protected health information

Handles PHI

Names the clinician who observed a value, the organisation that sent it and the document it arrived in. The chain is the disclosive part and it opens on request rather than rendering inline.

Source

Exactly what lands in your repository, read from the published registry so it can never drift from what the CLI installs.

Show source217 lines
provenance-chip.tsx
/** * ProvenanceChip — where a value came from, and how much of it a human has * actually looked at. * *     <ProvenanceChip record={provenance} now={serverTime} /> *     <ProvenanceChip resourceId="obs-1" ledger={ledger} now={serverTime} /> * * An affix, never a headline. It sits beside a value and does not compete with * it, because the value is what the reader came for and the provenance is what * decides whether they can act on it. * * Six source classes, each with a CSS glyph rather than a colour — colour * would put them on a scale from better to worse, and they are not one. A * patient-reported PHQ-9 is the correct provenance for a PHQ-9; the same class * standing in for a blood-pressure measurement is not, and that judgement * belongs to the caller. * * Styling lives in `styles/zoblocks-provenance.css`, installed alongside. */import * as React from "react";import { cn } from "@/lib/utils";import {  SOURCE_GLYPH,  SOURCE_LABEL,  describeAgeShort,  describeProvenance,  staleness,  type ProvenanceLedger,  type ProvenanceRecord,  type StalenessPolicy,} from "@/lib/zoblocks-provenance";export {  SOURCE_GLYPH,  SOURCE_LABEL,  describeAgeShort,  describeProvenance,  fromProvenance,  ledgerFrom,  staleness,  toSource,  type ProvenanceAgent,  type ProvenanceLedger,  type ProvenanceRecord,  type ProvenanceSource,  type Staleness,  type StalenessPolicy,} from "@/lib/zoblocks-provenance";type Base = Omit<React.HTMLAttributes<HTMLElement>, "children">;export interface ProvenanceChipProps extends Base {  /** The record, or a ledger lookup below. One of the two is required. */  record?: ProvenanceRecord;  /**   * Read from a ledger instead.   *   * Components never fetch their own provenance: a chart with two hundred   * values would make two hundred requests and every chip would settle at a   * different moment. The host subscribes once and passes this down.   */  ledger?: ProvenanceLedger;  /**   * The resource this provenance is about. Used to link back to the record rather than to   * re-fetch it.   */  resourceId?: string;  /**   * Which version was seen. Provenance for a value that has since changed is provenance for a   * different value.   */  versionId?: string;  /** ISO 8601, supplied by the host. No relative age is shown without it. */  now?: string;  /** How old is too old, per kind of datum. Four days differs by datum. */  stalenessPolicy?: StalenessPolicy;  /** Hides the source word, leaving the glyph and the age. For dense grids. */  glyphOnly?: boolean;  /** Opens the chain: the agents, the device, the document, the versions. */  onOpenChain?: (record: ProvenanceRecord) => void;  /**   * Jumps to the span an extracted value was lifted from.   *   * The single most requested behaviour from clinicians reviewing extraction,   * which is why it is its own handler rather than something folded into the   * chain.   */  onOpenSpan?: (span: NonNullable<ProvenanceRecord["span"]>, record: ProvenanceRecord) => void;}export const ProvenanceChip = React.forwardRef<HTMLElement, ProvenanceChipProps>(  function ProvenanceChip(    {      record: given,      ledger,      resourceId,      versionId,      now,      stalenessPolicy,      glyphOnly = false,      onOpenChain,      onOpenSpan,      className,      ...rest    },    ref,  ) {    const record = given ?? (resourceId ? ledger?.get(resourceId, versionId) : undefined);    // Nothing rather than a chip claiming an unknown origin. A chip that says    // "unknown" on every value it has no ledger entry for teaches readers to    // ignore the whole column.    if (!record) return null;    const age = now ? staleness(record, now, stalenessPolicy) : { state: "unknown" as const };    // The age is a fact and the staleness judgement is an opinion, so the age    // shows whenever there is a date to measure from and only the highlight    // waits for a policy.    const at = record.observedAt ?? record.recordedAt;    const elapsedMs = now && at ? Date.parse(now) - Date.parse(at) : Number.NaN;    const showAge = Number.isFinite(elapsedMs) && elapsedMs >= 0;    const label = describeProvenance(record, now, stalenessPolicy);    const extracted = record.source === "ai-extracted";    const unconfirmed = extracted && !record.confirmed;    const shared = {      className: cn("zb-prov", className),      "data-zb-provenance": "",      "data-zb-source": record.source,      "data-zb-staleness": age.state,      "data-zb-unconfirmed": unconfirmed ? "" : undefined,      "aria-label": label,      ...rest,    };    const body = (      <>        <span          className="zb-prov__glyph"          data-zb-glyph={SOURCE_GLYPH[record.source]}          aria-hidden="true"        />        {glyphOnly ? null : (          <span className="zb-prov__word" aria-hidden="true">            {SOURCE_LABEL[record.source]}          </span>        )}        {/*          Staleness is folded in rather than kept in the chain. A device          reading from four days ago and one from four minutes ago carry          different weight, and the reader has to see that without hovering.        */}        {showAge ? (          <span className="zb-prov__age" data-zb-staleness={age.state} aria-hidden="true">            {describeAgeShort(elapsedMs)}          </span>        ) : null}        {/*          The confirmation state, for extracted values only.          Absent means the question does not apply; a dot means nobody has          looked, which is a different thing from a low-confidence score.        */}        {unconfirmed ? (          <span className="zb-prov__unconfirmed" aria-hidden="true">            unreviewed          </span>        ) : null}      </>    );    const chip = onOpenChain ? (      <button        {...(shared as React.ButtonHTMLAttributes<HTMLButtonElement>)}        ref={ref as React.Ref<HTMLButtonElement>}        type="button"        onClick={() => onOpenChain(record)}      >        {body}      </button>    ) : (      // A span when there is nothing to open. A focusable element with no      // action is worse here than anywhere: there is one beside every value.      <span        {...(shared as React.HTMLAttributes<HTMLSpanElement>)}        ref={ref as React.Ref<HTMLSpanElement>}        role="img"      >        {body}      </span>    );    if (extracted && record.span && onOpenSpan) {      const span = record.span;      return (        <span className="zb-prov__pair">          {chip}          <button            type="button"            className="zb-prov__span"            onClick={() => onOpenSpan(span, record)}            aria-label={`View the source span: ${span.document}${              typeof span.page === "number" ? `, page ${span.page}` : ""            }`}          >            View span          </button>        </span>      );    }    return chip;  },);