mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
feat(backup): carry a lab result's external identity through backup and restore
Both the disaster-recovery and the portable file now carry lab_results.external_id, and a restore writes it back, so a restored account still recognises a Health Records result when it arrives again and a deleted one stays deleted. Older files restore unchanged.
This commit is contained in:
1 parent
376102a71e
commit
72a05ea411
8 files changed
+44
-20
No files matched your search
@@ -44,6 +44,9 @@ export const labResultBackupSchema = z
|
||||
sourceUnit: z.string().nullable().optional(),
|
||||
takenAt: isoDateTime,
|
||||
source: z.string().min(1),
|
||||
// The identity a reading arrived under from Health Records (a digest).
|
||||
// Optional: absent on every file written before the column.
|
||||
externalId: z.string().min(1).max(128).nullable().optional(),
|
||||
biomarkerName: z.string().nullable().optional(),
|
||||
biomarkerId: z.string().nullable().optional(),
|
||||
note: z.string().nullable().optional(),
|
||||
|
||||
@@ -81,6 +81,9 @@ export interface LabResultBackupEntry {
|
||||
sourceUnit?: string | null;
|
||||
takenAt: string;
|
||||
source: string;
|
||||
/** The identity a Health Records reading arrived under (a digest), so a
|
||||
* restored account still recognises it when it arrives again. */
|
||||
externalId?: string | null;
|
||||
/** Human-readable cross-reference into `biomarkers` below, not an id. */
|
||||
/** Stable canonical FK; legacy portable payloads use biomarkerName. */
|
||||
biomarkerId?: string | null;
|
||||
@@ -221,6 +224,7 @@ export async function buildLabsBackupSlice(
|
||||
sourceUnit: r.sourceUnit,
|
||||
takenAt: r.takenAt.toISOString(),
|
||||
source: r.source,
|
||||
externalId: r.externalId,
|
||||
biomarkerName: r.biomarker?.name ?? null,
|
||||
}));
|
||||
|
||||
@@ -464,6 +468,7 @@ export async function restoreLabResults(ctx: RestoreContext): Promise<void> {
|
||||
sourceUnit: lab.sourceUnit ?? null,
|
||||
takenAt: new Date(lab.takenAt),
|
||||
source: lab.source,
|
||||
externalId: lab.externalId ?? null,
|
||||
noteEncrypted:
|
||||
lab.noteEncrypted !== undefined
|
||||
? lab.noteEncrypted === null
|
||||
|
||||
@@ -902,8 +902,8 @@
|
||||
"id": "<id:37>",
|
||||
"biomarkerId": "<id:38>",
|
||||
"noteEncrypted": "<sealed:v1:rt-LabResult-noteEncrypted>",
|
||||
"createdAt": "2026-05-02T10:58:00.000Z",
|
||||
"updatedAt": "2026-05-02T10:59:00.000Z",
|
||||
"createdAt": "2026-05-02T10:59:00.000Z",
|
||||
"updatedAt": "2026-05-02T11:00:00.000Z",
|
||||
"deletedAt": null,
|
||||
"note": null,
|
||||
"panel": "rt-LabResult-panel",
|
||||
@@ -920,14 +920,15 @@
|
||||
"sourceUnit": "rt-LabResult-sourceUnit",
|
||||
"takenAt": "2026-06-30T09:00:00.000Z",
|
||||
"source": "rt-LabResult-source",
|
||||
"externalId": "rt-LabResult-externalId",
|
||||
"biomarkerName": "Ferritin"
|
||||
},
|
||||
{
|
||||
"id": "<id:39>",
|
||||
"biomarkerId": null,
|
||||
"noteEncrypted": null,
|
||||
"createdAt": "2026-05-02T10:58:01.000Z",
|
||||
"updatedAt": "2026-05-02T10:59:01.000Z",
|
||||
"createdAt": "2026-05-02T10:59:01.000Z",
|
||||
"updatedAt": "2026-05-02T11:00:01.000Z",
|
||||
"deletedAt": "<tombstone>",
|
||||
"note": null,
|
||||
"panel": null,
|
||||
@@ -944,6 +945,7 @@
|
||||
"sourceUnit": null,
|
||||
"takenAt": "2026-05-30T09:00:00.000Z",
|
||||
"source": "MANUAL",
|
||||
"externalId": null,
|
||||
"biomarkerName": null
|
||||
}
|
||||
],
|
||||
@@ -3361,13 +3363,14 @@
|
||||
"sourceUnit": "rt-LabResult-sourceUnit",
|
||||
"takenAt": "2026-06-30T09:00:00.000Z",
|
||||
"source": "rt-LabResult-source",
|
||||
"externalId": "rt-LabResult-externalId",
|
||||
"biomarkerName": "Ferritin",
|
||||
"biomarkerId": "<id:38>",
|
||||
"note": null,
|
||||
"createdAt": "2026-05-02T10:58:00.000Z",
|
||||
"createdAt": "2026-05-02T10:59:00.000Z",
|
||||
"noteEncrypted": "<sealed:v1:rt-LabResult-noteEncrypted>",
|
||||
"deletedAt": null,
|
||||
"updatedAt": "2026-05-02T10:59:00.000Z"
|
||||
"updatedAt": "2026-05-02T11:00:00.000Z"
|
||||
},
|
||||
{
|
||||
"id": "<id:39>",
|
||||
@@ -3385,13 +3388,14 @@
|
||||
"sourceUnit": null,
|
||||
"takenAt": "2026-05-30T09:00:00.000Z",
|
||||
"source": "MANUAL",
|
||||
"externalId": null,
|
||||
"biomarkerName": null,
|
||||
"biomarkerId": null,
|
||||
"note": null,
|
||||
"createdAt": "2026-05-02T10:58:01.000Z",
|
||||
"createdAt": "2026-05-02T10:59:01.000Z",
|
||||
"noteEncrypted": null,
|
||||
"deletedAt": "<tombstone>",
|
||||
"updatedAt": "2026-05-02T10:59:01.000Z"
|
||||
"updatedAt": "2026-05-02T11:00:01.000Z"
|
||||
}
|
||||
],
|
||||
"biomarkers": [
|
||||
|
||||
@@ -547,6 +547,7 @@
|
||||
"sourceUnit": "rt-LabResult-sourceUnit",
|
||||
"takenAt": "2026-06-30T09:00:00.000Z",
|
||||
"source": "rt-LabResult-source",
|
||||
"externalId": "rt-LabResult-externalId",
|
||||
"biomarkerName": "Ferritin"
|
||||
}
|
||||
],
|
||||
@@ -2216,6 +2217,7 @@
|
||||
"sourceUnit": "rt-LabResult-sourceUnit",
|
||||
"takenAt": "2026-06-30T09:00:00.000Z",
|
||||
"source": "rt-LabResult-source",
|
||||
"externalId": "rt-LabResult-externalId",
|
||||
"biomarkerName": "Ferritin",
|
||||
"note": "rt-LabResult-noteEncrypted"
|
||||
}
|
||||
|
||||
@@ -962,9 +962,10 @@
|
||||
"takenAt": "2026-06-30T09:00:00.000Z",
|
||||
"biomarkerId": "<id:26>",
|
||||
"source": "rt-LabResult-source",
|
||||
"externalId": "rt-LabResult-externalId",
|
||||
"noteEncrypted": "<sealed:v1:rt-LabResult-noteEncrypted>",
|
||||
"createdAt": "2026-05-02T10:58:00.000Z",
|
||||
"updatedAt": "2026-05-02T10:59:00.000Z",
|
||||
"createdAt": "2026-05-02T10:59:00.000Z",
|
||||
"updatedAt": "2026-05-02T11:00:00.000Z",
|
||||
"deletedAt": null
|
||||
},
|
||||
{
|
||||
@@ -985,9 +986,10 @@
|
||||
"takenAt": "2026-05-30T09:00:00.000Z",
|
||||
"biomarkerId": null,
|
||||
"source": "MANUAL",
|
||||
"externalId": null,
|
||||
"noteEncrypted": null,
|
||||
"createdAt": "2026-05-02T10:58:01.000Z",
|
||||
"updatedAt": "2026-05-02T10:59:01.000Z",
|
||||
"createdAt": "2026-05-02T10:59:01.000Z",
|
||||
"updatedAt": "2026-05-02T11:00:01.000Z",
|
||||
"deletedAt": "<tombstone>"
|
||||
}
|
||||
],
|
||||
@@ -3824,8 +3826,8 @@
|
||||
"id": "<id:37>",
|
||||
"biomarkerId": "<id:38>",
|
||||
"noteEncrypted": "<sealed:v1:rt-LabResult-noteEncrypted>",
|
||||
"createdAt": "2026-05-02T10:58:00.000Z",
|
||||
"updatedAt": "2026-05-02T10:59:00.000Z",
|
||||
"createdAt": "2026-05-02T10:59:00.000Z",
|
||||
"updatedAt": "2026-05-02T11:00:00.000Z",
|
||||
"deletedAt": null,
|
||||
"note": null,
|
||||
"panel": "rt-LabResult-panel",
|
||||
@@ -3842,14 +3844,15 @@
|
||||
"sourceUnit": "rt-LabResult-sourceUnit",
|
||||
"takenAt": "2026-06-30T09:00:00.000Z",
|
||||
"source": "rt-LabResult-source",
|
||||
"externalId": "rt-LabResult-externalId",
|
||||
"biomarkerName": "Ferritin"
|
||||
},
|
||||
{
|
||||
"id": "<id:39>",
|
||||
"biomarkerId": null,
|
||||
"noteEncrypted": null,
|
||||
"createdAt": "2026-05-02T10:58:01.000Z",
|
||||
"updatedAt": "2026-05-02T10:59:01.000Z",
|
||||
"createdAt": "2026-05-02T10:59:01.000Z",
|
||||
"updatedAt": "2026-05-02T11:00:01.000Z",
|
||||
"deletedAt": "<tombstone>",
|
||||
"note": null,
|
||||
"panel": null,
|
||||
@@ -3866,6 +3869,7 @@
|
||||
"sourceUnit": null,
|
||||
"takenAt": "2026-05-30T09:00:00.000Z",
|
||||
"source": "MANUAL",
|
||||
"externalId": null,
|
||||
"biomarkerName": null
|
||||
}
|
||||
],
|
||||
|
||||
@@ -976,6 +976,7 @@
|
||||
"takenAt": "2026-06-30T09:00:00.000Z",
|
||||
"biomarkerId": "<id:23>",
|
||||
"source": "rt-LabResult-source",
|
||||
"externalId": "rt-LabResult-externalId",
|
||||
"noteEncrypted": "<sealed:v2:rt-LabResult-noteEncrypted>",
|
||||
"createdAt": "<now>",
|
||||
"updatedAt": "<now>",
|
||||
@@ -2963,6 +2964,7 @@
|
||||
"sourceUnit": "rt-LabResult-sourceUnit",
|
||||
"takenAt": "2026-06-30T09:00:00.000Z",
|
||||
"source": "rt-LabResult-source",
|
||||
"externalId": "rt-LabResult-externalId",
|
||||
"biomarkerName": "Ferritin"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -738,6 +738,7 @@
|
||||
"takenAt": "2026-07-05T08:00:00.000Z",
|
||||
"biomarkerId": "<id:14>",
|
||||
"source": "MANUAL",
|
||||
"externalId": null,
|
||||
"noteEncrypted": "<sealed:v2:morning draw>",
|
||||
"createdAt": "<now>",
|
||||
"updatedAt": "<now>",
|
||||
@@ -1635,6 +1636,7 @@
|
||||
"sourceUnit": null,
|
||||
"takenAt": "2026-07-05T08:00:00.000Z",
|
||||
"source": "MANUAL",
|
||||
"externalId": null,
|
||||
"biomarkerName": "Ferritin"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -557,9 +557,10 @@
|
||||
"takenAt": "2026-06-30T09:00:00.000Z",
|
||||
"biomarkerId": "<id:26>",
|
||||
"source": "rt-LabResult-source",
|
||||
"externalId": "rt-LabResult-externalId",
|
||||
"noteEncrypted": "<sealed:v1:rt-LabResult-noteEncrypted>",
|
||||
"createdAt": "2026-05-02T10:58:00.000Z",
|
||||
"updatedAt": "2026-05-02T10:59:00.000Z",
|
||||
"createdAt": "2026-05-02T10:59:00.000Z",
|
||||
"updatedAt": "2026-05-02T11:00:00.000Z",
|
||||
"deletedAt": null
|
||||
},
|
||||
{
|
||||
@@ -580,9 +581,10 @@
|
||||
"takenAt": "2026-05-30T09:00:00.000Z",
|
||||
"biomarkerId": null,
|
||||
"source": "MANUAL",
|
||||
"externalId": null,
|
||||
"noteEncrypted": null,
|
||||
"createdAt": "2026-05-02T10:58:01.000Z",
|
||||
"updatedAt": "2026-05-02T10:59:01.000Z",
|
||||
"createdAt": "2026-05-02T10:59:01.000Z",
|
||||
"updatedAt": "2026-05-02T11:00:01.000Z",
|
||||
"deletedAt": "<tombstone>"
|
||||
}
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user