feat(apple-health): ingest the activity rings, mindfulness, State of Mind and AFib burden

Six Apple Health signals leave the deferred list and ride
POST /api/measurements/batch and the export.zip import end to end:
EXERCISE_MINUTES, STAND_MINUTES and STAND_HOURS (the exercise and stand
rings), MINDFUL_MINUTES, STATE_OF_MIND_VALENCE (iOS 18 State of Mind,
-1..1) and AFIB_BURDEN (AFib History, percent of the week). The ring
types and mindful minutes are cumulative, so the daily rollup is their
sum; AFib burden is scaled strictly from Apple's fraction and a value
above 1 is refused rather than guessed at. The archive import takes
mindful minutes from the session's dates and skips idle stand hours.
Every registry carries them: units, ranges, labels in all locales,
categories, chart tokens, report catalogue (mindful minutes and the
valence fenced as sensitive), signal registry with FHIR codings, and
MCP exposure for the three ring types only.

Workout GPS tracks are now an opt-in, off by default
(PATCH /api/auth/me/workout-routes, a switch on Data & Privacy). While
it is off, the workout batch route and the export import keep every
workout and drop its track with the same per-entry status. With it on,
the import reads the referenced GPX files from the archive one bounded
member at a time, thins each to the point cap and stores it sealed.
The climb a track carries is written to Workout.elevationM at write
time, so the workout insight no longer opens the track, and the AI
egress guard now freezes the set of files that read route geometry.
This commit is contained in:
Marc-André Bombeck committed 2026-10-21 20:14:20 +02:00
1 parent d44af06467
commit b045703493
58 files changed
+2233 -163

No files matched your search

