feat(illness): name the driving vital in the recovery-gap summary

The cross-episode summary already computes per-vital physiological returns
but the card surfaced only one bare line. Thread the dominant returning
vital through the aggregate and the DTO so the copy reads 'you tend to feel
better before your resting heart rate settles' instead of a context-free
gap figure.

The aggregate tallies which vital produced a real return across the
episodes that qualified for the typical-gap median and reports the most
frequent one (deterministic alphabetical tiebreak); the driver is named
only when a gap actually clears the magnitude gate. Zero new compute — the
returns were already in hand. Adds the localized copy in all six locales.
This commit is contained in:
Marc-André Bombeck committed 2026-06-21 14:11:20 +02:00
1 parent 36affd5daf
commit 638bc6c835
13 files changed
+152 -10

No files matched your search

+21 -2
View File
@@ -85,7 +85,11 @@ export const GET = apiHandler(async (request: NextRequest) => {
// out of the typical-gap median by the aggregate's signal-density gates.
const gapById = new Map<
string,
{ recoveryGapDays: number | null; gapMeasurementDays: number }
{
recoveryGapDays: number | null;
gapMeasurementDays: number;
gapReturnTypes: string[];
}
>();
if (includeRecoveryGap) {
const gapCandidates = rows
@@ -98,7 +102,11 @@ export const GET = apiHandler(async (request: NextRequest) => {
async (): Promise<
[
string,
{ recoveryGapDays: number | null; gapMeasurementDays: number },
{
recoveryGapDays: number | null;
gapMeasurementDays: number;
gapReturnTypes: string[];
},
]
> => {
const derived = await computeEpisodeCorrelation(
@@ -130,6 +138,15 @@ export const GET = apiHandler(async (request: NextRequest) => {
derived.status === "ok"
? derived.value.adverseCoverageDays
: 0,
// The vitals that produced a real physiological return —
// tallied across the qualifying episodes to name the dominant
// driving vital in the summary copy.
gapReturnTypes:
derived.status === "ok"
? derived.value.returns
.filter((r) => r.gapDays !== null)
.map((r) => String(r.type))
: [],
},
];
},
@@ -148,6 +165,7 @@ export const GET = apiHandler(async (request: NextRequest) => {
resolved: r.resolvedAt !== null,
recoveryGapDays: gap?.recoveryGapDays ?? null,
gapMeasurementDays: gap?.gapMeasurementDays ?? 0,
gapReturnTypes: gap?.gapReturnTypes ?? [],
lifecycle: r.lifecycle,
};
});
@@ -160,6 +178,7 @@ export const GET = apiHandler(async (request: NextRequest) => {
episode_count: summary.episodeCount,
gap_sample_size: summary.gapSampleSize,
typical_gap_days: summary.typicalRecoveryGapDays,
gap_driver_type: summary.gapDriverType,
include_recovery_gap: includeRecoveryGap,
},
});