Autosave: 20260304-044254

This commit is contained in:
Flatlogic Bot 2026-03-04 04:42:54 +00:00
parent aa6a7b2ed1
commit 85f641cde7
17 changed files with 1025 additions and 940 deletions

13
billing.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$section = 'billing';
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/helpers.php';
$db = db();
$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/billing.php';
require_once __DIR__ . '/includes/layout/footer.php';

13
dashboard.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$section = 'dashboard';
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/helpers.php';
$db = db();
$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/dashboard.php';
require_once __DIR__ . '/includes/layout/footer.php';

View File

@ -36,3 +36,14 @@ function get_lang_name() {
function get_lang_code() {
return $_SESSION['lang'] === 'ar' ? 'en' : 'ar';
}
function calculate_age($dob) {
if (empty($dob)) return '-';
try {
$birthDate = new DateTime($dob);
$today = new DateTime('today');
return $birthDate->diff($today)->y;
} catch (Exception $e) {
return '-';
}
}

117
includes/actions.php Normal file
View File

@ -0,0 +1,117 @@
<?php
// includes/actions.php
$message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action'])) {
if ($_POST['action'] === 'add_patient') {
$name = $_POST['name'] ?? '';
$phone = $_POST['phone'] ?? '';
$dob = $_POST['dob'] ?? '';
$gender = $_POST['gender'] ?? '';
$blood_group = $_POST['blood_group'] ?? '';
$address = $_POST['address'] ?? '';
$insurance_company_id = $_POST['insurance_company_id'] ?: null;
$policy_number = $_POST['policy_number'] ?? '';
if ($name && $phone) {
$stmt = $db->prepare("INSERT INTO patients (name, phone, dob, gender, blood_group, address, insurance_company_id, policy_number) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $phone, $dob, $gender, $blood_group, $address, $insurance_company_id, $policy_number]);
$message = __('add_patient') . ' ' . __('successfully');
}
} elseif ($_POST['action'] === 'add_insurance') {
$name_en = $_POST['name_en'] ?? '';
$name_ar = $_POST['name_ar'] ?? '';
$email = $_POST['email'] ?? '';
$phone = $_POST['phone'] ?? '';
$contact = $_POST['contact_info'] ?? '';
if ($name_en && $name_ar) {
$stmt = $db->prepare("INSERT INTO insurance_companies (name_en, name_ar, email, phone, contact_info) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name_en, $name_ar, $email, $phone, $contact]);
$message = __('insurance_company') . ' ' . __('successfully');
}
} elseif ($_POST['action'] === 'book_appointment') {
$patient_id = $_POST['patient_id'] ?? '';
$doctor_id = $_POST['doctor_id'] ?? '';
$date = $_POST['date'] ?? '';
$reason = $_POST['reason'] ?? '';
if ($patient_id && $doctor_id && $date) {
$stmt = $db->prepare("INSERT INTO appointments (patient_id, doctor_id, appointment_date, reason) VALUES (?, ?, ?, ?)");
$stmt->execute([$patient_id, $doctor_id, $date, $reason]);
$message = __('book_appointment') . ' ' . __('successfully');
}
} elseif ($_POST['action'] === 'record_visit') {
$patient_id = $_POST['patient_id'] ?? '';
$doctor_id = $_POST['doctor_id'] ?? '';
$appointment_id = $_POST['appointment_id'] ?: null;
$weight = $_POST['weight'] ?? '';
$bp = $_POST['blood_pressure'] ?? '';
$hr = $_POST['heart_rate'] ?? '';
$temp = $_POST['temperature'] ?? '';
$symptoms = $_POST['symptoms'] ?? '';
$diagnosis = $_POST['diagnosis'] ?? '';
$treatment = $_POST['treatment_plan'] ?? '';
if ($patient_id && $doctor_id) {
$stmt = $db->prepare("INSERT INTO visits (patient_id, doctor_id, appointment_id, weight, blood_pressure, heart_rate, temperature, symptoms, diagnosis, treatment_plan) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$patient_id, $doctor_id, $appointment_id, $weight, $bp, $hr, $temp, $symptoms, $diagnosis, $treatment]);
if ($appointment_id) {
$db->prepare("UPDATE appointments SET status = 'Completed' WHERE id = ?")->execute([$appointment_id]);
}
$message = __('visit_recorded');
}
} elseif ($_POST['action'] === 'create_report') {
$visit_id = $_POST['visit_id'] ?? '';
$type = $_POST['report_type'] ?? '';
$findings = $_POST['findings'] ?? '';
$recommendations = $_POST['recommendations'] ?? '';
if ($visit_id && $type) {
$stmt = $db->prepare("INSERT INTO provisional_reports (visit_id, report_type, findings, recommendations) VALUES (?, ?, ?, ?)");
$stmt->execute([$visit_id, $type, $findings, $recommendations]);
$message = __('report_created');
}
} elseif ($_POST['action'] === 'create_bill') {
$patient_id = $_POST['patient_id'] ?? '';
$visit_id = $_POST['visit_id'] ?: null;
$items = $_POST['items'] ?? [];
$amounts = $_POST['amounts'] ?? [];
if ($patient_id && !empty($items)) {
$total = array_sum($amounts);
// Check if patient has insurance
$patient = $db->prepare("SELECT insurance_company_id FROM patients WHERE id = ?");
$patient->execute([$patient_id]);
$p_data = $patient->fetch();
$insurance_covered = 0;
if ($p_data && $p_data['insurance_company_id']) {
// Simple logic: insurance covers 80% if they have insurance
$insurance_covered = $total * 0.8;
}
$patient_payable = $total - $insurance_covered;
$stmt = $db->prepare("INSERT INTO bills (patient_id, visit_id, total_amount, insurance_covered, patient_payable, status) VALUES (?, ?, ?, ?, ?, 'Pending')");
$stmt->execute([$patient_id, $visit_id, $total, $insurance_covered, $patient_payable]);
$bill_id = $db->lastInsertId();
$item_stmt = $db->prepare("INSERT INTO bill_items (bill_id, description, amount) VALUES (?, ?, ?)");
foreach ($items as $index => $desc) {
if ($desc && isset($amounts[$index])) {
$item_stmt->execute([$bill_id, $desc, $amounts[$index]]);
}
}
$message = __('bill_created');
}
} elseif ($_POST['action'] === 'mark_paid') {
$bill_id = $_POST['bill_id'] ?? '';
if ($bill_id) {
$db->prepare("UPDATE bills SET status = 'Paid' WHERE id = ?")->execute([$bill_id]);
$message = __('bill_paid');
}
}
}
}

11
includes/common_data.php Normal file
View File

@ -0,0 +1,11 @@
<?php
// Common data for selects
$all_doctors = $db->query("SELECT id, name_$lang as name FROM doctors")->fetchAll();
$all_patients = $db->query("SELECT id, name FROM patients")->fetchAll();
$all_insurance = $db->query("SELECT id, name_$lang as name FROM insurance_companies")->fetchAll();
$scheduled_appointments = $db->query("
SELECT a.id, p.name as patient_name, a.appointment_date, a.patient_id, a.doctor_id
FROM appointments a
JOIN patients p ON a.patient_id = p.id
WHERE a.status = 'Scheduled'
ORDER BY a.appointment_date ASC")->fetchAll();

368
includes/layout/footer.php Normal file
View File

@ -0,0 +1,368 @@
<?php
// includes/layout/footer.php
?>
</div>
</div>
<!-- Add Patient Modal -->
<div class="modal fade" id="addPatientModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_patient">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('add_patient'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?></label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="phone" class="form-control" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="date" name="dob" class="form-control">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('gender'); ?></label>
<select name="gender" class="form-select">
<option value="Male"><?php echo __('male'); ?></option>
<option value="Female"><?php echo __('female'); ?></option>
<option value="Other"><?php echo __('other'); ?></option>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('blood_group'); ?></label>
<input type="text" name="blood_group" class="form-control" placeholder="O+, A-, etc.">
</div>
</div>
<hr>
<h6 class="fw-bold mb-3"><?php echo __('insurance'); ?> (<?php echo __('optional'); ?>)</h6>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('insurance_company'); ?></label>
<select name="insurance_company_id" class="form-select">
<option value=""><?php echo __('not_insured'); ?></option>
<?php foreach ($all_insurance as $i): ?>
<option value="<?php echo $i['id']; ?>"><?php echo htmlspecialchars($i['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('policy_number'); ?></label>
<input type="text" name="policy_number" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('address'); ?></label>
<textarea name="address" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Insurance Modal -->
<div class="modal fade" id="addInsuranceModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=insurance" method="POST">
<input type="hidden" name="action" value="add_insurance">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('add_insurance'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?> (EN)</label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?> (AR)</label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('email'); ?></label>
<input type="email" name="email" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="phone" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('contact_info'); ?></label>
<textarea name="contact_info" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Book Appointment Modal -->
<div class="modal fade" id="bookAppointmentModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="book_appointment">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('book_appointment'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('patient'); ?></label>
<select name="patient_id" class="form-select" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_patients as $p): ?>
<option value="<?php echo $p['id']; ?>"><?php echo htmlspecialchars($p['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('doctor'); ?></label>
<select name="doctor_id" class="form-select" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_doctors as $d): ?>
<option value="<?php echo $d['id']; ?>"><?php echo htmlspecialchars($d['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('date'); ?></label>
<input type="datetime-local" name="date" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('reason'); ?></label>
<textarea name="reason" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-success px-4"><?php echo __('book_appointment'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Record Visit Modal -->
<div class="modal fade" id="recordVisitModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="record_visit">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('add_visit'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12 mb-3">
<label class="form-label"><?php echo __('appointment'); ?> (<?php echo __('optional'); ?>)</label>
<select name="appointment_id" class="form-select" id="visit_appointment_select" onchange="updateVisitFields()">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($scheduled_appointments as $sa): ?>
<option value="<?php echo $sa['id']; ?>" data-patient="<?php echo $sa['patient_id']; ?>" data-doctor="<?php echo $sa['doctor_id']; ?>">
<?php echo htmlspecialchars($sa['patient_name']); ?> - <?php echo $sa['appointment_date']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('patient'); ?></label>
<select name="patient_id" id="visit_patient_id" class="form-select" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_patients as $p): ?>
<option value="<?php echo $p['id']; ?>"><?php echo htmlspecialchars($p['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('doctor'); ?></label>
<select name="doctor_id" id="visit_doctor_id" class="form-select" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_doctors as $d): ?>
<option value="<?php echo $d['id']; ?>"><?php echo htmlspecialchars($d['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<hr>
<h6 class="fw-bold mb-3"><?php echo __('vitals'); ?></h6>
<div class="row">
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('weight'); ?></label>
<input type="text" name="weight" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('blood_pressure'); ?></label>
<input type="text" name="blood_pressure" class="form-control" placeholder="120/80">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('heart_rate'); ?></label>
<input type="text" name="heart_rate" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('temperature'); ?></label>
<input type="text" name="temperature" class="form-control">
</div>
</div>
<hr>
<div class="mb-3">
<label class="form-label"><?php echo __('symptoms'); ?></label>
<textarea name="symptoms" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('diagnosis'); ?></label>
<textarea name="diagnosis" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('treatment_plan'); ?></label>
<textarea name="treatment_plan" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-info text-white px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Create Bill Modal -->
<div class="modal fade" id="createBillModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=billing" method="POST">
<input type="hidden" name="action" value="create_bill">
<input type="hidden" name="visit_id" id="bill_visit_id">
<input type="hidden" name="patient_id" id="bill_patient_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('create_bill'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p class="mb-3"><?php echo __('patient'); ?>: <strong id="bill_patient_name"></strong></p>
<div class="alert alert-info py-2 small">
<i class="bi bi-info-circle me-1"></i> If patient has insurance, 80% coverage will be applied automatically.
</div>
<div id="bill_items_container">
<div class="row g-2 mb-2 align-items-end item-row">
<div class="col-8">
<label class="form-label small mb-1"><?php echo __('description'); ?></label>
<input type="text" name="items[]" class="form-control" required value="<?php echo __('consultation_fee'); ?>">
</div>
<div class="col-4">
<label class="form-label small mb-1"><?php echo __('amount'); ?></label>
<input type="number" step="0.01" name="amounts[]" class="form-control" required placeholder="0.00">
</div>
</div>
</div>
<button type="button" class="btn btn-link btn-sm p-0 mt-2" onclick="addBillItem()">+ <?php echo __('add_item'); ?></button>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-success px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Provisional Report Modal -->
<div class="modal fade" id="reportModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="create_report">
<input type="hidden" name="visit_id" id="report_visit_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('new_report'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('report_type'); ?></label>
<input type="text" name="report_type" class="form-control" required placeholder="General, Lab, X-Ray, etc.">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('findings'); ?></label>
<textarea name="findings" class="form-control" rows="3"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('recommendations'); ?></label>
<textarea name="recommendations" class="form-control" rows="3"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Bootstrap 5 Bundle JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
function updateVisitFields() {
const select = document.getElementById('visit_appointment_select');
const option = select.options[select.selectedIndex];
if (option.value) {
document.getElementById('visit_patient_id').value = option.dataset.patient;
document.getElementById('visit_doctor_id').value = option.dataset.doctor;
}
}
function showReportModal(visitId) {
document.getElementById('report_visit_id').value = visitId;
new bootstrap.Modal(document.getElementById('reportModal')).show();
}
function showBillModal(visitId, patientId, patientName) {
document.getElementById('bill_visit_id').value = visitId;
document.getElementById('bill_patient_id').value = patientId;
document.getElementById('bill_patient_name').innerText = patientName;
new bootstrap.Modal(document.getElementById('createBillModal')).show();
}
function addBillItem() {
const container = document.getElementById('bill_items_container');
const row = document.createElement('div');
row.className = 'row g-2 mb-2 align-items-end item-row';
row.innerHTML = `
<div class="col-8">
<input type="text" name="items[]" class="form-control" required>
</div>
<div class="col-4">
<input type="number" step="0.01" name="amounts[]" class="form-control" required placeholder="0.00">
</div>
`;
container.appendChild(row);
}
</script>
</body>
</html>

100
includes/layout/header.php Normal file
View File

@ -0,0 +1,100 @@
<?php
require_once __DIR__ . '/../../db/config.php';
require_once __DIR__ . '/../../helpers.php';
$db = db();
$lang = $_SESSION['lang'];
$section = $section ?? 'dashboard';
$message = $message ?? '';
?>
<!DOCTYPE html>
<html lang="<?php echo $_SESSION['lang']; ?>" dir="<?php echo get_dir(); ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo __('hospital_management'); ?></title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<?php if (is_rtl()): ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css">
<?php endif; ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Tajawal:wght@400;500;700&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', 'Tajawal', sans-serif; background-color: #f4f7f6; }
.sidebar { min-height: 100vh; width: 250px; background-color: #002D62; color: white; transition: all 0.3s; }
.sidebar-link { color: #cfd8dc; text-decoration: none; padding: 12px 20px; display: block; border-left: 4px solid transparent; }
.sidebar-link:hover, .sidebar-link.active { background-color: #003a80; color: white; border-left-color: #4fc3f7; }
.main-content { flex: 1; padding: 25px; }
.card { border: none; border-radius: 8px; box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); margin-bottom: 20px; }
.stat-card { padding: 20px; text-align: center; }
.stat-card i { font-size: 2.5rem; color: #0056b3; margin-bottom: 10px; }
.btn-primary { background-color: #0056b3; border-color: #0056b3; }
.table thead th { background-color: #f8f9fa; border-bottom: 2px solid #dee2e6; color: #495057; font-weight: 600; }
.navbar { background-color: white; border-bottom: 1px solid #e0e0e0; }
.card-header, .modal-header { background-color: #002D62 !important; color: white !important; border-bottom: none; }
.card-header .fw-bold, .modal-title { color: white !important; }
.modal-header .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
.card-header i { color: white !important; }
<?php if (is_rtl()): ?>
.sidebar-link { border-left: 0; border-right: 4px solid transparent; }
.sidebar-link:hover, .sidebar-link.active { border-right-color: #4fc3f7; }
<?php endif; ?>
</style>
</head>
<body>
<div class="d-flex">
<!-- Sidebar -->
<div class="sidebar d-none d-md-block">
<div class="p-4 text-center">
<h5 class="fw-bold"><i class="bi bi-hospital"></i> <?php echo __('hospital_management'); ?></h5>
</div>
<nav class="mt-3">
<a href="dashboard.php" class="sidebar-link <?php echo $section === 'dashboard' ? 'active' : ''; ?>"><i class="bi bi-speedometer2 me-2"></i> <?php echo __('dashboard'); ?></a>
<a href="patients.php" class="sidebar-link <?php echo $section === 'patients' ? 'active' : ''; ?>"><i class="bi bi-people me-2"></i> <?php echo __('patients'); ?></a>
<a href="visits.php" class="sidebar-link <?php echo $section === 'visits' ? 'active' : ''; ?>"><i class="bi bi-clipboard2-pulse me-2"></i> <?php echo __('visits'); ?></a>
<a href="billing.php" class="sidebar-link <?php echo $section === 'billing' ? 'active' : ''; ?>"><i class="bi bi-receipt me-2"></i> <?php echo __('billing'); ?></a>
<a href="insurance.php" class="sidebar-link <?php echo $section === 'insurance' ? 'active' : ''; ?>"><i class="bi bi-shield-check me-2"></i> <?php echo __('insurance'); ?></a>
<a href="#" class="sidebar-link"><i class="bi bi-calendar-event me-2"></i> <?php echo __('appointments'); ?></a>
<a href="#" class="sidebar-link"><i class="bi bi-person-badge me-2"></i> <?php echo __('doctors'); ?></a>
<a href="#" class="sidebar-link"><i class="bi bi-diagram-3 me-2"></i> <?php echo __('departments'); ?></a>
</nav>
</div>
<!-- Main Content -->
<div class="main-content">
<!-- Top Navbar -->
<nav class="navbar navbar-expand-lg navbar-light mb-4 rounded shadow-sm px-3">
<div class="container-fluid p-0">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#topNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="topNav">
<div class="ms-auto d-flex align-items-center">
<a href="?lang=<?php echo get_lang_code(); ?>" class="btn btn-outline-secondary btn-sm me-3">
<i class="bi bi-translate"></i> <?php echo get_lang_name(); ?>
</a>
<div class="dropdown">
<a class="nav-link dropdown-toggle d-flex align-items-center" href="#" role="button" data-bs-toggle="dropdown">
<img src="https://ui-avatars.com/api/?name=Admin&background=0056b3&color=fff" class="rounded-circle me-2" width="32" height="32">
<span>Admin</span>
</a>
<ul class="dropdown-menu dropdown-menu-end shadow border-0">
<li><a class="dropdown-item" href="#"><i class="bi bi-person me-2"></i> <?php echo __('profile'); ?></a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item text-danger" href="#"><i class="bi bi-box-arrow-right me-2"></i> <?php echo __('logout'); ?></a></li>
</ul>
</div>
</div>
</div>
</div>
</nav>
<?php if ($message): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?php echo $message; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>

View File

@ -0,0 +1,61 @@
<?php
$bills_sql = "
SELECT b.*, p.name as patient_name
FROM bills b
JOIN patients p ON b.patient_id = p.id
ORDER BY b.created_at DESC";
$bills = $db->query($bills_sql)->fetchAll();
?>
<div class="card shadow-sm">
<div class="card-header py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><i class="bi bi-receipt me-2 text-primary"></i> <?php echo __('billing'); ?></h5>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>ID</th>
<th><?php echo __('date'); ?></th>
<th><?php echo __('patient'); ?></th>
<th><?php echo __('total'); ?></th>
<th><?php echo __('insurance_covered'); ?></th>
<th><?php echo __('patient_payable'); ?></th>
<th><?php echo __('status'); ?></th>
<th><?php echo __('actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($bills as $b): ?>
<tr>
<td>#<?php echo $b['id']; ?></td>
<td><?php echo date('Y-m-d H:i', strtotime($b['created_at'])); ?></td>
<td><?php echo htmlspecialchars($b['patient_name']); ?></td>
<td>$<?php echo number_format($b['total_amount'], 2); ?></td>
<td class="text-primary">$<?php echo number_format($b['insurance_covered'], 2); ?></td>
<td class="fw-bold">$<?php echo number_format($b['patient_payable'], 2); ?></td>
<td>
<span class="badge <?php echo $b['status'] === 'Paid' ? 'bg-success' : 'bg-warning'; ?>">
<?php echo __($b['status']); ?>
</span>
</td>
<td>
<?php if ($b['status'] === 'Pending'): ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=billing" method="POST" class="d-inline">
<input type="hidden" name="action" value="mark_paid">
<input type="hidden" name="bill_id" value="<?php echo $b['id']; ?>">
<button type="submit" class="btn btn-sm btn-success">
<i class="bi bi-check-circle"></i> <?php echo __('mark_as_paid'); ?>
</button>
</form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; if (empty($bills)): ?>
<tr><td colspan="8" class="text-center py-4 text-muted">No bills found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>

View File

@ -0,0 +1,146 @@
<?php
// Fetch Stats
$total_patients = $db->query("SELECT COUNT(*) FROM patients")->fetchColumn();
$today_appointments = $db->query("SELECT COUNT(*) FROM appointments WHERE DATE(appointment_date) = CURDATE()")->fetchColumn();
$total_visits = $db->query("SELECT COUNT(*) FROM visits")->fetchColumn();
$total_revenue = $db->query("SELECT SUM(total_amount) FROM bills WHERE status = 'Paid'")->fetchColumn() ?: 0;
$pending_revenue = $db->query("SELECT SUM(total_amount) FROM bills WHERE status = 'Pending'")->fetchColumn() ?: 0;
$patients_sql = "
SELECT p.*, ic.name_$lang as insurance_name
FROM patients p
LEFT JOIN insurance_companies ic ON p.insurance_company_id = ic.id
ORDER BY p.id DESC LIMIT 5";
$patients = $db->query($patients_sql)->fetchAll();
$appointments_sql = "
SELECT a.*, p.name as patient_name, d.name_$lang as doctor_name
FROM appointments a
JOIN patients p ON a.patient_id = p.id
JOIN doctors d ON a.doctor_id = d.id
ORDER BY a.appointment_date DESC
LIMIT 5";
$appointments = $db->query($appointments_sql)->fetchAll();
?>
<!-- Dashboard Stats -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card stat-card">
<i class="bi bi-people"></i>
<h3><?php echo $total_patients; ?></h3>
<p class="text-muted mb-0"><?php echo __('total_patients'); ?></p>
</div>
</div>
<div class="col-md-3">
<div class="card stat-card">
<i class="bi bi-calendar-check"></i>
<h3><?php echo $today_appointments; ?></h3>
<p class="text-muted mb-0"><?php echo __('today_appointments'); ?></p>
</div>
</div>
<div class="col-md-3">
<div class="card stat-card">
<i class="bi bi-currency-dollar text-success"></i>
<h3>$<?php echo number_format($total_revenue, 2); ?></h3>
<p class="text-muted mb-0"><?php echo __('revenue'); ?></p>
</div>
</div>
<div class="col-md-3">
<div class="card stat-card">
<i class="bi bi-hourglass-split text-warning"></i>
<h3>$<?php echo number_format($pending_revenue, 2); ?></h3>
<p class="text-muted mb-0"><?php echo __('pending'); ?></p>
</div>
</div>
</div>
<!-- Quick Actions -->
<div class="row mb-4">
<div class="col-12">
<div class="card p-3 d-flex flex-row justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><?php echo __('dashboard'); ?></h5>
<div>
<button class="btn btn-primary btn-sm me-2" data-bs-toggle="modal" data-bs-target="#addPatientModal">
<i class="bi bi-plus-lg"></i> <?php echo __('add_patient'); ?>
</button>
<button class="btn btn-success btn-sm me-2" data-bs-toggle="modal" data-bs-target="#bookAppointmentModal">
<i class="bi bi-calendar-plus"></i> <?php echo __('book_appointment'); ?>
</button>
<button class="btn btn-info btn-sm text-white" data-bs-toggle="modal" data-bs-target="#recordVisitModal">
<i class="bi bi-clipboard-plus"></i> <?php echo __('add_visit'); ?>
</button>
</div>
</div>
</div>
</div>
<!-- Tables Section -->
<div class="row">
<div class="col-lg-6">
<div class="card shadow-sm h-100">
<div class="card-header py-3">
<h6 class="mb-0 fw-bold"><i class="bi bi-people-fill me-2 text-primary"></i> <?php echo __('patients'); ?></h6>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th><?php echo __('name'); ?></th>
<th><?php echo __('age'); ?></th>
<th><?php echo __('phone'); ?></th>
<th><?php echo __('insurance'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($patients as $p): ?>
<tr>
<td><?php echo htmlspecialchars($p['name']); ?></td>
<td><?php echo calculate_age($p['dob']); ?></td>
<td><?php echo htmlspecialchars($p['phone']); ?></td>
<td><span class="badge <?php echo $p['insurance_name'] ? 'bg-primary' : 'bg-secondary'; ?>"><?php echo $p['insurance_name'] ?: __('not_insured'); ?></span></td>
</tr>
<?php endforeach; if (empty($patients)): ?>
<tr><td colspan="4" class="text-center py-4 text-muted">No patients found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="card shadow-sm h-100">
<div class="card-header py-3">
<h6 class="mb-0 fw-bold"><i class="bi bi-calendar-event-fill me-2 text-primary"></i> <?php echo __('appointments'); ?></h6>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th><?php echo __('patient'); ?></th>
<th><?php echo __('doctor'); ?></th>
<th><?php echo __('date'); ?></th>
<th><?php echo __('status'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($appointments as $a): ?>
<tr>
<td><?php echo htmlspecialchars($a['patient_name']); ?></td>
<td><?php echo htmlspecialchars($a['doctor_name']); ?></td>
<td><?php echo date('M d, H:i', strtotime($a['appointment_date'])); ?></td>
<td><span class="badge <?php echo $a['status'] === 'Completed' ? 'bg-success' : 'bg-secondary'; ?>"><?php echo __($a['status']); ?></span></td>
</tr>
<?php endforeach; if (empty($appointments)): ?>
<tr><td colspan="4" class="text-center py-4 text-muted">No appointments found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,41 @@
<?php
$insurance_companies = $db->query("SELECT * FROM insurance_companies ORDER BY id DESC")->fetchAll();
?>
<div class="card shadow-sm">
<div class="card-header py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><i class="bi bi-shield-check me-2 text-primary"></i> <?php echo __('insurance_companies'); ?></h5>
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addInsuranceModal">
<i class="bi bi-plus-lg"></i> <?php echo __('add_insurance'); ?>
</button>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>ID</th>
<th><?php echo __('name'); ?> (EN)</th>
<th><?php echo __('name'); ?> (AR)</th>
<th><?php echo __('email'); ?></th>
<th><?php echo __('phone'); ?></th>
<th><?php echo __('date'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($insurance_companies as $ic): ?>
<tr>
<td>#<?php echo $ic['id']; ?></td>
<td><?php echo htmlspecialchars($ic['name_en']); ?></td>
<td><?php echo htmlspecialchars($ic['name_ar']); ?></td>
<td><?php echo htmlspecialchars($ic['email'] ?: '-'); ?></td>
<td><?php echo htmlspecialchars($ic['phone'] ?: '-'); ?></td>
<td><?php echo date('Y-m-d', strtotime($ic['created_at'])); ?></td>
</tr>
<?php endforeach; if (empty($insurance_companies)): ?>
<tr><td colspan="6" class="text-center py-4 text-muted">No insurance companies found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>

View File

@ -0,0 +1,46 @@
<?php
$patients_sql = "
SELECT p.*, ic.name_$lang as insurance_name
FROM patients p
LEFT JOIN insurance_companies ic ON p.insurance_company_id = ic.id
ORDER BY p.id DESC";
$patients = $db->query($patients_sql)->fetchAll();
?>
<div class="card shadow-sm">
<div class="card-header py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><i class="bi bi-people-fill me-2 text-primary"></i> <?php echo __('patients'); ?></h5>
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addPatientModal">
<i class="bi bi-plus-lg"></i> <?php echo __('add_patient'); ?>
</button>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th><?php echo __('name'); ?></th>
<th><?php echo __('age'); ?></th>
<th><?php echo __('phone'); ?></th>
<th><?php echo __('dob'); ?></th>
<th><?php echo __('insurance'); ?></th>
<th><?php echo __('policy_number'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($patients as $p): ?>
<tr>
<td><?php echo htmlspecialchars($p['name']); ?></td>
<td><?php echo calculate_age($p['dob']); ?></td>
<td><?php echo htmlspecialchars($p['phone']); ?></td>
<td><?php echo $p['dob']; ?></td>
<td><span class="badge <?php echo $p['insurance_name'] ? 'bg-primary' : 'bg-secondary'; ?>"><?php echo $p['insurance_name'] ?: __('not_insured'); ?></span></td>
<td><?php echo htmlspecialchars($p['policy_number'] ?: '-'); ?></td>
</tr>
<?php endforeach; if (empty($patients)): ?>
<tr><td colspan="6" class="text-center py-4 text-muted">No patients found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>

54
includes/pages/visits.php Normal file
View File

@ -0,0 +1,54 @@
<?php
$visits_sql = "
SELECT v.*, p.name as patient_name, d.name_$lang as doctor_name
FROM visits v
JOIN patients p ON v.patient_id = p.id
JOIN doctors d ON v.doctor_id = d.id
ORDER BY v.visit_date DESC";
$visits = $db->query($visits_sql)->fetchAll();
?>
<div class="card shadow-sm">
<div class="card-header py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><i class="bi bi-clipboard2-pulse me-2 text-primary"></i> <?php echo __('visits'); ?></h5>
<button class="btn btn-info btn-sm text-white" data-bs-toggle="modal" data-bs-target="#recordVisitModal">
<i class="bi bi-plus-lg"></i> <?php echo __('add_visit'); ?>
</button>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th><?php echo __('date'); ?></th>
<th><?php echo __('patient'); ?></th>
<th><?php echo __('doctor'); ?></th>
<th><?php echo __('diagnosis'); ?></th>
<th><?php echo __('actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($visits as $v): ?>
<tr>
<td><?php echo date('Y-m-d H:i', strtotime($v['visit_date'])); ?></td>
<td><?php echo htmlspecialchars($v['patient_name']); ?></td>
<td><?php echo htmlspecialchars($v['doctor_name']); ?></td>
<td><small class="text-truncate d-inline-block" style="max-width: 200px;"><?php echo htmlspecialchars($v['diagnosis']); ?></small></td>
<td>
<div class="btn-group">
<button class="btn btn-outline-primary btn-sm" onclick='showReportModal(<?php echo $v["id"]; ?>)'>
<i class="bi bi-file-earmark-plus"></i> <?php echo __('new_report'); ?>
</button>
<button class="btn btn-outline-success btn-sm" onclick='showBillModal(<?php echo $v["id"]; ?>, <?php echo $v["patient_id"]; ?>, "<?php echo addslashes($v["patient_name"]); ?>")'>
<i class="bi bi-receipt"></i> <?php echo __('create_bill'); ?>
</button>
</div>
</td>
</tr>
<?php endforeach; if (empty($visits)): ?>
<tr><td colspan="5" class="text-center py-4 text-muted">No visits recorded yet.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>

941
index.php
View File

@ -1,940 +1,3 @@
<?php
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/helpers.php';
$db = db();
$lang = $_SESSION['lang'];
$section = $_GET['section'] ?? 'dashboard';
// Handle form submissions
$message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action'])) {
if ($_POST['action'] === 'add_patient') {
$name = $_POST['name'] ?? '';
$phone = $_POST['phone'] ?? '';
$dob = $_POST['dob'] ?? '';
$gender = $_POST['gender'] ?? '';
$blood_group = $_POST['blood_group'] ?? '';
$address = $_POST['address'] ?? '';
$insurance_company_id = $_POST['insurance_company_id'] ?: null;
$policy_number = $_POST['policy_number'] ?? '';
if ($name && $phone) {
$stmt = $db->prepare("INSERT INTO patients (name, phone, dob, gender, blood_group, address, insurance_company_id, policy_number) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $phone, $dob, $gender, $blood_group, $address, $insurance_company_id, $policy_number]);
$message = __('add_patient') . ' ' . __('successfully');
}
} elseif ($_POST['action'] === 'add_insurance') {
$name_en = $_POST['name_en'] ?? '';
$name_ar = $_POST['name_ar'] ?? '';
$email = $_POST['email'] ?? '';
$phone = $_POST['phone'] ?? '';
$contact = $_POST['contact_info'] ?? '';
if ($name_en && $name_ar) {
$stmt = $db->prepare("INSERT INTO insurance_companies (name_en, name_ar, email, phone, contact_info) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name_en, $name_ar, $email, $phone, $contact]);
$message = __('insurance_company') . ' ' . __('successfully');
}
} elseif ($_POST['action'] === 'book_appointment') {
$patient_id = $_POST['patient_id'] ?? '';
$doctor_id = $_POST['doctor_id'] ?? '';
$date = $_POST['date'] ?? '';
$reason = $_POST['reason'] ?? '';
if ($patient_id && $doctor_id && $date) {
$stmt = $db->prepare("INSERT INTO appointments (patient_id, doctor_id, appointment_date, reason) VALUES (?, ?, ?, ?)");
$stmt->execute([$patient_id, $doctor_id, $date, $reason]);
$message = __('book_appointment') . ' ' . __('successfully');
}
} elseif ($_POST['action'] === 'record_visit') {
$patient_id = $_POST['patient_id'] ?? '';
$doctor_id = $_POST['doctor_id'] ?? '';
$appointment_id = $_POST['appointment_id'] ?: null;
$weight = $_POST['weight'] ?? '';
$bp = $_POST['blood_pressure'] ?? '';
$hr = $_POST['heart_rate'] ?? '';
$temp = $_POST['temperature'] ?? '';
$symptoms = $_POST['symptoms'] ?? '';
$diagnosis = $_POST['diagnosis'] ?? '';
$treatment = $_POST['treatment_plan'] ?? '';
if ($patient_id && $doctor_id) {
$stmt = $db->prepare("INSERT INTO visits (patient_id, doctor_id, appointment_id, weight, blood_pressure, heart_rate, temperature, symptoms, diagnosis, treatment_plan) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$patient_id, $doctor_id, $appointment_id, $weight, $bp, $hr, $temp, $symptoms, $diagnosis, $treatment]);
if ($appointment_id) {
$db->prepare("UPDATE appointments SET status = 'Completed' WHERE id = ?")->execute([$appointment_id]);
}
$message = __('visit_recorded');
}
} elseif ($_POST['action'] === 'create_report') {
$visit_id = $_POST['visit_id'] ?? '';
$type = $_POST['report_type'] ?? '';
$findings = $_POST['findings'] ?? '';
$recommendations = $_POST['recommendations'] ?? '';
if ($visit_id && $type) {
$stmt = $db->prepare("INSERT INTO provisional_reports (visit_id, report_type, findings, recommendations) VALUES (?, ?, ?, ?)");
$stmt->execute([$visit_id, $type, $findings, $recommendations]);
$message = __('report_created');
}
} elseif ($_POST['action'] === 'create_bill') {
$patient_id = $_POST['patient_id'] ?? '';
$visit_id = $_POST['visit_id'] ?: null;
$items = $_POST['items'] ?? [];
$amounts = $_POST['amounts'] ?? [];
if ($patient_id && !empty($items)) {
$total = array_sum($amounts);
// Check if patient has insurance
$patient = $db->prepare("SELECT insurance_company_id FROM patients WHERE id = ?");
$patient->execute([$patient_id]);
$p_data = $patient->fetch();
$insurance_covered = 0;
if ($p_data && $p_data['insurance_company_id']) {
// Simple logic: insurance covers 80% if they have insurance
$insurance_covered = $total * 0.8;
}
$patient_payable = $total - $insurance_covered;
$stmt = $db->prepare("INSERT INTO bills (patient_id, visit_id, total_amount, insurance_covered, patient_payable, status) VALUES (?, ?, ?, ?, ?, 'Pending')");
$stmt->execute([$patient_id, $visit_id, $total, $insurance_covered, $patient_payable]);
$bill_id = $db->lastInsertId();
$item_stmt = $db->prepare("INSERT INTO bill_items (bill_id, description, amount) VALUES (?, ?, ?)");
foreach ($items as $index => $desc) {
if ($desc && isset($amounts[$index])) {
$item_stmt->execute([$bill_id, $desc, $amounts[$index]]);
}
}
$message = __('bill_created');
}
} elseif ($_POST['action'] === 'mark_paid') {
$bill_id = $_POST['bill_id'] ?? '';
if ($bill_id) {
$db->prepare("UPDATE bills SET status = 'Paid' WHERE id = ?")->execute([$bill_id]);
$message = __('bill_paid');
}
}
}
}
// Fetch Stats
$total_patients = $db->query("SELECT COUNT(*) FROM patients")->fetchColumn();
$today_appointments = $db->query("SELECT COUNT(*) FROM appointments WHERE DATE(appointment_date) = CURDATE()")->fetchColumn();
$total_visits = $db->query("SELECT COUNT(*) FROM visits")->fetchColumn();
$total_revenue = $db->query("SELECT SUM(total_amount) FROM bills WHERE status = 'Paid'")->fetchColumn() ?: 0;
$pending_revenue = $db->query("SELECT SUM(total_amount) FROM bills WHERE status = 'Pending'")->fetchColumn() ?: 0;
// Fetch Data based on section
if ($section === 'dashboard') {
$patients_sql = "
SELECT p.*, ic.name_$lang as insurance_name
FROM patients p
LEFT JOIN insurance_companies ic ON p.insurance_company_id = ic.id
ORDER BY p.id DESC LIMIT 5";
$patients = $db->query($patients_sql)->fetchAll();
$appointments_sql = "
SELECT a.*, p.name as patient_name, d.name_$lang as doctor_name
FROM appointments a
JOIN patients p ON a.patient_id = p.id
JOIN doctors d ON a.doctor_id = d.id
ORDER BY a.appointment_date DESC
LIMIT 5";
$appointments = $db->query($appointments_sql)->fetchAll();
} elseif ($section === 'patients') {
$patients_sql = "
SELECT p.*, ic.name_$lang as insurance_name
FROM patients p
LEFT JOIN insurance_companies ic ON p.insurance_company_id = ic.id
ORDER BY p.id DESC";
$patients = $db->query($patients_sql)->fetchAll();
} elseif ($section === 'visits') {
$visits_sql = "
SELECT v.*, p.name as patient_name, d.name_$lang as doctor_name
FROM visits v
JOIN patients p ON v.patient_id = p.id
JOIN doctors d ON v.doctor_id = d.id
ORDER BY v.visit_date DESC";
$visits = $db->query($visits_sql)->fetchAll();
} elseif ($section === 'billing') {
$bills_sql = "
SELECT b.*, p.name as patient_name
FROM bills b
JOIN patients p ON b.patient_id = p.id
ORDER BY b.created_at DESC";
$bills = $db->query($bills_sql)->fetchAll();
} elseif ($section === 'insurance') {
$insurance_companies = $db->query("SELECT * FROM insurance_companies ORDER BY id DESC")->fetchAll();
}
// Common data for selects
$all_doctors = $db->query("SELECT id, name_$lang as name FROM doctors")->fetchAll();
$all_patients = $db->query("SELECT id, name FROM patients")->fetchAll();
$all_insurance = $db->query("SELECT id, name_$lang as name FROM insurance_companies")->fetchAll();
$scheduled_appointments = $db->query("
SELECT a.id, p.name as patient_name, a.appointment_date, a.patient_id, a.doctor_id
FROM appointments a
JOIN patients p ON a.patient_id = p.id
WHERE a.status = 'Scheduled'
ORDER BY a.appointment_date ASC")->fetchAll();
?>
<!DOCTYPE html>
<html lang="<?php echo $_SESSION['lang']; ?>" dir="<?php echo get_dir(); ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo __('hospital_management'); ?></title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<?php if (is_rtl()): ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css">
<?php endif; ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Tajawal:wght@400;500;700&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', 'Tajawal', sans-serif; background-color: #f4f7f6; }
.sidebar { min-height: 100vh; width: 250px; background-color: #002D62; color: white; transition: all 0.3s; }
.sidebar-link { color: #cfd8dc; text-decoration: none; padding: 12px 20px; display: block; border-left: 4px solid transparent; }
.sidebar-link:hover, .sidebar-link.active { background-color: #003a80; color: white; border-left-color: #4fc3f7; }
.main-content { flex: 1; padding: 25px; }
.card { border: none; border-radius: 8px; box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); margin-bottom: 20px; }
.stat-card { padding: 20px; text-align: center; }
.stat-card i { font-size: 2.5rem; color: #0056b3; margin-bottom: 10px; }
.btn-primary { background-color: #0056b3; border-color: #0056b3; }
.table thead th { background-color: #f8f9fa; border-bottom: 2px solid #dee2e6; color: #495057; font-weight: 600; }
.navbar { background-color: white; border-bottom: 1px solid #e0e0e0; }
<?php if (is_rtl()): ?>
.sidebar-link { border-left: 0; border-right: 4px solid transparent; }
.sidebar-link:hover, .sidebar-link.active { border-right-color: #4fc3f7; }
<?php endif; ?>
</style>
</head>
<body>
<div class="d-flex">
<!-- Sidebar -->
<div class="sidebar d-none d-md-block">
<div class="p-4 text-center">
<h5 class="fw-bold"><i class="bi bi-hospital"></i> <?php echo __('hospital_management'); ?></h5>
</div>
<nav class="mt-3">
<a href="index.php?section=dashboard" class="sidebar-link <?php echo $section === 'dashboard' ? 'active' : ''; ?>"><i class="bi bi-speedometer2 me-2"></i> <?php echo __('dashboard'); ?></a>
<a href="index.php?section=patients" class="sidebar-link <?php echo $section === 'patients' ? 'active' : ''; ?>"><i class="bi bi-people me-2"></i> <?php echo __('patients'); ?></a>
<a href="index.php?section=visits" class="sidebar-link <?php echo $section === 'visits' ? 'active' : ''; ?>"><i class="bi bi-clipboard2-pulse me-2"></i> <?php echo __('visits'); ?></a>
<a href="index.php?section=billing" class="sidebar-link <?php echo $section === 'billing' ? 'active' : ''; ?>"><i class="bi bi-receipt me-2"></i> <?php echo __('billing'); ?></a>
<a href="index.php?section=insurance" class="sidebar-link <?php echo $section === 'insurance' ? 'active' : ''; ?>"><i class="bi bi-shield-check me-2"></i> <?php echo __('insurance'); ?></a>
<a href="#" class="sidebar-link"><i class="bi bi-calendar-event me-2"></i> <?php echo __('appointments'); ?></a>
<a href="#" class="sidebar-link"><i class="bi bi-person-badge me-2"></i> <?php echo __('doctors'); ?></a>
<a href="#" class="sidebar-link"><i class="bi bi-diagram-3 me-2"></i> <?php echo __('departments'); ?></a>
</nav>
</div>
<!-- Main Content -->
<div class="main-content">
<!-- Top Navbar -->
<nav class="navbar navbar-expand-lg navbar-light mb-4 rounded shadow-sm px-3">
<div class="container-fluid p-0">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#topNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="topNav">
<div class="ms-auto d-flex align-items-center">
<a href="?lang=<?php echo get_lang_code(); ?>&section=<?php echo $section; ?>" class="btn btn-outline-secondary btn-sm me-3">
<i class="bi bi-translate"></i> <?php echo get_lang_name(); ?>
</a>
<div class="dropdown">
<a class="nav-link dropdown-toggle d-flex align-items-center" href="#" role="button" data-bs-toggle="dropdown">
<img src="https://ui-avatars.com/api/?name=Admin&background=0056b3&color=fff" class="rounded-circle me-2" width="32" height="32">
<span>Admin</span>
</a>
<ul class="dropdown-menu dropdown-menu-end shadow border-0">
<li><a class="dropdown-item" href="#"><i class="bi bi-person me-2"></i> <?php echo __('profile'); ?></a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item text-danger" href="#"><i class="bi bi-box-arrow-right me-2"></i> <?php echo __('logout'); ?></a></li>
</ul>
</div>
</div>
</div>
</div>
</nav>
<?php if ($message): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?php echo $message; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<?php if ($section === 'dashboard'): ?>
<!-- Dashboard Stats -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card stat-card">
<i class="bi bi-people"></i>
<h3><?php echo $total_patients; ?></h3>
<p class="text-muted mb-0"><?php echo __('total_patients'); ?></p>
</div>
</div>
<div class="col-md-3">
<div class="card stat-card">
<i class="bi bi-calendar-check"></i>
<h3><?php echo $today_appointments; ?></h3>
<p class="text-muted mb-0"><?php echo __('today_appointments'); ?></p>
</div>
</div>
<div class="col-md-3">
<div class="card stat-card">
<i class="bi bi-currency-dollar text-success"></i>
<h3>$<?php echo number_format($total_revenue, 2); ?></h3>
<p class="text-muted mb-0"><?php echo __('revenue'); ?></p>
</div>
</div>
<div class="col-md-3">
<div class="card stat-card">
<i class="bi bi-hourglass-split text-warning"></i>
<h3>$<?php echo number_format($pending_revenue, 2); ?></h3>
<p class="text-muted mb-0"><?php echo __('pending'); ?></p>
</div>
</div>
</div>
<!-- Quick Actions -->
<div class="row mb-4">
<div class="col-12">
<div class="card p-3 d-flex flex-row justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><?php echo __('dashboard'); ?></h5>
<div>
<button class="btn btn-primary btn-sm me-2" data-bs-toggle="modal" data-bs-target="#addPatientModal">
<i class="bi bi-plus-lg"></i> <?php echo __('add_patient'); ?>
</button>
<button class="btn btn-success btn-sm me-2" data-bs-toggle="modal" data-bs-target="#bookAppointmentModal">
<i class="bi bi-calendar-plus"></i> <?php echo __('book_appointment'); ?>
</button>
<button class="btn btn-info btn-sm text-white" data-bs-toggle="modal" data-bs-target="#recordVisitModal">
<i class="bi bi-clipboard-plus"></i> <?php echo __('add_visit'); ?>
</button>
</div>
</div>
</div>
</div>
<!-- Tables Section -->
<div class="row">
<div class="col-lg-6">
<div class="card shadow-sm h-100">
<div class="card-header bg-white py-3">
<h6 class="mb-0 fw-bold"><i class="bi bi-people-fill me-2 text-primary"></i> <?php echo __('patients'); ?></h6>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th><?php echo __('name'); ?></th>
<th><?php echo __('phone'); ?></th>
<th><?php echo __('insurance'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($patients as $p): ?>
<tr>
<td><?php echo htmlspecialchars($p['name']); ?></td>
<td><?php echo htmlspecialchars($p['phone']); ?></td>
<td><span class="badge <?php echo $p['insurance_name'] ? 'bg-primary' : 'bg-secondary'; ?>"><?php echo $p['insurance_name'] ?: __('not_insured'); ?></span></td>
</tr>
<?php endforeach; if (empty($patients)): ?>
<tr><td colspan="3" class="text-center py-4 text-muted">No patients found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="card shadow-sm h-100">
<div class="card-header bg-white py-3">
<h6 class="mb-0 fw-bold"><i class="bi bi-calendar-event-fill me-2 text-success"></i> <?php echo __('appointments'); ?></h6>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th><?php echo __('patient'); ?></th>
<th><?php echo __('doctor'); ?></th>
<th><?php echo __('date'); ?></th>
<th><?php echo __('status'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($appointments as $a): ?>
<tr>
<td><?php echo htmlspecialchars($a['patient_name']); ?></td>
<td><?php echo htmlspecialchars($a['doctor_name']); ?></td>
<td><?php echo date('M d, H:i', strtotime($a['appointment_date'])); ?></td>
<td><span class="badge <?php echo $a['status'] === 'Completed' ? 'bg-success' : 'bg-secondary'; ?>"><?php echo __($a['status']); ?></span></td>
</tr>
<?php endforeach; if (empty($appointments)): ?>
<tr><td colspan="4" class="text-center py-4 text-muted">No appointments found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php elseif ($section === 'patients'): ?>
<div class="card shadow-sm">
<div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><i class="bi bi-people-fill me-2 text-primary"></i> <?php echo __('patients'); ?></h5>
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addPatientModal">
<i class="bi bi-plus-lg"></i> <?php echo __('add_patient'); ?>
</button>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th><?php echo __('name'); ?></th>
<th><?php echo __('phone'); ?></th>
<th><?php echo __('dob'); ?></th>
<th><?php echo __('insurance'); ?></th>
<th><?php echo __('policy_number'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($patients as $p): ?>
<tr>
<td><?php echo htmlspecialchars($p['name']); ?></td>
<td><?php echo htmlspecialchars($p['phone']); ?></td>
<td><?php echo $p['dob']; ?></td>
<td><span class="badge <?php echo $p['insurance_name'] ? 'bg-primary' : 'bg-secondary'; ?>"><?php echo $p['insurance_name'] ?: __('not_insured'); ?></span></td>
<td><?php echo htmlspecialchars($p['policy_number'] ?: '-'); ?></td>
</tr>
<?php endforeach; if (empty($patients)): ?>
<tr><td colspan="5" class="text-center py-4 text-muted">No patients found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php elseif ($section === 'visits'): ?>
<div class="card shadow-sm">
<div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><i class="bi bi-clipboard2-pulse me-2 text-info"></i> <?php echo __('visits'); ?></h5>
<button class="btn btn-info btn-sm text-white" data-bs-toggle="modal" data-bs-target="#recordVisitModal">
<i class="bi bi-plus-lg"></i> <?php echo __('add_visit'); ?>
</button>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th><?php echo __('date'); ?></th>
<th><?php echo __('patient'); ?></th>
<th><?php echo __('doctor'); ?></th>
<th><?php echo __('diagnosis'); ?></th>
<th><?php echo __('actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($visits as $v): ?>
<tr>
<td><?php echo date('Y-m-d H:i', strtotime($v['visit_date'])); ?></td>
<td><?php echo htmlspecialchars($v['patient_name']); ?></td>
<td><?php echo htmlspecialchars($v['doctor_name']); ?></td>
<td><small class="text-truncate d-inline-block" style="max-width: 200px;"><?php echo htmlspecialchars($v['diagnosis']); ?></small></td>
<td>
<div class="btn-group">
<button class="btn btn-outline-primary btn-sm" onclick='showReportModal(<?php echo $v["id"]; ?>)'>
<i class="bi bi-file-earmark-plus"></i> <?php echo __('new_report'); ?>
</button>
<button class="btn btn-outline-success btn-sm" onclick='showBillModal(<?php echo $v["id"]; ?>, <?php echo $v["patient_id"]; ?>, "<?php echo addslashes($v["patient_name"]); ?>")'>
<i class="bi bi-receipt"></i> <?php echo __('create_bill'); ?>
</button>
</div>
</td>
</tr>
<?php endforeach; if (empty($visits)): ?>
<tr><td colspan="5" class="text-center py-4 text-muted">No visits recorded yet.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php elseif ($section === 'billing'): ?>
<div class="card shadow-sm">
<div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><i class="bi bi-receipt me-2 text-success"></i> <?php echo __('billing'); ?></h5>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>ID</th>
<th><?php echo __('date'); ?></th>
<th><?php echo __('patient'); ?></th>
<th><?php echo __('total'); ?></th>
<th><?php echo __('insurance_covered'); ?></th>
<th><?php echo __('patient_payable'); ?></th>
<th><?php echo __('status'); ?></th>
<th><?php echo __('actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($bills as $b): ?>
<tr>
<td>#<?php echo $b['id']; ?></td>
<td><?php echo date('Y-m-d H:i', strtotime($b['created_at'])); ?></td>
<td><?php echo htmlspecialchars($b['patient_name']); ?></td>
<td>$<?php echo number_format($b['total_amount'], 2); ?></td>
<td class="text-primary">$<?php echo number_format($b['insurance_covered'], 2); ?></td>
<td class="fw-bold">$<?php echo number_format($b['patient_payable'], 2); ?></td>
<td>
<span class="badge <?php echo $b['status'] === 'Paid' ? 'bg-success' : 'bg-warning'; ?>">
<?php echo __($b['status']); ?>
</span>
</td>
<td>
<?php if ($b['status'] === 'Pending'): ?>
<form action="index.php?section=billing" method="POST" class="d-inline">
<input type="hidden" name="action" value="mark_paid">
<input type="hidden" name="bill_id" value="<?php echo $b['id']; ?>">
<button type="submit" class="btn btn-sm btn-success">
<i class="bi bi-check-circle"></i> <?php echo __('mark_as_paid'); ?>
</button>
</form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; if (empty($bills)): ?>
<tr><td colspan="8" class="text-center py-4 text-muted">No bills found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php elseif ($section === 'insurance'): ?>
<div class="card shadow-sm">
<div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0 fw-bold"><i class="bi bi-shield-check me-2 text-primary"></i> <?php echo __('insurance_companies'); ?></h5>
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addInsuranceModal">
<i class="bi bi-plus-lg"></i> <?php echo __('add_insurance'); ?>
</button>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>ID</th>
<th><?php echo __('name'); ?> (EN)</th>
<th><?php echo __('name'); ?> (AR)</th>
<th><?php echo __('email'); ?></th>
<th><?php echo __('phone'); ?></th>
<th><?php echo __('date'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($insurance_companies as $ic): ?>
<tr>
<td>#<?php echo $ic['id']; ?></td>
<td><?php echo htmlspecialchars($ic['name_en']); ?></td>
<td><?php echo htmlspecialchars($ic['name_ar']); ?></td>
<td><?php echo htmlspecialchars($ic['email'] ?: '-'); ?></td>
<td><?php echo htmlspecialchars($ic['phone'] ?: '-'); ?></td>
<td><?php echo date('Y-m-d', strtotime($ic['created_at'])); ?></td>
</tr>
<?php endforeach; if (empty($insurance_companies)): ?>
<tr><td colspan="6" class="text-center py-4 text-muted">No insurance companies found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
<!-- Add Patient Modal -->
<div class="modal fade" id="addPatientModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="index.php?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_patient">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('add_patient'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?></label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="phone" class="form-control" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="date" name="dob" class="form-control">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('gender'); ?></label>
<select name="gender" class="form-select">
<option value="Male"><?php echo __('male'); ?></option>
<option value="Female"><?php echo __('female'); ?></option>
<option value="Other"><?php echo __('other'); ?></option>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('blood_group'); ?></label>
<input type="text" name="blood_group" class="form-control" placeholder="O+, A-, etc.">
</div>
</div>
<hr>
<h6 class="fw-bold mb-3"><?php echo __('insurance'); ?> (<?php echo __('optional'); ?>)</h6>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('insurance_company'); ?></label>
<select name="insurance_company_id" class="form-select">
<option value=""><?php echo __('not_insured'); ?></option>
<?php foreach ($all_insurance as $i): ?>
<option value="<?php echo $i['id']; ?>"><?php echo htmlspecialchars($i['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('policy_number'); ?></label>
<input type="text" name="policy_number" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('address'); ?></label>
<textarea name="address" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Insurance Modal -->
<div class="modal fade" id="addInsuranceModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="index.php?section=insurance" method="POST">
<input type="hidden" name="action" value="add_insurance">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('add_insurance'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?> (EN)</label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?> (AR)</label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('email'); ?></label>
<input type="email" name="email" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="phone" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('contact_info'); ?></label>
<textarea name="contact_info" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Book Appointment Modal -->
<div class="modal fade" id="bookAppointmentModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="index.php?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="book_appointment">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('book_appointment'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('patient'); ?></label>
<select name="patient_id" class="form-select" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_patients as $p): ?>
<option value="<?php echo $p['id']; ?>"><?php echo htmlspecialchars($p['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('doctor'); ?></label>
<select name="doctor_id" class="form-select" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_doctors as $d): ?>
<option value="<?php echo $d['id']; ?>"><?php echo htmlspecialchars($d['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('date'); ?></label>
<input type="datetime-local" name="date" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('reason'); ?></label>
<textarea name="reason" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-success px-4"><?php echo __('book_appointment'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Record Visit Modal -->
<div class="modal fade" id="recordVisitModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<form action="index.php?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="record_visit">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('add_visit'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12 mb-3">
<label class="form-label"><?php echo __('appointment'); ?> (<?php echo __('optional'); ?>)</label>
<select name="appointment_id" class="form-select" id="visit_appointment_select" onchange="updateVisitFields()">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($scheduled_appointments as $sa): ?>
<option value="<?php echo $sa['id']; ?>" data-patient="<?php echo $sa['patient_id']; ?>" data-doctor="<?php echo $sa['doctor_id']; ?>">
<?php echo htmlspecialchars($sa['patient_name']); ?> - <?php echo $sa['appointment_date']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('patient'); ?></label>
<select name="patient_id" id="visit_patient_id" class="form-select" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_patients as $p): ?>
<option value="<?php echo $p['id']; ?>"><?php echo htmlspecialchars($p['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('doctor'); ?></label>
<select name="doctor_id" id="visit_doctor_id" class="form-select" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_doctors as $d): ?>
<option value="<?php echo $d['id']; ?>"><?php echo htmlspecialchars($d['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<hr>
<h6 class="fw-bold mb-3"><?php echo __('vitals'); ?></h6>
<div class="row">
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('weight'); ?></label>
<input type="text" name="weight" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('blood_pressure'); ?></label>
<input type="text" name="blood_pressure" class="form-control" placeholder="120/80">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('heart_rate'); ?></label>
<input type="text" name="heart_rate" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('temperature'); ?></label>
<input type="text" name="temperature" class="form-control">
</div>
</div>
<hr>
<div class="mb-3">
<label class="form-label"><?php echo __('symptoms'); ?></label>
<textarea name="symptoms" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('diagnosis'); ?></label>
<textarea name="diagnosis" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('treatment_plan'); ?></label>
<textarea name="treatment_plan" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-info text-white px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Create Bill Modal -->
<div class="modal fade" id="createBillModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="index.php?section=billing" method="POST">
<input type="hidden" name="action" value="create_bill">
<input type="hidden" name="visit_id" id="bill_visit_id">
<input type="hidden" name="patient_id" id="bill_patient_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('create_bill'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p class="mb-3"><?php echo __('patient'); ?>: <strong id="bill_patient_name"></strong></p>
<div class="alert alert-info py-2 small">
<i class="bi bi-info-circle me-1"></i> If patient has insurance, 80% coverage will be applied automatically.
</div>
<div id="bill_items_container">
<div class="row g-2 mb-2 align-items-end item-row">
<div class="col-8">
<label class="form-label small mb-1"><?php echo __('description'); ?></label>
<input type="text" name="items[]" class="form-control" required value="<?php echo __('consultation_fee'); ?>">
</div>
<div class="col-4">
<label class="form-label small mb-1"><?php echo __('amount'); ?></label>
<input type="number" step="0.01" name="amounts[]" class="form-control" required placeholder="0.00">
</div>
</div>
</div>
<button type="button" class="btn btn-link btn-sm p-0 mt-2" onclick="addBillItem()">+ <?php echo __('add_item'); ?></button>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-success px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Provisional Report Modal -->
<div class="modal fade" id="reportModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="index.php?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="create_report">
<input type="hidden" name="visit_id" id="report_visit_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold"><?php echo __('new_report'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('report_type'); ?></label>
<input type="text" name="report_type" class="form-control" required placeholder="General, Lab, X-Ray, etc.">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('findings'); ?></label>
<textarea name="findings" class="form-control" rows="3"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('recommendations'); ?></label>
<textarea name="recommendations" class="form-control" rows="3"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Bootstrap 5 Bundle JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
function updateVisitFields() {
const select = document.getElementById('visit_appointment_select');
const option = select.options[select.selectedIndex];
if (option.value) {
document.getElementById('visit_patient_id').value = option.dataset.patient;
document.getElementById('visit_doctor_id').value = option.dataset.doctor;
}
}
function showReportModal(visitId) {
document.getElementById('report_visit_id').value = visitId;
new bootstrap.Modal(document.getElementById('reportModal')).show();
}
function showBillModal(visitId, patientId, patientName) {
document.getElementById('bill_visit_id').value = visitId;
document.getElementById('bill_patient_id').value = patientId;
document.getElementById('bill_patient_name').innerText = patientName;
new bootstrap.Modal(document.getElementById('createBillModal')).show();
}
function addBillItem() {
const container = document.getElementById('bill_items_container');
const row = document.createElement('div');
row.className = 'row g-2 mb-2 align-items-end item-row';
row.innerHTML = `
<div class="col-8">
<input type="text" name="items[]" class="form-control" required>
</div>
<div class="col-4">
<input type="number" step="0.01" name="amounts[]" class="form-control" required placeholder="0.00">
</div>
`;
container.appendChild(row);
}
</script>
</body>
</html>
header('Location: dashboard.php');
exit;

13
insurance.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$section = 'insurance';
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/helpers.php';
$db = db();
$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/insurance.php';
require_once __DIR__ . '/includes/layout/footer.php';

View File

@ -11,6 +11,7 @@ $translations = [
'name' => 'Name',
'phone' => 'Phone',
'dob' => 'Date of Birth',
'age' => 'Age',
'gender' => 'Gender',
'blood_group' => 'Blood Group',
'address' => 'Address',
@ -101,6 +102,7 @@ $translations = [
'name' => 'الاسم',
'phone' => 'الهاتف',
'dob' => 'تاريخ الميلاد',
'age' => 'العمر',
'gender' => 'الجنس',
'blood_group' => 'فصيلة الدم',
'address' => 'العنوان',

13
patients.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$section = 'patients';
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/helpers.php';
$db = db();
$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/patients.php';
require_once __DIR__ . '/includes/layout/footer.php';

13
visits.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$section = 'visits';
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/helpers.php';
$db = db();
$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/visits.php';
require_once __DIR__ . '/includes/layout/footer.php';