v1.37.10 — one drug, a different dose at each time - #770
Merged
Conversation
Add a nullable units_per_dose to medication_schedules so a split-dose plan can consume a different unit count at different times of day (a whole tablet in the morning, a half at noon) on ONE medication instead of two. NULL inherits the medication-level units_per_dose, so every existing row keeps its current behaviour. Migration 0332 adds one nullable Decimal(10,4) column with no backfill.
The inventory consume hook counted the medication-level units_per_dose for every dose, so a split plan could not decrement a whole tablet in the morning and a half at noon. Resolve the units from the taken intake's own slot: match its scheduled wall-clock time in the user's zone to a schedule and read that schedule's units_per_dose, inheriting the medication level on NULL or no match. A medication whose schedules all leave the column NULL resolves exactly as before. The batch-import path binds each dose by its scheduled anchor the same way.
Add schedules[].unitsPerDose to the create/update contract with the same whole-number-or-curated-fraction validation as the medication level, built into the Prisma data field-by-field on both the create and the schedule-replace path. Unwrap the nullable Decimal to a JSON number at every medication read/write response through one shared serializer so the wire shape cannot drift, keeping NULL as NULL to mean inherit-the-medication-level.
Give each parallel schedule its own optional dose and units-per-dose input on the times step, so a split plan (a whole tablet in the morning, a half at noon) is ONE medication with three schedules instead of two drugs that double-count. Leaving both blank inherits the medication-level values, so a single-dose plan is unchanged. An as-needed slot that sits alongside scheduled ones now rides the same medication as a PRN schedule rather than flipping the whole-medication as-needed flag. New keys land in all six locales.
Surface the per-schedule units-per-dose beside the per-slot dose the card already prints, identically on the standard and the GLP-1 card, so a split plan reads at a glance which time takes a half. Muted addendum, no width movement.
…store The schedule exporter enumerates columns, so the new per-schedule units-per-dose needs adding by hand: export it as a Decimal string in the disaster-recovery payload, accept it in the wire schema, and write it back on restore (NULL stays NULL to inherit). Extend the round-trip test to prove a half-tablet slot survives export and re-import.
…trip Integration: a medication with a morning slot at 1 unit and a noon slot at 0.5 draws the right count for each taken dose against a real Postgres. Unit: a per-slot dose + units set in the wizard survives create and round-trips on edit-hydrate.
The consume hook now loads the user's zone, the schedules, and the intake's scheduled anchor to resolve per-slot units, so the fake client grows the schedule read and the batch scheduledFor lookup. The Italian per-dose card label reworded so it no longer echoes English.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Assembled off
origin/main. Additive only: one nullable column, no drops, no restructuring.One drug, a different dose at each time
The reporter's case (@Limbolindi, #767): a "1-0.5-0.5" split forced two separate drug entries whose stocks never added up, and an occasional extra dose became a third phantom entry.
Most of the shape already existed: a
Medicationowns NMedicationSchedulechildren, each already with its own time and its own dose override, and inventory is already shared permedicationId. The one true gap was that units-consumed-per-dose lived at the medication level, so inventory could not draw a different tablet count for a half-dose. This adds that.MedicationSchedule.unitsPerDose Decimal?(migration0332_schedule_units_per_dose, one nullableADD COLUMN, no backfill). NULL inheritsMedication.unitsPerDose, so every existing medication counts down exactly as before.schedules[].unitsPerDoseon the API is additive and NULL-inherits, so an older iOS client that never sends it behaves exactly as today. The column carries through backup and restore. Both med cards show the per-slot amount identically.Verification
openapi:check(in sync; the diff is the version line plus the additive property), test (21116 passed), test:integration (per-slot consume + backup round trip against testcontainers Postgres), build: all green.Carry-forward
Existing single-schedule medications are untouched. A user who already made the two-drug workaround is not auto-merged (two ids, separate stock and history); new entries get the per-slot behaviour, and the manual path is to recreate as one drug. A guided merge could be a later follow-up.