-- Host: 127.0.0.1:3306
-- Generation Time: Oct 16, 2024 at 06:33 PM
-- Server version: 10.11.9-MariaDB
-- PHP Version: 7.2.34
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
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
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,
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_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 */;), i want to create folder called (longeva_health_journey_answers) this folder has file shows info who made survey from this page 8 (<?php
// longeva_health_journey/pages/page8.php
// Enable error reporting for debugging (Remove in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Start session and include database connection
session_start();
require '../db_connect.php';
// Check if patient_id is set; if not, redirect to page3.php to collect information
if (!isset($_SESSION['patient_id'])) {
header("Location: page3.php");
exit();
}
// Fetch existing patient_basic_info and consultation date/time to pre-fill the form
try {
// Fetch patient basic info
stmt=pdo->prepare("SELECT * FROM patient_basic_info WHERE patient_id = ?");
stmt−>execute([_SESSION['patient_id']]);
basicinfo=stmt->fetch();
code
if ($basic_info) {
$name = htmlspecialchars($basic_info['name']);
$email = htmlspecialchars($basic_info['email']);
$phone = htmlspecialchars($basic_info['phone']);
$gender = htmlspecialchars($basic_info['gender']);
$age = htmlspecialchars($basic_info['age']);
$weight = htmlspecialchars($basic_info['weight']);
$height = htmlspecialchars($basic_info['height']);
}
// Fetch existing consultation date and time if available
$stmt = $pdo->prepare("SELECT scheduled_at FROM patient_consultation WHERE patient_id = ?");
$stmt->execute([$_SESSION['patient_id']]);
$consultation = $stmt->fetch();
if ($consultation) {
// Ensure the datetime format is compatible with input[type="datetime-local"]
$scheduled_at = date('Y-m-d\TH:i', strtotime($consultation['scheduled_at']));
}
// 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 ?)";
searchparam="search%";
params=arraymerge(params, [searchparam,search_param, searchparam,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
// 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 Data Analysis Data
// Fetch total number of patients
stmt=pdo->query("SELECT COUNT() FROM patients");
totalpatients=stmt->fetchColumn();
// Fetch recent registrations (last 30 days)
stmt=pdo->query("SELECT COUNT() FROM patients WHERE registration_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)");
recentregistrations=stmt->fetchColumn();
// Fetch recent registrations (today)
stmt=pdo->query("SELECT COUNT() FROM patients WHERE DATE(registration_datetime) = CURDATE()");
todayregistrations=stmt->fetchColumn();
// Fetch total number of invoices
stpdo->query("SELECT COUNT() FROM invoices");
totalinvoices=stmt->fetchColumn();
// Fetch gender distribution
stmt=pdo->query("SELECT gender, COUNT() as count FROM patients GROUP BY gender");
genderdistribution=stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch age distribution
stmtpdo->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
");
agedistribution=stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch status distribution
stmt=pdo->query("SELECT status, COUNT(*) as count FROM patients GROUP BY status");
statusdistribution=stmt->fetchAll(PDO::FETCH_ASSOC);
?>
Certainly! Below is a comprehensive guide to creating the longeva_health_journey_answers folder with a PHP file that displays survey data collected from page8.php. This guide includes full code with comments, explanations, and best practices to help you set up an admin dashboard similar to the one you've provided.
Step 1: Create the Folder Structure
Create the Main Folder
Create a new folder named longeva_health_journey_answers in your project directory.
Make sure you have header.php and footer.php inside the includes folder. These files are essential for consistent layout and navigation across your admin dashboard.
Error Reporting: Enables error display for debugging purposes. Ensure you disable this in production for security reasons.
Session Management: Starts a session and checks if the admin is logged in by verifying $_SESSION['admin_id']. Redirects to login.php if not authenticated.
Including Header
php
include '../includes/header.php';
Header Inclusion: Adds the navigation bar and other common elements defined in header.php.
Executing Query: Prepares and executes the SQL statement with the appropriate parameters to prevent SQL injection.
Step 3: Create Viewing, Editing, and Deleting Functionality
To manage the survey answers effectively, you need separate PHP files to view, edit, and delete survey entries.
3.1. View Survey Answer (view_survey.php)
php
<?php
// longeva_health_journey_answers/view_survey.php
// Enable error reporting for debugging (Remove in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Start session and include database connection
session_start();
require '../db_connect.php';
// Check if the user is logged in as admin
if (!isset($_SESSION['admin_id'])) {
header("Location: login.php");
exit();
}
// Get patient_id from GET parameter
$patient_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($patient_id <= 0) {
header("Location: index.php");
exit();
}
// Fetch patient data
$stmt = $pdo->prepare("
SELECT
p.*,
pb.*,
pc.*
FROM patients p
LEFT JOIN patient_basic_info pb ON p.id = pb.patient_id
LEFT JOIN patient_consultation pc ON p.id = pc.patient_id
WHERE p.id = ?
");
$stmt->execute([$patient_id]);
$patient = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$patient) {
echo "Patient not found.";
exit();
}
// Include the header
include '../includes/header.php';
?>
<div class="container-fluid">
<h2 class="mb-4">View Survey Answer</h2>
<div class="card">
<div class="card-header">
Patient Information
</div>
<div class="card-body">
<p><strong>Name:</strong> <?= htmlspecialchars($patient['name']) ?></p>
<p><strong>Email:</strong> <?= htmlspecialchars($patient['email']) ?></p>
<p><strong>Phone:</strong> <?= htmlspecialchars($patient['phone']) ?></p>
<p><strong>Gender:</strong> <?= htmlspecialchars($patient['gender']) ?></p>
<p><strong>Age:</strong> <?= htmlspecialchars($patient['age']) ?></p>
<p><strong>Weight (kg):</strong> <?= htmlspecialchars($patient['weight']) ?></p>
<p><strong>Height (cm):</strong> <?= htmlspecialchars($patient['height']) ?></p>
<p><strong>Address:</strong> <?= htmlspecialchars($patient['address']) ?></p>
<p><strong>Scheduled Consultation At:</strong> <?= htmlspecialchars($patient['scheduled_at']) ?></p>
<p><strong>Status:</strong> <?= htmlspecialchars($patient['status']) ?></p>
</div>
</div>
<a href="edit_survey.php?id=<?= $patient['id'] ?>" class="btn btn-warning mt-3">Edit</a>
<a href="index.php" class="btn btn-secondary mt-3">Back to Dashboard</a>
</div>
<?php
// Include the footer
include '../includes/footer.php';
?>
3.2. Edit Survey Answer (edit_survey.php)
php
3.3. Delete Survey Answer (delete_survey.php)
php
<?php
// longeva_health_journey_answers/delete_survey.php
// Enable error reporting for debugging (Remove in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Start session and include database connection
session_start();
require '../db_connect.php';
// Check if the user is logged in as admin
if (!isset($_SESSION['admin_id'])) {
header("Location: login.php");
exit();
}
// Get patient_id from GET parameter
$patient_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($patient_id <= 0) {
header("Location: index.php");
exit();
}
// Delete patient data from related tables
try {
// Begin transaction
$pdo->beginTransaction();
// Delete from patient_consultation
$stmt = $pdo->prepare("DELETE FROM patient_consultation WHERE patient_id = ?");
$stmt->execute([$patient_id]);
// Delete from patient_basic_info
$stmt = $pdo->prepare("DELETE FROM patient_basic_info WHERE patient_id = ?");
$stmt->execute([$patient_id]);
// Optionally, delete from other related tables (e.g., payments, invoices, etc.)
// Delete from patients table
$stmt = $pdo->prepare("DELETE FROM patients WHERE id = ?");
$stmt->execute([$patient_id]);
// Commit transaction
$pdo->commit();
// Redirect to dashboard with success message
header("Location: index.php?message=Survey+Answer+Deleted+Successfully");
exit();
} catch (PDOException $e) {
// Rollback transaction on error
$pdo->rollBack();
echo "Error deleting survey answer: " . $e->getMessage();
exit();
}
?>
3.4. Add View/Edit/Delete Functionality in the Dashboard
Ensure that the action buttons in the patient table (index.php) correctly link to the respective files:
php
<td>
<a href="view_survey.php?id=<?= $patient['patient_id'] ?>" class="btn btn-info btn-sm">View</a>
<a href="edit_survey.php?id=<?= $patient['patient_id'] ?>" class="btn btn-warning btn-sm">Edit</a>
<a href="delete_survey.php?id=<?= $patient['patient_id'] ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want to delete this survey answer?')">Delete</a>
</td>
Step 4: Create the questionnaire_responses.php File (Optional)
If you want to display responses from the questionnaire_responses table, you can create another PHP file, e.g., questionnaire_responses.php following a similar structure as above.
Step 5: Styling and Enhancements
Stylesheet (styles.css)
Customize the appearance of your admin dashboard by editing the styles.css file located in assets/css/.
JavaScript Enhancements
DataTables: Enhance the HTML tables with features like pagination, searching, and sorting.
Chart.js: Visualize data distributions and trends.
Note: Ensure all necessary scripts are included in the footer.php as shown in the earlier code snippets.
Step 6: Security Best Practices
Input Validation and Sanitization
Always validate and sanitize user inputs to prevent SQL injection and XSS attacks.
Use prepared statements with parameterized queries, as demonstrated.
Session Management
Implement secure session handling.
Regenerate session IDs upon login to prevent session fixation attacks.
Use HTTPS to encrypt data transmitted between the client and server.
Error Handling
Disable error display in the production environment to prevent sensitive information leakage.
Log errors securely instead.
Access Control
Restrict access to admin dashboard pages to authorized users only.
Implement role-based access controls if multiple admin roles exist.
Modular Code: Consider separating logic from presentation by using MVC (Model-View-Controller) architecture for larger projects.
Reusable Components: Utilize Bootstrap components or other UI libraries to maintain a consistent and responsive design.
Documentation: Keep your code well-documented with comments for maintainability and ease of understanding.
Backup: Regularly backup your database and codebase to prevent data loss.
By following this guide, you should have a functional admin dashboard that displays survey answers collected from page8.php, complete with data analysis, filtering, and CRUD (Create, Read, Update, Delete) functionalities.