From a868bd1cf27088a17d1419d9929ea00d8d07e438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 28 May 2026 18:47:01 +0200 Subject: [PATCH] feat(meds): extend MedicationCategory with diabetes and antibiotic Adds DIABETES and ANTIBIOTIC to MEDICATION_CATEGORY_VALUES so the upcoming modal wizard's Step 2 taxonomy can write the two rows as first-class clinical categories instead of falling back to OTHER. The clinical category column on medication_categories is plain TEXT backed by Zod for validation; no Prisma enum exists to ALTER, so the migration is documentation-only and the category-label drift-guard gets the matching keys. Both new values feed back into the rendered badges on the medication card. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../migration.sql | 24 +++++++++++++++++++ src/lib/medications/category-label.ts | 2 ++ src/lib/validations/medication.ts | 11 +++++++++ 3 files changed, 37 insertions(+) create mode 100644 prisma/migrations/0082_v154_clinical_category_diabetes_antibiotic/migration.sql diff --git a/prisma/migrations/0082_v154_clinical_category_diabetes_antibiotic/migration.sql b/prisma/migrations/0082_v154_clinical_category_diabetes_antibiotic/migration.sql new file mode 100644 index 000000000..f37fb62e5 --- /dev/null +++ b/prisma/migrations/0082_v154_clinical_category_diabetes_antibiotic/migration.sql @@ -0,0 +1,24 @@ +-- v1.5.4 — Clinical category bucket additions. +-- +-- The medication's clinical category lives in a side-table +-- (`medication_categories`) with a TEXT column rather than a Prisma +-- enum, so adding a new bucket does not require an ALTER TYPE. The +-- migration is documentation-only — the new "DIABETES" and +-- "ANTIBIOTIC" values are enforced at the Zod layer +-- (`MEDICATION_CATEGORY_VALUES` in src/lib/validations/medication.ts) +-- and the side-table's `normalizeCategory` helper accepts them on +-- the same path as the pre-existing buckets. +-- +-- The modal-wizard's Step 2 taxonomy adds Diabetes and Antibiotikum +-- as first-class rows. The mapping table (see +-- src/components/medications/wizard/wizard-payload.ts — +-- WIZARD_TREATMENT_MAPPING) writes "DIABETES" and "ANTIBIOTIC" to +-- the side-table for those rows instead of collapsing them into +-- "OTHER". +-- +-- No SQL changes are needed — the index on `category` already covers +-- the new values, and existing rows retain their previous bucket. + +-- Force a non-empty migration body so prisma records the new step +-- in the `_prisma_migrations` ledger. +SELECT 1 WHERE FALSE; diff --git a/src/lib/medications/category-label.ts b/src/lib/medications/category-label.ts index 0e2e9989d..751213d20 100644 --- a/src/lib/medications/category-label.ts +++ b/src/lib/medications/category-label.ts @@ -29,6 +29,8 @@ const MEDICATION_CATEGORY_KEYS: Record = { HORMONE: "medications.categoryHormone", SKIN: "medications.categorySkin", SLEEP_AID: "medications.categorySleepAid", + DIABETES: "medications.categoryDiabetes", + ANTIBIOTIC: "medications.categoryAntibiotic", OTHER: "medications.categoryOther", }; diff --git a/src/lib/validations/medication.ts b/src/lib/validations/medication.ts index 20ad7ebdc..631a0c3b3 100644 --- a/src/lib/validations/medication.ts +++ b/src/lib/validations/medication.ts @@ -1,6 +1,14 @@ import { z } from "zod/v4"; const timeRegex = /^([01]\d|2[0-3]):([0-5]\d)$/; +/** + * Clinical-category values stored in the `medication_categories` side- + * table (TEXT column). v1.5.4 adds `DIABETES` and `ANTIBIOTIC` so the + * wizard's Step 2 taxonomy can write a first-class bucket for those + * two rows instead of collapsing them into `OTHER`. The column is a + * plain TEXT field — no Prisma enum exists to migrate; the Zod values + * list is the only enforcement layer. + */ export const MEDICATION_CATEGORY_VALUES = [ "BLOOD_PRESSURE", "VITAMIN", @@ -12,8 +20,11 @@ export const MEDICATION_CATEGORY_VALUES = [ "HORMONE", "SKIN", "SLEEP_AID", + "DIABETES", + "ANTIBIOTIC", "OTHER", ] as const; +export type MedicationCategoryValue = (typeof MEDICATION_CATEGORY_VALUES)[number]; /** * v1.4.25 W4d — Prisma-level treatment class. Orthogonal to