feat(share): name both reference windows on a diverging lab row

A reading judged against the window its own report printed, beside a
saved band that states different limits, is two answers about one
number. The PDF names both — the range in the column, the saved band in
a footnote under the table — and says in as many words that showing one
of them is a partial answer. The page carried only the first.

Both fit on the value line here, so there is no footnote to place.
Break-proof: force the divergence branch off and the case goes red.
This commit is contained in:
Marc-André Bombeck committed 2026-08-24 01:31:05 +02:00
1 parent b59a78155b
commit a7452c7a6c
2 files changed
+48 -7

No files matched your search

@@ -156,6 +156,37 @@ describe("<ClinicianView>", () => {
expect(html).not.toContain("Current smoker");
});
it("names both windows when a lab's report and the saved band disagree", () => {
// Two windows that disagree about the same number, and a card showing one
// of them is a partial answer. The PDF settles this with a footnote under
// the table; inline, both fit on the line.
const html = render(
makeReport({
labResults: [
{
panel: null,
analyte: "Potassium",
value: 5.2,
valueText: null,
unit: "mmol/L",
referenceLow: 3.9,
referenceHigh: 5.4,
catalogReferenceLow: 3.5,
catalogReferenceHigh: 5,
sourceReferenceText: null,
referenceOrigin: "source",
referenceDivergesFromCatalog: true,
takenAt: "2026-01-20T09:00:00.000Z",
count: 1,
},
],
}),
);
expect(html).toContain("Potassium");
expect(html).toContain("Reference 3.9–5.4");
expect(html).toContain("saved range 3.5–5");
});
it("renders the fenced wellness card with the descriptive disclaimer", () => {
const html = render(makeReport());
expect(html).toContain("Wellness scores");
+17 -7
View File
@@ -69,6 +69,10 @@ export function LabResultsSection({
const reading = qualitative
? lab.valueText
: `${fmtNum(lab.value as number)} ${lab.unit}`.trim();
const range = (low: number | null, high: number | null) =>
formatReferenceRange(low, high, (value) => String(fmtNum(value)), {
emptyText: "",
});
// The window the reading was judged against, printed as the source
// report printed it when that is where it came from, so a clinician
// comparing against the original reads the same characters.
@@ -76,12 +80,15 @@ export function LabResultsSection({
? null
: lab.referenceOrigin === "source" && lab.sourceReferenceText
? lab.sourceReferenceText
: formatReferenceRange(
lab.referenceLow,
lab.referenceHigh,
(value) => String(fmtNum(value)),
{ emptyText: "" },
);
: range(lab.referenceLow, lab.referenceHigh);
// When the report's own window and the saved band disagree about the
// same number, both are named. Showing one of two disagreeing windows
// is a partial answer, and the PDF's footnote says so; here it fits on
// the line rather than under a table.
const catalog =
!qualitative && lab.referenceDivergesFromCatalog
? range(lab.catalogReferenceLow, lab.catalogReferenceHigh)
: "";
return (
<StatRow
key={`${lab.panel ?? ""}-${lab.analyte}`}
@@ -89,7 +96,10 @@ export function LabResultsSection({
value={compose([
reading,
reference
? `${t("doctorReport.labsColReference")} ${reference}`
? `${t("doctorReport.labsColReference")} ${reference}` +
(catalog
? ` (${t("doctorReport.labsCatalogRangeLabel")} ${catalog})`
: "")
: null,
fmtDate(lab.takenAt),
])}