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 @@ + + + + + +
+ + + + + + + + + + + + + + + + + + + +