import { useEffect, useState } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { PageHeader } from '@/components/layout/PageHeader'; import { Card } from '@/components/common/Card'; import { Button } from '@/components/common/Button'; import { PieChart } from '@/components/charts/PieChart'; import * as medicationService from '@/services/medication.service'; import type { Medication, MedicationAdherence } from '@/types'; import styles from './MedicationDetailPage.module.css'; export function MedicationDetailPage() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const [medications, setMedications] = useState([]); const [adherence, setAdherence] = useState(null); useEffect(() => { medicationService.getMedications().then(setMedications); if (id) medicationService.getAdherence(id).then(setAdherence).catch(() => {}); }, [id]); const med = medications.find((m) => m.id === id); if (!med) { return (
药品不存在
); } return (
{med.drugName}
剂量{med.dosage}
服用时间{med.timeSlots.join(', ')}
日期{med.startDate} ~ {med.endDate || '长期'}
状态{med.status === 'active' ? '进行中' : '已结束'}
{med.notes &&
备注{med.notes}
}
{adherence && (
近30天依从性
{adherence.rate}%
)}
); }