Skip to content

Reference ranges

Flags a value low, high or critical against its reference range, and prints the range as a report does.

Flag
High
Reference range
3.5–5.1 mmol/L

A common adult range for illustration. Use the range your laboratory reports.

Installation

bunx shadcn@4.22.1 add https://organui.com/r/reference-ranges.json

This adds lib/reference-ranges.ts, with no dependencies.

Usage

import {
  flagValue,
  formatReferenceRange,
  rangeFlagLabels,
} from "@/lib/reference-ranges"

const potassium = { low: 3.5, high: 5.1, criticalHigh: 6 }

flagValue(6.4, potassium) // "critical-high"
rangeFlagLabels[flagValue(5.5, potassium)] // "High"
formatReferenceRange(potassium, 1) // "3.5–5.1"

API Reference

Reference ranges exports
ExportDescription
flagValue(value, range)critical-low, low, normal, high or critical-high, checking critical limits first. Text values and ranges without limits are unflagged.
formatReferenceRange(range, decimals?)The range as a report prints it: "70–99", "≤ 200", "≥ 60", or the range's own text.
rangeFlagLabelsA label for each flag, such as "Critical high".
ReferenceRangelow and high, inclusive; criticalLow and criticalHigh; and text, shown instead of the numbers.

Notes

Limits are inclusive: a value equal to low or high is normal.

Use the ranges your laboratory reports. The lab results table uses this file for its flags.