From 85f641cde7442eefb0767565260cd239364ff2cc Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 4 Mar 2026 04:42:54 +0000 Subject: [PATCH] Autosave: 20260304-044254 --- billing.php | 13 + dashboard.php | 13 + helpers.php | 11 + includes/actions.php | 117 +++++ includes/common_data.php | 11 + includes/layout/footer.php | 368 ++++++++++++++ includes/layout/header.php | 100 ++++ includes/pages/billing.php | 61 +++ includes/pages/dashboard.php | 146 ++++++ includes/pages/insurance.php | 41 ++ includes/pages/patients.php | 46 ++ includes/pages/visits.php | 54 ++ index.php | 941 +---------------------------------- insurance.php | 13 + lang.php | 4 +- patients.php | 13 + visits.php | 13 + 17 files changed, 1025 insertions(+), 940 deletions(-) create mode 100644 billing.php create mode 100644 dashboard.php create mode 100644 includes/actions.php create mode 100644 includes/common_data.php create mode 100644 includes/layout/footer.php create mode 100644 includes/layout/header.php create mode 100644 includes/pages/billing.php create mode 100644 includes/pages/dashboard.php create mode 100644 includes/pages/insurance.php create mode 100644 includes/pages/patients.php create mode 100644 includes/pages/visits.php create mode 100644 insurance.php create mode 100644 patients.php create mode 100644 visits.php diff --git a/billing.php b/billing.php new file mode 100644 index 0000000..7ade78e --- /dev/null +++ b/billing.php @@ -0,0 +1,13 @@ +diff($today)->y; + } catch (Exception $e) { + return '-'; + } +} \ No newline at end of file diff --git a/includes/actions.php b/includes/actions.php new file mode 100644 index 0000000..db83dbc --- /dev/null +++ b/includes/actions.php @@ -0,0 +1,117 @@ +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'); + } + } + } +} diff --git a/includes/common_data.php b/includes/common_data.php new file mode 100644 index 0000000..11f4845 --- /dev/null +++ b/includes/common_data.php @@ -0,0 +1,11 @@ +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(); diff --git a/includes/layout/footer.php b/includes/layout/footer.php new file mode 100644 index 0000000..065a9df --- /dev/null +++ b/includes/layout/footer.php @@ -0,0 +1,368 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/includes/layout/header.php b/includes/layout/header.php new file mode 100644 index 0000000..79029b3 --- /dev/null +++ b/includes/layout/header.php @@ -0,0 +1,100 @@ + + + + + + + <?php echo __('hospital_management'); ?> + + + + + + + + + + + +
+ + + + +
+ + + + + + diff --git a/includes/pages/billing.php b/includes/pages/billing.php new file mode 100644 index 0000000..13f53f1 --- /dev/null +++ b/includes/pages/billing.php @@ -0,0 +1,61 @@ +query($bills_sql)->fetchAll(); +?> +
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID
#$$$ + + + + + +
+ + + +
+ +
No bills found.
+
+
+
diff --git a/includes/pages/dashboard.php b/includes/pages/dashboard.php new file mode 100644 index 0000000..b7157d8 --- /dev/null +++ b/includes/pages/dashboard.php @@ -0,0 +1,146 @@ +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(); +?> + + +
+
+
+ +

+

+
+
+
+
+ +

+

+
+
+
+
+ +

$

+

+
+
+
+
+ +

$

+

+
+
+
+ + +
+
+
+
+
+ + + +
+
+
+
+ + +
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
No patients found.
+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
No appointments found.
+
+
+
+
+
diff --git a/includes/pages/insurance.php b/includes/pages/insurance.php new file mode 100644 index 0000000..baf3519 --- /dev/null +++ b/includes/pages/insurance.php @@ -0,0 +1,41 @@ +query("SELECT * FROM insurance_companies ORDER BY id DESC")->fetchAll(); +?> +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
ID (EN) (AR)
#
No insurance companies found.
+
+
+
diff --git a/includes/pages/patients.php b/includes/pages/patients.php new file mode 100644 index 0000000..4e1748a --- /dev/null +++ b/includes/pages/patients.php @@ -0,0 +1,46 @@ +query($patients_sql)->fetchAll(); +?> +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
No patients found.
+
+
+
diff --git a/includes/pages/visits.php b/includes/pages/visits.php new file mode 100644 index 0000000..b8fef11 --- /dev/null +++ b/includes/pages/visits.php @@ -0,0 +1,54 @@ +query($visits_sql)->fetchAll(); +?> +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
No visits recorded yet.
+
+
+
diff --git a/index.php b/index.php index cfc0dbc..6813f99 100644 --- a/index.php +++ b/index.php @@ -1,940 +1,3 @@ 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(); - -?> - - - - - - <?php echo __('hospital_management'); ?> - - - - - - - - - - - -
- - - - -
- - - - - - - - - -
-
-
- -

-

-
-
-
-
- -

-

-
-
-
-
- -

$

-

-
-
-
-
- -

$

-

-
-
-
- - -
-
-
-
-
- - - -
-
-
-
- - -
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - -
No patients found.
-
-
-
-
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - -
No appointments found.
-
-
-
-
-
- - -
-
-
- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - -
No patients found.
-
-
-
- - -
-
-
- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - -
-
- - -
-
No visits recorded yet.
-
-
-
- - -
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ID
#$$$ - - - - - -
- - - -
- -
No bills found.
-
-
-
- - -
-
-
- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
ID (EN) (AR)
#
No insurance companies found.
-
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file +header('Location: dashboard.php'); +exit; diff --git a/insurance.php b/insurance.php new file mode 100644 index 0000000..3127f55 --- /dev/null +++ b/insurance.php @@ -0,0 +1,13 @@ + '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' => 'العنوان', @@ -180,4 +182,4 @@ $translations = [ 'optional' => 'اختياري', 'email' => 'البريد الإلكتروني' ] -]; +]; \ No newline at end of file diff --git a/patients.php b/patients.php new file mode 100644 index 0000000..e92161f --- /dev/null +++ b/patients.php @@ -0,0 +1,13 @@ +