From a822aa5a0efd2300591bbf178697a293312e7276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Mon, 2 Nov 2026 20:31:33 +0100 Subject: [PATCH] fix(documents): send a read that states no unit itself to review A unit of "1" is the explicit no-unit choice a person makes. When a document read returns it on its own, the value is staged for review instead of passing straight through, so a unit the read dropped never lands as a dimensionless value. --- src/lib/documents/__tests__/extract.test.ts | 28 +++++++++++++++++++++ src/lib/documents/extract.ts | 8 +++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/lib/documents/__tests__/extract.test.ts b/src/lib/documents/__tests__/extract.test.ts index a5900338c..a637df428 100644 --- a/src/lib/documents/__tests__/extract.test.ts +++ b/src/lib/documents/__tests__/extract.test.ts @@ -165,6 +165,34 @@ describe("runInboundExtraction — stated-status-only mapping", () => { expect(med.statusStated).toBe("ongoing"); }); + it('sends a confident value the read itself gave no unit ("1") to review', async () => { + const provider = fakeProvider( + JSON.stringify({ + facts: [ + { + type: "OBSERVATION", + label: "CHOL/HDLC RATIO", + value: 4, + unit: "1", + confidence: 0.95, + sourceText: "CHOL/HDLC RATIO 4.0", + }, + { + type: "OBSERVATION", + label: "HDL", + value: 52, + unit: "mg/dL", + confidence: 0.95, + sourceText: "HDL 52 mg/dL", + }, + ], + }), + ); + + const result = await runInboundExtraction(oneRead(provider)); + expect(result.facts.map((f) => f.needsReview)).toEqual([true, false]); + }); + it("stores the document's real span, not the model's echo of it", async () => { // The OCR text says "Hämoglobin 14.2 g/dL"; the model echoes a tidied // rendering of it. The stored provenance must be the document's characters. diff --git a/src/lib/documents/extract.ts b/src/lib/documents/extract.ts index a1660adf5..a21f8eb44 100644 --- a/src/lib/documents/extract.ts +++ b/src/lib/documents/extract.ts @@ -57,6 +57,7 @@ import { type OcrMeter, type OcrReadSurface, } from "@/lib/documents/ocr-read"; +import { isDimensionlessUnit } from "@/lib/labs/dimensionless"; import { annotate } from "@/lib/logging/context"; import { INBOUND_CONFIDENCE_FLOOR, @@ -383,7 +384,12 @@ export async function runInboundExtraction( facts.push({ factType: raw.type, confidence, - needsReview: confidence < INBOUND_CONFIDENCE_FLOOR, + // A unit of "1" is the user's explicit no-unit choice. A read that + // states it itself goes to review rather than straight to the record, + // so a dropped unit never passes as a dimensionless value. + needsReview: + confidence < INBOUND_CONFIDENCE_FLOOR || + (raw.type === "OBSERVATION" && isDimensionlessUnit(raw.unit)), data, provenance: { sourceText: anchor.sourceText,