mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
Carry medication dose changes through backup and restore
The titration history was classified as backed up and travelled with nothing. An account restored from a backup showed the current dose and no record of how it got there: the ramp, the reductions, the note the prescriber gave for each step. For a long-running drug that history is often the more clinically interesting half. Export writes the rows nested inside their drug, ordered by effectiveFrom, so a portable restore that mints fresh ids needs no remap. The note follows the contract the side effects already use: a portable export decrypts it for a human reader, a disaster-recovery export carries the ciphertext verbatim, and a restore never writes it into the legacy plaintext column. Order is the content here, not decoration. Two rows on the same drug in the same unit, 5 mg then 10 mg, describe a ramp; the same two rows returned in the other order describe a taper. Counting them back cannot tell those apart, so the round-trip test asserts the sequence and the values, not the count. MedicationDoseChange moves from the coverage-pending register into the two-ended list, which makes the round-trip registry incomplete until a row is seeded and counted. That is a compile error, not a review note.
This commit is contained in:
1 parent
aca5b2d30b
commit
5e0994aab9
6 files changed
+152
-2
No files matched your search
@@ -184,6 +184,24 @@ const medicationPauseEraSchema = z
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
/**
|
||||
* One step of a titration: when the dose moved and to what.
|
||||
*
|
||||
* The note follows the side-effect contract — decrypted prose in a portable
|
||||
* file, ciphertext plus any legacy plaintext in a recovery one.
|
||||
*/
|
||||
const medicationDoseChangeSchema = z
|
||||
.object({
|
||||
id: z.string().min(1).optional(),
|
||||
effectiveFrom: isoDateTime,
|
||||
doseValue: z.number(),
|
||||
doseUnit: z.string().min(1),
|
||||
note: z.string().nullable().optional(),
|
||||
noteEncrypted: base64BytesSchema.nullable().optional(),
|
||||
createdAt: isoDateTime.optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
const medicationSchema = z
|
||||
.object({
|
||||
id: z.string().min(1).optional(),
|
||||
@@ -221,6 +239,9 @@ const medicationSchema = z
|
||||
// Defaulted for the same reason: a file written before pause eras rode the
|
||||
// wire still parses, and a drug that was never paused writes [].
|
||||
pauseEras: z.array(medicationPauseEraSchema).default([]),
|
||||
// Same default, same reason: an older file parses, a drug never titrated
|
||||
// writes [].
|
||||
doseChanges: z.array(medicationDoseChangeSchema).default([]),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
|
||||
Reference in new issue
Block a user