based on this databse (===Database u406552082_info

== Table structure for table admins

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|**username**|varchar(50)|No|
|password|varchar(255)|No|
|email|varchar(100)|No|
== Dumping data for table admins

|1|mmtawfik|$2y$10$V9jnPR/dZN0uoiHPQa038uBXCS1NC7xV.uVJxnlE6lmICqAwpSr1O|mmtawfik@example.com
|<PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>
== Table structure for table budgets

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|month|varchar(7)|Yes|NULL
|budgeted_revenue|decimal(10,2)|Yes|NULL
|budgeted_expenses|decimal(10,2)|Yes|NULL
|notes|text|Yes|NULL
== Dumping data for table budgets

|1|2024-09|20000.00|1000.00| 
== Table structure for table comments

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|patient_id|int(11)|No|
|sender|enum('patient', 'doctor', 'admin')|No|
|message|text|No|
|timestamp|datetime|Yes|current_timestamp()
|parent_id|int(11)|Yes|NULL
== Dumping data for table comments

|44|16|patient|Good|2024-10-03 03:28:46|NULL
|45|16|admin|Thanks|2024-10-03 03:29:02|44
== Table structure for table doctors

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|employee_id|int(11)|No|
|name|varchar(255)|No|
|**username**|varchar(100)|No|
|password|varchar(255)|No|
|**email**|varchar(255)|No|
|specialization|varchar(255)|Yes|NULL
|phone|varchar(20)|Yes|NULL
|registration_date|date|Yes|curdate()
|profile_picture|varchar(255)|Yes|NULL
|department|varchar(100)|Yes|NULL
|date_of_joining|date|Yes|NULL
|status|enum('active', 'inactive')|Yes|active
== Dumping data for table doctors

|12|18|Dr. Engy Shahbander|drengy|$2y$10$Tx74blqFrEdOB2tOZy/Qye7ndsmS9aBMUo23mOG0a9zgfHPoNBnI2|engy.shahbander@gmail.com|CEO - Longevacare|0151315489|2024-10-03|NULL|NULL|NULL|active
== Table structure for table doctor_patient

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|**doctor_id**|int(11)|No|
|**patient_id**|int(11)|No|
== Dumping data for table doctor_patient

|14|3|13
|31|12|13
|30|12|16
== Table structure for table employees

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|name|varchar(255)|No|
|role|enum('admin', 'doctor', 'staff', 'accountant')|No|
|**email**|varchar(255)|No|
|phone|varchar(20)|Yes|NULL
|department|varchar(100)|Yes|NULL
|date_of_joining|date|Yes|NULL
|status|enum('active', 'inactive')|Yes|active
|**username**|varchar(100)|No|
|password|varchar(255)|No|
|created_at|timestamp|Yes|current_timestamp()
|updated_at|timestamp|Yes|current_timestamp()
|profile_picture|varchar(255)|Yes|NULL
|specialization|varchar(255)|Yes|NULL
== Dumping data for table employees

|<PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>|0105131548|Nursing|2024-10-15|active|doaa123|$2y$10$jezEFBAuvB.2J56DTgGeZ.PbpKBaHGZARBNjy5mvnR21lImE9aala|2024-10-03 01:38:20|2024-10-03 01:38:20|doaa123_1727919500.jpg|Nurse
|18|Dr. Engy <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>|0151315489|Administration|2024-10-03|active|drengy|$2y$10$Tx74blqFrEdOB2tOZy/Qye7ndsmS9aBMUo23mOG0a9zgfHPoNBnI2|2024-10-03 01:51:32|2024-10-03 03:34:49|drengy_18.jpg|CEO - Longevacare
|19|Mahmoud <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>|01119235049|Administration|2024-10-03|active|mahmoudtawfik|$2y$10$qciyhqx0IHsZMviAa9YceOuw8JZ2RaK2CR2b2Ny.nOT1bogVRSKoy|2024-10-03 01:54:51|2024-10-03 03:35:14|mahmoudtawfik_19.png|Developer
|20|Mohamed <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>|0105134856|Accounting|2024-10-01|active|mohamed_5049|$2y$10$/RZk3a7dRiM4zSssCWK8ae7QidsQooQ5Y0U6k9KrE7d5XwN5h5IUC|2024-10-03 04:15:27|2024-10-03 04:15:40|default_profile.png|Accountant
== Table structure for table health_records

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|patient_id|int(11)|No|
|blood_pressure|varchar(20)|Yes|NULL
|weight|decimal(5,2)|Yes|NULL
|bmi|decimal(4,2)|Yes|NULL
|cholesterol|decimal(5,2)|Yes|NULL
|prescription|text|Yes|NULL
|treatment_progress|text|Yes|NULL
|record_date|date|No|
== Dumping data for table health_records

|36|12|80|80.00|80.00|5.00|STR - 32|Isn't good for this patient|2024-10-02
|37|16|80|80.00|99.99|169.00|This new precept|Hi|2024-10-03
== Table structure for table insurance_claims

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|patient_id|int(11)|Yes|NULL
|invoice_id|int(11)|Yes|NULL
|claim_amount|decimal(10,2)|Yes|NULL
|status|enum('Pending', 'Approved', 'Rejected')|Yes|NULL
|submission_date|date|Yes|NULL
|processing_date|date|Yes|NULL
|notes|text|Yes|NULL
== Dumping data for table insurance_claims

|1|16|31|1000.00|Rejected|2024-10-05|2024-10-05| 
== Table structure for table invoices

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|patient_id|int(11)|No|
|service_name|varchar(255)|No|
|service_description|text|Yes|NULL
|cost|decimal(10,2)|No|
|tax_rate|decimal(5,2)|Yes|0.00
|discount|decimal(5,2)|Yes|0.00
|total_amount|decimal(10,2)|No|
|invoice_date|date|Yes|curdate()
|notes|text|Yes|NULL
|tax|decimal(5,2)|Yes|0.00
== Dumping data for table invoices

|19|13| |NULL|0.00|0.00|300.00|1284.00|2024-09-29| |7.00
|28|15| |NULL|0.00|0.00|150.00|720.00|2024-09-30| |20.00
|31|16| | |750.00|5.00|100.00|650.00|2024-10-03| |0.00
== Table structure for table invoice_services

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|invoice_id|int(11)|No|
|service_id|int(11)|No|
|service_name|varchar(255)|No|
|cost|decimal(10,2)|No|
== Dumping data for table invoice_services

|13|19|10|Stress|750.00
|14|19|9|Depression|750.00
|36|28|10|Stress|750.00
|39|31|9|Depression|750.00
== Table structure for table patients

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|name|varchar(100)|No|
|age|int(11)|No|
|gender|enum('Male', 'Female', 'Other')|No|
|phone|varchar(20)|Yes|NULL
|email|varchar(100)|Yes|NULL
|medical_history|text|Yes|NULL
|created_at|timestamp|Yes|current_timestamp()
|updated_at|timestamp|Yes|current_timestamp()
|date_of_birth|date|Yes|NULL
|registration_datetime|datetime|Yes|current_timestamp()
|registration_date|date|Yes|NULL
|status|enum('Initial Consultation', 'Diagnostic Phase', 'Treatment in Progress', 'Improving', 'Monitoring', 'Maintenance Phase', 'Awaiting Test Results', 'Follow-up Needed', 'Paused', 'Completed Program', 'Relapsed', 'Discontinued', 'Inactive')|Yes|Initial Consultation
|doctor_id|int(11)|Yes|NULL
== Dumping data for table patients

|<PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>|DEP - XRA 12Mg|2024-09-28 23:15:43|2024-09-29 02:53:36|1999-09-28|2024-09-28 23:15:43|2024-09-28|Discontinued|NULL
|<PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>|Sr - Dep - 323Mg/d|2024-09-28 23:17:04|2024-09-29 02:53:27|1963-09-28|2024-09-28 23:17:04|2024-09-28|Awaiting Test Results|NULL
|13|Ahmed <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>|Has Bad Medical History|2024-09-29 01:14:56|2024-09-29 21:59:09|1988-09-29|2024-09-29 01:14:56|2024-09-29|Relapsed|NULL
|15|Ali <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>|.|2024-09-29 23:23:06|2024-09-29 23:24:12|1998-09-29|2024-09-29 23:23:06|2024-09-29|Paused|NULL
|16|Soha <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>|Doesn't have Medical History 1|2024-10-03 02:28:58|2024-10-03 02:29:52|2001-10-03|2024-10-03 02:28:58|2024-10-03|Paused|NULL
== Table structure for table patient_logins

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|**patient_id**|int(11)|No|
|**username**|varchar(50)|No|
|password|varchar(255)|No|
== Dumping data for table patient_logins

|24|11|mahmoud_507|$2y$10$aWr138nBYi1CPnOp6Zd2geqUfpAO6zhAGWh0EUtiEMNcUIEIBw4RS
|25|12|mona_630|$2y$10$YMU9RdPOpW1MIELx8W6NBel0fl7NmzGl3GiRitSCQadQYx8Ux4U8e
|26|13|ahmed_697|$2y$10$PVsNfLKdc5gVD0TxjIil8u968rEq3ixyeOKImGLJZXvT8jiOjHNwa
|28|15|ali_127|$2y$10$sNDe.Ka5.Ne9z409SKVew.Diqw6P5cFurRyU1P1pBrTZRV6.LeJFy
|29|16|soha_554|$2y$10$dZEFXbXdX8oe2CWRBFxcOek1DD7O4iiOuvxB3A3cMgdKu7GutJ39K
== Table structure for table payments

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|patient_id|int(11)|No|
|invoice_id|int(11)|No|
|amount_paid|decimal(10,2)|No|
|payment_date|date|No|
|payment_method|varchar(50)|Yes|NULL
|notes|text|Yes|NULL
== Dumping data for table payments

== Table structure for table salaries

|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|employee_id|int(11)|No|
|basic_salary|decimal(10,2)|No|
|bonuses|decimal(10,2)|Yes|0.00
|deductions|decimal(10,2)|Yes|0.00
|overtime_hours|int(11)|Yes|0
|overtime_rate|decimal(10,2)|Yes|0.00
|tax|decimal(10,2)|Yes|0.00
|payment_date|date|No|
|net_salary|decimal(10,2)|No|
|status|enum('Pending', 'Paid')|Yes|Pending
|notes|text|Yes|NULL
|payslip_path|varchar(255)|Yes|NULL
== Dumping data for table salaries

== Table structure for table services

|------
|Column|Type|Null|Default
|------
|//**service_id**//|int(11)|No|
|service_name|varchar(255)|No|
|service_price|decimal(10,2)|No|
|service_description|text|Yes|NULL
|created_at|timestamp|Yes|current_timestamp()
|updated_at|timestamp|Yes|current_timestamp()
== Dumping data for table services

|9|Depression|750.00|New Service Depression - longevacare|2024-09-28 23:19:56|2024-09-28 23:19:56
|10|Stress|750.00|New Service Stress - Longevacare|2024-09-29 10:24:07|2024-09-29 10:24:07) i need to create chat between doctors and admin and accountant, so i want to create chat folder, this folder, chat/, this admin_dasboard(<?php
session_start();
require_once 'db_connect.php';

// Check if the admin is logged in
if (!isset($_SESSION['admin_id'])) {
    header("Location: admin_login.php");
    exit();
}

// Initialize filter variables
$search = $_GET['search'] ?? '';
$gender = $_GET['gender'] ?? '';
$min_age = $_GET['min_age'] ?? '';
$max_age = $_GET['max_age'] ?? '';
$status = $_GET['status'] ?? '';
$sort_by = $_GET['sort_by'] ?? 'id'; // Default sort by ID

// Build the SQL query with filters
$sql = "
    SELECT p.*, pl.username,
           hr.blood_pressure, hr.weight, hr.bmi, hr.cholesterol, 
           hr.prescription, hr.treatment_progress, hr.record_date
    FROM patients p
    LEFT JOIN patient_logins pl ON p.id = pl.patient_id
    LEFT JOIN (
        SELECT patient_id, blood_pressure, weight, bmi, cholesterol, 
               prescription, treatment_progress, record_date,
               ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY record_date DESC) as rn
        FROM health_records
    ) hr ON p.id = hr.patient_id AND hr.rn = 1
    WHERE 1=1
