prepare("UPDATE appointments SET status = ? WHERE id = ?");
$stmt->bind_param("si", $status, $appointment_id);
if ($stmt->execute()) {
$message = "Appointment updated successfully.";
} else {
$error = "Unable to update appointment.";
}
$stmt->close();
} else {
$error = "You do not have permission to update this appointment.";
}
}
/* Delete Appointment - Super Admin Only */
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_appointment'])) {
if ($isSuperAdmin) {
$appointment_id = intval($_POST['appointment_id']);
$stmt = $conn->prepare("DELETE FROM appointments WHERE id = ?");
$stmt->bind_param("i", $appointment_id);
if ($stmt->execute()) {
$message = "Appointment deleted successfully.";
} else {
$error = "Unable to delete appointment.";
}
$stmt->close();
} else {
$error = "Only Super Admin can delete appointments.";
}
}
/* Filters */
$search = $_GET['search'] ?? '';
$status_filter = $_GET['status'] ?? '';
$territory_filter = $_GET['territory'] ?? '';
$date_filter = $_GET['date'] ?? '';
$query = "
SELECT
a.id,
a.patient_id,
a.appointment_date,
a.appointment_time,
a.territory,
a.reason,
a.status,
a.created_at,
p.first_name,
p.last_name,
p.email,
p.phone,
p.card_number,
p.plan
FROM appointments a
LEFT JOIN patients p ON a.patient_id = p.id
WHERE 1
";
$params = [];
$types = "";
if (!empty($search)) {
$query .= " AND (
p.first_name LIKE ?
OR p.last_name LIKE ?
OR p.email LIKE ?
OR p.phone LIKE ?
OR p.card_number LIKE ?
)";
$searchTerm = "%$search%";
$params = array_merge($params, [$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm]);
$types .= "sssss";
}
if (!empty($status_filter)) {
$query .= " AND a.status = ?";
$params[] = $status_filter;
$types .= "s";
}
if (!empty($territory_filter)) {
$query .= " AND a.territory = ?";
$params[] = $territory_filter;
$types .= "s";
}
if (!empty($date_filter)) {
$query .= " AND a.appointment_date = ?";
$params[] = $date_filter;
$types .= "s";
}
$query .= " ORDER BY a.appointment_date ASC, a.appointment_time ASC";
$stmt = $conn->prepare($query);
if (!empty($params)) {
$stmt->bind_param($types, ...$params);
}
$stmt->execute();
$result = $stmt->get_result();
/* Get Territories */
$territories = [];
$territoryQuery = $conn->query("SELECT DISTINCT territory FROM appointments WHERE territory IS NOT NULL AND territory != '' ORDER BY territory ASC");
if ($territoryQuery) {
while ($t = $territoryQuery->fetch_assoc()) {
$territories[] = $t['territory'];
}
}
?>
Appointment Management | Novaryn Admin
Appointment Management
Logged in as:
| Patient |
Contact |
Card / Plan |
Appointment |
Territory |
Reason |
Status |
Created |
Management Actions |
num_rows > 0): ?>
fetch_assoc()): ?>
|
Patient ID:
Appointment ID:
|
Patient ID:
Appointment ID:
|
|
|
|
|
|
|
|
|
| No appointments found. |
close();
$conn->close();
?>