From 44bc91c3eac92114a1fea278bb38b4e20dfca3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 5 Jul 2026 14:47:58 +0200 Subject: [PATCH 1/6] feat(mental-health): drop the trend chart from the check-in page A rising score curve on the check-in page itself reads as a verdict at the moment someone is taking stock of how they feel. The page keeps the calm dated list of past check-ins (severity badge, score, the discreet crisis-resource re-surface); the score trend stays available through the PHQ9_SCORE / GAD7_SCORE measurement rows on the Insights / Measurements surfaces. The per-card trend sheet and its chart component are removed, along with the now-unused chart i18n keys in all six locales. --- messages/de.json | 8 +- messages/en.json | 8 +- messages/es.json | 8 +- messages/fr.json | 8 +- messages/it.json | 8 +- messages/pl.json | 8 +- .../__tests__/mental-wellbeing.test.tsx | 84 +----- .../assessment-history-chart.tsx | 161 ------------ .../mental-health/assessment-history.tsx | 239 +++++++----------- .../mental-health/instrument-card.tsx | 27 +- .../mental-health/mental-wellbeing.tsx | 40 +-- 11 files changed, 125 insertions(+), 474 deletions(-) delete mode 100644 src/components/mental-health/assessment-history-chart.tsx diff --git a/messages/de.json b/messages/de.json index 28604c9b1..e9e1948be 100644 --- a/messages/de.json +++ b/messages/de.json @@ -7680,14 +7680,11 @@ "history": { "title": "Dein Verlauf", "empty": "Noch keine Check-ins. Dein Verlauf erscheint hier, sobald du einen abgeschlossen hast.", - "chartTitle": "Punkteverlauf", "flaggedBadge": "Hilfe angezeigt", - "totalLabel": "Punkte", "tab": { "phq9": "PHQ-9", "gad7": "GAD-7" - }, - "bandLabel": "Einstufung" + } }, "crisis": { "title": "Du musst das nicht allein durchstehen", @@ -7755,8 +7752,7 @@ "review": { "title": "Überblick", "recap": "Du hast {answered} von {total} Fragen beantwortet." - }, - "openDetail": "Verlauf anzeigen" + } }, "records": { "disclaimer": "Das sind deine eigenen Angaben, keine ärztliche Diagnose. HealthLog stellt keine Diagnose, behandelt nicht und deutet nichts.", diff --git a/messages/en.json b/messages/en.json index df45fbd25..486122f95 100644 --- a/messages/en.json +++ b/messages/en.json @@ -7680,14 +7680,11 @@ "history": { "title": "Your history", "empty": "No check-ins yet. Your trend will appear here once you complete one.", - "chartTitle": "Score trend", "flaggedBadge": "Support shown", - "totalLabel": "Score", "tab": { "phq9": "PHQ-9", "gad7": "GAD-7" - }, - "bandLabel": "Category" + } }, "crisis": { "title": "You don't have to face this alone", @@ -7755,8 +7752,7 @@ "review": { "title": "Review", "recap": "You answered {answered} of {total} questions." - }, - "openDetail": "Show trend" + } }, "records": { "disclaimer": "These are your own records, not a medical diagnosis. HealthLog does not diagnose, treat, or interpret them.", diff --git a/messages/es.json b/messages/es.json index 35f95049a..cf87c537c 100644 --- a/messages/es.json +++ b/messages/es.json @@ -7680,14 +7680,11 @@ "history": { "title": "Tu historial", "empty": "Aún no hay revisiones. Tu tendencia aparecerá aquí cuando completes una.", - "chartTitle": "Evolución de la puntuación", "flaggedBadge": "Apoyo mostrado", - "totalLabel": "Puntuación", "tab": { "phq9": "PHQ-9", "gad7": "GAD-7" - }, - "bandLabel": "Categoría" + } }, "crisis": { "title": "No tienes que afrontar esto a solas", @@ -7755,8 +7752,7 @@ "review": { "title": "Resumen", "recap": "Has respondido {answered} de {total} preguntas." - }, - "openDetail": "Ver evolución" + } }, "records": { "disclaimer": "Son tus propios registros, no un diagnóstico médico. HealthLog no diagnostica, no trata ni los interpreta.", diff --git a/messages/fr.json b/messages/fr.json index 92682f7a4..94a427606 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -7680,14 +7680,11 @@ "history": { "title": "Ton historique", "empty": "Aucun bilan pour le moment. Ta tendance apparaîtra ici dès que tu en auras terminé un.", - "chartTitle": "Évolution du score", "flaggedBadge": "Aide affichée", - "totalLabel": "Score", "tab": { "phq9": "PHQ-9", "gad7": "GAD-7" - }, - "bandLabel": "Catégorie" + } }, "crisis": { "title": "Tu n'as pas à affronter cela seul(e)", @@ -7755,8 +7752,7 @@ "review": { "title": "Récapitulatif", "recap": "Vous avez répondu à {answered} questions sur {total}." - }, - "openDetail": "Voir l’évolution" + } }, "records": { "disclaimer": "Ce sont vos propres informations, pas un diagnostic médical. HealthLog ne diagnostique pas, ne traite pas et ne les interprète pas.", diff --git a/messages/it.json b/messages/it.json index 6a20cc358..1575f4e47 100644 --- a/messages/it.json +++ b/messages/it.json @@ -7680,14 +7680,11 @@ "history": { "title": "La tua cronologia", "empty": "Ancora nessun check-in. Il tuo andamento apparirà qui dopo che ne avrai completato uno.", - "chartTitle": "Andamento del punteggio", "flaggedBadge": "Supporto mostrato", - "totalLabel": "Punteggio", "tab": { "phq9": "PHQ-9", "gad7": "GAD-7" - }, - "bandLabel": "Categoria" + } }, "crisis": { "title": "Non devi affrontare tutto questo da solo/a", @@ -7755,8 +7752,7 @@ "review": { "title": "Riepilogo", "recap": "Hai risposto a {answered} domande su {total}." - }, - "openDetail": "Mostra andamento" + } }, "records": { "disclaimer": "Sono i tuoi dati, non una diagnosi medica. HealthLog non diagnostica, non cura e non li interpreta.", diff --git a/messages/pl.json b/messages/pl.json index 179663f05..d36985dbc 100644 --- a/messages/pl.json +++ b/messages/pl.json @@ -7680,14 +7680,11 @@ "history": { "title": "Twoja historia", "empty": "Brak sprawdzeń. Twój trend pojawi się tutaj po ukończeniu pierwszego.", - "chartTitle": "Przebieg wyniku", "flaggedBadge": "Pokazano wsparcie", - "totalLabel": "Wynik", "tab": { "phq9": "PHQ-9", "gad7": "GAD-7" - }, - "bandLabel": "Kategoria" + } }, "crisis": { "title": "Nie musisz mierzyć się z tym sam(a)", @@ -7755,8 +7752,7 @@ "review": { "title": "Podsumowanie", "recap": "Odpowiedziano na {answered} z {total} pytań." - }, - "openDetail": "Pokaż przebieg" + } }, "records": { "disclaimer": "To Twoje własne wpisy, a nie diagnoza lekarska. HealthLog nie diagnozuje, nie leczy i ich nie interpretuje.", diff --git a/src/components/mental-health/__tests__/mental-wellbeing.test.tsx b/src/components/mental-health/__tests__/mental-wellbeing.test.tsx index f983ed473..a20c42337 100644 --- a/src/components/mental-health/__tests__/mental-wellbeing.test.tsx +++ b/src/components/mental-health/__tests__/mental-wellbeing.test.tsx @@ -11,8 +11,9 @@ import en from "../../../../messages/en.json"; * means clicks can't be driven here — the wizard's advance/back grammar is * pinned in `check-in-nav.test.ts`. These tests pin the SSR-observable * contracts: the disclaimer renders ONLY on the landing (never while testing), - * a positive item-9 surfaces the crisis card, and the history paints its chart - * shell + dated list with severity + "support shown" badges. + * a positive item-9 surfaces the crisis card, and the history paints its + * dated list with severity + "support shown" badges — and NO trend chart + * (v1.27.6: the score curve lives in Insights / Measurements, not here). */ vi.mock("@/lib/api/api-fetch", () => ({ @@ -174,9 +175,12 @@ describe("history rendering", () => { const html = withProviders(); - it("paints the lazy chart shell + the dated list", () => { - expect(html).toContain('data-slot="skeleton"'); + it("paints the dated list WITHOUT a trend chart shell", () => { expect(html).toContain('data-slot="history-list"'); + // v1.27.6 — no chart on this surface: no lazy-chart skeleton, no + // recharts container. + expect(html).not.toContain('data-slot="skeleton"'); + expect(html).not.toContain("recharts"); }); it("shows the PHQ-9 / GAD-7 toggle and a severity badge", () => { @@ -196,74 +200,14 @@ describe("history rendering", () => { }); }); -describe("instrument card → per-instrument trend (v1.25.12)", () => { - it("exposes the card body as a detail target separate from Start", () => { +describe("instrument card (v1.27.6 — no trend-detail target)", () => { + it("renders the card body as plain content with Start as the single action", () => { const html = withProviders( - {}} - onOpenDetail={() => {}} - />, + {}} />, ); - // The title + last-result block is a button that opens the Verlauf… - expect(html).toContain('data-slot="instrument-card-open"'); - expect(html).toContain(mh.openDetail); - // …and the Start action is still its own button. + // The former trend-detail button is gone… + expect(html).not.toContain('data-slot="instrument-card-open"'); + // …and the Start action remains. expect(html).toContain(mh.start); }); - - it("pins the history to one instrument: no toggle, bare (no titled card)", () => { - const rows: AssessmentRow[] = [ - { - id: "p1", - instrument: "PHQ9", - locale: "en", - totalScore: 8, - severityBand: "mild", - item9Flagged: false, - crisisShownAt: null, - takenAt: "2026-06-20T00:00:00.000Z", - }, - { - id: "g1", - instrument: "GAD7", - locale: "en", - totalScore: 12, - severityBand: "moderate", - item9Flagged: false, - crisisShownAt: null, - takenAt: "2026-06-20T00:00:00.000Z", - }, - ]; - const html = withProviders( - , - ); - // Pinned: the PHQ-9 / GAD-7 toggle + the titled landing card are gone… - expect(html).toContain('data-pinned="PHQ9"'); - expect(html).not.toContain('role="tablist"'); - // …only the chosen instrument's row paints (its band), not the other's. - expect(html).toContain(mh.band.PHQ9.mild); - expect(html).not.toContain(mh.band.GAD7.moderate); - }); - - it("shows the per-instrument empty state when that instrument has no rows", () => { - const onlyGad: AssessmentRow[] = [ - { - id: "g2", - instrument: "GAD7", - locale: "en", - totalScore: 5, - severityBand: "mild", - item9Flagged: false, - crisisShownAt: null, - takenAt: "2026-06-20T00:00:00.000Z", - }, - ]; - const html = withProviders( - , - ); - expect(html).toContain(mh.history.empty); - expect(html).not.toContain('data-slot="history-list"'); - }); }); diff --git a/src/components/mental-health/assessment-history-chart.tsx b/src/components/mental-health/assessment-history-chart.tsx deleted file mode 100644 index 7d8648c66..000000000 --- a/src/components/mental-health/assessment-history-chart.tsx +++ /dev/null @@ -1,161 +0,0 @@ -"use client"; - -/** - * v1.25.3 — per-instrument screener trend chart. - * - * v1.25.5 — aligned to the dashboard's chart language exactly: a single - * `type="monotone"` line over the primary colour with a soft gradient area - * fill beneath (same `fillOpacity` + margins the dashboard line charts use), - * the shared grid / axis tokens, and `RichChartTooltip`. The earlier - * severity-band `ReferenceArea`s — unique to this surface — are gone so it - * reads like every other trend; the band still surfaces in the tooltip. - * - * One instrument at a time: PHQ-9 (0–27) and GAD-7 (0–21) have different ranges - * and bands, so the parent toggles which series this paints. - */ -import { useMemo } from "react"; -import { - Area, - CartesianGrid, - ComposedChart, - Line, - ResponsiveContainer, - Tooltip, - XAxis, - YAxis, -} from "recharts"; - -import { RichChartTooltip, type RichTooltipRow } from "../charts/chart-tooltip"; -import { CHART_HEIGHT_PX } from "@/lib/charts/constants"; -import { prefersReducedMotion } from "@/lib/charts/reduced-motion"; -import { formatDateShort } from "@/lib/format"; -import { useTranslations } from "@/lib/i18n/context"; -import { INSTRUMENTS } from "@/lib/mental-health/instruments"; - -import type { AssessmentRow, InstrumentId } from "./types"; - -interface ChartPoint { - timestamp: number; - value: number; - band: string; -} - -export function AssessmentHistoryChart({ - instrument, - rows, -}: { - instrument: InstrumentId; - /** Rows for THIS instrument, any order (sorted internally, ascending time). */ - rows: AssessmentRow[]; -}) { - const { t } = useTranslations(); - const def = INSTRUMENTS[instrument]; - - const points = useMemo(() => { - return [...rows] - .sort( - (a, b) => new Date(a.takenAt).getTime() - new Date(b.takenAt).getTime(), - ) - .map((r) => ({ - timestamp: new Date(r.takenAt).getTime(), - value: r.totalScore, - band: r.severityBand, - })); - }, [rows]); - - const animate = !prefersReducedMotion(); - const primary = "var(--primary)"; - const gradientId = `mh-trend-${instrument}`; - - if (points.length === 0) { - return ( -

- {t("mentalHealth.history.empty")} -

- ); - } - - return ( - - - - - - - - - - formatDateShort(new Date(ts))} - tick={{ fontSize: 11, fill: "var(--muted-foreground)" }} - stroke="var(--border)" - minTickGap={32} - /> - - { - const active = props.active ?? false; - const payload = props.payload as - ReadonlyArray<{ payload?: ChartPoint }> | undefined; - const point = payload?.[0]?.payload; - if (!active || !point) { - return ; - } - const rowsOut: RichTooltipRow[] = [ - { - name: t("mentalHealth.history.totalLabel"), - value: String(point.value), - color: primary, - }, - { - name: t("mentalHealth.history.bandLabel"), - value: t(`mentalHealth.band.${instrument}.${point.band}`), - color: "var(--muted-foreground)", - }, - ]; - return ( - - ); - }} - /> - - - - - ); -} diff --git a/src/components/mental-health/assessment-history.tsx b/src/components/mental-health/assessment-history.tsx index d570fe7e9..1bda8bfe8 100644 --- a/src/components/mental-health/assessment-history.tsx +++ b/src/components/mental-health/assessment-history.tsx @@ -1,13 +1,17 @@ "use client"; /** - * v1.25.3 — the history card: a per-instrument trend chart over a band-shaded - * plot, then the dated list with severity badges. Mirrors the labs detail spine - * (chart → list) and lazy-loads Recharts through `next/dynamic` so it stays off - * the surface's first-load JS, with a `ChartSkeleton` shell. + * v1.25.3 — the history card: a dated list with severity badges. * - * PHQ-9 / GAD-7 toggle: the two instruments have different score ranges + bands, - * so the chart paints one at a time. + * v1.27.6 — the trend CHART is gone from this surface. A rising score curve + * on the check-in page itself reads as a verdict at the exact moment someone + * is taking stock of how they feel; the page stays a calm list of past + * check-ins. The score trend still exists — the totals ride PHQ9_SCORE / + * GAD7_SCORE measurement rows, so Insights / Measurements carry the curve + * for whoever seeks it out. + * + * PHQ-9 / GAD-7 toggle: the two instruments have different score ranges + + * bands, so the list shows one at a time. * * CRISIS-SAFETY: a flagged PHQ-9 row carries a discreet "support shown" marker; * tapping it re-surfaces the STATIC crisis-resource card derived from the row's @@ -16,16 +20,11 @@ * leaves the safety boundary. */ import { useMemo, useState } from "react"; -import dynamic from "next/dynamic"; -import type { ComponentProps } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { EmptyState } from "@/components/ui/empty-state"; -import { ChartErrorBoundary } from "@/components/charts/chart-error-state"; -import { ChartSkeleton } from "@/components/charts/chart-skeleton"; -import { importWithRetry } from "@/lib/retry-import"; import { useFormatters, useTranslations } from "@/lib/i18n/context"; import { crisisResourcesForLocale } from "@/lib/mental-health/crisis-resources"; import { Activity } from "lucide-react"; @@ -33,25 +32,6 @@ import { Activity } from "lucide-react"; import { CrisisCard } from "./crisis-card"; import type { AssessmentRow, CrisisSet, InstrumentId } from "./types"; -// Defer the recharts trend chart so recharts stays off the surface's first-load -// JS (the labs detail precedent). The `` shell holds the layout. -const AssessmentHistoryChartLazy = dynamic( - () => - importWithRetry(() => import("./assessment-history-chart")).then((mod) => ({ - default: mod.AssessmentHistoryChart, - })), - { ssr: false, loading: () => }, -); -function AssessmentHistoryChart( - props: ComponentProps, -) { - return ( - - - - ); -} - function lower(id: InstrumentId): "phq9" | "gad7" { return id === "PHQ9" ? "phq9" : "gad7"; } @@ -68,73 +48,57 @@ function crisisFromRow(row: AssessmentRow): CrisisSet { }; } -export function AssessmentHistory({ - rows, - instrument, -}: { - rows: AssessmentRow[]; - /** - * Pin the history to a single instrument. When set, the PHQ-9 / GAD-7 - * toggle + the outer Card chrome are dropped — the surface is a per- - * instrument detail (opened from an instrument card; the chrome + title - * come from the host sheet). Unset, it renders the combined landing card - * with the toggle, exactly as before. - */ - instrument?: InstrumentId; -}) { +export function AssessmentHistory({ rows }: { rows: AssessmentRow[] }) { const { t } = useTranslations(); const { date: formatDate } = useFormatters(); - const [tab, setTab] = useState(instrument ?? "PHQ9"); + const [tab, setTab] = useState("PHQ9"); // Which flagged row's crisis card is currently expanded (re-surfaced). const [openCrisisRowId, setOpenCrisisRowId] = useState(null); - const pinned = instrument != null; - // When pinned, the tab is forced to the host instrument so re-opening the - // detail for the other instrument never paints a stale series. - const activeTab = pinned ? instrument : tab; - const forTab = useMemo( () => rows - .filter((r) => r.instrument === activeTab) + .filter((r) => r.instrument === tab) .sort( (a, b) => new Date(b.takenAt).getTime() - new Date(a.takenAt).getTime(), ), - [rows, activeTab], + [rows, tab], ); - // Pinned: emptiness is per-instrument (the host opened THIS instrument's - // detail). Combined: emptiness spans both instruments, as before. - const isEmpty = pinned ? forTab.length === 0 : rows.length === 0; + const isEmpty = rows.length === 0; - const body = ( - <> - {isEmpty ? ( - } - title={t("mentalHealth.history.title")} - description={t("mentalHealth.history.empty")} - /> - ) : ( - <> - {/* PHQ-9 / GAD-7 toggle — the two ranges + band sets can't share an - axis, so the chart + list paint one instrument at a time. Hidden - when pinned: the host already chose the instrument. */} - {!pinned && ( + return ( + + + + {t("mentalHealth.history.title")} + + + + {isEmpty ? ( + } + title={t("mentalHealth.history.title")} + description={t("mentalHealth.history.empty")} + /> + ) : ( + <> + {/* PHQ-9 / GAD-7 toggle — the two ranges + band sets differ, so + the list shows one instrument at a time. */}
{(["PHQ9", "GAD7"] as InstrumentId[]).map((id) => ( ))}
- )} - - - {forTab.length === 0 ? ( -

- {t("mentalHealth.history.empty")} -

- ) : ( -
    - {forTab.map((row) => { - const flagged = row.item9Flagged; - const open = openCrisisRowId === row.id; - return ( -
  • -
    - - {formatDate(row.takenAt)} - -
    - {flagged && ( - - )} - - {t( - `mentalHealth.band.${row.instrument}.${row.severityBand}`, - )} - - - {row.totalScore} + {forTab.length === 0 ? ( +

    + {t("mentalHealth.history.empty")} +

    + ) : ( +
      + {forTab.map((row) => { + const flagged = row.item9Flagged; + const open = openCrisisRowId === row.id; + return ( +
    • +
      + + {formatDate(row.takenAt)} +
      + {flagged && ( + + )} + + {t( + `mentalHealth.band.${row.instrument}.${row.severityBand}`, + )} + + + {row.totalScore} + +
      -
    - {flagged && open && ( - - )} -
  • - ); - })} -
- )} - - )} - - ); - - // Pinned: render bare (the host sheet owns the chrome + title). Combined: - // the landing's titled history card, unchanged. - if (pinned) { - return ( -
- {body} -
- ); - } - - return ( - - - - {t("mentalHealth.history.title")} - - - {body} + {flagged && open && ( + + )} + + ); + })} + + )} + + )} +
); } diff --git a/src/components/mental-health/instrument-card.tsx b/src/components/mental-health/instrument-card.tsx index 57c9875b6..bb8751403 100644 --- a/src/components/mental-health/instrument-card.tsx +++ b/src/components/mental-health/instrument-card.tsx @@ -24,18 +24,11 @@ export function InstrumentCard({ instrument, last, onStart, - onOpenDetail, }: { instrument: InstrumentId; /** Most-recent assessment for this instrument, or undefined when none yet. */ last: AssessmentRow | undefined; onStart: () => void; - /** - * Open this instrument's trend detail. The card BODY (title + last-result - * line) is the navigation target — mirroring how a medication card opens its - * detail — while the bottom-pinned Start button stays a separate action. - */ - onOpenDetail: () => void; }) { const { t } = useTranslations(); const { date: formatDate } = useFormatters(); @@ -45,16 +38,10 @@ export function InstrumentCard({ return ( - {/* Body is the detail target: clicking the title / last-result block - opens this instrument's Verlauf, like a medication card. The Start - button below is a separate, deliberately non-overlapping action. */} - +
From 07f48d215c516a6d86d90f61ee2b62a8892f88b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 5 Jul 2026 14:50:15 +0200 Subject: [PATCH 3/6] feat(mental-health): recommend a gentle check-in rhythm in the page intro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both instruments ask about the last two weeks, so the landing gains one soft sentence suggesting a check-in every two to four weeks — an orientation aid, not a directive. All six locales. --- messages/de.json | 1 + messages/en.json | 1 + messages/es.json | 1 + messages/fr.json | 1 + messages/it.json | 1 + messages/pl.json | 1 + src/components/mental-health/mental-wellbeing.tsx | 7 +++++++ 7 files changed, 13 insertions(+) diff --git a/messages/de.json b/messages/de.json index 3a5359378..49f998221 100644 --- a/messages/de.json +++ b/messages/de.json @@ -7626,6 +7626,7 @@ "mentalHealth": { "pageTitle": "Check-in zum seelischen Wohlbefinden", "pageDescription": "Zwei validierte, freiwillige Selbsttests — PHQ-9 (Stimmung) und GAD-7 (Sorgen) — ergänzend zu deinem Stimmungstagebuch. Aussagekräftig ist der Verlauf über die Zeit, nicht ein einzelner Wert.", + "pageRhythmHint": "Beide Tests blicken auf die letzten zwei Wochen zurück — ein Check-in alle zwei bis vier Wochen ist deshalb ein guter Rhythmus.", "attributionLabel": "Quelle", "choosePrompt": "Check-in auswählen", "start": "Starten", diff --git a/messages/en.json b/messages/en.json index bbbbd05ae..aec969447 100644 --- a/messages/en.json +++ b/messages/en.json @@ -7626,6 +7626,7 @@ "mentalHealth": { "pageTitle": "Mental wellbeing check-in", "pageDescription": "Two validated, opt-in self-assessments — PHQ-9 (mood) and GAD-7 (worry) — that sit beside your mood tracking. The value is the trend over time, not any single number.", + "pageRhythmHint": "Both tests look back over the last two weeks, so a check-in every two to four weeks is a comfortable rhythm.", "attributionLabel": "Attribution", "choosePrompt": "Choose a check-in", "start": "Start", diff --git a/messages/es.json b/messages/es.json index f46501f73..2174a68d1 100644 --- a/messages/es.json +++ b/messages/es.json @@ -7626,6 +7626,7 @@ "mentalHealth": { "pageTitle": "Revisión de bienestar mental", "pageDescription": "Dos autoevaluaciones validadas y opcionales — PHQ-9 (estado de ánimo) y GAD-7 (preocupación) — junto a tu registro de ánimo. Lo valioso es la tendencia en el tiempo, no un único número.", + "pageRhythmHint": "Ambos tests se refieren a las últimas dos semanas, por lo que un check-in cada dos a cuatro semanas es un buen ritmo.", "attributionLabel": "Fuente", "choosePrompt": "Elige una revisión", "start": "Empezar", diff --git a/messages/fr.json b/messages/fr.json index f09d5b325..e80ea7316 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -7626,6 +7626,7 @@ "mentalHealth": { "pageTitle": "Point sur le bien-être mental", "pageDescription": "Deux auto-évaluations validées et facultatives — PHQ-9 (humeur) et GAD-7 (inquiétude) — en complément de ton suivi de l'humeur. Ce qui compte, c'est la tendance dans le temps, pas un chiffre isolé.", + "pageRhythmHint": "Les deux tests portent sur les deux dernières semaines — un check-in toutes les deux à quatre semaines est donc un bon rythme.", "attributionLabel": "Source", "choosePrompt": "Choisis un bilan", "start": "Commencer", diff --git a/messages/it.json b/messages/it.json index 9163c8997..759817a6d 100644 --- a/messages/it.json +++ b/messages/it.json @@ -7626,6 +7626,7 @@ "mentalHealth": { "pageTitle": "Check-in sul benessere mentale", "pageDescription": "Due autovalutazioni validate e facoltative — PHQ-9 (umore) e GAD-7 (preoccupazione) — accanto al tuo diario dell'umore. Ciò che conta è l'andamento nel tempo, non un singolo numero.", + "pageRhythmHint": "Entrambi i test riguardano le ultime due settimane, quindi un check-in ogni due-quattro settimane è un buon ritmo.", "attributionLabel": "Fonte", "choosePrompt": "Scegli un check-in", "start": "Inizia", diff --git a/messages/pl.json b/messages/pl.json index 2ac2c9d69..6e376b390 100644 --- a/messages/pl.json +++ b/messages/pl.json @@ -7626,6 +7626,7 @@ "mentalHealth": { "pageTitle": "Sprawdzenie dobrostanu psychicznego", "pageDescription": "Dwa zwalidowane, dobrowolne testy — PHQ-9 (nastrój) i GAD-7 (lęk) — obok Twojego dziennika nastroju. Liczy się trend w czasie, a nie pojedynczy wynik.", + "pageRhythmHint": "Oba testy dotyczą ostatnich dwóch tygodni, dlatego check-in co dwa–cztery tygodnie to dobry rytm.", "attributionLabel": "Źródło", "choosePrompt": "Wybierz sprawdzenie", "start": "Rozpocznij", diff --git a/src/components/mental-health/mental-wellbeing.tsx b/src/components/mental-health/mental-wellbeing.tsx index feb10184b..d42c11dd2 100644 --- a/src/components/mental-health/mental-wellbeing.tsx +++ b/src/components/mental-health/mental-wellbeing.tsx @@ -113,6 +113,13 @@ export function MentalWellbeing() { description={t("mentalHealth.pageDescription")} /> + {/* v1.27.6 — one gentle cadence hint: both instruments ask about + the last two weeks, so every 2–4 weeks is a sensible rhythm. + Body prose (foreground), not another muted description line. */} +

+ {t("mentalHealth.pageRhythmHint")} +

+

{t("mentalHealth.choosePrompt")}

    From f7920d81a6a113d5450709f172b3e0086d7fc7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 5 Jul 2026 14:52:10 +0200 Subject: [PATCH 4/6] feat(mental-health): slim the check-in to questions only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The question-overview strip (the dot/jump row borrowed from the medication wizard) and the "N of N answered" review interstitial are gone — a screening is a quiet, linear moment, not a form to audit. The Back button and a small "3 / 9" caption stay for orientation; answering the last question arms the submit directly and the next screen is the result view. The optional functional-difficulty follow-up leaves the web wizard with the review step (the API keeps accepting it). Unused wizard keys removed from all six locale bundles. --- messages/de.json | 16 +- messages/en.json | 16 +- messages/es.json | 16 +- messages/fr.json | 16 +- messages/it.json | 16 +- messages/pl.json | 16 +- .../__tests__/check-in-nav.test.ts | 80 ++----- .../__tests__/mental-wellbeing.test.tsx | 11 +- src/components/mental-health/check-in-nav.ts | 57 ++--- .../mental-health/check-in-wizard.tsx | 213 ++++++------------ .../mental-health/mental-wellbeing.tsx | 7 +- 11 files changed, 121 insertions(+), 343 deletions(-) diff --git a/messages/de.json b/messages/de.json index 49f998221..69d71c137 100644 --- a/messages/de.json +++ b/messages/de.json @@ -7650,13 +7650,6 @@ "2": "An mehr als der Hälfte der Tage", "3": "Beinahe jeden Tag" }, - "functionalTitle": "Wenn du eine oder mehrere Beschwerden angegeben hast: Wie sehr haben diese deine Arbeit, deinen Haushalt oder den Umgang mit anderen Menschen erschwert?", - "functional": { - "0": "Überhaupt nicht erschwert", - "1": "Etwas erschwert", - "2": "Sehr erschwert", - "3": "Extrem erschwert" - }, "result": { "title": "Dein Ergebnis", "totalLabel": "Gesamtwert", @@ -7743,18 +7736,11 @@ "gad7": "Angst-Screening mit 7 Fragen. Beziehe dich auf die letzten zwei Wochen." }, "progress": "{current} / {total}", - "questionAria": "Frage {current} von {total}", "next": "Weiter", "lastResult": "Letzter Test", "lastScore": "Letztes Ergebnis", "noResultYet": "Noch kein Check-in", - "backToList": "Übersicht", - "jumpFirst": "Zur ersten Frage springen", - "jumpLast": "Zur letzten Frage springen", - "review": { - "title": "Überblick", - "recap": "Du hast {answered} von {total} Fragen beantwortet." - } + "backToList": "Übersicht" }, "records": { "disclaimer": "Das sind deine eigenen Angaben, keine ärztliche Diagnose. HealthLog stellt keine Diagnose, behandelt nicht und deutet nichts.", diff --git a/messages/en.json b/messages/en.json index aec969447..2f1811cdf 100644 --- a/messages/en.json +++ b/messages/en.json @@ -7650,13 +7650,6 @@ "2": "More than half the days", "3": "Nearly every day" }, - "functionalTitle": "If you checked off any problems, how difficult have these made it to do your work, take care of things at home, or get along with other people?", - "functional": { - "0": "Not difficult at all", - "1": "Somewhat difficult", - "2": "Very difficult", - "3": "Extremely difficult" - }, "result": { "title": "Your result", "totalLabel": "Total score", @@ -7743,18 +7736,11 @@ "gad7": "7-question anxiety screen. Answer for the last two weeks." }, "progress": "{current} / {total}", - "questionAria": "Question {current} of {total}", "next": "Next", "lastResult": "Last test", "lastScore": "Last result", "noResultYet": "No check-in yet", - "backToList": "Overview", - "jumpFirst": "Jump to first question", - "jumpLast": "Jump to last question", - "review": { - "title": "Review", - "recap": "You answered {answered} of {total} questions." - } + "backToList": "Overview" }, "records": { "disclaimer": "These are your own records, not a medical diagnosis. HealthLog does not diagnose, treat, or interpret them.", diff --git a/messages/es.json b/messages/es.json index 2174a68d1..731843472 100644 --- a/messages/es.json +++ b/messages/es.json @@ -7650,13 +7650,6 @@ "2": "Más de la mitad de los días", "3": "Casi todos los días" }, - "functionalTitle": "Si marcaste algún problema, ¿cuánta dificultad te han causado para trabajar, ocuparte de la casa o relacionarte con otras personas?", - "functional": { - "0": "Ninguna dificultad", - "1": "Algo de dificultad", - "2": "Mucha dificultad", - "3": "Dificultad extrema" - }, "result": { "title": "Tu resultado", "totalLabel": "Puntuación total", @@ -7743,18 +7736,11 @@ "gad7": "Cribado de ansiedad de 7 preguntas. Responde pensando en las últimas dos semanas." }, "progress": "{current} / {total}", - "questionAria": "Pregunta {current} de {total}", "next": "Siguiente", "lastResult": "Última prueba", "lastScore": "Último resultado", "noResultYet": "Aún sin check-in", - "backToList": "Vista general", - "jumpFirst": "Ir a la primera pregunta", - "jumpLast": "Ir a la última pregunta", - "review": { - "title": "Resumen", - "recap": "Has respondido {answered} de {total} preguntas." - } + "backToList": "Vista general" }, "records": { "disclaimer": "Son tus propios registros, no un diagnóstico médico. HealthLog no diagnostica, no trata ni los interpreta.", diff --git a/messages/fr.json b/messages/fr.json index e80ea7316..12ffdd534 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -7650,13 +7650,6 @@ "2": "Plus de la moitié des jours", "3": "Presque tous les jours" }, - "functionalTitle": "Si tu as coché des problèmes, à quel point t'ont-ils gêné(e) dans ton travail, à la maison ou dans tes relations avec les autres ?", - "functional": { - "0": "Pas du tout gênant", - "1": "Un peu gênant", - "2": "Très gênant", - "3": "Extrêmement gênant" - }, "result": { "title": "Ton résultat", "totalLabel": "Score total", @@ -7743,18 +7736,11 @@ "gad7": "Dépistage de l'anxiété en 7 questions. Répondez en pensant aux deux dernières semaines." }, "progress": "{current} / {total}", - "questionAria": "Question {current} sur {total}", "next": "Suivant", "lastResult": "Dernier test", "lastScore": "Dernier résultat", "noResultYet": "Pas encore de check-in", - "backToList": "Vue d'ensemble", - "jumpFirst": "Aller à la première question", - "jumpLast": "Aller à la dernière question", - "review": { - "title": "Récapitulatif", - "recap": "Vous avez répondu à {answered} questions sur {total}." - } + "backToList": "Vue d'ensemble" }, "records": { "disclaimer": "Ce sont vos propres informations, pas un diagnostic médical. HealthLog ne diagnostique pas, ne traite pas et ne les interprète pas.", diff --git a/messages/it.json b/messages/it.json index 759817a6d..15225f0b5 100644 --- a/messages/it.json +++ b/messages/it.json @@ -7650,13 +7650,6 @@ "2": "Più della metà dei giorni", "3": "Quasi ogni giorno" }, - "functionalTitle": "Se hai indicato dei problemi, quanto ti hanno reso difficile lavorare, occuparti della casa o andare d'accordo con gli altri?", - "functional": { - "0": "Per niente difficile", - "1": "Un po' difficile", - "2": "Molto difficile", - "3": "Estremamente difficile" - }, "result": { "title": "Il tuo risultato", "totalLabel": "Punteggio totale", @@ -7743,18 +7736,11 @@ "gad7": "Screening dell'ansia in 7 domande. Rispondi pensando alle ultime due settimane." }, "progress": "{current} / {total}", - "questionAria": "Domanda {current} di {total}", "next": "Avanti", "lastResult": "Ultimo test", "lastScore": "Ultimo risultato", "noResultYet": "Ancora nessun check-in", - "backToList": "Panoramica", - "jumpFirst": "Vai alla prima domanda", - "jumpLast": "Vai all'ultima domanda", - "review": { - "title": "Riepilogo", - "recap": "Hai risposto a {answered} domande su {total}." - } + "backToList": "Panoramica" }, "records": { "disclaimer": "Sono i tuoi dati, non una diagnosi medica. HealthLog non diagnostica, non cura e non li interpreta.", diff --git a/messages/pl.json b/messages/pl.json index 6e376b390..72c898efe 100644 --- a/messages/pl.json +++ b/messages/pl.json @@ -7650,13 +7650,6 @@ "2": "Więcej niż połowę dni", "3": "Niemal codziennie" }, - "functionalTitle": "Jeśli zaznaczyłeś(-aś) jakiekolwiek problemy, na ile utrudniły Ci one pracę, prowadzenie domu lub kontakty z innymi ludźmi?", - "functional": { - "0": "Wcale nie utrudniły", - "1": "Trochę utrudniły", - "2": "Bardzo utrudniły", - "3": "Skrajnie utrudniły" - }, "result": { "title": "Twój wynik", "totalLabel": "Wynik łączny", @@ -7743,18 +7736,11 @@ "gad7": "Przesiew w kierunku lęku, 7 pytań. Odpowiadaj, myśląc o ostatnich dwóch tygodniach." }, "progress": "{current} / {total}", - "questionAria": "Pytanie {current} z {total}", "next": "Dalej", "lastResult": "Ostatni test", "lastScore": "Ostatni wynik", "noResultYet": "Brak check-inów", - "backToList": "Przegląd", - "jumpFirst": "Przejdź do pierwszego pytania", - "jumpLast": "Przejdź do ostatniego pytania", - "review": { - "title": "Podsumowanie", - "recap": "Odpowiedziano na {answered} z {total} pytań." - } + "backToList": "Przegląd" }, "records": { "disclaimer": "To Twoje własne wpisy, a nie diagnoza lekarska. HealthLog nie diagnozuje, nie leczy i ich nie interpretuje.", diff --git a/src/components/mental-health/__tests__/check-in-nav.test.ts b/src/components/mental-health/__tests__/check-in-nav.test.ts index 9e0d4cdd1..784690c16 100644 --- a/src/components/mental-health/__tests__/check-in-nav.test.ts +++ b/src/components/mental-health/__tests__/check-in-nav.test.ts @@ -2,23 +2,19 @@ import { describe, it, expect } from "vitest"; import { UNANSWERED, - answeredCount, - buildStepList, isComplete, - isReviewStep, + isLastStep, nextStep, prevStep, - reachableUntilIndex, - reviewStep, } from "../check-in-nav"; /** - * The one-question-at-a-time check-in is LINEAR: the step list is - * `[1..itemCount, review]`, backward navigation is always allowed, and the - * forward ceiling never lets a user skip ahead onto an unanswered question. - * These are the contracts the wizard's advance / back / reachability behaviour - * rests on (the SSR-only test convention can't drive the clicks, so the pure - * grammar is pinned here — the medication wizard's `wizard-payload` precedent). + * The one-question-at-a-time check-in is LINEAR: the steps are exactly the + * questions `1..itemCount`, backward navigation is always allowed, and the + * last question arms the submit directly (v1.27.6 — no review/summary step). + * These are the contracts the wizard's advance / back behaviour rests on + * (the SSR-only test convention can't drive the clicks, so the pure grammar + * is pinned here — the medication wizard's `wizard-payload` precedent). */ const PHQ9 = 9; @@ -28,71 +24,35 @@ function blank(count: number): number[] { return Array(count).fill(UNANSWERED); } -describe("check-in step grammar", () => { - it("builds questions + a single review dot (itemCount + 1)", () => { - expect(buildStepList(PHQ9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); - expect(buildStepList(GAD7)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); - expect(reviewStep(PHQ9)).toBe(10); - expect(reviewStep(GAD7)).toBe(8); - }); - - it("advances forward on a question and into review from the last question", () => { +describe("check-in step grammar (v1.27.6 — questions only, no review step)", () => { + it("advances forward and stays put on the last question (submit, not advance)", () => { expect(nextStep(1, PHQ9)).toBe(2); expect(nextStep(8, PHQ9)).toBe(9); - // last question (9) → review (10) - expect(nextStep(9, PHQ9)).toBe(10); - // review stays put (submit, not advance) - expect(nextStep(10, PHQ9)).toBe(10); + // The last question is the end of the line — no review step behind it. + expect(nextStep(9, PHQ9)).toBe(9); + expect(nextStep(7, GAD7)).toBe(7); }); it("steps back, clamped at the first question", () => { - expect(prevStep(10)).toBe(9); + expect(prevStep(9)).toBe(8); expect(prevStep(2)).toBe(1); expect(prevStep(1)).toBe(1); }); - it("identifies the review step", () => { - expect(isReviewStep(9, PHQ9)).toBe(false); - expect(isReviewStep(10, PHQ9)).toBe(true); - expect(isReviewStep(7, GAD7)).toBe(false); - expect(isReviewStep(8, GAD7)).toBe(true); + it("identifies the last question per instrument", () => { + expect(isLastStep(8, PHQ9)).toBe(false); + expect(isLastStep(9, PHQ9)).toBe(true); + expect(isLastStep(6, GAD7)).toBe(false); + expect(isLastStep(7, GAD7)).toBe(true); }); }); -describe("reachability ceiling (never skip ahead to an unanswered question)", () => { - it("with nothing answered, only the first question is reachable", () => { - expect(reachableUntilIndex(blank(PHQ9))).toBe(0); - }); - - it("the frontier follows the first unanswered item", () => { - const items = blank(PHQ9); - items[0] = 2; // Q1 answered → can reach Q2 (index 1) - expect(reachableUntilIndex(items)).toBe(1); - items[1] = 0; - items[2] = 3; // Q3 answered too → frontier at the first gap (index 3) - expect(reachableUntilIndex(items)).toBe(3); - }); - - it("once every item is answered the review slot (last index) is reachable", () => { - const items = blank(GAD7).map(() => 1); - // step list length is itemCount + 1; review index == itemCount - expect(reachableUntilIndex(items)).toBe(GAD7); - expect(buildStepList(GAD7).length - 1).toBe(GAD7); - }); -}); - -describe("completeness + recap", () => { +describe("completeness (gates the submit on the last question)", () => { it("isComplete requires every item answered", () => { expect(isComplete(blank(PHQ9))).toBe(false); const partial = blank(PHQ9).map((_, i) => (i < 5 ? 1 : UNANSWERED)); expect(isComplete(partial)).toBe(false); expect(isComplete(blank(PHQ9).map(() => 0))).toBe(true); - }); - - it("answeredCount counts only real (0–3) answers", () => { - const items = blank(PHQ9); - items[0] = 0; - items[1] = 3; - expect(answeredCount(items)).toBe(2); + expect(isComplete(blank(GAD7).map(() => 3))).toBe(true); }); }); diff --git a/src/components/mental-health/__tests__/mental-wellbeing.test.tsx b/src/components/mental-health/__tests__/mental-wellbeing.test.tsx index 8ddfcdfa1..0c6868b49 100644 --- a/src/components/mental-health/__tests__/mental-wellbeing.test.tsx +++ b/src/components/mental-health/__tests__/mental-wellbeing.test.tsx @@ -75,7 +75,7 @@ describe("landing chrome (v1.25.5 — disclaimer + heading removed)", () => { }); }); -describe("check-in wizard scaffolding", () => { +describe("check-in wizard scaffolding (v1.27.6 — questions only)", () => { const html = withProviders( { />, ); - it("reuses the medication wizard stepper", () => { - expect(html).toContain('data-slot="wizard-stepper"'); + it("no longer renders the question-overview strip", () => { + expect(html).not.toContain('data-slot="wizard-stepper"'); + }); + + it("no longer renders the review recap or the functional follow-up", () => { + expect(html).not.toContain("You have answered"); + expect(html).not.toContain('data-slot="check-in-submit"'); }); it("opens on the first question with the Back/Next footer", () => { diff --git a/src/components/mental-health/check-in-nav.ts b/src/components/mental-health/check-in-nav.ts index 125d04a6b..dbe4fe983 100644 --- a/src/components/mental-health/check-in-nav.ts +++ b/src/components/mental-health/check-in-nav.ts @@ -2,61 +2,32 @@ * v1.25.3 — pure step grammar for the one-question-at-a-time check-in. * * The PHQ-9 / GAD-7 screeners are LINEAR (no mode/cadence branching like the - * medication wizard), so the step list is a fixed `[1..itemCount, review]` and - * the reachability ceiling is just "the question you are currently working on" - * — you can always step backward to change an answer, never skip ahead onto an - * unanswered question. Keeping the navigation here (mirroring the medication - * wizard's `wizard-payload.ts`) makes the advance/back/reachability contract + * medication wizard), so the steps are exactly the questions `1..itemCount`: + * you can always step backward to change an answer, and never skip ahead past + * an unanswered question. Keeping the navigation here (mirroring the + * medication wizard's `wizard-payload.ts`) makes the advance/back contract * unit-testable without driving a DOM. * - * Step numbers are 1-based and run `1..itemCount` for the questions; the review - * step is `itemCount + 1`. The optional functional-difficulty control folds - * into the review step (it is unscored), so the dot count stays at - * `itemCount + 1` rather than gaining its own dot. + * v1.27.6 — the review/summary step is gone: answering the last question + * arms the submit directly (no "9 of 9 answered" interstitial demanding one + * more decision). Step numbers are 1-based and run `1..itemCount`. * * An unanswered item carries the sentinel `-1`. */ export const UNANSWERED = -1; -/** The 1-based review step number for an instrument of `itemCount` items. */ -export function reviewStep(itemCount: number): number { - return itemCount + 1; -} - -/** Ordered raw step numbers fed straight to `WizardStepper`: questions + review. */ -export function buildStepList(itemCount: number): number[] { - return Array.from({ length: itemCount + 1 }, (_, i) => i + 1); -} - -/** Index (into the step list) of the highest forward-reachable slot. */ -export function reachableUntilIndex(items: readonly number[]): number { - const firstUnanswered = items.findIndex((v) => v < 0); - // All answered → the review slot (last index) is reachable. - if (firstUnanswered === -1) return items.length; - // Otherwise the frontier is the question currently being answered; its index - // in the step list equals its 0-based item index. - return firstUnanswered; -} - -/** Every item answered (0–3) — gates the review step + submit. */ +/** Every item answered (0–3) — gates the submit on the last question. */ export function isComplete(items: readonly number[]): boolean { return items.length > 0 && items.every((v) => v >= 0); } -/** How many items carry a real answer (for the review recap). */ -export function answeredCount(items: readonly number[]): number { - return items.filter((v) => v >= 0).length; -} - /** - * The next step after `step`. A question advances to the next question, the - * last question advances to the review step, and the review step stays put - * (submit, not advance). + * The next step after `step`: a question advances to the next question; the + * last question stays put (submit, not advance). */ export function nextStep(step: number, itemCount: number): number { - const review = reviewStep(itemCount); - if (step >= review) return review; + if (step >= itemCount) return itemCount; return step + 1; } @@ -65,7 +36,7 @@ export function prevStep(step: number): number { return step > 1 ? step - 1 : 1; } -/** Whether `step` is the review step for this instrument. */ -export function isReviewStep(step: number, itemCount: number): boolean { - return step >= reviewStep(itemCount); +/** Whether `step` is the last question for this instrument. */ +export function isLastStep(step: number, itemCount: number): boolean { + return step >= itemCount; } diff --git a/src/components/mental-health/check-in-wizard.tsx b/src/components/mental-health/check-in-wizard.tsx index 8d337b859..d7b178857 100644 --- a/src/components/mental-health/check-in-wizard.tsx +++ b/src/components/mental-health/check-in-wizard.tsx @@ -1,44 +1,39 @@ "use client"; /** - * v1.25.3 — one-question-at-a-time check-in. + * v1.25.3 — one-question-at-a-time check-in, rendered INLINE on the page + * (not a modal), because here the page *is* the surface. * - * Replaces the all-questions-at-once `
      ` wall with a linear stepper that - * reuses the medication wizard's presentational `WizardStepper` (the dot row + - * "Question 3 of 9" caption) and its Back/Next footer grammar — rendered INLINE - * on the page (not a modal), because here the page *is* the surface. The step - * navigation lives in `check-in-nav.ts` (pure, linear: backward always allowed, - * never skip ahead to an unanswered question). + * v1.27.6 — slimmed to questions only. The question-overview strip (the + * dot/jump row borrowed from the medication wizard) and the "N of N + * answered" review interstitial are gone: a screening is a quiet, linear + * moment, not a form to audit. The Back button stays; a small "3 / 9" + * caption keeps orientation without turning progress into a scoreboard. + * Answering the last question arms the submit directly — the next thing + * the user sees is the dignified result view. * - * Header: instrument title + ONE standardized explanation line, NO disclaimer - * (§2 — the "voluntary self-test, not a diagnosis" disclaimer renders only on - * the landing + behind the InfoHint, never while taking the test). The optional - * functional-difficulty control folds into the review step. + * Header: instrument title + ONE standardized explanation line, NO + * disclaimer (§2 — the "voluntary self-test, not a diagnosis" disclaimer + * renders only on the landing, never while taking the test). */ import { useEffect, useRef, useState } from "react"; import { ArrowLeft } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; -import { WizardStepper } from "@/components/medications/wizard/wizard-stepper"; import { useTranslations } from "@/lib/i18n/context"; -import { cn } from "@/lib/utils"; import { INSTRUMENTS } from "@/lib/mental-health/instruments"; import { - UNANSWERED, - answeredCount, - buildStepList, isComplete, - isReviewStep, + isLastStep, nextStep, prevStep, - reachableUntilIndex, + UNANSWERED, } from "./check-in-nav"; import type { InstrumentId } from "./types"; const SCALE = [0, 1, 2, 3] as const; -const FUNCTIONAL = [0, 1, 2, 3] as const; function lower(id: InstrumentId): "phq9" | "gad7" { return id === "PHQ9" ? "phq9" : "gad7"; @@ -52,8 +47,8 @@ export function CheckInWizard({ isError, }: { instrument: InstrumentId; - /** Submit the completed check-in. `functional` is null when unanswered. */ - onSubmit: (items: number[], functional: number | null) => void; + /** Submit the completed check-in. */ + onSubmit: (items: number[]) => void; /** Return to the landing (abandons the in-progress check-in). */ onBack: () => void; isPending: boolean; @@ -67,17 +62,14 @@ export function CheckInWizard({ const [items, setItems] = useState(() => Array(itemCount).fill(UNANSWERED), ); - const [functional, setFunctional] = useState(null); - const stepList = buildStepList(itemCount); - const onReview = isReviewStep(step, itemCount); - const questionIndex = step - 1; // 0-based item index for a question step + const onLast = isLastStep(step, itemCount); + const questionIndex = step - 1; // 0-based item index for the current question const complete = isComplete(items); - const reachableUntil = reachableUntilIndex(items); - // a11y: announce each step by moving focus to its heading (the question text - // / the review title). Mirrors the medication dialog's per-step title focus - // so a keyboard / screen-reader user hears the new question after an + // a11y: announce each step by moving focus to its heading (the question + // text). Mirrors the medication dialog's per-step title focus so a + // keyboard / screen-reader user hears the new question after an // auto-advance, not silence. const headingRef = useRef(null); useEffect(() => { @@ -90,15 +82,12 @@ export function CheckInWizard({ next[questionIndex] = value; return next; }); - // Forward-on-select: advance to the next question, or onto the review step - // from the last question. The footer Next is the redundant keyboard path. - setStep((s) => nextStep(s, itemCount)); + // Forward-on-select: advance to the next question. On the last question + // the selection stays visible and the footer submit arms — submitting is + // a deliberate second tap, never a side effect of answering. + if (!onLast) setStep((s) => nextStep(s, itemCount)); } - const srLabel = onReview - ? t("mentalHealth.review.title") - : t("mentalHealth.questionAria", { current: step, total: itemCount }); - return (
      {/* In-test header — instrument title + ONE standardized explanation line. - No disclaimer here (§2); the (i) tooltip on the landing carries it. */} + No disclaimer here (§2); the landing carries it. */}

      {t(`mentalHealth.instrument.${key}`)} @@ -129,114 +118,48 @@ export function CheckInWizard({

      -
      - [ - i + 1, - String(i + 1), - ]), - [itemCount + 1, t("mentalHealth.review.title")], - ])} - onJump={(target) => setStep(target)} - onFirst={() => setStep(1)} - onLast={() => setStep(itemCount + 1)} - firstEnabled={step > 1} - lastEnabled={complete && !onReview} - firstLabel={t("mentalHealth.jumpFirst")} - lastLabel={t("mentalHealth.jumpLast")} - srLabel={srLabel} - /> -
      - - {!onReview ? ( -
      -

      - {t("mentalHealth.progress", { - current: step, - total: itemCount, - })} -

      -

      - {t(`mentalHealth.items.${key}.${step}`)} -

      -
      - {SCALE.map((v) => ( - - ))} -
      -
      - ) : ( -
      -

      - {t("mentalHealth.review.title")} -

      -

      - {t("mentalHealth.review.recap", { - answered: answeredCount(items), - total: itemCount, - })} -

      - - {/* The optional, unscored functional-difficulty follow-up folds - into the review step rather than its own dot (§1). */} -
      - - {t("mentalHealth.functionalTitle")} - -
      +

      + {t("mentalHealth.progress", { + current: step, + total: itemCount, + })} +

      +

      + {t(`mentalHealth.items.${key}.${step}`)} +

      +
      + {SCALE.map((v) => ( + - ))} -
      -
      - - {isError && ( -

      - {t("mentalHealth.error")} -

      - )} + {t(`mentalHealth.options.${v}`)} + + ))}
      - )} + + {isError && ( +

      + {t("mentalHealth.error")} +

      + )} +
      @@ -250,7 +173,7 @@ export function CheckInWizard({ > {t("mentalHealth.back")} - {!onReview ? ( + {!onLast ? ( {headerActions} diff --git a/src/lib/jobs/__tests__/reminder-satisfy.test.ts b/src/lib/jobs/__tests__/reminder-satisfy.test.ts index 7995ce86c..add9c1298 100644 --- a/src/lib/jobs/__tests__/reminder-satisfy.test.ts +++ b/src/lib/jobs/__tests__/reminder-satisfy.test.ts @@ -160,6 +160,52 @@ describe("runReminderSatisfyForUser", () => { expect(prisma.measurement.findFirst).not.toHaveBeenCalled(); }); + it("satisfies a screening reminder from the server-written score row (v1.27.6)", async () => { + // A completed PHQ-9 check-in writes a COMPUTED PHQ9_SCORE measurement; + // the screening reminder resolves from that row like any typed reminder. + const measuredAt = new Date("2026-07-01T10:00:00Z"); + const { prisma, updates } = makePrisma({ + reminders: [ + reminderRow({ measurementType: "PHQ9_SCORE", intervalDays: 28 }), + ], + measurement: { measuredAt }, + }); + const isModuleEnabled = vi.fn(async () => true); + + const summary = await runReminderSatisfyForUser( + prisma as never, + "u1", + new Date("2026-07-01T12:00:00Z"), + { isModuleEnabled }, + ); + + expect(summary.satisfied).toBe(1); + expect(isModuleEnabled).toHaveBeenCalledWith("u1", "mentalHealth"); + expect(updates[0].data.lastSatisfiedAt).toEqual(measuredAt); + }); + + it("produces no engine activity for a screening reminder when the mental-health module is off", async () => { + const { prisma, updates } = makePrisma({ + reminders: [ + reminderRow({ measurementType: "GAD7_SCORE", intervalDays: 28 }), + ], + measurement: { measuredAt: new Date("2026-07-01T10:00:00Z") }, + }); + const isModuleEnabled = vi.fn(async () => false); + + const summary = await runReminderSatisfyForUser( + prisma as never, + "u1", + new Date(), + { isModuleEnabled }, + ); + + expect(summary.skippedModuleDisabled).toBe(1); + expect(summary.satisfied).toBe(0); + expect(isModuleEnabled).toHaveBeenCalledWith("u1", "mentalHealth"); + expect(updates).toHaveLength(0); + }); + it("is forward-only: a stale event is a no-op (cron + hook converge)", async () => { const { prisma, updates } = makePrisma({ reminders: [ diff --git a/src/lib/jobs/measurement-reminder.ts b/src/lib/jobs/measurement-reminder.ts index 186ad7cdf..1138cf54b 100644 --- a/src/lib/jobs/measurement-reminder.ts +++ b/src/lib/jobs/measurement-reminder.ts @@ -51,9 +51,11 @@ import { satisfyReminder } from "@/lib/measurement-reminders/satisfy"; * pressure, pulse, body composition) or has no module of its own. A * `null` reminder type (free-text Vorsorge entry) also yields `null`. * - * Only the two secondary-domain types carry a gate: glucose and sleep. - * Everything else is core and dispatches regardless — disabling a module - * must never silence a core-vital reminder. + * Only the secondary-domain types carry a gate: glucose, sleep, and the + * mental-wellbeing screenings (v1.27.6 — the PHQ-9 / GAD-7 module is + * opt-in, so a screening reminder must fall silent the moment the module + * is off). Everything else is core and dispatches regardless — disabling + * a module must never silence a core-vital reminder. */ function moduleForMeasurementType( type: MeasurementType | null, @@ -63,6 +65,9 @@ function moduleForMeasurementType( return "glucose"; case "SLEEP_DURATION": return "sleep"; + case "PHQ9_SCORE": + case "GAD7_SCORE": + return "mentalHealth"; default: return null; } diff --git a/src/lib/validations/__tests__/measurement-reminders.test.ts b/src/lib/validations/__tests__/measurement-reminders.test.ts index 219e395ee..9ac7458cc 100644 --- a/src/lib/validations/__tests__/measurement-reminders.test.ts +++ b/src/lib/validations/__tests__/measurement-reminders.test.ts @@ -14,7 +14,7 @@ import { describe("measurementReminderTypeEnum (V3 — completeness)", () => { const allowed = measurementReminderTypeEnum.options; - it("exposes the full active set: vitals + body composition", () => { + it("exposes the full active set: vitals + body composition + screenings", () => { expect(new Set(allowed)).toEqual( new Set([ // Vitals @@ -34,10 +34,22 @@ describe("measurementReminderTypeEnum (V3 — completeness)", () => { "TOTAL_BODY_WATER", "VISCERAL_FAT", "BODY_MASS_INDEX", + // v1.27.6 — plannable mental-wellbeing screenings + "PHQ9_SCORE", + "GAD7_SCORE", ]), ); }); + it("accepts a plannable screening reminder with the 4-week default cadence", () => { + const parsed = createMeasurementReminderSchema.safeParse({ + label: "PHQ-9 Check-in", + measurementType: "PHQ9_SCORE", + intervalDays: 28, + }); + expect(parsed.success).toBe(true); + }); + it("accepts a newly-added body-composition type on create", () => { const parsed = createMeasurementReminderSchema.safeParse({ label: "Körperzusammensetzung messen", diff --git a/src/lib/validations/measurement-reminders.ts b/src/lib/validations/measurement-reminders.ts index 3c17f2ea4..39794123a 100644 --- a/src/lib/validations/measurement-reminders.ts +++ b/src/lib/validations/measurement-reminders.ts @@ -56,17 +56,44 @@ export const measurementReminderTypeEnum = z "TOTAL_BODY_WATER", "VISCERAL_FAT", "BODY_MASS_INDEX", + // v1.27.6 — the mental-wellbeing screeners become plannable Vorsorge + // items. Not a passive wearable score: a screening is an active "go and + // do it" action exactly like stepping on the scale. Auto-resolves from + // the server-owned COMPUTED PHQ9_SCORE / GAD7_SCORE row the assessment + // route writes on completion. Gated on the opt-in mentalHealth module in + // the dispatcher (see `moduleForMeasurementType`). + "PHQ9_SCORE", + "GAD7_SCORE", ]) .meta({ id: "MeasurementReminderType", description: - "Auto-resolve target metric (vitals + body-composition family). BP resolves on BLOOD_PRESSURE_SYS (the SYS row is the 'a BP was measured' sentinel). Omit for a free-text Vorsorge that resolves only on a manual satisfy or a matching lab result.", + "Auto-resolve target metric (vitals + body-composition family + the PHQ-9 / GAD-7 screenings). BP resolves on BLOOD_PRESSURE_SYS (the SYS row is the 'a BP was measured' sentinel); a screening reminder resolves on the server-written PHQ9_SCORE / GAD7_SCORE row when a check-in completes. Omit for a free-text Vorsorge that resolves only on a manual satisfy or a matching lab result.", }); export type MeasurementReminderType = z.infer< typeof measurementReminderTypeEnum >; +/** + * v1.27.6 — the reminder types that are SCREENINGS, not numeric readings. + * Every surface with a per-reminder primary action branches on this: a + * screening routes to the check-in page (`/mental-wellbeing`) instead of + * opening the numeric MeasurementForm — a score is never typed in, it + * falls out of a completed test (which then auto-satisfies the reminder). + */ +export const SCREENING_REMINDER_TYPES: ReadonlySet = new Set([ + "PHQ9_SCORE", + "GAD7_SCORE", +]); + +/** Whether a reminder's `measurementType` targets a screening check-in. */ +export function isScreeningReminderType( + type: string | null | undefined, +): boolean { + return type != null && SCREENING_REMINDER_TYPES.has(type); +} + /** * RFC-5545 RRULE guard. The recurrence engine parses it; here we only * bound the length and require the `FREQ=` token so a typo doesn't reach