mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 13:01:00 +00:00
Range bars and the lab list, detail rows, chart tooltip and reference ranges printed numbers with a plain `String()`, so a German reader saw "1.8 mIU/L" and "61.3 kg" under a German interface. The same was true of the mean, GMI, eA1C and the advanced indices on the glucose panel. `RangeBar` now prints value, bounds and delta through the locale number formatter and takes an optional `formatValue` for surfaces with their own precision. Lab values keep their trim rule (whole numbers bare, at most two decimals) in `formatLabValue`, which now hands the digits to a caller-supplied locale formatter; `useLabNumber` wires it to the reader's locale for every lab surface. Inputs are unchanged.
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
"use client";
|
||
|
||
import { formatReferenceRange } from "@/lib/labs/reference-range";
|
||
import { useTranslations } from "@/lib/i18n/context";
|
||
|
||
import type { LabResultDto } from "./types";
|
||
import { useLabNumber } from "./use-lab-format";
|
||
|
||
/**
|
||
* The reference window a reading's own report printed, shown wherever that
|
||
* reading is shown.
|
||
*
|
||
* Renders nothing for a reading with no printed window — most of them — so it
|
||
* costs no space on the common row. When the report DID state a window it
|
||
* names it, verbatim where the report gave words; and when that window and the
|
||
* catalog band disagree it names the catalog band too. A reader told only
|
||
* "3,9–5,4" and a reader told only "3,5–5,0" draw different conclusions from
|
||
* the same number, so a surface that shows one silently is showing a partial
|
||
* answer.
|
||
*
|
||
* Neutral by construction: no tint, no icon, muted text. The in/out verdict is
|
||
* the badge's job — this element states where the window came from, nothing
|
||
* about whether the value is good news.
|
||
*/
|
||
export function SourceRangeNote({
|
||
reading,
|
||
className,
|
||
}: {
|
||
reading: Pick<
|
||
LabResultDto,
|
||
| "unit"
|
||
| "referenceLow"
|
||
| "referenceHigh"
|
||
| "catalogReferenceLow"
|
||
| "catalogReferenceHigh"
|
||
| "sourceReferenceText"
|
||
| "referenceOrigin"
|
||
| "referenceDivergesFromCatalog"
|
||
>;
|
||
className?: string;
|
||
}) {
|
||
const { t } = useTranslations();
|
||
const labNumber = useLabNumber();
|
||
if (reading.referenceOrigin !== "source") return null;
|
||
|
||
const printed =
|
||
reading.sourceReferenceText ??
|
||
`${formatReferenceRange(
|
||
reading.referenceLow,
|
||
reading.referenceHigh,
|
||
labNumber,
|
||
)} ${reading.unit}`.trim();
|
||
|
||
const catalog = formatReferenceRange(
|
||
reading.catalogReferenceLow,
|
||
reading.catalogReferenceHigh,
|
||
labNumber,
|
||
);
|
||
|
||
return (
|
||
<span className={className}>
|
||
{t("labs.sourceRange.fromReport", { range: printed })}
|
||
{reading.referenceDivergesFromCatalog && catalog
|
||
? ` · ${t("labs.sourceRange.catalogDiffers", {
|
||
range: `${catalog} ${reading.unit}`.trim(),
|
||
})}`
|
||
: null}
|
||
</span>
|
||
);
|
||
}
|