<?php
// Common data for selects
$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();
$all_insurance = $db->query("SELECT id, name_$lang as name FROM insurance_companies")->fetchAll();
$all_test_groups = $db->query("SELECT id, name_$lang as name FROM test_groups")->fetchAll();
$all_tests = $db->query("SELECT id, name_$lang as name, price, normal_range FROM laboratory_tests")->fetchAll();
$all_services = $db->query("SELECT id, name_$lang as name, price FROM services WHERE is_active = 1")->fetchAll();

// X-Ray Data
$all_xray_groups = $db->query("SELECT id, name_$lang as name FROM xray_groups")->fetchAll();
$all_xrays = $db->query("SELECT id, name_$lang as name, price FROM xray_tests")->fetchAll();

// Drugs Data
$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,
           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();