From e4e7b4a24690f3807432ba70c055a93b98d5c1b5 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Mon, 16 Mar 2026 14:25:36 +0000 Subject: [PATCH] fix: resolve 500 error in actions.php and re-implement token system checkbox --- includes/actions.php | 24 +++++++++++++++++++++++- includes/layout/footer.php | 6 ++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/includes/actions.php b/includes/actions.php index 73687b1..97bbfd6 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -303,6 +303,28 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $stmt = $db->prepare("INSERT INTO visits (patient_id, doctor_id, appointment_id, weight, blood_pressure, heart_rate, temperature, symptoms, diagnosis, treatment_plan) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$patient_id, $doctor_id, $appointment_id, $weight, $bp, $hr, $temp, $symptoms, $diagnosis, $treatment]); $visit_id = $db->lastInsertId(); + $token_message = ''; + + // Token Generation + if (isset($_POST['generate_token']) && $_POST['generate_token'] == '1') { + $stmtDoc = $db->prepare("SELECT department_id FROM doctors WHERE id = ?"); + $stmtDoc->execute([$doctor_id]); + $docData = $stmtDoc->fetch(); + $dept_id = $docData ? $docData['department_id'] : null; + + if ($dept_id) { + $today = date('Y-m-d'); + $stmtTok = $db->prepare("SELECT MAX(token_number) FROM patient_queue WHERE department_id = ? AND DATE(created_at) = ?"); + $stmtTok->execute([$dept_id, $today]); + $max_token = $stmtTok->fetchColumn(); + $next_token = ($max_token) ? $max_token + 1 : 1; + + $stmtQueue = $db->prepare("INSERT INTO patient_queue (patient_id, department_id, doctor_id, visit_id, token_number, status, created_at) VALUES (?, ?, ?, ?, ?, 'waiting', NOW())"); + $stmtQueue->execute([$patient_id, $dept_id, $doctor_id, $visit_id, $next_token]); + + $token_message = " (" . __('token') . ": #" . $next_token . ")"; + } + } if (isset($_POST['prescriptions']) && is_array($_POST['prescriptions'])) { $drug_names = $_POST['prescriptions']['drug_name'] ?? []; $dosages = $_POST['prescriptions']['dosage'] ?? []; @@ -320,7 +342,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $stmt->execute([$appointment_id]); } $db->commit(); - $_SESSION['flash_message'] = __('add_visit') . ' ' . __('successfully'); + $_SESSION['flash_message'] = __('add_visit') . ' ' . __('successfully') . $token_message; $redirect = true; } } elseif ($_POST['action'] === 'edit_visit') { diff --git a/includes/layout/footer.php b/includes/layout/footer.php index 46d94eb..a613f68 100644 --- a/includes/layout/footer.php +++ b/includes/layout/footer.php @@ -972,6 +972,12 @@ +
+
+ + +
+