Let a person name their own medication categories

A medication can be filed under a category the person named, next to the
built-in ones (#1041). The labels live in medication_category_labels,
encrypted at rest, capped at 20 per account; a medication filed under one
carries its custom:<uuid> key in the category column.

- GET/POST /api/medications/categories (POST idempotent, 30/min per actor,
  admitted at MANAGE like the cycle symptom vocabulary) and owner-only
  PATCH/DELETE /api/medications/categories/{key}. DELETE moves every
  medication filed under the category to OTHER in the same transaction
  and answers movedCount.
- category is widened to a built-in value or custom:<uuid> on the wire,
  the create and update bodies refuse a key that is not the caller's
  (422 medications.category.unknown), and list, detail, the insights
  medication tiles and the MCP medications resource carry categoryLabel.
  A key with no owned label reads as OTHER and is counted on the event.
- The wizard's class step lists the person's categories under the
  built-in rows with an inline add row; the list page gains a category
  filter (session only) and a manage sheet for rename, hide and delete.
- Backup carries customMedicationCategories (decrypted labels) and the
  restore writes them before the medications; wipe plan, encrypted
  column registry, rotation script, sharing guards and OpenAPI follow.
This commit is contained in:
Marc-André Bombeck committed 2026-10-03 21:38:03 +02:00
1 parent 350c646463
commit 4cb8118802
55 files changed
+3201 -187

No files matched your search

@@ -467,6 +467,14 @@ const REGISTRY: DestructiveEntry[] = [
recovery: "permanent",
confirm: ["AlertDialog"],
},
{
file: "components/medications/use-medication-categories.ts",
destroys:
"one of the person's own medication categories; the medications filed under it move to Other, they are not deleted",
triggers: ["components/medications/medication-categories-sheet.tsx"],
recovery: "permanent",
confirm: ["AlertDialog"],
},
{
file: "components/medications/use-medication-intake.ts",
destroys: "an intake event recorded seconds ago",
+15 -2
View File
@@ -1023,6 +1023,10 @@ const DELEGABLE_ROUTES: Record<string, DelegableEntry> = {
domain: "medications",
why: "The record's medication cabinet. The cached list projection keys on the same resolved id it scopes to, so the owner's cell holds the owner's data. Returns no ingest endpoint and no token count — the route that does is refused.",
},
"app/api/medications/categories/route.ts": {
domain: "medications",
why: "The record's own medication category vocabulary, read and added to from the wizard. The labels and the per-category counts are scoped to the resolved id; renaming and deleting live in the owner-only `[key]` sibling.",
},
"app/api/medications/[id]/route.ts": {
domain: "medications",
why: "One medication of the record, fetch-then-guard against the resolved user before anything is serialised.",
@@ -1646,6 +1650,11 @@ const DELEGABLE_MANAGE_ROUTES: Record<string, ManageEntry> = {
conditions: ["C1"],
why: "Adding to the record's own symptom vocabulary. C1.",
},
"app/api/medications/categories/route.ts": {
domain: "medications",
conditions: ["C1"],
why: "Adding to the record's own medication category vocabulary, the cycle symptom precedent. C1.",
},
"app/api/medications/[id]/route.ts": {
domain: "medications",
conditions: ["C4", "C7"],
@@ -1960,8 +1969,12 @@ const ACTOR_ROUTES: Record<string, string> = {
* v1.39.2 -- the body-site view adds one: a read on the record list in the
* visits' domain, with conditions joined only under an illness grant.
* 231 -> 232.
*
* v1.40 -- the custom medication categories add two: the vocabulary read on
* the record list and its create on the manage literal, the cycle symptom
* precedent. Rename and delete stay owner-only. 232 -> 234.
*/
const FROZEN_ENTRY_COUNT = 232;
const FROZEN_ENTRY_COUNT = 234;
/**
* The two surfaces that authenticate a Bearer token outside `requireAuth` —
@@ -2722,7 +2735,7 @@ describe("(g) the MANAGE route set is frozen", () => {
it("keeps the admitted mutation inventory complete and discoverable", () => {
expect(ADMITTED_MUTATING_HANDLERS.length).toBeGreaterThan(0);
expect(ADMITTED_MUTATING_HANDLERS.length).toBe(77);
expect(ADMITTED_MUTATING_HANDLERS.length).toBe(78);
const expected = ADMITTED_MUTATING_HANDLERS.map(
({ handlerModule, action, level }) =>
@@ -267,6 +267,10 @@ const PINNED_AFFORDANCES: Record<
"src/components/medications/sections/inventory-section.tsx": {
"toast.success": 1,
},
// v1.40 — the delete names how many medications moved to Other.
"src/components/medications/medication-categories-sheet.tsx": {
"toast.success": 1,
},
"src/components/medications/sections/notifications-section.tsx": {
"toast.success": 1,
},
@@ -26,7 +26,7 @@ describe("sharing and handler inventories", () => {
});
it("keeps every admitted mutation uniquely addressable and fully controlled", () => {
expect(ADMITTED_MUTATING_HANDLERS).toHaveLength(77);
expect(ADMITTED_MUTATING_HANDLERS).toHaveLength(78);
expect(
new Set(
ADMITTED_MUTATING_HANDLERS.map(