mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 22:02:16 +00:00
A converted reading's bounds move with its value, but the printed range text stays in the unit the report used, and every reader preferred that text: the list showed "Report range 3.9 to 5.5" beside 100.9 mg/dL, and the doctor report and the FHIR referenceRange.text did the same. The text is still stored verbatim. The range resolver now takes the reading's sourceUnit (as a required field, so no reader can forget to select it) and, for a converted reading, leaves the window's text empty so every surface states the converted bounds in the marker's unit, and hands the printed text over separately with its unit. The lab DTO carries it as printedReferenceText, and the note beside a reading shows it as "as printed in mmol/L: ...".
74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
import { renderToStaticMarkup } from "react-dom/server";
|
||
import { describe, expect, it } from "vitest";
|
||
|
||
import { I18nProvider } from "@/lib/i18n/context";
|
||
|
||
import { SourceRangeNote } from "../source-range-note";
|
||
|
||
type Reading = Parameters<typeof SourceRangeNote>[0]["reading"];
|
||
|
||
function render(reading: Reading) {
|
||
return renderToStaticMarkup(
|
||
<I18nProvider initialLocale="en">
|
||
<SourceRangeNote reading={reading} />
|
||
</I18nProvider>,
|
||
);
|
||
}
|
||
|
||
const STATED: Reading = {
|
||
unit: "mg/dL",
|
||
referenceLow: 70,
|
||
referenceHigh: 99,
|
||
catalogReferenceLow: 70,
|
||
catalogReferenceHigh: 99,
|
||
sourceReferenceText: "70 - 99",
|
||
printedReferenceText: null,
|
||
sourceUnit: null,
|
||
referenceOrigin: "source",
|
||
referenceDivergesFromCatalog: false,
|
||
};
|
||
|
||
// 5.6 mmol/L stored as 100.9 mg/dL, with the report's 3.9 to 5.5 mmol/L window
|
||
// converted alongside it.
|
||
const CONVERTED: Reading = {
|
||
unit: "mg/dL",
|
||
referenceLow: 70.27,
|
||
referenceHigh: 99.1,
|
||
catalogReferenceLow: 70,
|
||
catalogReferenceHigh: 100,
|
||
sourceReferenceText: null,
|
||
printedReferenceText: "3.9 - 5.5",
|
||
sourceUnit: "mmol/L",
|
||
referenceOrigin: "source",
|
||
referenceDivergesFromCatalog: true,
|
||
};
|
||
|
||
describe("<SourceRangeNote>", () => {
|
||
it("names a stated reading's window verbatim", () => {
|
||
const html = render(STATED);
|
||
expect(html).toContain("Report range 70 - 99");
|
||
expect(html).not.toContain("as printed");
|
||
});
|
||
|
||
it("states a converted reading's window in the marker's unit", () => {
|
||
const html = render(CONVERTED);
|
||
expect(html).toContain("Report range 70.27–99.1 mg/dL");
|
||
});
|
||
|
||
it("keeps the printed text as evidence, labelled with the unit it is in", () => {
|
||
const html = render(CONVERTED);
|
||
expect(html).toContain("as printed in mmol/L: 3.9 - 5.5");
|
||
});
|
||
|
||
it("never puts the printed numbers in the statement about the stored unit", () => {
|
||
const html = render(CONVERTED);
|
||
// The window in force is followed by the marker's unit, not the printed text.
|
||
expect(html).not.toContain("Report range 3.9 - 5.5");
|
||
expect(html).toContain("your range 70–100 mg/dL");
|
||
});
|
||
|
||
it("renders nothing when the window in force is not the report's", () => {
|
||
expect(render({ ...CONVERTED, referenceOrigin: "catalog" })).toBe("");
|
||
});
|
||
});
|