based on this database (Updated Database Structure
Database Structure
The database for the admin dashboard and patient management system consists of the following tables:
a. patients
id (INT, AUTO_INCREMENT, PRIMARY KEY): Unique identifier for each patient.
name (VARCHAR): Full name of the patient.
age (INT): Age of the patient.
gender (ENUM('Male', 'Female', 'Other')): Gender of the patient.
phone (VARCHAR): Phone number of the patient.
email (VARCHAR): Email address of the patient.
medical_history (TEXT): Medical history of the patient.
date_of_birth (DATE): Date of birth of the patient.
registration_date (DATE): Date when the patient was registered.
registration_datetime (DATETIME): Date and time when the patient was registered.
status (ENUM): Current status of the patient (e.g., 'Initial Consultation', 'Treatment in Progress').
b. health_records
id (INT, AUTO_INCREMENT, PRIMARY KEY): Unique identifier for each health record.
patient_id (INT, FOREIGN KEY REFERENCES patients(id)): ID of the patient associated with this health record.
blood_pressure (VARCHAR): Blood pressure reading.
weight (DECIMAL): Weight of the patient.
bmi (DECIMAL): Body Mass Index of the patient.
cholesterol (DECIMAL): Cholesterol level of the patient.
prescription (TEXT): Prescriptions given to the patient.
treatment_progress (TEXT): Notes on the treatment progress.
record_date (DATE): Date of the health record.
c. admins
id (INT, AUTO_INCREMENT, PRIMARY KEY): Unique identifier for each admin.
username (VARCHAR): Admin's username.
password (VARCHAR): Hashed password for the admin.
email (VARCHAR): Email address of the admin.
d. patient_logins
id (INT, AUTO_INCREMENT, PRIMARY KEY): Unique identifier for each patient login.
patient_id (INT, FOREIGN KEY REFERENCES patients(id)): ID of the patient associated with this login.
username (VARCHAR): Username for patient login.
password (VARCHAR): Hashed password for patient login.
e. invoices
id (INT, AUTO_INCREMENT, PRIMARY KEY): Unique identifier for each invoice.
patient_id (INT NOT NULL, FOREIGN KEY REFERENCES patients(id)): ID of the patient associated with this invoice.
service_name (VARCHAR(255) NOT NULL): Name of the service rendered.
service_description (TEXT): Description of the service.
cost (DECIMAL(10, 2) NOT NULL): Cost of the service.
tax_rate (DECIMAL(5, 2) DEFAULT 0): Tax rate applied to the service.
discount (DECIMAL(5, 2) DEFAULT 0): Discount applied to the service.
total_amount (DECIMAL(10, 2) NOT NULL): Total amount due after tax and discount.
invoice_date (DATE DEFAULT CURRENT_DATE): Date of the invoice.
notes (TEXT): Additional notes for the invoice.
f. services
service_id (INT, AUTO_INCREMENT, PRIMARY KEY): Unique identifier for each service.
service_name (VARCHAR(255) NOT NULL): Name of the service.
service_price (DECIMAL(10, 2) NOT NULL): Price of the service.
service_description (TEXT): Description of the service.
created_at (TIMESTAMP DEFAULT CURRENT_TIMESTAMP): Timestamp when the service was created.
updated_at (TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP): Timestamp when the service was last updated.
g. invoice_services
id (INT, AUTO_INCREMENT, PRIMARY KEY): Unique identifier for each entry in the invoice services table.
invoice_id (INT NOT NULL, FOREIGN KEY REFERENCES invoices(id)): ID of the associated invoice.
service_id (INT NOT NULL, FOREIGN KEY REFERENCES services(service_id)): ID of the associated service.
service_name (VARCHAR(255) NOT NULL): Name of the service rendered.
cost (DECIMAL(10, 2) NOT NULL): Cost of the service rendered.
h. comments
id (INT, AUTO_INCREMENT, PRIMARY KEY): Unique identifier for each comment.
patient_id (INT NOT NULL, FOREIGN KEY REFERENCES patients(id)): ID of the patient associated with the comment.
sender (VARCHAR(10) NOT NULL): Sender of the comment, either 'patient' or 'doctor'.
message (TEXT NOT NULL): The message or comment content.
timestamp (DATETIME DEFAULT CURRENT_TIMESTAMP): Date and time the comment was made.
parent_id (INT NULL DEFAULT NULL): ID of the parent comment (for threaded conversations), if applicable.
i. doctor_patient (New Table)
id (INT, AUTO_INCREMENT, PRIMARY KEY): Unique identifier for each doctor-patient relationship.
doctor_id (INT NOT NULL, FOREIGN KEY REFERENCES doctors(id)): ID of the associated doctor.
patient_id (INT NOT NULL, FOREIGN KEY REFERENCES patients(id)): ID of the associated patient.
UNIQUE (doctor_id, patient_id): Ensures a unique doctor-patient pair.


2. File Paths
Here are the file paths for the PHP files mentioned in the previous messages:
/your_web_root/
│
├── admin_dashboard.php          // Admin dashboard displaying patient list
├── admin_login.php              // Admin login page
├── admin_logout.php             // Admin logout functionality
├── create_patient.php           // Page for creating a new patient
├── view_patient.php             // Page for viewing patient details
├── edit_patient.php             // Page for editing patient information
├── delete_patient.php           // Page for deleting a patient
├── add_health_record.php        // Page for adding health records for a patient
├── edit_health_record.php       // Page for editing health records
├── patient_login.php            // Patient login page
├── patient_dashboard.php        // Patient dashboard displaying their information
├── patient_logout.php           // Patient logout functionality
├── db_connect.php               // Database connection file
├── index.php               // index home 
├── update_patient_status.php               // update patient st
├── doctors/
│   ├── login.php
│   ├── logout.php
│   ├── dashboard.php
│   ├── view_patient.php
│   ├── edit_health_record.php
│   ├── add_health_record.php
│   └── health_records.php
│   └── manage_doctors.php – this file for admin login




├── patients/
│   ├── delete_comment.php
│   ├── patient_dashboard.php
│   ├── patient_login.php
│   ├── send_comment.php
│   ├── patient_logout.php
├── invoice/
│   ├── index.php       // Page for generating an invoice
│   ├── services.php     // Page for generating a services
│   ├── create_invoice.php      
│   ├── edit_invoice.php     
│   ├── print_invoice.php       
│   ├── view_invoice.php     /
) in edit_health_record.php (<?php
// doctors/edit_health_record.php

session_start();
require_once '../db_connect.php';

// Ensure the doctor is logged in
if (!isset($_SESSION['doctor_id'])) {
    header("Location: login.php");
    exit();
}

// Get the health record ID
$record_id = $_GET['id'] ?? null;

if (!$record_id) {
    header("Location: dashboard.php");
    exit();
}

// Fetch the health record and ensure the doctor has access to it
$doctor_id = $_SESSION['doctor_id'];

$stmt = $pdo->prepare("
    SELECT hr.*
    FROM health_records hr
    JOIN doctor_patient dp ON hr.patient_id = dp.patient_id
    WHERE hr.id = ? AND dp.doctor_id = ?
");
$stmt->execute([$record_id, $doctor_id]);

$health_record = $stmt->fetch();

if (!$health_record) {
    // Either the record doesn't exist or the doctor doesn't have access
    echo "You are not authorized to edit this health record.";
    exit();
}

$patient_id = $health_record['patient_id'];

$errors = [];
// Initialize form variables with existing values
$blood_pressure = $health_record['blood_pressure'];
$weight = $health_record['weight'];
$bmi = $health_record['bmi'];
$cholesterol = $health_record['cholesterol'];
$prescription = $health_record['prescription'];
$treatment_progress = $health_record['treatment_progress'];
$record_date = $health_record['record_date'];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Collect and sanitize inputs
    $blood_pressure = trim($_POST['blood_pressure']);
    $weight = $_POST['weight'];
    $bmi = $_POST['bmi'];
    $cholesterol = $_POST['cholesterol'];
    $prescription = trim($_POST['prescription']);
    $treatment_progress = trim($_POST['treatment_progress']);
    $record_date = $_POST['record_date'];

    // Validate inputs
    if (empty($blood_pressure)) {
        $errors[] = "Blood pressure is required.";
    }
    if (!is_numeric($weight) || $weight <= 0) {
        $errors[] = "Weight must be a positive number.";
    }
    if (!is_numeric($bmi) || $bmi <= 0) {
        $errors[] = "BMI must be a positive number.";
    }
    if (!is_numeric($cholesterol) || $cholesterol <= 0) {
        $errors[] = "Cholesterol level must be a positive number.";
    }
    if (empty($prescription)) {
        $errors[] = "Prescription is required.";
    }
    if (empty($treatment_progress)) {
        $errors[] = "Treatment progress notes are required.";
    }
    if (empty($record_date)) {
        $errors[] = "Record date is required.";
    } else {
        // Check if date is valid
        $d = DateTime::createFromFormat('Y-m-d', $record_date);
        if (!$d || $d->format('Y-m-d') != $record_date) {
            $errors[] = "Invalid date format for record date.";
        }
    }

    if (empty($errors)) {
        // Proceed to update the database
        $update_stmt = $pdo->prepare("
            UPDATE health_records
            SET blood_pressure = ?, weight = ?, bmi = ?, cholesterol = ?, prescription = ?, treatment_progress = ?, record_date = ?
            WHERE id = ?
        ");
        $update_stmt->execute([$blood_pressure, $weight, $bmi, $cholesterol, $prescription, $treatment_progress, $record_date, $record_id]);

        if ($update_stmt) {
            // Record updated successfully
            header("Location: view_patient.php?id=" . urlencode($patient_id));
            exit();
        } else {
            $errors[] = "Failed to update health record. Please try again.";
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Edit Health Record</title>
    <!-- Include your CSS files here -->
    <style>
        /* Basic styling for demonstration */
        .container { width: 600px; margin: 0 auto; }
        .header { text-align: center; }
        .form-group { margin-bottom: 15px; }
        label { display: block; margin-bottom: 5px; }
        input[type="text"], input[type="number"], input[type="date"], textarea { width: 100%; padding: 8px; box-sizing: border-box; }
        .error-messages { color: red; }
        .back-link { display: block; margin-top: 20px; }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h2>Edit Health Record</h2>
        </div>

        <div class="section">
            <?php if (!empty($errors)): ?>
                <div class="error-messages">
                    <p>Please correct the following errors:</p>
                    <ul>
                        <?php foreach ($errors as $error): ?>
                            <li><?= htmlspecialchars($error) ?></li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            <?php endif; ?>

            <form method="POST" action="">
                <div class="form-group">
                    <label for="blood_pressure">Blood Pressure:</label>
                    <input type="text" id="blood_pressure" name="blood_pressure" value="<?= htmlspecialchars($blood_pressure) ?>" required>
                </div>
                <div class="form-group">
                    <label for="weight">Weight (kg):</label>
                    <input type="number" step="0.01" id="weight" name="weight" value="<?= htmlspecialchars($weight) ?>" required>
                </div>
                <div class="form-group">
                    <label for="bmi">BMI:</label>
                    <input type="number" step="0.01" id="bmi" name="bmi" value="<?= htmlspecialchars($bmi) ?>" required>
                </div>
                <div class="form-group">
                    <label for="cholesterol">Cholesterol (mg/dL):</label>
                    <input type="number" step="0.01" id="cholesterol" name="cholesterol" value="<?= htmlspecialchars($cholesterol) ?>" required>
                </div>
                <div class="form-group">
                    <label for="prescription">Prescription:</label>
                    <textarea id="prescription" name="prescription" rows="4" required><?= htmlspecialchars($prescription) ?></textarea>
                </div>
                <div class="form-group">
                    <label for="treatment_progress">Treatment Progress Notes:</label>
                    <textarea id="treatment_progress" name="treatment_progress" rows="4" required><?= htmlspecialchars($treatment_progress) ?></textarea>
                </div>
                <div class="form-group">
                    <label for="record_date">Record Date:</label>
                    <input type="date" id="record_date" name="record_date" value="<?= htmlspecialchars($record_date) ?>" required>
                </div>
                <input type="submit" value="Update Health Record">
            </form>

            <a href="view_patient.php?id=<?= htmlspecialchars($patient_id) ?>" class="back-link">Back to Patient Record</a>
        </div>
    </div>
</body>
</html>) make it has access to edit as doctor and type full codes