mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
fix(import): leave out Apple Health samples HealthLog wrote itself
The iOS app writes manual entries into Apple Health, and mirrors Withings and import rows into it, each stamped with dev.healthlog.app.origin = healthlog. The server already holds those readings under their own source, so the same sample arriving through an Apple Health export is a second copy: the series shows it twice and the rollups count it twice. The export import now leaves out a record carrying that marker. The marker is a child <MetadataEntry>, read after the record's open tag, so a record is committed at its close tag. As a fallback for manual entries mirrored before the app set the marker, a record is also left out when a MANUAL row of the same type and value sits within 2 s (same rule and tolerance as the sync path). Withings and import rows are not matched by value and time: they reach Apple Health only through the mirror, which always sets the marker. The import summary says how many records were left out for this reason. Fixes #1109
This commit is contained in:
1 parent
808b2672cd
commit
a5e98c9e71
11 files changed
+353
-41
No files matched your search
@@ -31,6 +31,8 @@ interface JobStatus {
|
||||
totals?: { recordsRead?: number; rowsUpserted?: number };
|
||||
clinical?: { skipped?: number };
|
||||
cumulativeEstimates?: { days?: number; rows?: number };
|
||||
/** Records HealthLog wrote into Apple Health itself, left out here. */
|
||||
writtenByHealthLog?: { byMarker?: number; matchedManual?: number };
|
||||
/** HK types deferred by design — read but not (yet) imported. */
|
||||
deferred?: Record<string, number>;
|
||||
/** Per-key drop counters — plain HK types are unsupported-by-design,
|
||||
@@ -342,6 +344,9 @@ export function AppleHealthImportCard() {
|
||||
const status = statusQuery.data ?? null;
|
||||
const isRunning = status !== null && !TERMINAL_STATES.includes(status.status);
|
||||
const isDone = status?.status === "done";
|
||||
const ownRecordsSkipped =
|
||||
(status?.result?.writtenByHealthLog?.byMarker ?? 0) +
|
||||
(status?.result?.writtenByHealthLog?.matchedManual ?? 0);
|
||||
const isFailed = status?.status === "failed";
|
||||
const busy = uploading || isRunning;
|
||||
const percent = status?.progress?.percent ?? null;
|
||||
@@ -492,6 +497,19 @@ export function AppleHealthImportCard() {
|
||||
})}
|
||||
</p>
|
||||
)}
|
||||
{isDone && ownRecordsSkipped > 0 && (
|
||||
<p
|
||||
data-testid="import-apple-health-own-skipped"
|
||||
className="text-muted-foreground text-sm"
|
||||
>
|
||||
{t(
|
||||
"settings.sections.export.import.appleHealth.writtenByHealthLog",
|
||||
{
|
||||
count: ownRecordsSkipped,
|
||||
},
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{isDone && (status?.result?.cumulativeEstimates?.days ?? 0) > 0 && (
|
||||
<AppleHealthEstimateWarning
|
||||
days={status?.result?.cumulativeEstimates?.days ?? 0}
|
||||
|
||||
Reference in new issue
Block a user