";

$params = [];

if ($search) {
    $sql .= " AND (p.name LIKE ? OR pl.username LIKE ? OR p.id LIKE ? OR p.phone LIKE ? OR p.email LIKE ?)";
    $search_param = "%$search%";
    $params = array_merge($params, [$search_param, $search_param, $search_param, $search_param, $search_param]);
}

if ($gender) {
    $sql .= " AND p.gender = ?";
    $params[] = $gender;
}

if ($min_age) {
    $sql .= " AND p.age >= ?";
    $params[] = $min_age;
}

if ($max_age) {
    $sql .= " AND p.age <= ?";
    $params[] = $max_age;
}

if ($status) {
    $sql .= " AND p.status = ?";
    $params[] = $status;
}

// Note: Sorting will be handled client-side by DataTables

$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$patients = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Get all possible status options
$status_options = [
    'Initial Consultation', 'Diagnostic Phase', 'Treatment in Progress', 'Improving',
    'Monitoring', 'Maintenance Phase', 'Awaiting Test Results', 'Follow-up Needed',
    'Paused', 'Completed Program', 'Relapsed', 'Discontinued', 'Inactive'
];

// Fetch new comments count (comments from patients without admin replies)
$new_comments_query = "
    SELECT COUNT(*) AS new_comments_count
    FROM comments c
    WHERE c.parent_id IS NULL 
      AND c.sender = 'patient' 
      AND NOT EXISTS (
          SELECT 1 FROM comments r 
          WHERE r.parent_id = c.id 
            AND r.sender = 'admin'
      )
