fix(labs): word a value without a unit the same on every remaining surface

The briefing's lab input passed the stored "1" to the model, the unit
mismatch refusal read "is in 1", and the trend card left a gap where a
language puts the unit before a particle. get_labs says that a value
without a unit has an empty unit, and a lab link id is scrubbed like its
label. The review row is back at its baseline length.
This commit is contained in:
Marc-André Bombeck committed 2026-11-02 20:52:18 +01:00
1 parent 6a8ac98613
commit 49a0eb92ff
9 files changed
+48 -18

No files matched your search

+18 -1
View File
@@ -17,6 +17,7 @@ import { withIdempotency } from "@/lib/idempotency";
import { enqueueReminderSatisfy } from "@/lib/jobs/reminder-satisfy";
import { emitDataArrival } from "@/lib/arrivals/emit-shared";
import { resolveOrMintBiomarker } from "@/lib/labs/biomarker-store";
import { isDimensionlessUnit } from "@/lib/labs/dimensionless";
import { readingInMarkerUnit } from "@/lib/labs/reading-conversion";
import {
type ResolvedBiomarker,
@@ -270,7 +271,7 @@ async function postLabResult(request: NextRequest) {
meta: { biomarkerId: biomarker.id, reason: reading.reason },
});
return apiError(
`The reading is in ${unit}, but ${biomarker.name} is tracked in ${biomarker.unit}.`,
unitMismatchMessage(unit, biomarker.name, biomarker.unit),
422,
{
errorCode: "labs.unit.mismatch",
@@ -392,3 +393,19 @@ async function postLabResult(request: NextRequest) {
return apiSuccess(dto, 201);
}
/** The refusal for a reading whose unit differs from its marker's. */
function unitMismatchMessage(
readingUnit: string | undefined,
markerName: string,
markerUnit: string,
): string {
const readingSide =
!readingUnit || isDimensionlessUnit(readingUnit)
? "The reading has no unit"
: `The reading is in ${readingUnit}`;
const markerSide = isDimensionlessUnit(markerUnit)
? "tracked without a unit"
: `tracked in ${markerUnit}`;
return `${readingSide}, but ${markerName} is ${markerSide}.`;
}