diff --git a/assets/images/logo_1772630133.png b/assets/images/logo_1772630133.png new file mode 100644 index 0000000..eef6921 Binary files /dev/null and b/assets/images/logo_1772630133.png differ diff --git a/assets/images/logo_1772630277.png b/assets/images/logo_1772630277.png new file mode 100644 index 0000000..33a1f2d Binary files /dev/null and b/assets/images/logo_1772630277.png differ diff --git a/assets/uploads/xrays/1772636719_file_0000000075d072469947147bc1c7d810.png b/assets/uploads/xrays/1772636719_file_0000000075d072469947147bc1c7d810.png new file mode 100644 index 0000000..33a1f2d Binary files /dev/null and b/assets/uploads/xrays/1772636719_file_0000000075d072469947147bc1c7d810.png differ diff --git a/db/migrations/20260304_add_attachment_to_lab_tests.sql b/db/migrations/20260304_add_attachment_to_lab_tests.sql new file mode 100644 index 0000000..81318ff --- /dev/null +++ b/db/migrations/20260304_add_attachment_to_lab_tests.sql @@ -0,0 +1,30 @@ +-- Migration: Add attachment to inquiry_tests +-- This table might have been created by previous agents or manually + +CREATE TABLE IF NOT EXISTS inquiry_tests ( + id INT AUTO_INCREMENT PRIMARY KEY, + inquiry_id INT, + test_id INT, + result VARCHAR(255), + normal_range VARCHAR(255), + attachment VARCHAR(255), + FOREIGN KEY (inquiry_id) REFERENCES laboratory_inquiries(id) ON DELETE CASCADE, + FOREIGN KEY (test_id) REFERENCES laboratory_tests(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +-- Ensure attachment column exists (in case inquiry_tests already existed without it) +SET @dbname = DATABASE(); +SET @tablename = "inquiry_tests"; +SET @columnname = "attachment"; +SET @preparedStatement = (SELECT IF( + (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = @dbname + AND TABLE_NAME = @tablename + AND COLUMN_NAME = @columnname + ) > 0, + "SELECT 1", + "ALTER TABLE inquiry_tests ADD COLUMN attachment VARCHAR(255) AFTER normal_range" +)); +PREPARE stmt FROM @preparedStatement; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; diff --git a/db/migrations/20260304_add_attachment_to_xrays.sql b/db/migrations/20260304_add_attachment_to_xrays.sql new file mode 100644 index 0000000..7cc5a81 --- /dev/null +++ b/db/migrations/20260304_add_attachment_to_xrays.sql @@ -0,0 +1,2 @@ +-- Add attachment column to xray_inquiry_items to store uploaded images/results +ALTER TABLE xray_inquiry_items ADD COLUMN attachment VARCHAR(255) DEFAULT NULL; diff --git a/db/migrations/20260304_create_settings_table.sql b/db/migrations/20260304_create_settings_table.sql new file mode 100644 index 0000000..599edce --- /dev/null +++ b/db/migrations/20260304_create_settings_table.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS settings ( + id INT AUTO_INCREMENT PRIMARY KEY, + setting_key VARCHAR(100) NOT NULL UNIQUE, + setting_value TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +); + +INSERT INTO settings (setting_key, setting_value) VALUES +('company_name', 'Hospital Management System'), +('company_logo', ''), +('company_favicon', ''), +('company_ctr_no', ''), +('company_registration_no', ''), +('company_address', ''), +('company_phone', ''), +('company_email', ''), +('company_vat_no', ''); diff --git a/db/migrations/20260304_link_inquiries_to_visits.sql b/db/migrations/20260304_link_inquiries_to_visits.sql new file mode 100644 index 0000000..81ec9b9 --- /dev/null +++ b/db/migrations/20260304_link_inquiries_to_visits.sql @@ -0,0 +1,15 @@ + +-- Update laboratory_inquiries and xray_inquiries to link with patients and visits +ALTER TABLE laboratory_inquiries ADD COLUMN patient_id INT NULL AFTER id; +ALTER TABLE laboratory_inquiries ADD COLUMN visit_id INT NULL AFTER patient_id; +ALTER TABLE laboratory_inquiries MODIFY patient_name VARCHAR(255) NULL; + +ALTER TABLE laboratory_inquiries ADD CONSTRAINT fk_lab_patient FOREIGN KEY (patient_id) REFERENCES patients(id) ON DELETE CASCADE; +ALTER TABLE laboratory_inquiries ADD CONSTRAINT fk_lab_visit FOREIGN KEY (visit_id) REFERENCES visits(id) ON DELETE SET NULL; + +ALTER TABLE xray_inquiries ADD COLUMN patient_id INT NULL AFTER id; +ALTER TABLE xray_inquiries ADD COLUMN visit_id INT NULL AFTER patient_id; +ALTER TABLE xray_inquiries MODIFY patient_name VARCHAR(255) NULL; + +ALTER TABLE xray_inquiries ADD CONSTRAINT fk_xray_patient FOREIGN KEY (patient_id) REFERENCES patients(id) ON DELETE CASCADE; +ALTER TABLE xray_inquiries ADD CONSTRAINT fk_xray_visit FOREIGN KEY (visit_id) REFERENCES visits(id) ON DELETE SET NULL; diff --git a/includes/actions.php b/includes/actions.php index b821b39..9af1905 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -3,6 +3,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { require_once __DIR__ . '/../db/config.php'; require_once __DIR__ . '/../helpers.php'; $db = db(); + function upload_file($file_array, $index, $target_dir = "assets/uploads/") { + if (!isset($file_array["name"][$index]) || $file_array["error"][$index] !== UPLOAD_ERR_OK) { + return null; + } + if (!is_dir(__DIR__ . "/../" . $target_dir)) { + mkdir(__DIR__ . "/../" . $target_dir, 0775, true); + } + $filename = time() . "_" . basename($file_array["name"][$index]); + $target_file = $target_dir . $filename; + if (move_uploaded_file($file_array["tmp_name"][$index], __DIR__ . "/../" . $target_file)) { + return $target_file; + } + return null; + } $lang = $_SESSION['lang'] ?? 'en'; $redirect = false; @@ -408,15 +422,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($patient_name) { $db->beginTransaction(); - $stmt = $db->prepare("INSERT INTO laboratory_inquiries (patient_name, source, inquiry_date, status, notes) VALUES (?, ?, ?, ?, ?)"); - $stmt->execute([$patient_name, $source, $date, $status, $notes]); + $stmt = $db->prepare("INSERT INTO laboratory_inquiries (patient_id, visit_id, patient_name, source, inquiry_date, status, notes) VALUES (?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$_POST['patient_id'] ?: null, $_POST['visit_id'] ?: null, $patient_name, $source, $date, $status, $notes]); $inquiry_id = $db->lastInsertId(); if (!empty($test_ids)) { - $testStmt = $db->prepare("INSERT INTO inquiry_tests (inquiry_id, test_id, result) VALUES (?, ?, ?)"); + $testStmt = $db->prepare("INSERT INTO inquiry_tests (inquiry_id, test_id, result, attachment) VALUES (?, ?, ?, ?)"); foreach ($test_ids as $index => $tid) { if ($tid) { - $testStmt->execute([$inquiry_id, $tid, $results[$index] ?? '']); + $attachment = upload_file($_FILES['attachments'] ?? null, $index, "assets/uploads/labs/"); + $testStmt->execute([$inquiry_id, $tid, $results[$index] ?? '', $attachment]); } } } @@ -429,6 +444,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $patient_name = $_POST['patient_name'] ?? ''; $test_ids = $_POST['test_ids'] ?? []; $results = $_POST['results'] ?? []; + $existing_attachments = $_POST['existing_attachments'] ?? []; $source = $_POST['source'] ?? 'Internal'; $date = $_POST['inquiry_date'] ?: date('Y-m-d H:i'); $status = $_POST['status'] ?? 'Pending'; @@ -436,18 +452,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($id && $patient_name) { $db->beginTransaction(); - $stmt = $db->prepare("UPDATE laboratory_inquiries SET patient_name = ?, source = ?, inquiry_date = ?, status = ?, notes = ? WHERE id = ?"); - $stmt->execute([$patient_name, $source, $date, $status, $notes, $id]); + $stmt = $db->prepare("UPDATE laboratory_inquiries SET patient_id = ?, visit_id = ?, patient_name = ?, source = ?, inquiry_date = ?, status = ?, notes = ? WHERE id = ?"); + $stmt->execute([$_POST['patient_id'] ?: null, $_POST['visit_id'] ?: null, $patient_name, $source, $date, $status, $notes, $id]); // Remove old tests and insert new ones $stmt = $db->prepare("DELETE FROM inquiry_tests WHERE inquiry_id = ?"); $stmt->execute([$id]); if (!empty($test_ids)) { - $testStmt = $db->prepare("INSERT INTO inquiry_tests (inquiry_id, test_id, result) VALUES (?, ?, ?)"); + $testStmt = $db->prepare("INSERT INTO inquiry_tests (inquiry_id, test_id, result, attachment) VALUES (?, ?, ?, ?)"); foreach ($test_ids as $index => $tid) { if ($tid) { - $testStmt->execute([$id, $tid, $results[$index] ?? '']); + $attachment = upload_file($_FILES['attachments'] ?? null, $index, "assets/uploads/labs/") ?: ($existing_attachments[$index] ?? null); + $testStmt->execute([$id, $tid, $results[$index] ?? '', $attachment]); } } } @@ -531,14 +548,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $notes = $_POST['notes'] ?? ''; if ($patient_name) { $db->beginTransaction(); - $stmt = $db->prepare("INSERT INTO xray_inquiries (patient_name, source, inquiry_date, status, notes) VALUES (?, ?, ?, ?, ?)"); - $stmt->execute([$patient_name, $source, $date, $status, $notes]); + $stmt = $db->prepare("INSERT INTO xray_inquiries (patient_id, visit_id, patient_name, source, inquiry_date, status, notes) VALUES (?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$_POST['patient_id'] ?: null, $_POST['visit_id'] ?: null, $patient_name, $source, $date, $status, $notes]); $inquiry_id = $db->lastInsertId(); if (!empty($xray_ids)) { - $testStmt = $db->prepare("INSERT INTO xray_inquiry_items (inquiry_id, xray_id, result) VALUES (?, ?, ?)"); + $testStmt = $db->prepare("INSERT INTO xray_inquiry_items (inquiry_id, xray_id, result, attachment) VALUES (?, ?, ?, ?)"); foreach ($xray_ids as $index => $tid) { if ($tid) { - $testStmt->execute([$inquiry_id, $tid, $results[$index] ?? '']); + $attachment = upload_file($_FILES['attachments'] ?? null, $index, "assets/uploads/xrays/"); + $testStmt->execute([$inquiry_id, $tid, $results[$index] ?? '', $attachment]); } } } @@ -550,6 +568,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = $_POST['id'] ?? ''; $patient_name = $_POST['patient_name'] ?? ''; $xray_ids = $_POST['xray_ids'] ?? []; + $existing_attachments = $_POST['existing_attachments'] ?? []; $results = $_POST['results'] ?? []; $source = $_POST['source'] ?? 'Internal'; $date = $_POST['inquiry_date'] ?: date('Y-m-d H:i'); @@ -557,15 +576,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $notes = $_POST['notes'] ?? ''; if ($id && $patient_name) { $db->beginTransaction(); - $stmt = $db->prepare("UPDATE xray_inquiries SET patient_name = ?, source = ?, inquiry_date = ?, status = ?, notes = ? WHERE id = ?"); - $stmt->execute([$patient_name, $source, $date, $status, $notes, $id]); + $stmt = $db->prepare("UPDATE xray_inquiries SET patient_id = ?, visit_id = ?, patient_name = ?, source = ?, inquiry_date = ?, status = ?, notes = ? WHERE id = ?"); + $stmt->execute([$_POST['patient_id'] ?: null, $_POST['visit_id'] ?: null, $patient_name, $source, $date, $status, $notes, $id]); $stmt = $db->prepare("DELETE FROM xray_inquiry_items WHERE inquiry_id = ?"); $stmt->execute([$id]); if (!empty($xray_ids)) { - $testStmt = $db->prepare("INSERT INTO xray_inquiry_items (inquiry_id, xray_id, result) VALUES (?, ?, ?)"); + $testStmt = $db->prepare("INSERT INTO xray_inquiry_items (inquiry_id, xray_id, result, attachment) VALUES (?, ?, ?, ?)"); foreach ($xray_ids as $index => $tid) { if ($tid) { - $testStmt->execute([$id, $tid, $results[$index] ?? '']); + $attachment = upload_file($_FILES['attachments'] ?? null, $index, "assets/uploads/xrays/") ?: ($existing_attachments[$index] ?? null); + $testStmt->execute([$id, $tid, $results[$index] ?? '', $attachment]); } } } @@ -588,4 +608,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { header("Location: " . $_SERVER['REQUEST_URI']); exit; } -} \ No newline at end of file +} diff --git a/includes/layout/footer.php b/includes/layout/footer.php index 1f7271f..b1b0841 100644 --- a/includes/layout/footer.php +++ b/includes/layout/footer.php @@ -7,7 +7,7 @@
@@ -64,7 +83,11 @@ $message = $message ?? '';diff --git a/includes/layout/header.php b/includes/layout/header.php index 202bb46..cbf757f 100644 --- a/includes/layout/header.php +++ b/includes/layout/header.php @@ -7,13 +7,26 @@ $lang = $_SESSION['lang']; $section = $section ?? 'dashboard'; $message = $message ?? ''; +// Fetch company settings for dynamic branding +$stmt = $db->query("SELECT setting_key, setting_value FROM settings WHERE setting_key IN ('company_name', 'company_logo', 'company_favicon')"); +$site_settings = []; +while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $site_settings[$row['setting_key']] = $row['setting_value']; +} +$site_name = !empty($site_settings['company_name']) ? $site_settings['company_name'] : __('hospital_management'); +$site_logo = !empty($site_settings['company_logo']) ? $site_settings['company_logo'] : null; +$site_favicon = !empty($site_settings['company_favicon']) ? $site_settings['company_favicon'] : null; + ?>
-
+
+ + + @@ -24,6 +37,8 @@ $message = $message ?? ''; + +