merge: Labs overhaul — biomarker catalog, structured entry, dashboard-style chart, edit/undo, backfill

# Conflicts:
#	src/app/api/labs/route.ts
This commit is contained in:
Marc-André Bombeck committed 2026-06-16 21:17:09 +02:00
commit cc32e2adf7
40 files changed
+4403 -360

No files matched your search

@@ -0,0 +1,78 @@
import { describe, expect, it } from "vitest";
import {
createBiomarkerSchema,
updateBiomarkerSchema,
} from "../biomarkers";
describe("createBiomarkerSchema", () => {
it("accepts a minimal marker (name + unit only)", () => {
const r = createBiomarkerSchema.safeParse({ name: "LDL", unit: "mg/dL" });
expect(r.success).toBe(true);
});
it("accepts both bounds when low <= high", () => {
const r = createBiomarkerSchema.safeParse({
name: "Fasting glucose",
unit: "mg/dL",
lowerBound: 70,
upperBound: 100,
});
expect(r.success).toBe(true);
});
it("accepts an open-ended upper bound (lower omitted)", () => {
const r = createBiomarkerSchema.safeParse({
name: "LDL",
unit: "mg/dL",
upperBound: 116,
});
expect(r.success).toBe(true);
});
it("rejects a transposed range (low > high)", () => {
const r = createBiomarkerSchema.safeParse({
name: "LDL",
unit: "mg/dL",
lowerBound: 200,
upperBound: 100,
});
expect(r.success).toBe(false);
});
it("rejects an empty name", () => {
const r = createBiomarkerSchema.safeParse({ name: " ", unit: "mg/dL" });
expect(r.success).toBe(false);
});
it("normalises an empty context to undefined", () => {
const r = createBiomarkerSchema.safeParse({
name: "TSH",
unit: "mIU/L",
context: "",
});
expect(r.success).toBe(true);
if (r.success) expect(r.data.context).toBeUndefined();
});
});
describe("updateBiomarkerSchema", () => {
it("accepts a partial edit", () => {
const r = updateBiomarkerSchema.safeParse({ unit: "mmol/L" });
expect(r.success).toBe(true);
});
it("accepts an explicit null to clear a bound", () => {
const r = updateBiomarkerSchema.safeParse({ lowerBound: null });
expect(r.success).toBe(true);
if (r.success) expect(r.data.lowerBound).toBeNull();
});
it("still rejects a transposed range on update", () => {
const r = updateBiomarkerSchema.safeParse({
lowerBound: 10,
upperBound: 5,
});
expect(r.success).toBe(false);
});
});
@@ -75,6 +75,32 @@ describe("createLabResultSchema", () => {
expect(r.success).toBe(true);
});
it("accepts a structured entry (biomarkerId, no analyte/unit)", () => {
const r = createLabResultSchema.safeParse({
biomarkerId: "bm_123",
value: 110,
takenAt: RECENT,
});
expect(r.success).toBe(true);
});
it("rejects an entry with neither biomarkerId nor analyte", () => {
const r = createLabResultSchema.safeParse({
value: 110,
takenAt: RECENT,
});
expect(r.success).toBe(false);
});
it("rejects a free-text entry missing the unit", () => {
const r = createLabResultSchema.safeParse({
analyte: "LDL",
value: 110,
takenAt: RECENT,
});
expect(r.success).toBe(false);
});
it("normalises an empty-string panel to undefined", () => {
const r = createLabResultSchema.safeParse({
analyte: "TSH",