Merge remote-tracking branch 'origin/main' into chore/deps-2026-11-15

# Conflicts:
#	CHANGELOG.md
This commit is contained in:
Marc-André Bombeck committed 2026-11-16 00:06:17 +01:00
commit e451f64c3a
11 files changed
+289 -28

No files matched your search

+23
View File
@@ -12,6 +12,15 @@
* other way round. Only the display differs: nobody wants "3.6 1", so the
* helpers below render the unity as nothing beside a value.
*
* A marker's unit has one more state: empty. A marker minted from a text
* result ("negative", "SEE NOTE") has no unit because nothing has chosen one
* yet, and the first numeric reading gives it its unit, the unity included
* (`adoptFirstNumericUnit` in `./reading-conversion.ts`). Empty is therefore
* not a second spelling of `"1"`: the unity refuses a reading in mg/dL, an
* empty unit takes it. Both hold no number in a unit, so the editor shows
* both as "no unit" (`markerHasNoUnit`), and the unit lock, which guards the
* numbers stored under a unit, never fires on either while they hold none.
*
* Pure and dependency-free.
*/
@@ -23,6 +32,17 @@ export function isDimensionlessUnit(unit: string | null | undefined): boolean {
return typeof unit === "string" && unit.trim() === DIMENSIONLESS_UNIT;
}
/**
* Whether a marker's unit reads as "no unit" in the editor: the unity, or the
* empty unit of a marker no number has given a unit yet.
*/
export function markerHasNoUnit(unit: string | null | undefined): boolean {
return (
typeof unit === "string" &&
(unit.trim() === "" || unit.trim() === DIMENSIONLESS_UNIT)
);
}
/** The unit as it reads beside a value: trimmed, and empty for the unity. */
export function labUnitText(unit: string | null | undefined): string {
if (typeof unit !== "string") return "";
@@ -54,3 +74,6 @@ export function labUnitLabel(
/** How the API contract describes a lab unit field. */
export const LAB_UNIT_DESCRIPTION =
'The unit the value is in, free-form as the report prints it (e.g. `mg/dL`). `"1"`, the UCUM unity, means the value has no unit: a ratio or an index such as INR or cholesterol/HDL. It is an explicit choice and a unit of its own: it matches only `"1"`, so a reading without a unit is refused under a marker kept in a real unit and the other way round. Clients show nothing beside such a value. An empty unit on a numeric value is never read as `"1"` and stays refused.';
/** How the API contract describes a marker's stored unit. */
export const BIOMARKER_UNIT_DESCRIPTION = `${LAB_UNIT_DESCRIPTION} On a marker, an empty unit means none has been chosen yet: the marker was minted from a text result, and its first numeric reading gives it that reading's unit. It is not the unity: it holds no number, so a \`PUT\` may set any unit on it.`;
+3 -3
View File
@@ -14,7 +14,7 @@
import type { ZodOpenApiObject } from "zod-openapi";
import { z } from "zod/v4";
import { LAB_UNIT_DESCRIPTION } from "@/lib/labs/dimensionless";
import { BIOMARKER_UNIT_DESCRIPTION } from "@/lib/labs/dimensionless";
import { dateKeySchema } from "@/lib/day/date-key-schema";
import {
labSeriesQuerySchema,
@@ -62,7 +62,7 @@ const biomarkerRow = z
.object({
id: z.string(),
name: z.string(),
unit: z.string().describe(LAB_UNIT_DESCRIPTION),
unit: z.string().describe(BIOMARKER_UNIT_DESCRIPTION),
lowerBound: z.number().nullable(),
upperBound: z.number().nullable(),
panel: z.string().nullable(),
@@ -318,7 +318,7 @@ export const biomarkerPaths: NonNullable<ZodOpenApiObject["paths"]> = {
tags: ["Labs"],
summary: "Edit a biomarker",
description:
"Partial edit; omitted fields are untouched, an explicit null clears `context` / `panel` / a bound. Since v1.43 `aliases` (0..50, each 1..120 characters) replaces the marker's set of other spellings: listed spellings stay or are added, unlisted ones are removed; omitting the field leaves them as they are. Audits as `biomarker.update`. Since v1.40.0 a `unit` different from the stored one is refused with 422 `biomarkers.unit.locked` while any reading is linked to the marker (`meta.readingCount` carries how many): readers label every linked reading with the marker's unit, so a change would relabel stored numbers without converting them. Sending the current unit, or changing it on a marker with no readings, is accepted.",
"Partial edit; omitted fields are untouched, an explicit null clears `context` / `panel` / a bound. Since v1.43 `aliases` (0..50, each 1..120 characters) replaces the marker's set of other spellings: listed spellings stay or are added, unlisted ones are removed; omitting the field leaves them as they are. Audits as `biomarker.update`. Since v1.40.0 a `unit` different from the stored one is refused with 422 `biomarkers.unit.locked` while a numeric reading is linked to the marker, a deleted one included (`meta.readingCount` carries how many): readers label every linked number with the marker's unit, so a change would relabel stored numbers without converting them. Sending the current unit or another spelling of it (`mg/dl` for `mg/dL`), or changing it on a marker whose readings are all text or that has none, is accepted. A marker minted from a text result has an empty unit, so any unit may be set on it.",
requestParams: { path: z.object({ id: z.string() }) },
requestBody: {
required: true,