prepare("SELECT * FROM patients WHERE id = ?");
$stmt->execute([$patient_id]);
$patient = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$patient) {
die("Patient not found.");
}
// Now, fetch all visits for this patient using their patient_id
$history_stmt = db()->prepare(
"SELECT p.*, d.username as doctor_name
FROM patients p
LEFT JOIN users d ON p.doctor_id = d.id
WHERE p.patient_id = ?
ORDER BY p.created_at DESC"
);
$history_stmt->execute([$patient['patient_id']]);
$visit_history = $history_stmt->fetchAll(PDO::FETCH_ASSOC);
?>