mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
feat(illness): surface sleep as a context line on the recovery card
Adds a neutral sleep observation alongside the per-episode recovery gap: the user's usual asleep minutes over their well baseline vs the mean over the episode window, narrated as 'you slept more/less than usual' when the two diverge. It is an observation only — never a recovery claim, never a return track, and never part of the headline recovery-gap number. Per-night asleep totals come from the canonical night reconstruction over the baseline and episode windows, so a multi-source night (two writers for one sleep) is counted once, matching every other sleep surface. The observation withholds entirely on thin data — too few baseline or episode nights, or a delta below a 30-minute floor — so day-to-day jitter is never narrated as a finding. Additive optional DTO field; no schema, no migration. Two locale keys across the six bundles. Regenerate the OpenAPI contract from the Zod source.
This commit is contained in:
1 parent
e432b53e0d
commit
8d6d63cd1a
13 files changed
+562
-4
No files matched your search
@@ -41,6 +41,11 @@ function DeviationRow({ d }: { d: IllnessVitalDeviation }) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Round asleep-minutes to a friendly hours figure (one decimal). */
|
||||
function hoursFromMinutes(minutes: number): string {
|
||||
return (Math.round((minutes / 60) * 10) / 10).toString();
|
||||
}
|
||||
|
||||
function CorrelationBody({ value }: { value: IllnessCorrelationValue }) {
|
||||
const { t } = useTranslations();
|
||||
const gap = value.recoveryGapDays;
|
||||
@@ -48,6 +53,9 @@ function CorrelationBody({ value }: { value: IllnessCorrelationValue }) {
|
||||
// the symptoms ("…before your symptoms eased"); otherwise the existing
|
||||
// vital-driven phrasing. Clinically calm — observation, never prediction.
|
||||
const symptomDriven = value.gapDriverType === "FUNCTIONAL_IMPACT";
|
||||
// Sleep-as-context: a neutral observation subordinate to the gap, withheld by
|
||||
// the engine on thin data — never a recovery claim, never a second gap.
|
||||
const sleep = value.sleepContext;
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
@@ -90,6 +98,16 @@ function CorrelationBody({ value }: { value: IllnessCorrelationValue }) {
|
||||
)
|
||||
: t("illness.correlation.recoveryGapSame")}
|
||||
</p>
|
||||
{sleep ? (
|
||||
<p className="text-muted-foreground mt-1.5 text-xs">
|
||||
{t(
|
||||
sleep.deltaMinutes > 0
|
||||
? "illness.correlation.sleepContextMore"
|
||||
: "illness.correlation.sleepContextLess",
|
||||
{ hours: hoursFromMinutes(Math.abs(sleep.deltaMinutes)) },
|
||||
)}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
|
||||
@@ -111,6 +111,19 @@ export interface IllnessRedFlag {
|
||||
days: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A neutral sleep-as-context observation for the episode — slept more / less
|
||||
* than usual — surfaced ALONGSIDE the gap, never part of the recovery-gap
|
||||
* number. Null when the sleep data is too thin or the delta sub-floor.
|
||||
*/
|
||||
export interface SleepContext {
|
||||
baselineMeanMinutes: number;
|
||||
episodeMeanMinutes: number;
|
||||
/** `episode − baseline` asleep minutes (positive = slept more than usual). */
|
||||
deltaMinutes: number;
|
||||
nightsCounted: number;
|
||||
}
|
||||
|
||||
export interface IllnessCorrelationValue {
|
||||
episodeId: string;
|
||||
preOnset: IllnessVitalDeviation[];
|
||||
@@ -126,6 +139,11 @@ export interface IllnessCorrelationValue {
|
||||
*/
|
||||
gapDriverType: string | null;
|
||||
redFlags: IllnessRedFlag[];
|
||||
/**
|
||||
* Sleep-as-context observation, or null when withheld (thin data / sub-floor
|
||||
* delta). Additive — never part of the headline recovery-gap.
|
||||
*/
|
||||
sleepContext: SleepContext | null;
|
||||
}
|
||||
|
||||
/** The flat `Derived<T>` wire shape the correlation route returns. */
|
||||
|
||||
Reference in new issue
Block a user