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.
This commit is contained in:
Marc-André Bombeck committed 2026-11-02 20:31:33 +01:00
1 parent 2c6fb82326
commit a822aa5a0e
2 files changed
+35 -1

No files matched your search

@@ -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.
+7 -1
View File
@@ -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,