fix(labs): keep the printed range on a marker minted from a text result

A report that prints a text result such as "SEE NOTE" with a numeric
range beside it minted the marker without bounds: the document commit,
the scan commit, the free-text lab write and the CSV import each passed
null bounds for a qualitative reading, and the CSV row reader and the
scan review payload dropped the range before that. The marker's first
number then had nothing to be judged against.

Every mint path now passes the printed window. A range that is text
itself yields no bounds, an existing marker keeps its own, a transposed
window is not minted, and the reading itself still records no window.
The scan review shows the range on a text row that mints a new marker.

Refs #1313
This commit is contained in:
Marc-André Bombeck committed 2026-11-05 10:59:52 +01:00
1 parent e9886ee554
commit ef61c7d5d1
13 files changed
+520 -39

No files matched your search

@@ -115,6 +115,27 @@ describe("toCommitRow agrees with validateReviewRow", () => {
it("anchors the date at noon UTC", () => {
expect(toCommitRow(row())?.takenAt).toBe("2026-06-10T12:00:00.000Z");
});
it("sends the range printed beside a text result", () => {
expect(
toCommitRow(
row({
value: null,
valueText: "SEE NOTE",
unit: null,
referenceLow: 10,
referenceHigh: 20,
referenceText: "10 - 20",
biomarkerMatch: "new",
}),
),
).toMatchObject({
valueText: "SEE NOTE",
referenceLow: 10,
referenceHigh: 20,
referenceText: "10 - 20",
});
});
});
describe("collectRowErrors", () => {
@@ -125,6 +125,44 @@ describe("<OcrRowEditor> layout", () => {
});
});
describe("<OcrRowEditor> range beside a text result", () => {
const text: OcrReviewRow = {
...baseRow,
value: null,
valueText: "SEE NOTE",
unit: null,
referenceLow: 10,
referenceHigh: 20,
referenceText: "10 - 20",
};
it("offers the range for review when the row mints a new marker", () => {
const html = render(undefined, "en", { ...text, biomarkerMatch: "new" });
for (const id of ["-lo", "-hi", "-refText"]) {
expect(html, `field ${id}`).toContain(`${id}"`);
}
expect(html).toContain("Reference range taken from the scan");
});
it("does not ask to verify a range a new text marker never had", () => {
const html = render(undefined, "en", {
...text,
biomarkerMatch: "new",
referenceLow: null,
referenceHigh: null,
referenceText: null,
});
expect(html).not.toContain("Verify the reference range");
});
it("leaves it out when the row goes to an existing marker", () => {
const html = render(undefined, "en", text);
for (const id of ["-lo", "-hi", "-refText"]) {
expect(html, `field ${id}`).not.toContain(`${id}"`);
}
});
});
describe("<OcrRowEditor> unit differs from the marker's", () => {
const mismatched: OcrReviewRow = {
...baseRow,
+13 -1
View File
@@ -157,6 +157,9 @@ export function toCommitRow(row: OcrReviewRow): OcrCommitRowInput | null {
analyte,
valueText,
takenAt: takenAt.toISOString(),
// A text result has no window of its own, but a new marker minted from
// it takes the one printed beside it.
...printedRange(row),
...chosen(row),
};
}
@@ -170,10 +173,19 @@ export function toCommitRow(row: OcrReviewRow): OcrCommitRowInput | null {
value: row.value,
unit,
takenAt: takenAt.toISOString(),
...printedRange(row),
...chosen(row),
};
}
/** The reviewed window: the two bounds and the string they were read from. */
function printedRange(
row: OcrReviewRow,
): Pick<OcrCommitRowInput, "referenceLow" | "referenceHigh" | "referenceText"> {
return {
...(row.referenceLow !== null ? { referenceLow: row.referenceLow } : {}),
...(row.referenceHigh !== null ? { referenceHigh: row.referenceHigh } : {}),
...(row.referenceText ? { referenceText: row.referenceText } : {}),
...chosen(row),
};
}
+32 -13
View File
@@ -75,6 +75,33 @@ function unitMismatchMessage(
: ["labs.ocr.errorUnitMismatch", { markerUnit: row.markerUnit ?? "" }];
}
/**
* v1.18.10 (#5) — a NEW biomarker mints its catalog reference range from THIS
* extracted row, so the range is load-bearing and worth a second look. Surface
* the range confidence for a new numeric marker, and call it out when the
* model was unsure (or set no bounds at all) so the user verifies the range it
* will be judged against. A text result ("SEE NOTE") records no window of its
* own, but a new marker minted from it takes the one printed beside it, so the
* range is shown there too, and only called out when there is one: a text
* result often has no numeric range, and that is not a gap.
*/
function rangeReview(row: OcrReviewRow): {
showRange: boolean;
showRangeBadge: boolean;
flagRange: boolean;
} {
const isQualitative = row.valueText !== null && row.valueText !== undefined;
const isNew = row.biomarkerMatch === "new";
const lowRangeConfidence = row.confidence.range < CONFIDENCE_THRESHOLD;
const hasBounds = row.referenceLow !== null || row.referenceHigh !== null;
const showRangeBadge = isNew && (!isQualitative || hasBounds);
return {
showRange: !isQualitative || isNew,
showRangeBadge,
flagRange: showRangeBadge && (lowRangeConfidence || !hasBounds),
};
}
export function OcrRowEditor({
row,
onChange,
@@ -138,15 +165,7 @@ export function OcrRowEditor({
? row.confidence.value < CONFIDENCE_THRESHOLD
: lowValueConfidence);
// v1.18.10 (#5) — a NEW numeric biomarker mints its catalog reference range
// from THIS extracted row. The range is therefore load-bearing and worth a
// second look. Surface the range confidence prominently for new numeric
// markers, and call it out explicitly when the model was unsure (or set no
// bounds at all) so the user verifies the range it will be judged against.
const isNewNumericMarker = !isQualitative && row.biomarkerMatch === "new";
const lowRangeConfidence = row.confidence.range < CONFIDENCE_THRESHOLD;
const hasBounds = row.referenceLow !== null || row.referenceHigh !== null;
const flagRange = isNewNumericMarker && (lowRangeConfidence || !hasBounds);
const { showRange, showRangeBadge, flagRange } = rangeReview(row);
return (
// `@container` makes the row follow the width of the dialog, not the
@@ -353,11 +372,11 @@ export function OcrRowEditor({
</div>
</div>
{/* v1.18.10 (#5) — for a NEW numeric biomarker the reference range below
{/* v1.18.10 (#5) — for a NEW biomarker the reference range below
becomes the marker's catalog range. Make that consequence visible, and
flag low range-confidence / a missing range so the user verifies it
before saving. A calm `secondary` badge, not an alarm. */}
{isNewNumericMarker ? (
{showRangeBadge ? (
<div className="flex flex-wrap items-center gap-1.5">
<Badge variant={flagRange ? "secondary" : "outline"}>
<Ruler aria-hidden />
@@ -368,7 +387,7 @@ export function OcrRowEditor({
</div>
) : null}
{!isQualitative ? (
{showRange ? (
<div className="grid grid-cols-2 gap-2">
<div className="space-y-1">
<Label htmlFor={`${fieldId}-lo`} className="text-xs">
@@ -424,7 +443,7 @@ export function OcrRowEditor({
reading of this string, and correcting the string is how a range the
parser could not read ("bis 5,0", "negativ") still reaches the row
instead of being dropped. */}
{!isQualitative ? (
{showRange ? (
<div className="space-y-1">
<Label htmlFor={`${fieldId}-refText`} className="text-xs">
{t("labs.ocr.refTextLabel")}