// Fetch doctor information using the employee_id
stmt=pdo->prepare("SELECT * FROM doctors WHERE employee_id = ?");
stmt−>execute([employee_id]);
doctor=stmt->fetch();
if (!$doctor) {
// Invalid session or doctor not found
session_destroy();
header("Location: login.php");
exit();
}
doctorid=doctor['id'];
// Get patient ID from GET request (using 'id')
if (!isset(GET[′id′])∣∣!isnumeric(_GET['id'])) {
echo "Invalid patient ID. Return to Dashboard";
exit();
}
patientid=(int)_GET['id'];
// Debugging: Check what patient_id is received
// Uncomment the line below during debugging
// echo "Received patient ID: " . $patient_id . "";
// Verify that the patient is assigned to the logged-in doctor
verifystmt=pdo->prepare("SELECT * FROM doctor_patient WHERE doctor_id = ? AND patient_id = ?");
verifystmt−>execute([doctor_id, patientid]);assignment = $verify_stmt->fetch();
// Debugging: Check if the assignment exists
// Uncomment the lines below during debugging
// if (!assignment) {
// echo "Assignment Check: No assignment found for Doctor ID doctor_id and Patient ID $patient_id.";
// }
if (!$assignment) {
echo "You are not assigned to this patient. Return to Dashboard";
exit();
}
// Fetch patient information
patientstmt=pdo->prepare("SELECT * FROM patients WHERE id = ?");
patientstmt−>execute([patient_id]);
patient=patient_stmt->fetch();
if (!$patient) {
echo "Patient not found. Return to Dashboard";
exit();
}
// Fetch medical notes for the patient
notesstmt=pdo->prepare("
SELECT mn.*, d.name AS doctor_name
FROM medical_notes mn
JOIN doctors d ON mn.doctor_id = d.id
WHERE mn.patient_id = ?
ORDER BY mn.created_at DESC
");
notesstmt−>execute([patient_id]);
notes=notes_stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!-- Navigation Buttons -->
<div class="d-flex justify-content-between mb-3">
<a href="dashboard.php" class="btn btn-secondary">Back to Dashboard</a>
<a href="add_note.php?id=<?= htmlspecialchars($patient_id); ?>" class="btn btn-custom">
<i class="fas fa-plus"></i> Add New Note
</a>
</div>
<!-- Patient Information -->
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">Patient Details</h5>
<p class="card-text">
<strong>Name:</strong> <?= htmlspecialchars($patient['name']); ?><br>
<strong>Age:</strong> <?= htmlspecialchars($patient['age']); ?><br>
<strong>Gender:</strong> <?= htmlspecialchars($patient['gender']); ?><br>
<strong>Phone:</strong> <?= htmlspecialchars($patient['phone']); ?><br>
<strong>Email:</strong> <?= htmlspecialchars($patient['email']); ?><br>
<strong>Address:</strong> <?= htmlspecialchars($patient['address']); ?><br>
</p>
</div>
</div>
<!-- Medical Notes -->
<div class="card">
<div class="card-header">
<h3>Medical Notes</h3>
</div>
<div class="card-body">
<?php if ($notes): ?>
<?php foreach ($notes as $note): ?>
<div class="border p-3 mb-3 bg-light rounded">
<div class="d-flex justify-content-between">
<div>
<strong>Dr. <?= htmlspecialchars($note['doctor_name']); ?></strong>
<small class="text-muted"><?= htmlspecialchars($note['created_at']); ?></small>
</div>
<?php if ($note['doctor_id'] == $doctor_id): ?>
<div>
<a href="edit_note.php?id_note=<?= htmlspecialchars($note['id']); ?>" class="btn btn-sm btn-primary">
<i class="fas fa-edit"></i>
</a>
<a href="delete_note.php?id_note=<?= htmlspecialchars($note['id']); ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this note?');">
<i class="fas fa-trash"></i>
</a>
</div>
<?php endif; ?>
</div>
<hr>
<div>
<?= $note['note']; // Rendered as HTML from the text editor ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>No medical notes found for this patient.</p>
<?php endif; ?>
</div>
</div>
</div>
<!-- Include your JS scripts here -->
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Font Awesome -->
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
A valid API key is required to continue using TinyMCE.
Please alert the admin to check the current API key. Click here to learn more. ) so please fix in this add_note(<?php
// doctors/add_note.php
// Enable error reporting for debugging (Disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
require_once '../db_connect.php'; // Ensure the path is correct
// Ensure the doctor is logged in
if (!isset(SESSION[′employeeid′])∣∣_SESSION['role'] !== 'doctor') {
header("Location: login.php");
exit();
}
employeeid=_SESSION['employee_id'];
// Fetch doctor information using the employee_id
stmt=pdo->prepare("SELECT * FROM doctors WHERE employee_id = ?");
stmt−>execute([employee_id]);
doctor=stmt->fetch();
if (!$doctor) {
// Invalid session or doctor not found
session_destroy();
header("Location: login.php");
exit();
}
doctorid=doctor['id'];
// Get patient ID from GET request (using 'id')
if (!isset(GET[′id′])∣∣!isnumeric(_GET['id'])) {
echo "Invalid patient ID. Return to Dashboard";
exit();
}
patientid=(int)_GET['id'];
// Debugging: Check what patient_id is received
// Uncomment the line below during debugging
// echo "Received patient ID: " . $patient_id . "";
// Verify that the patient is assigned to the logged-in doctor
verifystmt=pdo->prepare("SELECT * FROM doctor_patient WHERE doctor_id = ? AND patient_id = ?");
verifystmt−>execute([doctor_id, patientid]);assignment = $verify_stmt->fetch();
if (!$assignment) {
echo "You are not assigned to this patient. Return to Dashboard";
exit();
}
// Fetch patient information
patientstmt=pdo->prepare("SELECT * FROM patients WHERE id = ?");
patientstmt−>execute([patient_id]);
patient=patient_stmt->fetch();
if (!$patient) {
echo "Patient not found. Return to Dashboard";
exit();
}
// Handle form submission
if (_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset(_POST['note']) && !empty(trim(_POST['note']))) {
note = $_POST['note'];
// Insert the new note into the database
$insert_stmt = $pdo->prepare("INSERT INTO medical_notes (patient_id, doctor_id, note) VALUES (?, ?, ?)");
$insert_stmt->execute([$patient_id, $doctor_id, $note]);
// Redirect back to notes page
header("Location: notes.php?id=" . $patient_id);
exit();
} else {
$error = "Please enter a note.";
}
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/!40101 SET NAMES utf8mb4 */;
--
-- Database: u406552082_info
--
-- Table structure for table admins
CREATE TABLE admins (
id int(11) NOT NULL,
username varchar(50) NOT NULL,
password varchar(255) NOT NULL,
email varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table appointments
CREATE TABLE appointments (
id int(11) NOT NULL,
package_id int(11) NOT NULL,
appointment_date datetime NOT NULL,
proposed_appointment_date datetime DEFAULT NULL,
name varchar(255) NOT NULL,
email varchar(255) NOT NULL,
phone varchar(20) NOT NULL,
age int(3) DEFAULT NULL,
gender enum('Male','Female','Other') DEFAULT NULL,
address varchar(255) DEFAULT NULL,
preferred_contact_method enum('Email','Phone','WhatsApp') DEFAULT NULL,
additional_notes text DEFAULT NULL,
admin_notes text DEFAULT NULL,
status enum('Pending','Confirmed','Completed','Cancelled') DEFAULT 'Pending',
created_at timestamp NULL DEFAULT current_timestamp(),
patient_id int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table budgets
CREATE TABLE budgets (
id int(11) NOT NULL,
month varchar(7) DEFAULT NULL,
budgeted_revenue decimal(10,2) DEFAULT NULL,
budgeted_expenses decimal(10,2) DEFAULT NULL,
notes text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table comments
CREATE TABLE comments (
id int(11) NOT NULL,
patient_id int(11) NOT NULL,
sender enum('patient','doctor','admin') NOT NULL,
message text NOT NULL,
timestamp datetime DEFAULT current_timestamp(),
parent_id int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table doctors
CREATE TABLE doctors (
id int(11) NOT NULL,
employee_id int(11) NOT NULL,
name varchar(255) NOT NULL,
username varchar(100) NOT NULL,
password varchar(255) NOT NULL,
email varchar(255) NOT NULL,
specialization varchar(255) DEFAULT NULL,
phone varchar(20) DEFAULT NULL,
registration_date date DEFAULT curdate(),
profile_picture varchar(255) DEFAULT NULL,
department varchar(100) DEFAULT NULL,
date_of_joining date DEFAULT NULL,
status enum('active','inactive') DEFAULT 'active'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table doctor_patient
CREATE TABLE doctor_patient (
id int(11) NOT NULL,
doctor_id int(11) NOT NULL,
patient_id int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table employees
CREATE TABLE employees (
id int(11) NOT NULL,
name varchar(255) NOT NULL,
role enum('admin','doctor','staff','accountant') NOT NULL,
email varchar(255) NOT NULL,
phone varchar(20) DEFAULT NULL,
department varchar(100) DEFAULT NULL,
date_of_joining date DEFAULT NULL,
status enum('active','inactive') DEFAULT 'active',
username varchar(100) NOT NULL,
password varchar(255) NOT NULL,
created_at timestamp NULL DEFAULT current_timestamp(),
updated_at timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
profile_picture varchar(255) DEFAULT NULL,
specialization varchar(255) DEFAULT NULL,
is_online tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table expenses
CREATE TABLE expenses (
id int(11) NOT NULL,
expense_date date NOT NULL,
category varchar(100) NOT NULL,
description varchar(255) DEFAULT NULL,
amount decimal(10,2) NOT NULL,
created_at timestamp NULL DEFAULT current_timestamp(),
updated_at timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table health_records
CREATE TABLE health_records (
id int(11) NOT NULL,
patient_id int(11) NOT NULL,
blood_pressure varchar(20) DEFAULT NULL,
weight decimal(5,2) DEFAULT NULL,
bmi decimal(4,2) DEFAULT NULL,
cholesterol decimal(5,2) DEFAULT NULL,
prescription text DEFAULT NULL,
treatment_progress text DEFAULT NULL,
record_date date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table insurance_claims
CREATE TABLE insurance_claims (
id int(11) NOT NULL,
patient_id int(11) DEFAULT NULL,
invoice_id int(11) DEFAULT NULL,
claim_amount decimal(10,2) DEFAULT NULL,
status enum('Pending','Approved','Rejected') DEFAULT NULL,
submission_date date DEFAULT NULL,
processing_date date DEFAULT NULL,
notes text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table invoices
CREATE TABLE invoices (
id int(11) NOT NULL,
patient_id int(11) NOT NULL,
service_name varchar(255) NOT NULL,
service_description text DEFAULT NULL,
cost decimal(10,2) NOT NULL,
tax_rate decimal(5,2) DEFAULT 0.00,
discount decimal(5,2) DEFAULT 0.00,
total_amount decimal(10,2) NOT NULL,
invoice_date date DEFAULT curdate(),
due_date date DEFAULT NULL,
notes text DEFAULT NULL,
tax decimal(5,2) DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table invoice_services
CREATE TABLE invoice_services (
id int(11) NOT NULL,
invoice_id int(11) NOT NULL,
service_id int(11) NOT NULL,
service_name varchar(255) NOT NULL,
cost decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table packages
CREATE TABLE packages (
id int(11) NOT NULL,
package_name varchar(255) NOT NULL,
description text DEFAULT NULL,
details text DEFAULT NULL,
created_at timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table patients
CREATE TABLE patients (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
age int(3) DEFAULT NULL,
gender enum('Male','Female','Other') DEFAULT NULL,
phone varchar(20) DEFAULT NULL,
email varchar(100) DEFAULT NULL,
medical_history text DEFAULT NULL,
created_at timestamp NULL DEFAULT current_timestamp(),
updated_at timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
date_of_birth date DEFAULT NULL,
registration_datetime datetime DEFAULT current_timestamp(),
registration_date date DEFAULT 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') DEFAULT 'Initial Consultation',
doctor_id int(11) DEFAULT NULL,
address varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table patient_basic_info
CREATE TABLE patient_basic_info (
patient_id int(11) NOT NULL,
gender enum('Male','Female','Other') NOT NULL,
age int(3) NOT NULL,
weight decimal(5,2) NOT NULL,
height decimal(5,2) NOT NULL,
address varchar(255) DEFAULT NULL,
name varchar(100) NOT NULL,
email varchar(100) NOT NULL,
phone varchar(20) NOT NULL,
created_at timestamp NULL DEFAULT current_timestamp(),
updated_at timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table patient_consent
CREATE TABLE patient_consent (
patient_id int(11) NOT NULL,
consent enum('accepted','declined') NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table patient_consultation
CREATE TABLE patient_consultation (
patient_id int(11) NOT NULL,
scheduled_at datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table patient_goals
CREATE TABLE patient_goals (
patient_id int(11) NOT NULL,
primary_health_goals text NOT NULL,
health_concerns text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table patient_health_metrics
CREATE TABLE patient_health_metrics (
patient_id int(11) NOT NULL,
exercise_frequency enum('Daily','Weekly','Rarely','Never') NOT NULL,
diet enum('Yes','No') NOT NULL,
diet_specify varchar(255) DEFAULT NULL,
sleep_average enum('<5 Hours','5-7 Hours','7-9 Hours','>9 Hours') NOT NULL,
smoking_status enum('Yes','No','Occasionally') NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table patient_logins
CREATE TABLE patient_logins (
id int(11) NOT NULL,
patient_id int(11) NOT NULL,
username varchar(50) NOT NULL,
password varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table patient_medical_history
CREATE TABLE patient_medical_history (
patient_id int(11) NOT NULL,
chronic_conditions enum('Yes','No') NOT NULL,
chronic_conditions_specify varchar(255) DEFAULT NULL,
medications enum('Yes','No') NOT NULL,
medications_list text DEFAULT NULL,
major_surgeries enum('Yes','No') NOT NULL,
major_surgeries_specify varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table payments
CREATE TABLE payments (
id int(11) NOT NULL,
patient_id int(11) NOT NULL,
invoice_id int(11) NOT NULL,
amount_paid decimal(10,2) NOT NULL,
payment_date date NOT NULL,
payment_method varchar(50) DEFAULT NULL,
notes text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table prescriptions
CREATE TABLE prescriptions (
id int(11) NOT NULL,
patient_id int(11) NOT NULL,
doctor_id int(11) DEFAULT NULL,
medications text NOT NULL,
instructions text DEFAULT NULL,
date_prescribed datetime DEFAULT current_timestamp(),
status enum('active','inactive') DEFAULT 'active'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table questionnaire_responses
CREATE TABLE questionnaire_responses (
id int(11) NOT NULL,
session_id varchar(255) NOT NULL,
page_number int(2) NOT NULL,
question varchar(255) NOT NULL,
answer text NOT NULL,
submitted_at timestamp NULL DEFAULT current_timestamp(),
consent enum('Yes','No') DEFAULT 'No'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
--
-- Table structure for table salaries
CREATE TABLE salaries (
id int(11) NOT NULL,
employee_id int(11) NOT NULL,
basic_salary decimal(10,2) NOT NULL,
bonuses decimal(10,2) DEFAULT 0.00,
deductions decimal(10,2) DEFAULT 0.00,
overtime_hours int(11) DEFAULT 0,
overtime_rate decimal(10,2) DEFAULT 0.00,
tax decimal(10,2) DEFAULT 0.00,
payment_date date NOT NULL,
net_salary decimal(10,2) NOT NULL,
status enum('Pending','Paid') DEFAULT 'Pending',
notes text DEFAULT NULL,
payslip_path varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table services
CREATE TABLE services (
service_id int(11) NOT NULL,
service_name varchar(255) NOT NULL,
service_price decimal(10,2) NOT NULL,
service_description text DEFAULT NULL,
created_at timestamp NULL DEFAULT current_timestamp(),
updated_at timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE invoice_services
ADD CONSTRAINT invoice_services_ibfk_1 FOREIGN KEY (invoice_id) REFERENCES invoices (id) ON DELETE CASCADE,
ADD CONSTRAINT invoice_services_ibfk_2 FOREIGN KEY (service_id) REFERENCES services (service_id) ON DELETE CASCADE;
--
-- Constraints for table patients
ALTER TABLE patients
ADD CONSTRAINT patients_ibfk_1 FOREIGN KEY (doctor_id) REFERENCES doctors (id) ON DELETE SET NULL ON UPDATE CASCADE;
--
-- Constraints for table patient_basic_info
ALTER TABLE patient_basic_info
ADD CONSTRAINT fk_patient_basic_info_patient FOREIGN KEY (patient_id) REFERENCES patients (id) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table patient_logins
ALTER TABLE patient_logins
ADD CONSTRAINT patient_logins_ibfk_1 FOREIGN KEY (patient_id) REFERENCES patients (id) ON DELETE CASCADE;
--
-- Constraints for table payments
ALTER TABLE payments
ADD CONSTRAINT payments_ibfk_1 FOREIGN KEY (patient_id) REFERENCES patients (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT payments_ibfk_2 FOREIGN KEY (invoice_id) REFERENCES invoices (id) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table prescriptions
ALTER TABLE prescriptions
ADD CONSTRAINT prescriptions_ibfk_1 FOREIGN KEY (patient_id) REFERENCES patients (id) ON DELETE CASCADE,
ADD CONSTRAINT prescriptions_ibfk_2 FOREIGN KEY (doctor_id) REFERENCES doctors (id) ON DELETE SET NULL;
--
-- Constraints for table salaries
ALTER TABLE salaries
ADD CONSTRAINT salaries_ibfk_1 FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;)
Certainly! Let's address both issues you've encountered and enhance the design of your application for a better user experience.
1. Fixing the htmlspecialchars() Deprecated Warning in notes.php
Issue:
The warning Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated indicates that htmlspecialchars() is being called with a null value. This typically happens when the expected data isn't retrieved correctly from the database.
Solution:
Ensure that the variables passed to htmlspecialchars() are not null. You can provide default values or handle null cases gracefully.
Updated notes.php:
<?php
// doctors/notes.php
// Enable error reporting for debugging (Disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
require_once '../db_connect.php'; // Ensure the path is correct
// Ensure the doctor is logged in
if (!isset($_SESSION['employee_id']) || $_SESSION['role'] !== 'doctor') {
header("Location: login.php");
exit();
}
$employee_id = $_SESSION['employee_id'];
// Fetch doctor information using the employee_id
$stmt = $pdo->prepare("SELECT * FROM doctors WHERE employee_id = ?");
$stmt->execute([$employee_id]);
$doctor = $stmt->fetch();
if (!$doctor) {
// Invalid session or doctor not found
session_destroy();
header("Location: login.php");
exit();
}
$doctor_id = $doctor['id'];
// Get patient ID from GET request (using 'id')
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
echo "Invalid patient ID. <a href='dashboard.php'>Return to Dashboard</a>";
exit();
}
$patient_id = (int)$_GET['id'];
// Verify that the patient is assigned to the logged-in doctor
$verify_stmt = $pdo->prepare("SELECT * FROM doctor_patient WHERE doctor_id = ? AND patient_id = ?");
$verify_stmt->execute([$doctor_id, $patient_id]);
$assignment = $verify_stmt->fetch();
if (!$assignment) {
echo "You are not assigned to this patient. <a href='dashboard.php'>Return to Dashboard</a>";
exit();
}
// Fetch patient information
$patient_stmt = $pdo->prepare("SELECT * FROM patients WHERE id = ?");
$patient_stmt->execute([$patient_id]);
$patient = $patient_stmt->fetch();
if (!$patient) {
echo "Patient not found. <a href='dashboard.php'>Return to Dashboard</a>";
exit();
}
// Fetch medical notes for the patient
$notes_stmt = $pdo->prepare("
SELECT mn.*, d.name AS doctor_name
FROM medical_notes mn
JOIN doctors d ON mn.doctor_id = d.id
WHERE mn.patient_id = ?
ORDER BY mn.created_at DESC
");
$notes_stmt->execute([$patient_id]);
$notes = $notes_stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Medical Notes - <?= htmlspecialchars($patient['name'] ?? 'Unknown Patient'); ?> | Doctor Dashboard</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://kit.fontawesome.com/a076d05399.css">
<!-- Date Range Picker CSS (if needed) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css">
<!-- Your custom CSS if any -->
<style>
body {
background-color: #f8f9fa;
font-family: Arial, sans-serif;
}
.notes-header {
background-color: #4F3F02; /* Brown color */
color: #fff;
padding: 20px;
border-radius: 8px;
margin-bottom: 30px;
text-align: center;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.notes-header img {
max-width: 20%;
margin-bottom: 20px;
}
.btn-custom {
background-color: #D1C287; /* Light golden color */
color: #4F3F02;
border-radius: 50px;
transition: all 0.3s ease;
}
.btn-custom:hover {
background-color: #4F3F02;
color: #fff;
}
.card {
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.note-actions {
text-align: right;
}
</style>
</head>
<body>
<div class="container-fluid">
<!-- Header -->
<div class="notes-header">
<img src="../images/white-logo.png" alt="Logo">
<h1>Medical Notes for <?= htmlspecialchars($patient['name'] ?? 'Unknown Patient'); ?></h1>
<p>Welcome, Dr. <?= htmlspecialchars($doctor['name'] ?? 'Doctor'); ?>!</p>
</div>
<!-- Navigation Buttons -->
<div class="d-flex justify-content-between mb-3">
<a href="dashboard.php" class="btn btn-secondary">Back to Dashboard</a>
<a href="add_note.php?id=<?= htmlspecialchars($patient_id); ?>" class="btn btn-custom">
<i class="fas fa-plus"></i> Add New Note
</a>
</div>
<!-- Patient Information -->
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">Patient Details</h5>
<p class="card-text">
<strong>Name:</strong> <?= htmlspecialchars($patient['name'] ?? 'N/A'); ?><br>
<strong>Age:</strong> <?= htmlspecialchars($patient['age'] ?? 'N/A'); ?><br>
<strong>Gender:</strong> <?= htmlspecialchars($patient['gender'] ?? 'N/A'); ?><br>
<strong>Phone:</strong> <?= htmlspecialchars($patient['phone'] ?? 'N/A'); ?><br>
<strong>Email:</strong> <?= htmlspecialchars($patient['email'] ?? 'N/A'); ?><br>
<strong>Address:</strong> <?= htmlspecialchars($patient['address'] ?? 'N/A'); ?><br>
</p>
</div>
</div>
<!-- Medical Notes -->
<div class="card">
<div class="card-header">
<h3>Medical Notes</h3>
</div>
<div class="card-body">
<?php if ($notes): ?>
<?php foreach ($notes as $note): ?>
<div class="border p-3 mb-3 bg-light rounded">
<div class="d-flex justify-content-between">
<div>
<strong>Dr. <?= htmlspecialchars($note['doctor_name'] ?? 'Unknown'); ?></strong>
<small class="text-muted"><?= htmlspecialchars($note['created_at'] ?? 'N/A'); ?></small>
</div>
<?php if ($note['doctor_id'] == $doctor_id): ?>
<div>
<a href="edit_note.php?id_note=<?= htmlspecialchars($note['id']); ?>" class="btn btn-sm btn-primary">
<i class="fas fa-edit"></i>
</a>
<a href="delete_note.php?id_note=<?= htmlspecialchars($note['id']); ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this note?');">
<i class="fas fa-trash"></i>
</a>
</div>
<?php endif; ?>
</div>
<hr>
<div>
<?= nl2br(htmlspecialchars($note['note'] ?? '')); // Safely render the note ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>No medical notes found for this patient.</p>
<?php endif; ?>
</div>
</div>
</div>
<!-- Include your JS scripts here -->
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Font Awesome -->
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
</body>
</html>
Key Changes:
Null Handling: Used the null coalescing operator (??) to provide default values if certain fields are null. For example:
2. Fixing the TinyMCE API Key Issue in add_note.php
Issue:
The warning A valid API key is required to continue using TinyMCE. occurs because TinyMCE now requires a valid API key for its cloud services. Using no-api-key triggers this warning.
Solution:
Obtain a valid API key from TinyMCE or self-host TinyMCE without using their cloud services.
Security Enhancements: Ensure that user input is properly sanitized and escaped to prevent security vulnerabilities.
3. Enhancing the Design for a Modern and "Cool" Look
To further enhance the design, consider the following improvements:
Upgrade to Bootstrap 5:
Bootstrap 5 offers better utilities and components compared to Bootstrap 4. Update the CDN links accordingly.
Use a Consistent Color Scheme:
Stick to a consistent color palette that reflects professionalism and is easy on the eyes. You can use tools like Coolors to generate complementary color schemes.
Improve Typography and Spacing:
Use modern fonts (like Google Fonts) and ensure adequate spacing for better readability.
Add Responsive Enhancements:
Ensure that the application looks good on all devices by leveraging Bootstrap's responsive utilities.
Incorporate Interactive Elements:
Use subtle animations and transitions to make the UI more engaging.
Use Google Fonts: Integrate modern fonts like Roboto for a cleaner look.
Shadows and Rounded Corners: Enhance cards and headers with shadows and rounded corners for a modern feel.
Button Styles: Create custom button styles with smooth transitions.
Responsive Adjustments: Ensure that images and text scale appropriately on different devices.
4. Final Touches
Ensure that all pages (notes.php, add_note.php, etc.) follow the same design principles for consistency. Test the application across different browsers and devices to guarantee a seamless user experience.
5. Database Considerations
Based on your provided database structure, ensure that all necessary tables and relationships are correctly set up. Some additional tips:
Indexes and Foreign Keys: Ensure that all foreign keys and indexes are correctly defined to maintain database integrity and optimize performance.
Data Validation: Implement server-side validation to ensure that data entered into the database is correct and secure.
Security Measures: Protect against SQL injection by using prepared statements (as you've done) and consider implementing additional security layers like token-based CSRF protection.
By implementing these changes, you should resolve the htmlspecialchars() warning, fix the TinyMCE API key issue, and enhance the overall design of your application for a modern and professional appearance.