feat(labs): convert a reading into its marker's unit when the pair is known

Slice 2 of phase 3 of #1095. A reading that stated a unit other than its
marker's was refused. When the marker's analyte is known and the registry has the
pair, the three write paths now convert it instead: POST /api/labs, the OCR
commit and the document commit.

The converted value is stored at full precision in the marker's unit, with what
the report printed in the existing source_value and source_unit columns. The
report's own reference window is in the printed unit, so it is converted with the
value; otherwise the verdict would compare a converted value with an unconverted
window. A pair the registry does not have is still refused as before (the 422
now says why), as is a marker whose analyte is unknown.

The marker's key is filled the first time a reading needs it. The same scan
committed again is still a duplicate: a converted row holds the number in the
marker's unit, so the duplicate check also matches on what the report printed.
Editing the value of a converted reading clears the conversion record, because
the number is then the person's own.

The lab result DTO and the OpenAPI schemas (labs and the OCR commit) carry
converted, sourceValue and sourceUnit.

Refs #1095
This commit is contained in:
BernhardBuckel committed 2026-10-11 20:28:00 +02:00
1 parent 08c69d4a5a
commit caa7a937fd
18 files changed
+1011 -105

No files matched your search

@@ -68,6 +68,9 @@ function reading(id: string, value: number, takenAt: string): LabResultDto {
value,
valueText: null,
unit: "mg/dL",
converted: false,
sourceValue: null,
sourceUnit: null,
referenceLow: 0,
referenceHigh: 100,
catalogReferenceLow: 0,
+8
View File
@@ -15,6 +15,14 @@ export interface LabResultDto {
/** v1.18.9 — qualitative result text ("negativ" / …); null for a numeric row. */
valueText: string | null;
unit: string;
/**
* True when the stored number was converted into the marker's unit from
* another one; `sourceValue` and `sourceUnit` are then what the report
* printed. A reading stored as stated has `converted: false` and two nulls.
*/
converted: boolean;
sourceValue: number | null;
sourceUnit: string | null;
/**
* The window this reading is judged against and the one `rangeStatus` was
* computed from: the range its own report printed when it carries one, the