diff --git a/apply_migrations.php b/apply_migrations.php new file mode 100644 index 0000000..3e8640e --- /dev/null +++ b/apply_migrations.php @@ -0,0 +1,18 @@ +exec($sql); + echo "Done.\n"; + } catch (PDOException $e) { + echo "Error: " . $e->getMessage() . "\n"; + } +} + diff --git a/db/migrations/20260305_create_drugs_tables.sql b/db/migrations/20260305_create_drugs_tables.sql new file mode 100644 index 0000000..8dd0e8d --- /dev/null +++ b/db/migrations/20260305_create_drugs_tables.sql @@ -0,0 +1,20 @@ +CREATE TABLE IF NOT EXISTS drugs_groups ( + id INT AUTO_INCREMENT PRIMARY KEY, + name_en VARCHAR(255) NOT NULL, + name_ar VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS drugs ( + id INT AUTO_INCREMENT PRIMARY KEY, + group_id INT, + name_en VARCHAR(255) NOT NULL, + name_ar VARCHAR(255) NOT NULL, + description_en TEXT, + description_ar TEXT, + default_dosage VARCHAR(255), + default_instructions TEXT, + price DECIMAL(10, 2) DEFAULT 0.00, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (group_id) REFERENCES drugs_groups(id) ON DELETE SET NULL +); diff --git a/db/migrations/20260305_create_visit_prescriptions_table.sql b/db/migrations/20260305_create_visit_prescriptions_table.sql new file mode 100644 index 0000000..8050727 --- /dev/null +++ b/db/migrations/20260305_create_visit_prescriptions_table.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS visit_prescriptions ( + id INT AUTO_INCREMENT PRIMARY KEY, + visit_id INT NOT NULL, + drug_name VARCHAR(255) NOT NULL, + dosage VARCHAR(100), + instructions TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (visit_id) REFERENCES visits(id) ON DELETE CASCADE +); diff --git a/includes/actions.php b/includes/actions.php index 9af1905..c3cd2e4 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -191,6 +191,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $db->beginTransaction(); $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]); + $visit_id = $db->lastInsertId(); + if (isset($_POST['prescriptions']) && is_array($_POST['prescriptions'])) { + $drug_names = $_POST['prescriptions']['drug_name'] ?? []; + $dosages = $_POST['prescriptions']['dosage'] ?? []; + $instructions = $_POST['prescriptions']['instructions'] ?? []; + $pStmt = $db->prepare("INSERT INTO visit_prescriptions (visit_id, drug_name, dosage, instructions) VALUES (?, ?, ?, ?)"); + foreach ($drug_names as $i => $drug) { + if (!empty($drug)) { + $pStmt->execute([$visit_id, $drug, $dosages[$i] ?? '', $instructions[$i] ?? '']); + } + } + } if ($appointment_id) { $stmt = $db->prepare("UPDATE appointments SET status = 'Completed' WHERE id = ?"); @@ -215,6 +227,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($id && $patient_id && $doctor_id) { $stmt = $db->prepare("UPDATE visits SET patient_id = ?, doctor_id = ?, weight = ?, blood_pressure = ?, heart_rate = ?, temperature = ?, symptoms = ?, diagnosis = ?, treatment_plan = ? WHERE id = ?"); $stmt->execute([$patient_id, $doctor_id, $weight, $bp, $hr, $temp, $symptoms, $diagnosis, $treatment, $id]); + $stmt = $db->prepare("DELETE FROM visit_prescriptions WHERE visit_id = ?"); + $stmt->execute([$id]); + if (isset($_POST['prescriptions']) && is_array($_POST['prescriptions'])) { + $drug_names = $_POST['prescriptions']['drug_name'] ?? []; + $dosages = $_POST['prescriptions']['dosage'] ?? []; + $instructions = $_POST['prescriptions']['instructions'] ?? []; + $pStmt = $db->prepare("INSERT INTO visit_prescriptions (visit_id, drug_name, dosage, instructions) VALUES (?, ?, ?, ?)"); + foreach ($drug_names as $i => $drug) { + if (!empty($drug)) { + $pStmt->execute([$id, $drug, $dosages[$i] ?? '', $instructions[$i] ?? '']); + } + } + } $_SESSION['flash_message'] = __('edit_visit') . ' ' . __('successfully'); $redirect = true; } @@ -602,6 +627,75 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $redirect = true; } } + } elseif ($_POST['action'] === 'add_drug_group') { + $name_en = $_POST['name_en'] ?? ''; + $name_ar = $_POST['name_ar'] ?? ''; + if ($name_en && $name_ar) { + $stmt = $db->prepare("INSERT INTO drugs_groups (name_en, name_ar) VALUES (?, ?)"); + $stmt->execute([$name_en, $name_ar]); + $_SESSION['flash_message'] = __('add_drug_group') . ' ' . __('successfully'); + $redirect = true; + } + } elseif ($_POST['action'] === 'edit_drug_group') { + $id = $_POST['id'] ?? ''; + $name_en = $_POST['name_en'] ?? ''; + $name_ar = $_POST['name_ar'] ?? ''; + if ($id && $name_en && $name_ar) { + $stmt = $db->prepare("UPDATE drugs_groups SET name_en = ?, name_ar = ? WHERE id = ?"); + $stmt->execute([$name_en, $name_ar, $id]); + $_SESSION['flash_message'] = __('edit_drug_group') . ' ' . __('successfully'); + $redirect = true; + } + } elseif ($_POST['action'] === 'delete_drug_group') { + $id = $_POST['id'] ?? ''; + if ($id) { + $stmt = $db->prepare("DELETE FROM drugs_groups WHERE id = ?"); + $stmt->execute([$id]); + $_SESSION['flash_message'] = __('delete') . ' ' . __('successfully'); + $redirect = true; + } + } elseif ($_POST['action'] === 'add_drug') { + $name_en = $_POST['name_en'] ?? ''; + $name_ar = $_POST['name_ar'] ?? ''; + $group_id = $_POST['group_id'] ?: null; + $desc_en = $_POST['description_en'] ?? ''; + $desc_ar = $_POST['description_ar'] ?? ''; + $dosage = $_POST['default_dosage'] ?? ''; + $instructions = $_POST['default_instructions'] ?? ''; + $price = $_POST['price'] ?? 0; + + if ($name_en && $name_ar) { + $stmt = $db->prepare("INSERT INTO drugs (name_en, name_ar, group_id, description_en, description_ar, default_dosage, default_instructions, price) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$name_en, $name_ar, $group_id, $desc_en, $desc_ar, $dosage, $instructions, $price]); + $_SESSION['flash_message'] = __('add_drug') . ' ' . __('successfully'); + $redirect = true; + } + } elseif ($_POST['action'] === 'edit_drug') { + $id = $_POST['id'] ?? ''; + $name_en = $_POST['name_en'] ?? ''; + $name_ar = $_POST['name_ar'] ?? ''; + $group_id = $_POST['group_id'] ?: null; + $desc_en = $_POST['description_en'] ?? ''; + $desc_ar = $_POST['description_ar'] ?? ''; + $dosage = $_POST['default_dosage'] ?? ''; + $instructions = $_POST['default_instructions'] ?? ''; + $price = $_POST['price'] ?? 0; + + if ($id && $name_en && $name_ar) { + $stmt = $db->prepare("UPDATE drugs SET name_en = ?, name_ar = ?, group_id = ?, description_en = ?, description_ar = ?, default_dosage = ?, default_instructions = ?, price = ? WHERE id = ?"); + $stmt->execute([$name_en, $name_ar, $group_id, $desc_en, $desc_ar, $dosage, $instructions, $price, $id]); + $_SESSION['flash_message'] = __('edit_drug') . ' ' . __('successfully'); + $redirect = true; + } + } elseif ($_POST['action'] === 'delete_drug') { + $id = $_POST['id'] ?? ''; + if ($id) { + $stmt = $db->prepare("DELETE FROM drugs WHERE id = ?"); + $stmt->execute([$id]); + $_SESSION['flash_message'] = __('delete') . ' ' . __('successfully'); + $redirect = true; + } + } if ($redirect) { diff --git a/includes/layout/footer.php b/includes/layout/footer.php index 36a3230..483b9bd 100644 --- a/includes/layout/footer.php +++ b/includes/layout/footer.php @@ -1295,6 +1295,16 @@ +
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+ + + + + +
+ +
+ diff --git a/includes/pages/drugs.php b/includes/pages/drugs.php new file mode 100644 index 0000000..e7831b4 --- /dev/null +++ b/includes/pages/drugs.php @@ -0,0 +1,135 @@ +prepare($query); +$stmt->execute($params); +$drugs = $stmt->fetchAll(); + +// Fetch all groups for filter dropdown +$gStmt = $db->query("SELECT * FROM drugs_groups ORDER BY name_$lang"); +$all_drug_groups = $gStmt->fetchAll(); +?> + +
+

+ +
+ + +
+
+
+
+
+ + +
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#
+ + +
+
+
+ +
+
+
+ +
+
+
+ + + + + + + + +
+ + +
+
+
+
+
diff --git a/includes/pages/drugs_groups.php b/includes/pages/drugs_groups.php new file mode 100644 index 0000000..36be019 --- /dev/null +++ b/includes/pages/drugs_groups.php @@ -0,0 +1,61 @@ +query($query); +$groups = $stmt->fetchAll(); +?> + +
+

+ +
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
#
+ + +
+
+ + +
+
+
+
+
diff --git a/includes/pages/visits.php b/includes/pages/visits.php index eb19e39..6b952f7 100644 --- a/includes/pages/visits.php +++ b/includes/pages/visits.php @@ -43,6 +43,10 @@ foreach ($raw_visits as $v) { foreach($v['xray_inquiries'] as &$xi) { $xi['items'] = $db->query("SELECT xit.*, xt.name_$lang as xray_name FROM xray_inquiry_items xit JOIN xray_tests xt ON xit.xray_id = xt.id WHERE xit.inquiry_id = " . (int)$xi['id'])->fetchAll(); } + + // Fetch Prescriptions + $v['prescriptions'] = $db->query("SELECT * FROM visit_prescriptions WHERE visit_id = " . (int)$v['id'])->fetchAll(); + $visits[] = $v; } ?> @@ -191,6 +195,11 @@ foreach ($raw_visits as $v) { data-bs-toggle="tooltip" title=""> + + + diff --git a/lang.php b/lang.php index a055160..e4e4223 100644 --- a/lang.php +++ b/lang.php @@ -208,7 +208,27 @@ $translations = [ 'close' => 'Close', 'results' => 'Results', 'laboratory_inquiries' => 'Laboratory Inquiries', - 'xray_inquiries' => 'X-Ray Inquiries' + 'xray_inquiries' => 'X-Ray Inquiries', + 'prescriptions' => 'Prescriptions', + 'add_drug' => 'Add Drug', + 'drug_name' => 'Drug Name', + 'dosage' => 'Dosage', + 'instructions' => 'Instructions', + 'print_prescription' => 'Print Prescription', + 'drugs_groups' => 'Drugs Groups', + 'add_drug_group' => 'Add Drug Group', + 'edit_drug_group' => 'Edit Drug Group', + 'delete_drug_group' => 'Delete Drug Group', + 'drugs' => 'Drugs', + 'edit_drug' => 'Edit Drug', + 'delete_drug' => 'Delete Drug', + 'drug_group' => 'Drug Group', + 'default_dosage' => 'Default Dosage', + 'default_instructions' => 'Default Instructions', + 'no_drugs_found' => 'No drugs found', + 'select_drug' => 'Select Drug', + 'select' => 'Select', + ], 'ar' => [ 'attachment' => 'المرفق', @@ -420,6 +440,26 @@ $translations = [ 'company_logo' => 'شعار الشركة', 'company_favicon' => 'أيقونة الشركة', 'save_changes' => 'حفظ التغييرات', - 'settings_updated_successfully' => 'تم تحديث الإعدادات بنجاح' + 'settings_updated_successfully' => 'تم تحديث الإعدادات بنجاح', + 'prescriptions' => 'الوصفات الطبية', + 'add_drug' => 'إضافة دواء', + 'drug_name' => 'اسم الدواء', + 'dosage' => 'الجرعة', + 'instructions' => 'التعليمات', + 'print_prescription' => 'طباعة الوصفة', + 'drugs_groups' => 'مجموعات الأدوية', + 'add_drug_group' => 'إضافة مجموعة أدوية', + 'edit_drug_group' => 'تعديل مجموعة أدوية', + 'delete_drug_group' => 'حذف مجموعة أدوية', + 'drugs' => 'الأدوية', + 'edit_drug' => 'تعديل دواء', + 'delete_drug' => 'حذف دواء', + 'drug_group' => 'مجموعة الدواء', + 'default_dosage' => 'الجرعة الافتراضية', + 'default_instructions' => 'التعليمات الافتراضية', + 'no_drugs_found' => 'لم يتم العثور على أدوية', + 'select_drug' => 'اختر الدواء', + 'select' => 'اختيار', + ] ]; diff --git a/print_prescription.php b/print_prescription.php new file mode 100644 index 0000000..0367bf4 --- /dev/null +++ b/print_prescription.php @@ -0,0 +1,156 @@ +prepare(" + SELECT + v.*, + p.name as patient_name, + p.age, + p.gender, + d.name_en as doctor_name_en, + d.name_ar as doctor_name_ar, + d.specialization_en, + d.specialization_ar + FROM visits v + JOIN patients p ON v.patient_id = p.id + JOIN doctors d ON v.doctor_id = d.id + WHERE v.id = ? + "); + $stmt->execute([$visit_id]); + $visit = $stmt->fetch(); + + if (!$visit) { + throw new Exception("Visit not found"); + } + + // Fetch prescriptions + // Check if table exists implicitly by try-catch + $stmt = $db->prepare("SELECT * FROM visit_prescriptions WHERE visit_id = ?"); + $stmt->execute([$visit_id]); + $prescriptions = $stmt->fetchAll(); + + $lang = $_SESSION['lang'] ?? 'en'; +} catch (Exception $e) { + die("Error: " . $e->getMessage()); +} +?> + + + + + + Prescription #<?php echo $visit_id; ?> + + + + + +
+
+ + +
+ +
+

Hospital Management System

+

123 Medical Center Street, City, Country

+

Phone: +123 456 7890 | Email: info@hospital.com

+
+ +
+
+
Doctor:
+

+

+
+
+
Date:
+

+
+
+ +
+
+ Patient Name: +
+
+ Age: +
+
+ Gender: +
+
+ +
Rx
+ +
+ +

No medications prescribed.

+ +
+ $p): ?> +
+
+
.
+
+
+
+
+ Dose: +
+
+ Instructions: +
+
+
+
+
+ +
+ +
+ + +
+ + + \ No newline at end of file