Merge remote-tracking branch 'origin/main' into wip/v140-E

This commit is contained in:
Marc-André Bombeck committed 2026-10-03 18:56:39 +02:00
commit f3ccc809a8
28 files changed
+891 -38

No files matched your search

@@ -12,6 +12,7 @@ import {
handleFilePickerChange,
OcrPageCoverageNote,
OcrReviewDialog,
unitSkippedAnalytes,
} from "../ocr-review-dialog";
const hookState = vi.hoisted(() => ({ extractPending: false }));
@@ -223,3 +224,40 @@ describe("<OcrPageCoverageNote> — a long PDF read from its first pages", () =>
expect(html).toBe("");
});
});
describe("unitSkippedAnalytes", () => {
const unit = (analyte: string) => ({
analyte,
reason: "unit_mismatch" as const,
});
it("is null when nothing was skipped for a unit", () => {
expect(unitSkippedAnalytes([])).toBeNull();
expect(
unitSkippedAnalytes([{ analyte: "LDL", reason: "duplicate" }]),
).toBeNull();
});
it("names the analytes skipped for a unit, ignoring duplicates", () => {
expect(
unitSkippedAnalytes([
{ analyte: "LDL", reason: "duplicate" },
unit("Glucose"),
unit("Creatinine"),
]),
).toBe("Glucose, Creatinine");
});
it("lists three and counts the rest, once each", () => {
expect(
unitSkippedAnalytes([
unit("A"),
unit("A"),
unit("B"),
unit("C"),
unit("D"),
unit("E"),
]),
).toBe("A, B, C +2");
});
});
@@ -1,9 +1,11 @@
import { describe, expect, it } from "vitest";
import type { OcrReviewRow } from "../ocr-review-types";
import { seedReviewRows } from "../ocr-review-types";
import {
collectRowErrors,
planSave,
readingUnitDiffers,
toCommitRow,
validateReviewRow,
} from "../ocr-review-validation";
@@ -21,6 +23,7 @@ function row(overrides: Partial<OcrReviewRow> = {}): OcrReviewRow {
takenAt: "2026-06-10",
confidence: { analyte: 1, value: 1, unit: 1, range: 1 },
biomarkerMatch: "existing",
markerUnit: "mmol/L",
duplicateOf: null,
confirmed: true,
...overrides,
@@ -140,3 +143,72 @@ describe("planSave", () => {
}
});
});
describe("a reading in another unit than its marker's", () => {
it.each([
["the same unit", { unit: "mmol/L" }, false],
["the same unit, spelled differently", { unit: "mmol/l" }, false],
["a different unit", { unit: "mg/dL" }, true],
["a different magnitude of the same substance", { unit: "µmol/L" }, true],
["a new marker (no unit yet)", { unit: "mg/dL", markerUnit: null }, false],
["no unit stated", { unit: "", markerUnit: "mmol/L" }, false],
[
"a qualitative result",
{ value: null, valueText: "negative", unit: "mg/dL" },
false,
],
] as const)("%s → differs: %s", (_name, overrides, differs) => {
expect(readingUnitDiffers(row(overrides))).toBe(differs);
});
it("is a blocking error on the unit field, distinct from a missing unit", () => {
expect(validateReviewRow(row({ unit: "mg/dL" }))).toEqual({
unitMismatch: true,
});
expect(validateReviewRow(row({ unit: "" }))).toEqual({ unit: true });
});
it("cannot be turned into a payload, whatever its other fields say", () => {
expect(toCommitRow(row({ unit: "mg/dL" }))).toBeNull();
expect(toCommitRow(row({ unit: "mmol/l" }))?.unit).toBe("mmol/l");
});
it("blocks the whole save when it is selected, and not when it is not", () => {
expect(
planSave([row({ key: "a" }), row({ key: "b", unit: "mg/dL" })]),
).toEqual({ kind: "blocked" });
const plan = planSave([
row({ key: "a" }),
row({ key: "b", unit: "mg/dL", confirmed: false }),
]);
expect(plan.kind).toBe("ready");
expect(
collectRowErrors([row({ unit: "mg/dL", confirmed: false })]).size,
).toBe(0);
});
it("starts unselected on the review screen, like a duplicate, so it is a choice", () => {
const dto = (unit: string, markerUnit: string | null) => ({
analyte: "Glucose",
value: 5.6,
valueText: null,
unit,
referenceLow: null,
referenceHigh: null,
referenceText: null,
takenAt: "2026-06-10",
confidence: { analyte: 1, value: 1, unit: 1, range: 1 },
biomarkerMatch: "existing" as const,
markerUnit,
duplicateOf: null,
});
const [same, other, fresh] = seedReviewRows(
[dto("mmol/L", "mmol/L"), dto("mmol/L", "mg/dL"), dto("mmol/L", null)],
null,
);
expect(same.confirmed).toBe(true);
expect(other.confirmed).toBe(false);
expect(other.markerUnit).toBe("mg/dL");
expect(fresh.confirmed).toBe(true);
});
});
@@ -18,6 +18,7 @@ const baseRow: OcrReviewRow = {
takenAt: null,
confidence: { analyte: 1, value: 1, unit: 1, range: 1 },
biomarkerMatch: "existing",
markerUnit: "mmol/L",
duplicateOf: null,
confirmed: true,
};
@@ -115,3 +116,42 @@ describe("<OcrRowEditor> layout", () => {
}
});
});
describe("<OcrRowEditor> unit differs from the marker's", () => {
const mismatched: OcrReviewRow = {
...baseRow,
takenAt: "2026-06-10",
unit: "mg/dL",
markerUnit: "mmol/L",
};
it("says so before any save attempt, in calm wording", () => {
const html = render(undefined, "en", mismatched);
expect(html).toContain("Tracked in mmol/L; this report says mg/dL");
expect(html).not.toContain('aria-invalid="true"');
expect(html).not.toContain('role="alert"');
});
it("marks the unit field and names the marker's unit once a save was refused", () => {
const html = render({ unitMismatch: true }, "en", mismatched);
const invalid = html.match(/<input[^>]*aria-invalid="true"[^>]*>/g) ?? [];
expect(invalid).toHaveLength(1);
expect(invalid[0]).toMatch(/id="[^"]*-unit"/);
expect(html).toContain("This marker is tracked in mmol/L.");
});
it("shows nothing when the units agree, however they are spelled", () => {
const html = render(undefined, "en", { ...mismatched, unit: "mmol/l" });
expect(html).not.toContain("Tracked in");
});
it("shows nothing for a new marker, which adopts the row's unit", () => {
const html = render(undefined, "en", { ...mismatched, markerUnit: null });
expect(html).not.toContain("Tracked in");
});
it("speaks German too", () => {
const html = render(undefined, "de", mismatched);
expect(html).toContain("Geführt in mmol/L; dieser Befund nennt mg/dL");
});
});