import { useNavigate, useParams } from "react-router-dom"; import type { DrugRef, Indication, MedsReference } from "../api/types"; import { AppShell, Notice, TopBar } from "../components/AppShell"; import { Icon, type IconName } from "../components/Icon"; import { useMedsReference } from "../content/reference"; import { ru } from "../content/ru"; import { useDialog } from "../dialog/DialogContext"; import { sendSideEffect } from "./Meds"; import { useToday } from "./useToday"; /* * E6 · О препарате (spec «Модуль Лекарства»: карточка препарата). Patient information from the drug reference * built on the Minzdrav guidelines: when to expect the effect, how long, what may bother, when to see a doctor * urgently. No doses or ranges are shown — the prescription comes from the doctor only. */ const cap = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); /** «3–4 недели» → the upper bound in days, for the progress bar (null when the text has no weeks). */ function weeksToDays(text: string | null | undefined): number | null { const m = /(\d+)(?:\s*[–-]\s*(\d+))?\s*недел/.exec(text ?? ""); return m ? Number(m[2] ?? m[1]) * 7 : null; } function Section({ icon, tone, title, children }: { icon: IconName; tone?: string; title: string; children: React.ReactNode }) { return (

{title}

{children}
); } function EffectTimeline({ day, horizon, when }: { day: number; horizon: number; when: string }) { const pct = Math.min(100, (day / horizon) * 100); return (
{ru.meds.card.progress(day)} {ru.meds.card.effectAt(when)}
); } function Card({ drug, reference: ref, indication, day, prescribed, }: { drug: DrugRef; reference: MedsReference; indication: Indication | null; day: number | null; prescribed?: string; }) { const c = ru.meds.card; const ind = indication ? drug.indications[indication] : Object.values(drug.indications)[0]; const expect = indication === "ptsd" ? ref.texts.expect_effect_ptsd : ref.texts.expect_effect_depression; const horizon = weeksToDays(ind?.expected_response); const sources = ind?.source ?? ""; return (

{drug.name_ru}

{drug.group} {drug.group !== drug.class && `, ${drug.class}`}

{prescribed && (

{c.prescribed}: {prescribed}

)}
{ind?.expected_response && (
{day !== null && horizon && }

{expect}

)} {(ind?.course || drug.max_course_days) && (
{ind?.course &&

{ind.course}.

} {drug.max_course_days &&

{c.courseShort(drug.max_course_days)}.

} {indication === "depression" &&

{ref.texts.why_continue_depression}

}
)}
{drug.diary_items.length ? (
    {drug.diary_items.map((s) => (
  • {s}
  • ))}
) : (

{c.sideEffectsNone}

)}

{c.sideEffectsHint}

{drug.red_flags.length > 0 && (

{c.redFlags}

    {drug.red_flags.map((s) => (
  • {s}
  • ))}

{ref.texts.red_flag}

)}

{ref.texts.dont_stop_alone}

{drug.withdrawal_risk === "high" &&

{c.withdrawal}

} {drug.overdose_danger &&

{c.overdose}

} {ind?.off_label &&

{c.offLabel}

} {drug.monitoring.length > 0 && ( <>

{c.monitoring}:

    {drug.monitoring.map((s) => (
  • {s}
  • ))}
)}

{ref.texts.instruction_fallback}

{c.source(sources)}

); } export function DrugInfo() { const c = ru.meds.card; const { ref: refId } = useParams(); const navigate = useNavigate(); const dialog = useDialog(); const { plan } = useToday(); const ref = useMedsReference(); const drug = ref?.drugs.find((d) => d.id === refId); const rx = plan?.prescriptions.find((p) => p.ref_id === refId); const ask = () => void dialog.send({ type: "button", button: "menu:med_question" }, c.ask).then((ok) => ok && navigate("/flow")); return (
navigate("/meds")} /> {!ref ? (
) : !drug ? ( {c.unknown} ) : ( )} {rx && (
{plan?.has_doctor && ( )}
)}
); }