@@ -132,6 +132,13 @@ export const MEASUREMENT_TYPE_LABEL_KEYS: Record<string, string> = {
PAIN_NRS: "measurements.typePainNrs",
WAIST_CIRCUMFERENCE: "measurements.typeWaistCircumference",
WAIST_TO_HEIGHT: "measurements.typeWaistToHeight",
// ── v1.44 — activity rings, mindfulness, State of Mind, AFib burden ──
EXERCISE_MINUTES: "measurements.typeExerciseMinutes",
STAND_MINUTES: "measurements.typeStandMinutes",
STAND_HOURS: "measurements.typeStandHours",
MINDFUL_MINUTES: "measurements.typeMindfulMinutes",
STATE_OF_MIND_VALENCE: "measurements.typeStateOfMindValence",
AFIB_BURDEN: "measurements.typeAfibBurden",
};
export const MEASUREMENT_TYPE_ICONS: Record<string, LucideIcon> = {
@@ -267,6 +274,14 @@ export const MEASUREMENT_TYPE_ICONS: Record<string, LucideIcon> = {
PAIN_NRS: Activity,
WAIST_CIRCUMFERENCE: Scale,
WAIST_TO_HEIGHT: Scale,
// ── v1.44 — the rings take the activity glyphs, mindful minutes the
// breath, the valence the score dial, AFib burden the rhythm trace.
EXERCISE_MINUTES: Dumbbell,
STAND_MINUTES: PersonStanding,
STAND_HOURS: PersonStanding,
MINDFUL_MINUTES: Wind,
STATE_OF_MIND_VALENCE: Gauge,
AFIB_BURDEN: HeartPulse,
};
// The colour map lives in its own icon-free module so a surface that only
@@ -129,4 +129,13 @@ export const MEASUREMENT_TYPE_COLORS: Record<string, string> = {
PAIN_NRS: "bg-chart-3/10 text-chart-3 dark:bg-chart-3/20",
WAIST_CIRCUMFERENCE: "bg-chart-4/10 text-chart-4 dark:bg-chart-4/20",
WAIST_TO_HEIGHT: "bg-chart-4/10 text-chart-4 dark:bg-chart-4/20",
// ── v1.44 — the rings and mindful minutes join the activity family
// (chart-2), the valence the score family (chart-1), AFib burden the
// cardio family (chart-3).
EXERCISE_MINUTES: "bg-chart-2/10 text-chart-2 dark:bg-chart-2/20",
STAND_MINUTES: "bg-chart-2/10 text-chart-2 dark:bg-chart-2/20",
STAND_HOURS: "bg-chart-2/10 text-chart-2 dark:bg-chart-2/20",
MINDFUL_MINUTES: "bg-chart-2/10 text-chart-2 dark:bg-chart-2/20",
STATE_OF_MIND_VALENCE: "bg-chart-1/10 text-chart-1 dark:bg-chart-1/20",
AFIB_BURDEN: "bg-chart-3/10 text-chart-3 dark:bg-chart-3/20",
};
@@ -194,8 +194,8 @@ describe("<HealthRecordExportPanel> — the first run", () => {
expect(groupChip(html, "medications")).toBe("0/4");
// ALLERGIES, ILLNESS_EPISODES, VISITS, SURGICAL_HISTORY, IMMUNIZATIONS.
expect(groupChip(html, "history")).toBe("0/5");
expect(groupChip(html, "cardio")).toBe("0/14");
expect(groupChip(html, "activity")).toBe("0/8");
expect(groupChip(html, "cardio")).toBe("0/15");
expect(groupChip(html, "activity")).toBe("0/11");
expect(groupChip(html, "sleepRecovery")).toBe("0/16");
expect(groupChip(html, "mobility")).toBe("0/11");
expect(groupChip(html, "environment")).toBe("0/4");
@@ -32,6 +32,7 @@ import { SettingsInfoTile } from "@/components/settings/_info-tile";
import { SecuritySessionsCard } from "@/components/settings/security-sessions-card";
import { SecurityActivityCard } from "@/components/settings/security-activity-card";
import { TrustedDevicesCard } from "@/components/settings/trusted-devices-card";
import { WorkoutRoutesCard } from "@/components/settings/workout-routes-card";
import { useAuth } from "@/hooks/use-auth";
import { useTranslations } from "@/lib/i18n/context";
import { MODULE_KEYS, MODULE_REGISTRY } from "@/lib/modules/registry";
@@ -130,6 +131,9 @@ export function PrivacySection() {
</ul>
</SettingsCard>
{/* Workout GPS tracks: kept only on opt-in. */}
<WorkoutRoutesCard />
{/* Retention */}
<SettingsCard>
<SettingsCardHeader
@@ -0,0 +1,83 @@
"use client";
/**
* The workout-route opt-in on the Data & Privacy page.
*
* Off by default. A GPS track shows where a person lives, works and trains,
* so new tracks from the iPhone app and the Apple Health export are kept
* only once this is on; the workouts themselves are kept either way. No AI
* feature ever reads a track.
*/
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { MapPinned } from "lucide-react";
import { toastWrittenOutcome } from "@/components/outcome/outcome-toast";
import { SettingsCardHeader } from "@/components/settings/_card-header";
import { SettingsCard } from "@/components/settings/settings-card";
import { QueryErrorRow } from "@/components/ui/query-error-row";
import { Switch } from "@/components/ui/switch";
import { apiGet, apiPatch } from "@/lib/api/api-fetch";
import { showErrorToast } from "@/lib/errors/error-toast";
import { useTranslations } from "@/lib/i18n/context";
import { queryKeys } from "@/lib/query-keys";
interface WorkoutRoutesPref {
storeWorkoutRoutes: boolean;
}
export function WorkoutRoutesCard() {
const { t } = useTranslations();
const queryClient = useQueryClient();
const pref = useQuery<WorkoutRoutesPref>({
queryKey: queryKeys.workoutRoutesPref(),
queryFn: () => apiGet<WorkoutRoutesPref>("/api/auth/me/workout-routes"),
staleTime: 60_000,
});
const update = useMutation<WorkoutRoutesPref, Error, boolean>({
mutationFn: (storeWorkoutRoutes) =>
apiPatch<WorkoutRoutesPref>("/api/auth/me/workout-routes", {
storeWorkoutRoutes,
}),
onSuccess: (data) => {
queryClient.setQueryData(queryKeys.workoutRoutesPref(), data);
},
});
return (
<SettingsCard data-testid="workout-routes-card">
<SettingsCardHeader
anchor="workout-routes"
icon={MapPinned}
title={t("settings.privacy.workoutRoutes.title")}
description={t("settings.privacy.workoutRoutes.description")}
status={
<Switch
checked={pref.data?.storeWorkoutRoutes ?? false}
disabled={pref.isLoading || pref.isError || update.isPending}
onCheckedChange={(checked) =>
update.mutate(checked, {
onSuccess: () =>
toastWrittenOutcome("success", t("settings.saved")),
onError: (failure) =>
showErrorToast(t("settings.savingError"), {
cause: failure,
}),
})
}
aria-label={t("settings.privacy.workoutRoutes.title")}
/>
}
/>
{pref.isError ? (
<QueryErrorRow
inset
error={pref.error}
onRetry={() => void pref.refetch()}
message={t("settings.privacy.workoutRoutes.loadError")}
/>
) : (
<p className="text-sm">{t("settings.privacy.workoutRoutes.detail")}</p>
)}
</SettingsCard>
);
}