diff --git a/api/appointments.php b/api/appointments.php index d987b1d..e22f21a 100644 --- a/api/appointments.php +++ b/api/appointments.php @@ -36,12 +36,12 @@ if ($method === 'GET') { a.id, a.start_time as start, a.end_time as end, a.reason, a.status, a.patient_id, a.doctor_id, a.nurse_id, a.visit_type, a.address, p.name as patient_name, - d.name_$lang as doctor_name, - n.name_$lang as nurse_name + doc.name_$lang as doctor_name, + nur.name_$lang as nurse_name FROM appointments a JOIN patients p ON a.patient_id = p.id - LEFT JOIN doctors d ON a.doctor_id = d.id - LEFT JOIN nurses n ON a.nurse_id = n.id + LEFT JOIN employees doc ON a.doctor_id = doc.id + LEFT JOIN employees nur ON a.nurse_id = nur.id WHERE 1=1"; $params = []; @@ -148,19 +148,27 @@ if ($method === 'GET') { ]; } - // Fetch Doctor Holidays - $docHolidayQuery = "SELECT dh.*, d.name_$lang as doctor_name FROM doctor_holidays dh JOIN doctors d ON dh.doctor_id = d.id WHERE 1=1"; + // Fetch Doctor Holidays (from Leave Requests) + // Updated to join employees instead of doctors + $docHolidayQuery = " + SELECT lr.id, lr.start_date, lr.end_date, lr.reason as note, + lr.employee_id as doctor_id, + e.name_$lang as doctor_name + FROM leave_requests lr + JOIN employees e ON lr.employee_id = e.id + WHERE lr.status = 'Approved'"; + $docHolidayParams = []; // Date filtering for doctor holidays (ranges) if ($startStr && $endStr) { - $docHolidayQuery .= " AND dh.start_date <= ? AND dh.end_date >= ?"; + $docHolidayQuery .= " AND lr.start_date <= ? AND lr.end_date >= ?"; $docHolidayParams[] = date('Y-m-d', strtotime($endStr)); $docHolidayParams[] = date('Y-m-d', strtotime($startStr)); } if ($doctor_id) { - $docHolidayQuery .= " AND dh.doctor_id = ?"; + $docHolidayQuery .= " AND lr.employee_id = ?"; $docHolidayParams[] = $doctor_id; } @@ -223,36 +231,16 @@ if ($method === 'GET') { ]; } - // Fetch Doctor Business Hours - if ($doctor_id) { - $scheduleStmt = $db->prepare("SELECT day_of_week as day, start_time as start, end_time as end FROM doctor_schedules WHERE doctor_id = ?"); - $scheduleStmt->execute([$doctor_id]); - $schedules = $scheduleStmt->fetchAll(PDO::FETCH_ASSOC); - - $bhMap = []; - foreach ($schedules as $s) { - $key = $s['start'] . '-' . $s['end']; - if (!isset($bhMap[$key])) { - $bhMap[$key] = [ - 'daysOfWeek' => [], - 'startTime' => $s['start'], - 'endTime' => $s['end'] - ]; - } - $bhMap[$key]['daysOfWeek'][] = (int)$s['day']; - } - $businessHours = array_values($bhMap); - } else { - $st = $s['working_hours_start'] ?? '08:00'; - $et = $s['working_hours_end'] ?? '17:00'; - $businessHours = [ - [ - 'daysOfWeek' => [0, 1, 2, 3, 4, 5, 6], - 'startTime' => $st, - 'endTime' => $et - ] - ]; - } + // Set Business Hours (Global Default since individual schedules are removed) + $st = $s['working_hours_start'] ?? '08:00'; + $et = $s['working_hours_end'] ?? '17:00'; + $businessHours = [ + [ + 'daysOfWeek' => [0, 1, 2, 3, 4, 5, 6], + 'startTime' => $st, + 'endTime' => $et + ] + ]; echo json_encode([ 'events' => $events, @@ -269,7 +257,8 @@ function checkDoctorHoliday($db, $doctor_id, $start_time) { if (!$doctor_id || !$start_time) return false; $date = date('Y-m-d', strtotime($start_time)); try { - $stmt = $db->prepare("SELECT COUNT(*) FROM doctor_holidays WHERE doctor_id = ? AND ? BETWEEN start_date AND end_date"); + // Query leave_requests directly using employee_id (which is $doctor_id) + $stmt = $db->prepare("SELECT COUNT(*) FROM leave_requests WHERE employee_id = ? AND status = 'Approved' AND ? BETWEEN start_date AND end_date"); $stmt->execute([$doctor_id, $date]); return $stmt->fetchColumn() > 0; } catch (PDOException $e) { diff --git a/api/doctor_holidays.php b/api/doctor_holidays.php index 6bf29b8..1796e8e 100644 --- a/api/doctor_holidays.php +++ b/api/doctor_holidays.php @@ -2,52 +2,31 @@ require_once __DIR__ . '/../db/config.php'; require_once __DIR__ . '/../helpers.php'; +// Prevent caching +header('Cache-Control: no-cache, no-store, must-revalidate'); +header('Pragma: no-cache'); +header('Expires: 0'); header('Content-Type: application/json'); $db = db(); -$method = $_SERVER['REQUEST_METHOD']; -$input = json_decode(file_get_contents('php://input'), true) ?? $_POST; +$doctor_id = $_GET['doctor_id'] ?? null; -if ($method === 'GET') { - $doctor_id = $_GET['doctor_id'] ?? null; - if (!$doctor_id) { - echo json_encode(['success' => false, 'error' => 'Missing doctor_id']); - exit; - } +if (!$doctor_id) { + echo json_encode(['success' => false, 'error' => 'Missing doctor_id']); + exit; +} - $stmt = $db->prepare("SELECT * FROM doctor_holidays WHERE doctor_id = ? ORDER BY start_date DESC"); +try { + // $doctor_id is expected to be employee_id now + $stmt = $db->prepare(" + SELECT start_date, end_date, reason + FROM leave_requests + WHERE employee_id = ? AND status = 'Approved' AND end_date >= CURDATE() + "); $stmt->execute([$doctor_id]); - $holidays = $stmt->fetchAll(); + $holidays = $stmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode(['success' => true, 'holidays' => $holidays]); - exit; -} - -if ($method === 'POST') { - $action = $input['action'] ?? ''; - - if ($action === 'create') { - $doctor_id = $input['doctor_id'] ?? null; - $start_date = $input['start_date'] ?? null; - $end_date = $input['end_date'] ?? null; - $note = $input['note'] ?? ''; - - if ($doctor_id && $start_date && $end_date) { - $stmt = $db->prepare("INSERT INTO doctor_holidays (doctor_id, start_date, end_date, note) VALUES (?, ?, ?, ?)"); - $stmt->execute([$doctor_id, $start_date, $end_date, $note]); - echo json_encode(['success' => true]); - } else { - echo json_encode(['success' => false, 'error' => 'Missing fields']); - } - } elseif ($action === 'delete') { - $id = $input['id'] ?? null; - if ($id) { - $stmt = $db->prepare("DELETE FROM doctor_holidays WHERE id = ?"); - $stmt->execute([$id]); - echo json_encode(['success' => true]); - } else { - echo json_encode(['success' => false, 'error' => 'Missing ID']); - } - } - exit; +} catch (PDOException $e) { + echo json_encode(['success' => false, 'error' => 'DB Error: ' . $e->getMessage()]); } diff --git a/api/queue.php b/api/queue.php index 3f91da1..cf1358d 100644 --- a/api/queue.php +++ b/api/queue.php @@ -85,7 +85,7 @@ try { FROM patient_queue q JOIN patients p ON q.patient_id = p.id JOIN departments dept ON q.department_id = dept.id - LEFT JOIN doctors d ON q.doctor_id = d.id + LEFT JOIN employees d ON q.doctor_id = d.id $where ORDER BY CASE WHEN q.status = 'serving' THEN 1 WHEN q.status = 'waiting' THEN 2 ELSE 3 END, diff --git a/db/migrations/20260322_add_employee_to_nurses.sql b/db/migrations/20260322_add_employee_to_nurses.sql new file mode 100644 index 0000000..f417c81 --- /dev/null +++ b/db/migrations/20260322_add_employee_to_nurses.sql @@ -0,0 +1,2 @@ +ALTER TABLE nurses ADD COLUMN IF NOT EXISTS employee_id INT; +ALTER TABLE nurses ADD CONSTRAINT fk_nurse_employee FOREIGN KEY (employee_id) REFERENCES employees(id) ON DELETE SET NULL; diff --git a/db/migrations/20260322_merge_doctors_nurses_into_hr.sql b/db/migrations/20260322_merge_doctors_nurses_into_hr.sql new file mode 100644 index 0000000..1a550b6 --- /dev/null +++ b/db/migrations/20260322_merge_doctors_nurses_into_hr.sql @@ -0,0 +1,59 @@ +-- Migration to merge Doctors and Nurses into HR (Employees) +-- Step 1: Add new columns to hold Employee IDs +ALTER TABLE visits ADD COLUMN IF NOT EXISTS doctor_employee_id INT NULL; +ALTER TABLE appointments ADD COLUMN IF NOT EXISTS doctor_employee_id INT NULL; +ALTER TABLE appointments ADD COLUMN IF NOT EXISTS nurse_employee_id INT NULL; + +-- Step 2: Migrate data (if doctors/nurses have employee_id set) +-- Update Visits +UPDATE visits v +JOIN doctors d ON v.doctor_id = d.id +SET v.doctor_employee_id = d.employee_id +WHERE d.employee_id IS NOT NULL; + +-- Update Appointments (Doctor) +UPDATE appointments a +JOIN doctors d ON a.doctor_id = d.id +SET a.doctor_employee_id = d.employee_id +WHERE d.employee_id IS NOT NULL; + +-- Update Appointments (Nurse) +UPDATE appointments a +JOIN nurses n ON a.nurse_id = n.id +SET a.nurse_employee_id = n.employee_id +WHERE n.employee_id IS NOT NULL; + +-- Step 3: Drop old Foreign Keys (Constraint names might vary, so we try standard names or rely on DROP COLUMN to drop FKs in some DBs, but explicitly dropping FK is safer) +-- Finding constraint names is hard in SQL script without dynamic SQL. +-- However, in MariaDB/MySQL, dropping the column usually drops the FK. +-- But to be safe, we will try to drop the standard named constraints if known, or just proceed with DROP COLUMN which should work if no other constraints block it. + +ALTER TABLE visits DROP FOREIGN KEY IF EXISTS visits_ibfk_2; -- doctor_id +ALTER TABLE appointments DROP FOREIGN KEY IF EXISTS appointments_ibfk_2; -- doctor_id +ALTER TABLE appointments DROP FOREIGN KEY IF EXISTS appointments_ibfk_3; -- nurse_id + +-- Also drop keys/indexes if they exist separate from FK +ALTER TABLE visits DROP KEY IF EXISTS doctor_id; +ALTER TABLE appointments DROP KEY IF EXISTS doctor_id; +ALTER TABLE appointments DROP KEY IF EXISTS nurse_id; + +-- Step 4: Drop old columns +ALTER TABLE visits DROP COLUMN doctor_id; +ALTER TABLE appointments DROP COLUMN doctor_id; +ALTER TABLE appointments DROP COLUMN nurse_id; + +-- Step 5: Rename new columns to match standard naming (or keep them and add FK) +-- Let's rename them back to doctor_id and nurse_id but now they point to employees +ALTER TABLE visits CHANGE COLUMN doctor_employee_id doctor_id INT NULL; +ALTER TABLE appointments CHANGE COLUMN doctor_employee_id doctor_id INT NULL; +ALTER TABLE appointments CHANGE COLUMN nurse_employee_id nurse_id INT NULL; + +-- Step 6: Add new Foreign Keys to employees +ALTER TABLE visits ADD CONSTRAINT fk_visit_doctor_employee FOREIGN KEY (doctor_id) REFERENCES employees(id) ON DELETE SET NULL; +ALTER TABLE appointments ADD CONSTRAINT fk_appt_doctor_employee FOREIGN KEY (doctor_id) REFERENCES employees(id) ON DELETE SET NULL; +ALTER TABLE appointments ADD CONSTRAINT fk_appt_nurse_employee FOREIGN KEY (nurse_id) REFERENCES employees(id) ON DELETE SET NULL; + +-- Step 7: Drop obsolete tables +DROP TABLE IF EXISTS doctor_holidays; -- If exists +DROP TABLE IF EXISTS doctors; +DROP TABLE IF EXISTS nurses; diff --git a/db/migrations/20260322_merge_doctors_nurses_into_hr_final.sql b/db/migrations/20260322_merge_doctors_nurses_into_hr_final.sql new file mode 100644 index 0000000..718c95c --- /dev/null +++ b/db/migrations/20260322_merge_doctors_nurses_into_hr_final.sql @@ -0,0 +1,25 @@ +-- Final cleanup for Doctors/Nurses migration + +-- Fix Patient Queue Doctor ID (References doctors) +ALTER TABLE patient_queue ADD COLUMN IF NOT EXISTS doctor_employee_id INT NULL; + +-- Migrate data +UPDATE patient_queue q +JOIN doctors d ON q.doctor_id = d.id +SET q.doctor_employee_id = d.employee_id +WHERE d.employee_id IS NOT NULL; + +-- Drop old FK +ALTER TABLE patient_queue DROP FOREIGN KEY IF EXISTS patient_queue_ibfk_3; + +-- Drop old column +ALTER TABLE patient_queue DROP COLUMN doctor_id; + +-- Rename new column +ALTER TABLE patient_queue CHANGE COLUMN doctor_employee_id doctor_id INT NULL; + +-- Add new FK to employees +ALTER TABLE patient_queue ADD CONSTRAINT fk_queue_doctor_employee FOREIGN KEY (doctor_id) REFERENCES employees(id) ON DELETE SET NULL; + +-- Now drop doctors table +DROP TABLE IF EXISTS doctors; diff --git a/db/migrations/20260322_merge_doctors_nurses_into_hr_fix.sql b/db/migrations/20260322_merge_doctors_nurses_into_hr_fix.sql new file mode 100644 index 0000000..209061f --- /dev/null +++ b/db/migrations/20260322_merge_doctors_nurses_into_hr_fix.sql @@ -0,0 +1,56 @@ +-- Fix Migration: Merge Doctors and Nurses into HR (Employees) - Cleanup + +-- 1. Drop dependent tables that reference doctors +DROP TABLE IF EXISTS doctor_schedules; + +-- 2. Fix Visits Nurse ID +-- Add temp column if it doesn't exist (it wasn't added in previous migration) +ALTER TABLE visits ADD COLUMN IF NOT EXISTS nurse_employee_id INT NULL; + +-- Migrate data from nurses table to visits.nurse_employee_id +UPDATE visits v +JOIN nurses n ON v.nurse_id = n.id +SET v.nurse_employee_id = n.employee_id +WHERE n.employee_id IS NOT NULL; + +-- Drop old FK on visits.nurse_id +ALTER TABLE visits DROP FOREIGN KEY IF EXISTS fk_visit_nurse; + +-- Drop old column visits.nurse_id +-- We use a check to avoid error if it was already dropped (though unlikely) +ALTER TABLE visits DROP COLUMN nurse_id; + +-- Rename new column to nurse_id +ALTER TABLE visits CHANGE COLUMN nurse_employee_id nurse_id INT NULL; + +-- Add new FK to employees +ALTER TABLE visits ADD CONSTRAINT fk_visit_nurse_employee FOREIGN KEY (nurse_id) REFERENCES employees(id) ON DELETE SET NULL; + + +-- 3. Fix Appointments Nurse ID +-- Ensure nurse_employee_id exists (might have been created in previous migration) +ALTER TABLE appointments ADD COLUMN IF NOT EXISTS nurse_employee_id INT NULL; + +-- Migrate data again just in case +UPDATE appointments a +JOIN nurses n ON a.nurse_id = n.id +SET a.nurse_employee_id = n.employee_id +WHERE n.employee_id IS NOT NULL; + +-- Drop old FK on appointments.nurse_id +ALTER TABLE appointments DROP FOREIGN KEY IF EXISTS fk_appointment_nurse; + +-- Drop old column appointments.nurse_id +ALTER TABLE appointments DROP COLUMN nurse_id; + +-- Rename new column to nurse_id +ALTER TABLE appointments CHANGE COLUMN nurse_employee_id nurse_id INT NULL; + +-- Add new FK to employees +ALTER TABLE appointments ADD CONSTRAINT fk_appt_nurse_employee FOREIGN KEY (nurse_id) REFERENCES employees(id) ON DELETE SET NULL; + + +-- 4. Drop obsolete tables +-- Now that FKs are gone, this should succeed. +DROP TABLE IF EXISTS doctors; +DROP TABLE IF EXISTS nurses; diff --git a/doctor_holidays.php b/doctor_holidays.php deleted file mode 100644 index 89e814b..0000000 --- a/doctor_holidays.php +++ /dev/null @@ -1,4 +0,0 @@ - +getMessage()); +} catch (Exception $e) { + die("General Error: " . $e->getMessage()); +} + +require_once __DIR__ . '/helpers.php'; +require_once __DIR__ . '/includes/auth.php'; +check_auth(); + +$lang = $_SESSION['lang']; + +require_once __DIR__ . '/includes/actions.php'; +require_once __DIR__ . '/includes/common_data.php'; + +require_once __DIR__ . '/includes/layout/header.php'; + +require_once __DIR__ . '/includes/pages/hr_attendance.php'; + +require_once __DIR__ . '/includes/layout/footer.php'; \ No newline at end of file diff --git a/hr_dashboard.php b/hr_dashboard.php index aa85990..275cb87 100644 --- a/hr_dashboard.php +++ b/hr_dashboard.php @@ -1,8 +1,32 @@ getMessage()); +} catch (Exception $e) { + die("General Error: " . $e->getMessage()); +} + +require_once __DIR__ . '/helpers.php'; +require_once __DIR__ . '/includes/auth.php'; +check_auth(); + +$lang = $_SESSION['lang']; + +require_once __DIR__ . '/includes/actions.php'; +require_once __DIR__ . '/includes/common_data.php'; + +require_once __DIR__ . '/includes/layout/header.php'; + +require_once __DIR__ . '/includes/pages/hr_dashboard.php'; + +require_once __DIR__ . '/includes/layout/footer.php'; \ No newline at end of file diff --git a/hr_leaves.php b/hr_leaves.php index b58b119..8c2a542 100644 --- a/hr_leaves.php +++ b/hr_leaves.php @@ -1 +1,32 @@ - +getMessage()); +} catch (Exception $e) { + die("General Error: " . $e->getMessage()); +} + +require_once __DIR__ . '/helpers.php'; +require_once __DIR__ . '/includes/auth.php'; +check_auth(); + +$lang = $_SESSION['lang']; + +require_once __DIR__ . '/includes/actions.php'; +require_once __DIR__ . '/includes/common_data.php'; + +require_once __DIR__ . '/includes/layout/header.php'; + +require_once __DIR__ . '/includes/pages/hr_leaves.php'; + +require_once __DIR__ . '/includes/layout/footer.php'; \ No newline at end of file diff --git a/includes/actions.php b/includes/actions.php index 48f9ac9..5e7f9c4 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -146,80 +146,6 @@ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') $_SESSION['flash_message'] = __('delete') . ' ' . __('successfully'); $redirect = true; } - } elseif ($_POST['action'] === 'add_doctor') { - $name_en = $_POST['name_en'] ?? ''; - $name_ar = $_POST['name_ar'] ?? ''; - $tel = $_POST['tel'] ?? ''; - $email = $_POST['email'] ?? ''; - $spec_en = $_POST['specialization_en'] ?? ''; - $spec_ar = $_POST['specialization_ar'] ?? ''; - $dept_id = $_POST['department_id'] ?: null; - - if ($name_en && $name_ar) { - $stmt = $db->prepare("INSERT INTO doctors (name_en, name_ar, tel, email, specialization_en, specialization_ar, department_id) VALUES (?, ?, ?, ?, ?, ?, ?)"); - $stmt->execute([$name_en, $name_ar, $tel, $email, $spec_en, $spec_ar, $dept_id]); - $_SESSION['flash_message'] = __('add_doctor') . ' ' . __('successfully'); - $redirect = true; - } - } elseif ($_POST['action'] === 'edit_doctor') { - $id = $_POST['id'] ?? ''; - $name_en = $_POST['name_en'] ?? ''; - $name_ar = $_POST['name_ar'] ?? ''; - $tel = $_POST['tel'] ?? ''; - $email = $_POST['email'] ?? ''; - $spec_en = $_POST['specialization_en'] ?? ''; - $spec_ar = $_POST['specialization_ar'] ?? ''; - $dept_id = $_POST['department_id'] ?: null; - - if ($id && $name_en && $name_ar) { - $stmt = $db->prepare("UPDATE doctors SET name_en = ?, name_ar = ?, tel = ?, email = ?, specialization_en = ?, specialization_ar = ?, department_id = ? WHERE id = ?"); - $stmt->execute([$name_en, $name_ar, $tel, $email, $spec_en, $spec_ar, $dept_id, $id]); - $_SESSION['flash_message'] = __('edit_doctor') . ' ' . __('successfully'); - $redirect = true; - } - } elseif ($_POST['action'] === 'delete_doctor') { - $id = $_POST['id'] ?? ''; - if ($id) { - $stmt = $db->prepare("DELETE FROM doctors WHERE id = ?"); - $stmt->execute([$id]); - $_SESSION['flash_message'] = __('delete') . ' ' . __('successfully'); - $redirect = true; - } - } elseif ($_POST['action'] === 'add_nurse') { - $name_en = $_POST['name_en'] ?? ''; - $name_ar = $_POST['name_ar'] ?? ''; - $tel = $_POST['tel'] ?? ''; - $email = $_POST['email'] ?? ''; - $dept_id = $_POST['department_id'] ?: null; - - if ($name_en && $name_ar) { - $stmt = $db->prepare("INSERT INTO nurses (name_en, name_ar, tel, email, department_id) VALUES (?, ?, ?, ?, ?)"); - $stmt->execute([$name_en, $name_ar, $tel, $email, $dept_id]); - $_SESSION['flash_message'] = __('add_nurse') . ' ' . __('successfully'); - $redirect = true; - } - } elseif ($_POST['action'] === 'edit_nurse') { - $id = $_POST['id'] ?? ''; - $name_en = $_POST['name_en'] ?? ''; - $name_ar = $_POST['name_ar'] ?? ''; - $tel = $_POST['tel'] ?? ''; - $email = $_POST['email'] ?? ''; - $dept_id = $_POST['department_id'] ?: null; - - if ($id && $name_en && $name_ar) { - $stmt = $db->prepare("UPDATE nurses SET name_en = ?, name_ar = ?, tel = ?, email = ?, department_id = ? WHERE id = ?"); - $stmt->execute([$name_en, $name_ar, $tel, $email, $dept_id, $id]); - $_SESSION['flash_message'] = __('edit_nurse') . ' ' . __('successfully'); - $redirect = true; - } - } elseif ($_POST['action'] === 'delete_nurse') { - $id = $_POST['id'] ?? ''; - if ($id) { - $stmt = $db->prepare("DELETE FROM nurses WHERE id = ?"); - $stmt->execute([$id]); - $_SESSION['flash_message'] = __('delete') . ' ' . __('successfully'); - $redirect = true; - } } elseif ($_POST['action'] === 'add_department') { $name_en = $_POST['name_en'] ?? ''; $name_ar = $_POST['name_ar'] ?? ''; @@ -322,7 +248,8 @@ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') // Token Generation (Only for Doctor visits in Clinic usually) if (isset($_POST['generate_token']) && $_POST['generate_token'] == '1' && $doctor_id) { - $stmtDoc = $db->prepare("SELECT department_id FROM doctors WHERE id = ?"); + // Updated to query employees table + $stmtDoc = $db->prepare("SELECT department_id FROM employees WHERE id = ?"); $stmtDoc->execute([$doctor_id]); $docData = $stmtDoc->fetch(); $dept_id = $docData ? $docData['department_id'] : null; diff --git a/includes/auth.php b/includes/auth.php index 1930cbc..d995cf2 100644 --- a/includes/auth.php +++ b/includes/auth.php @@ -83,4 +83,8 @@ function require_permission($permission) { http_response_code(403); die("Access Denied: You do not have the required permission: " . htmlspecialchars($permission)); } -} \ No newline at end of file +} + +function is_admin() { + return has_role('admin'); +} diff --git a/includes/common_data.php b/includes/common_data.php index 95f4ee7..fb13387 100644 --- a/includes/common_data.php +++ b/includes/common_data.php @@ -1,8 +1,20 @@ query("SELECT id, name_$lang as name FROM doctors")->fetchAll(); -$all_patients = $db->query("SELECT id, name, phone, civil_id, dob, gender FROM patients")->fetchAll(); -$all_nurses = $db->query("SELECT id, name_$lang as name FROM nurses")->fetchAll(); +$all_doctors = $db->query(" + SELECT e.id, e.name_$lang as name + FROM employees e + JOIN positions p ON e.position_id = p.id + WHERE UPPER(p.name_en) = 'DOCTOR' +")->fetchAll(); + +$all_nurses = $db->query(" + SELECT e.id, e.name_$lang as name + FROM employees e + JOIN positions p ON e.position_id = p.id + WHERE UPPER(p.name_en) = 'NURSE' +")->fetchAll(); + +$all_patients = $db->query("SELECT id, name, phone, civil_id, dob, gender, address FROM patients")->fetchAll(); $all_departments = $db->query("SELECT id, name_$lang as name FROM departments")->fetchAll(); $all_employees = $db->query("SELECT id, name_$lang as name FROM employees")->fetchAll(); $all_positions = $db->query("SELECT id, name_$lang as name FROM positions")->fetchAll(); @@ -19,12 +31,14 @@ $all_xrays = $db->query("SELECT id, name_$lang as name, price FROM xray_tests")- $all_drugs = $db->query("SELECT id, name_$lang as name, default_dosage, default_instructions, price FROM drugs")->fetchAll(); $scheduled_appointments = $db->query(" - SELECT a.id, p.name as patient_name, a.start_time, a.patient_id, a.doctor_id + SELECT a.id, p.name as patient_name, a.start_time, a.patient_id, a.doctor_id, + e.name_$lang as doctor_name FROM appointments a JOIN patients p ON a.patient_id = p.id + LEFT JOIN employees e ON a.doctor_id = e.id WHERE a.status = 'Scheduled' ORDER BY a.start_time ASC")->fetchAll(); $all_countries = require __DIR__ . "/countries.php"; -$all_cities = $db->query("SELECT id, name_$lang as name FROM cities")->fetchAll(); +$all_cities = $db->query("SELECT id, name_$lang as name FROM cities")->fetchAll(); \ No newline at end of file diff --git a/includes/layout/footer.php b/includes/layout/footer.php index 80f9a18..c80cd48 100644 --- a/includes/layout/footer.php +++ b/includes/layout/footer.php @@ -327,6 +327,15 @@ +