mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
The doctor report PDF printed lab values and reference ranges with one decimal and the share page with two at most, so a PSA of 0.034 read 0.0 or 0.03 and a TSH window of 0.27 read 0.3, while the labs page kept more. The labs page itself cut values above 1 to two decimals. One rule now decides every recorded number (src/lib/format/recorded-number): a stored value keeps every digit it holds, minus binary float noise, and a value converted from the unit its report printed keeps the precision of the printed figure. The report payload carries sourceValue for that. The labs page, its chart and history, the PDF lab table and footnote, the share page, the day view and the OCR review all print through it, reference bounds included. Doses on the PDF and the share page follow the same rule. Measurement statistics in the PDF and on the share page now share one per-row precision: up to three significant digits but never more decimals than recorded, so a waist-to-height ratio of 0.52 no longer reads 0.5; glucose keeps its unit's precision. Refs #1228
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
/**
|
|
* Shared lab-value number formatting.
|
|
*
|
|
* Every surface that prints a lab reading (the list card, the detail history,
|
|
* the chart tooltip, the doctor report PDF, the clinician share page) prints
|
|
* it through here, so a reading reads the same everywhere. The precision rule
|
|
* is the recorded-number rule in `src/lib/format/recorded-number.ts`: a
|
|
* reading keeps every digit it was stored with (TSH 0.004, PSA 0.034, a
|
|
* troponin of 0.0012 never shortened), and a reading converted from the unit
|
|
* its report printed keeps the precision of the printed figure.
|
|
*
|
|
* The digits themselves come from the caller's locale number formatter, so a
|
|
* German reader sees "1,8 mIU/L" where an English one sees "1.8 mIU/L". This
|
|
* module only decides the precision.
|
|
*/
|
|
import {
|
|
formatRecordedNumber,
|
|
type FractionDigitsFormat,
|
|
} from "@/lib/format/recorded-number";
|
|
|
|
/**
|
|
* A lab number in the reader's locale. `printed` is the figure the source
|
|
* report printed when the number was converted from it (`sourceValue`).
|
|
*/
|
|
export type LabNumberFormat = (
|
|
value: number,
|
|
printed?: number | null,
|
|
) => string;
|
|
|
|
export function formatLabValue(
|
|
value: number,
|
|
formatNumber: FractionDigitsFormat,
|
|
printed?: number | null,
|
|
): string {
|
|
return formatRecordedNumber(value, formatNumber, printed);
|
|
}
|
|
|
|
/**
|
|
* Render a reading's display value: a qualitative row (numeric `value` is
|
|
* null) shows its `valueText` verbatim; a numeric row shows the formatted
|
|
* number plus its unit. One helper so the list card, the history rows, and
|
|
* the detail header stay consistent.
|
|
*/
|
|
export function formatLabReading(
|
|
reading: {
|
|
value: number | null;
|
|
valueText: string | null;
|
|
unit: string;
|
|
sourceValue?: number | null;
|
|
},
|
|
formatNumber: LabNumberFormat,
|
|
): string {
|
|
if (reading.value === null) {
|
|
return reading.valueText ?? "";
|
|
}
|
|
return `${formatNumber(reading.value, reading.sourceValue)} ${reading.unit}`.trim();
|
|
}
|