";
$stmt = $pdo->query($new_comments_query);
$new_comments_count = $stmt->fetchColumn();

// Fetch Data Analysis Data
// Fetch total number of patients
$stmt = $pdo->query("SELECT COUNT(*) FROM patients");
$total_patients = $stmt->fetchColumn();
// Fetch recent registrations (last 30 days)
$stmt = $pdo->query("SELECT COUNT(*) FROM patients WHERE registration_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)");
$recent_registrations = $stmt->fetchColumn();
// Fetch recent registrations (today)
$stmt = $pdo->query("SELECT COUNT(*) FROM patients WHERE DATE(registration_datetime) = CURDATE()");
$today_registrations = $stmt->fetchColumn();
// Fetch total number of invoices
$stmt = $pdo->query("SELECT COUNT(*) FROM invoices");
$total_invoices = $stmt->fetchColumn();
// Fetch gender distribution
$stmt = $pdo->query("SELECT gender, COUNT(*) as count FROM patients GROUP BY gender");
$gender_distribution = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch age distribution
$stmt = $pdo->query("
    SELECT 
        CASE 
            WHEN age < 18 THEN 'Under 18'
            WHEN age BETWEEN 18 AND 30 THEN '18-30'
            WHEN age BETWEEN 31 AND 50 THEN '31-50'
            WHEN age BETWEEN 51 AND 70 THEN '51-70'
            ELSE 'Over 70'
        END AS age_group,
        COUNT(*) as count
    FROM patients
    GROUP BY age_group
");
$age_distribution = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch status distribution
$stmt = $pdo->query("SELECT status, COUNT(*) as count FROM patients GROUP BY status");
$status_distribution = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <title>Admin Dashboard</title>

    
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap4.min.css">
    
    <style>
        /* Custom CSS for modern design */
        body {
            background-color: #f8f9fa;
            font-family: Arial, sans-serif;
        }

        .dashboard-header {
            background-color: #4F3F02; /* Brown color */
            color: #fff;
            padding: 20px;
            text-align: center;
            border-radius: 8px;
            margin-bottom: 30px;
        }

        h1, h2 {
            font-weight: bold;
        }

        .btn-primary {
            background-color: #D1C287; /* Light golden color */
            border-color: #D1C287;
            color: #4F3F02; /* Brown color */
            font-weight: bold;
        }

        .btn-primary:hover {
            background-color: #4F3F02; /* Brown color */
            border-color: #D1C287;
            color: #fff;
        }

        .btn-secondary {
            background-color: #4F3F02; /* Brown color */
            border-color: #4F3F02;
            color: #fff;
            font-weight: bold;
        }

        .btn-secondary:hover {
            background-color: #D1C287; /* Light golden color */
            color: #4F3F02; /* Brown color */
        }

        .filters {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }


        .filters .form-control, .filters select {
            margin-bottom: 15px;
            border: 1px solid #D1C287;
            border-radius: 5px;
        }

        .filters .form-control:focus, .filters select:focus {
            border-color: #4F3F02;
            box-shadow: none;
        }

        .table-responsive {
            margin-top: 20px;
        }

        .table {
            background-color: #fff;
            border-radius: 8px;
            overflow: hidden;
        }

        .table thead th {
            background-color: #4F3F02;
            color: #fff;
            border-color: #4F3F02;
        }

        th, td {
            vertical-align: middle !important;
        }

        .card {
            border: none;
            border-radius: 10px;
        }

        .card .card-title {
            color: #4F3F02;
        }

        /* DataTables customizations */
        .dataTables_wrapper .dataTables_filter input {
            border-radius: 5px;
            border: 1px solid #D1C287;
        }

        .dataTables_wrapper .dataTables_length select {
            border-radius: 5px;
            border: 1px solid #D1C287;
        }

        /* Responsive adjustments */
        @media (max-width: 768px) {
            .filters .form-control, .filters select {
                margin-bottom: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="container-fluid"> 
        
        <div class="dashboard-header text-center">
                <img src="images/white-logo.png" alt="White Logo" style="max-width: 30%; height: auto; margin-bottom: 20px;"> 

            <h1>Admin Dashboard</h1>
            <p>Welcome, Admin!</p>
        </div>

        
        <div class="d-flex flex-wrap mb-3">
            <a href="create_patient.php" class="btn btn-primary mb-2 mr-2">Create New Patient</a>
            <a href="invoice/" class="btn btn-primary mb-2 mr-2">An Invoice</a>
            <a href="admin_report.php" class="btn btn-primary mb-2 mr-2">Report (Data Analysis)</a>
            <a href="manage_comments.php" class="btn btn-primary mb-2 mr-2 position-relative">
                Manage Comments
                <?php if ($new_comments_count > 0): ?>
                    <span class="badge badge-danger badge-position">
                        <?= $new_comments_count ?>
                    </span>
                <?php endif; ?>
            </a>
            <a href="doctors/manage_doctors.php" class="btn btn-primary mb-2 mr-2">Manage Doctors</a>
            <a href="team/manage_employees.php" class="btn btn-primary mb-2 mr-2">Manage Employees</a>
            <a href="admin_logout.php" class="btn btn-secondary mb-2">Log Out</a>
        </div>

        
        <h2 class="mb-3">Data Analysis</h2>
        <div class="row g-3">
            
            <div class="col-lg-3 col-md-6">
                <div class="card h-100 text-center">
                    <div class="card-body">
                        <h5 class="card-title">Total Patients</h5>
                        <p class="card-text fs-4"><?= $total_patients ?></p>
                    </div>
                </div>
            </div>
            
            <div class="col-lg-3 col-md-6">
                <div class="card h-100 text-center">
                    <div class="card-body">
                        <h5 class="card-title">Recent Registrations (30 days)</h5>
                        <p class="card-text fs-4"><?= $recent_registrations ?></p>
                    </div>
                </div>
            </div>
            
            <div class="col-lg-3 col-md-6">
                <div class="card h-100 text-center">
                    <div class="card-body">
                        <h5 class="card-title">Registrations Today</h5>
                        <p class="card-text fs-4"><?= $today_registrations ?></p>
                    </div>
                </div>
            </div>
            
            <div class="col-lg-3 col-md-6">
                <div class="card h-100 text-center">
                    <div class="card-body">
                        <h5 class="card-title">Total Invoices</h5>
                        <p class="card-text fs-4"><?= $total_invoices ?></p>
                    </div>
                </div>
            </div>
        </div>

        
        <div class="row g-3 mt-3">
            
            <div class="col-lg-4 col-md-6">
                <div class="card h-100">
                    <div class="card-body">
                        <canvas id="genderChart"></canvas>
                    </div>
                </div>
            </div>
            
            <div class="col-lg-4 col-md-6">
                <div class="card h-100">
                    <div class="card-body">
                        <canvas id="ageChart"></canvas>
                    </div>
                </div>
            </div>
            
            <div class="col-lg-4 col-md-12">
                <div class="card h-100">
                    <div class="card-body">
                        <canvas id="statusChart"></canvas>
                    </div>
                </div>
            </div>
        </div>

        
        <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
        <script>
        // Gender Distribution Chart
        var genderCtx = document.getElementById('genderChart').getContext('2d');
        var genderChart = new Chart(genderCtx, {
            type: 'pie',
            data: {
                labels: <?= json_encode(array_column($gender_distribution, 'gender')) ?>,
                datasets: [{
                    data: <?= json_encode(array_column($gender_distribution, 'count')) ?>,
                    backgroundColor: ['#4F3F02', '#D1C287', '#FFCE56']
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    title: {
                        display: true,
                        text: 'Gender Distribution'
                    }
                }
            }
        });

        // Age Distribution Chart
        var ageCtx = document.getElementById('ageChart').getContext('2d');
        var ageChart = new Chart(ageCtx, {
            type: 'bar',
            data: {
                labels: <?= json_encode(array_column($age_distribution, 'age_group')) ?>,
                datasets: [{
                    label: 'Number of Patients',
                    data: <?= json_encode(array_column($age_distribution, 'count')) ?>,
                    backgroundColor: '#D1C287'
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    title: {
                        display: true,
                        text: 'Age Distribution'
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true
                    }
                }
            }
        });

        // Status Distribution Chart
        var statusCtx = document.getElementById('statusChart').getContext('2d');
        var statusChart = new Chart(statusCtx, {
            type: 'doughnut',
            data: {
                labels: <?= json_encode(array_column($status_distribution, 'status')) ?>,
                datasets: [{
                    data: <?= json_encode(array_column($status_distribution, 'count')) ?>,
                    backgroundColor: ['#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0', '#9966FF', '#FF9F40', '#C9CBCF', '#8D6E63', '#7986CB', '#81C784', '#DCE775', '#FFB74D', '#BA68C8']
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    title: {
                        display: true,
                        text: 'Status Distribution'
                    }
                }
            }
        });
        </script>

        
        <h2 class="mt-5">Patient List</h2>

        
        <div class="filters">
            <form action="" method="GET" class="row">
                <!-- Filter form can go here if needed -->
            </form>
        </div>

        
        <div class="table-responsive"> 
            <table id="patientTable" class="table table-bordered table-striped mt-3">
                <thead>
                    <tr>
                        <th>Patient ID</th>
                        <th>Name</th>
                        <th>Username</th>
                        <th>Age</th>
                        <th>Gender</th>
                        <th>Phone</th>
                        <th>Email</th>
                        <th>Registration Date</th>
                        <th>Has Invoice</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($patients as $patient): ?>
                    <tr>
                        <td><?= $patient['id'] ?></td>
                        <td><?= htmlspecialchars($patient['name']) ?></td>
                        <td><?= htmlspecialchars($patient['username']) ?></td>
                        <td><?= $patient['age'] ?></td>
                        <td><?= $patient['gender'] ?></td>
                        <td><?= htmlspecialchars($patient['phone']) ?></td>
                        <td><?= htmlspecialchars($patient['email']) ?></td>
                        <td><?= $patient['registration_date'] ?></td>
                        <td>
                            <?php
                            // Query to check if the patient has any invoices
                            $has_invoice_query = "SELECT COUNT(*) AS invoice_count FROM invoices WHERE patient_id = ?";
                            $stmt = $pdo->prepare($has_invoice_query);
                            $stmt->execute([$patient['id']]);
                            $invoice_result = $stmt->fetch();

                            if ($invoice_result['invoice_count'] > 0): ?>
                                <span class="text-success font-weight-bold">Yes</span>
                            <?php else: ?>
                                <span class="text-danger font-weight-bold">No</span>
                            <?php endif; ?>
                        </td>

                        <td>
                            <form method="POST" action="update_patient_status.php">
                                <input type="hidden" name="patient_id" value="<?= $patient['id'] ?>">
                                <select name="status" onchange="this.form.submit()" class="form-control form-control-sm">
                                    <?php foreach ($status_options as $option): ?>
                                        <option value="<?= htmlspecialchars($option) ?>" <?= $patient['status'] == $option ? 'selected' : '' ?>><?= htmlspecialchars($option) ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </form>
                        </td>
                        <td>
                            <div class="btn-group" role="group">
                                <a href="view_patient.php?id=<?= $patient['id'] ?>" class="btn btn-info btn-sm">View</a>
                                <a href="edit_patient.php?id=<?= $patient['id'] ?>" class="btn btn-warning btn-sm">Edit</a>
                                <a href="delete_patient.php?id=<?= $patient['id'] ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want to delete this patient?')">Delete</a>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        
        
    </div>

    
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    
    <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap4.min.js"></script>
    
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
    
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    
    <script>
        $(document).ready(function() {
            $('#patientTable').DataTable({
                "order": [],
                "responsive": true
            });
        });
    </script>
</body>
</html>) so make and i want to add button on admin_dasbaord.php, this button is Chat Button