import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Badge } from "@/components/ui/badge"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from "@/components/ui/dialog"; import { Plus, Pencil, Trash2, Printer } from "lucide-react"; interface Prescription { id: number; date: string; medication: string; dosage: string; frequency: string; duration: string; refills: number; route: string; indication: string; instructions: string; prescriber: string; } const COMMON_MEDICATIONS = [ "Amoxicillin 500mg", "Amoxicillin 875mg", "Clindamycin 300mg", "Clindamycin 150mg", "Metronidazole 500mg", "Azithromycin 250mg", "Ibuprofen 400mg", "Ibuprofen 600mg", "Ibuprofen 800mg", "Acetaminophen 500mg", "Naproxen 500mg", "Hydrocodone/APAP 5-325mg", "Oxycodone 5mg", "Tramadol 50mg", "Dexamethasone 4mg", "Prednisone 20mg", "Chlorhexidine 0.12% Rinse", "Nystatin Oral Suspension", "Fluconazole 150mg", "Benzocaine Topical", ]; const FREQUENCIES = [ "Once daily (QD)", "Twice daily (BID)", "Three times daily (TID)", "Four times daily (QID)", "Every 4 hours", "Every 6 hours", "Every 8 hours", "Every 12 hours", "As needed (PRN)", "With food", ]; const ROUTES = ["Oral", "Topical", "Sublingual", "Rinse and spit"]; let nextId = 1; const newRx = (): Prescription => ({ id: nextId++, date: new Date().toISOString().substring(0, 10), medication: "", dosage: "", frequency: "", duration: "", refills: 0, route: "Oral", indication: "", instructions: "", prescriber: "", }); export function PrescriptionTab() { const [prescriptions, setPrescriptions] = useState([]); const [dialogOpen, setDialogOpen] = useState(false); const [editing, setEditing] = useState(newRx()); const openAdd = () => { setEditing(newRx()); setDialogOpen(true); }; const openEdit = (rx: Prescription) => { setEditing({ ...rx }); setDialogOpen(true); }; const handleSave = () => { setPrescriptions((prev) => { const idx = prev.findIndex((r) => r.id === editing.id); if (idx >= 0) { const next = [...prev]; next[idx] = editing; return next; } return [...prev, editing]; }); setDialogOpen(false); }; const handleDelete = (id: number) => { setPrescriptions((prev) => prev.filter((r) => r.id !== id)); }; return (

{prescriptions.length} prescription{prescriptions.length !== 1 ? "s" : ""}

Date Medication Frequency Duration Refills Prescriber Actions {prescriptions.length === 0 ? ( No prescriptions yet. Click "New Prescription" to add one. ) : ( prescriptions.map((rx) => ( {rx.date}

{rx.medication}

{rx.dosage} · {rx.route}

{rx.instructions && (

{rx.instructions}

)}
{rx.frequency} {rx.duration} {rx.refills} {rx.prescriber || "—"}
)) )}
New Prescription
setEditing((d) => ({ ...d, date: e.target.value }))} className="h-9 text-sm" />
setEditing((d) => ({ ...d, dosage: e.target.value }))} className="h-9 text-sm" />
setEditing((d) => ({ ...d, duration: e.target.value }))} className="h-9 text-sm" />
setEditing((d) => ({ ...d, refills: Number(e.target.value) }))} className="h-9 text-sm" />
setEditing((d) => ({ ...d, indication: e.target.value }))} className="h-9 text-sm" />