Files
HealthLog/src/lib/medications/category-label.ts
T
Marc-André Bombeck fea1d1e0b5 chore: strip planning tags from comments and enable the rule
Output of `node scripts/strip-planning-tags.mjs --write`: 3,157 comment
lines in 1,308 files lose the work-item identifier at their head. Release
versions and issue references stay; nothing outside comment text
changes, which the script checks per file against a comment-free
printout. healthlog/no-planning-tags is enabled at error level with this
commit, so the tree it lands on is clean.
2026-10-20 09:08:40 +02:00

56 lines
2.1 KiB
TypeScript

/**
* v1.4.37 — shared medication category-label lookup.
*
* Both the generic `<MedicationCard>` and the GLP-1 variant render
* `categoryLabel` into the same `<MedicationCardHeader>` outline badge.
* Historically the generic card kept its own inline lookup table while
* the GLP-1 card hard-coded `medications.treatmentClassGlp1` into the
* slot — the maintainer reported the asymmetry during the v1.4.37 UX audit
* (audit item 11). The GLP-1 nature is already implied by the
* rotation hint + injection metadata rows, so both surfaces should
* paint the actual medication category instead.
*
* The lookup is a small string map; we keep it as a function that takes
* the bound `t()` translator so the keys stay one source of truth and
* we don't need to drill a separate `categoryLabels` object through
* the card props.
*/
type Translator = (
key: string,
params?: Record<string, string | number>,
) => string;
const MEDICATION_CATEGORY_KEYS: Record<string, string> = {
BLOOD_PRESSURE: "medications.categoryBloodPressure",
VITAMIN: "medications.categoryVitamin",
SUPPLEMENT: "medications.categorySupplement",
PAIN_RELIEF: "medications.categoryPainRelief",
ALLERGY: "medications.categoryAllergy",
DIGESTIVE: "medications.categoryDigestive",
THYROID: "medications.categoryThyroid",
HORMONE: "medications.categoryHormone",
SKIN: "medications.categorySkin",
SLEEP_AID: "medications.categorySleepAid",
DIABETES: "medications.categoryDiabetes",
ANTIBIOTIC: "medications.categoryAntibiotic",
MENTAL_HEALTH: "medications.categoryMentalHealth",
OTHER: "medications.categoryOther",
};
/**
* v1.40 (#1041) — a category the person named themselves arrives as
* `custom:<uuid>` with its decrypted label beside it (`categoryLabel` on the
* medication wire); that label wins. A custom key without a label (the server
* resolved it to nothing) reads as Other, like any unknown value.
*/
export function getMedicationCategoryLabel(
category: string,
t: Translator,
customLabel?: string | null,
): string {
if (customLabel) return customLabel;
const key = MEDICATION_CATEGORY_KEYS[category] ?? "medications.categoryOther";
return t(key);
}