alert('无效的药品ID'); window.location.href='list.php';"; exit; } // 查询药品信息 $sql = "SELECT * FROM medications WHERE id = $medication_id"; $result = mysqli_query($connID, $sql); if (mysqli_num_rows($result) == 0) { echo ""; exit; } $medication = mysqli_fetch_assoc($result); // 获取药品使用统计信息 $stats_sql = "SELECT COUNT(DISTINCT mr.id) as total_prescriptions, COUNT(DISTINCT mr.patient_id) as total_patients, COUNT(CASE WHEN DATE(mr.created_at) = CURDATE() THEN 1 END) as today_prescriptions, COUNT(CASE WHEN mr.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY) THEN 1 END) as month_prescriptions FROM medical_records mr WHERE mr.prescription LIKE '%{$medication['name']}%'"; $stats_result = mysqli_query($connID, $stats_sql); $stats = mysqli_fetch_assoc($stats_result); // 获取最近的处方记录 $recent_prescriptions_sql = "SELECT mr.*, p.name as patient_name, p.phone as patient_phone, d.name as doctor_name FROM medical_records mr JOIN patients p ON mr.patient_id = p.id JOIN doctors d ON mr.doctor_id = d.id WHERE mr.prescription LIKE '%{$medication['name']}%' ORDER BY mr.created_at DESC LIMIT 5"; $recent_prescriptions_result = mysqli_query($connID, $recent_prescriptions_sql); ?>