@zenuinebit/lab-reference-ranges
v0.1.0
Published
Flag lab results as low, normal, high or critical against age/sex ranges; common unit conversions.
Readme
@zenuinebit/lab-reference-ranges
Flag lab results as low, normal, high or critical against reference ranges you supply, and convert common units between conventional and SI. No dependencies.
No normal ranges are built in. Ranges differ between labs, methods and populations, so they must come from your lab. A flag is a prompt for a clinician, not a diagnosis.
import { evaluate, flagSymbol, isCritical, convert, type RangeRule } from "@zenuinebit/lab-reference-ranges";
// Your lab's ranges for one test (hemoglobin here is only an example)
const hemoglobin: RangeRule[] = [
{ unit: "g/dL", sex: "M", minAgeYears: 18, low: 13, high: 17, criticalLow: 7 },
{ unit: "g/dL", sex: "F", minAgeYears: 18, low: 12, high: 15, criticalLow: 7 },
{ unit: "g/dL", maxAgeYears: 18, low: 11, high: 16 },
];
const r = evaluate(11.2, hemoglobin, { sex: "F", ageYears: 30 });
r.flag; // "low"
r.display; // "12 - 15 g/dL"
flagSymbol(r.flag); // "L" (LL, L, H, HH on a printed report)
isCritical(r.flag); // false
convert(100, "glucose", "mg/dL", "mmol/L"); // 5.55
convert(1, "creatinine", "mg/dL", "umol/L"); // 88.4How it works
- A rule can be limited by
sexand age (minAgeYearsinclusive,maxAgeYearsexclusive). The most specific matching rule wins; if none fits (including a rule that needs an age the patient does not have), the flag is"unknown". - A value equal to
loworhighis normal. It is critical only when strictly beyondcriticalLow/criticalHigh. - One-sided ranges work:
{ high: 200 }means "< 200". - Conversions: glucose, cholesterol (total/HDL/LDL), triglycerides, creatinine, uric acid, bilirubin, calcium and hemoglobin, between the conventional unit and the SI unit. Results are rounded to 2 decimals unless you pass
digits.
Not included: built-in ranges, calculated values (eGFR, LDL by Friedewald), trend or delta checks, and pregnancy or other special populations. Add rules for those yourself.
