From c8d83e1d5c2aa222dec57191d39f00b26e838313 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 25 Nov 2025 08:14:18 +0000 Subject: [PATCH] version 2 --- add_prescription.php | 43 ++++++ alter_visits_table.php | 12 ++ billing.php | 56 +++++--- dispense.php | 34 +++++ doctor_dashboard.php | 283 ++++++++++++++++++++++++++++++++------ enter_results.php | 32 +++++ get_tests.php | 18 +++ invoice.php | 95 +++++++++---- lab_imaging_config.php | 151 ++++++++++++++++++++ lab_reports.php | 199 +++++++++++++++++++++++++++ order_tests.php | 42 ++++++ patient_profile.php | 260 +++++++++++++++++++++++++++------- pharmacy.php | 165 ++++++++++++++++++++++ prescription_view.php | 134 ++++++++++++++++++ reception.php | 12 ++ update_patient_status.php | 21 +-- 16 files changed, 1406 insertions(+), 151 deletions(-) create mode 100644 add_prescription.php create mode 100644 alter_visits_table.php create mode 100644 dispense.php create mode 100644 enter_results.php create mode 100644 get_tests.php create mode 100644 lab_imaging_config.php create mode 100644 lab_reports.php create mode 100644 order_tests.php create mode 100644 pharmacy.php create mode 100644 prescription_view.php diff --git a/add_prescription.php b/add_prescription.php new file mode 100644 index 0000000..106e476 --- /dev/null +++ b/add_prescription.php @@ -0,0 +1,43 @@ + false, 'message' => 'An unknown error occurred.']; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $visit_id = $_POST['visit_id'] ?? null; + $patient_id = $_POST['patient_id'] ?? null; + $medication = $_POST['medication'] ?? null; + $dosage = $_POST['dosage'] ?? null; + $frequency = $_POST['frequency'] ?? null; + $notes = $_POST['notes'] ?? ''; + $doctor_id = $_SESSION['user_id'] ?? null; + + if ($visit_id && $patient_id && $doctor_id && $medication && $dosage && $frequency) { + try { + $pdo = db(); + $stmt = $pdo->prepare( + "INSERT INTO prescriptions (visit_id, patient_id, doctor_id, medication, dosage, frequency, notes) + VALUES (?, ?, ?, ?, ?, ?, ?)" + ); + $stmt->execute([$visit_id, $patient_id, $doctor_id, $medication, $dosage, $frequency, $notes]); + + $response['success'] = true; + $response['message'] = 'Prescription saved successfully.'; + + } catch (PDOException $e) { + // In a real app, log this error instead of echoing it. + $response['message'] = 'Database error: ' . $e->getMessage(); + } + } else { + $response['message'] = 'Invalid or missing data provided.'; + } +} else { + $response['message'] = 'Invalid request method.'; +} + +echo json_encode($response); +?> \ No newline at end of file diff --git a/alter_visits_table.php b/alter_visits_table.php new file mode 100644 index 0000000..dd3d163 --- /dev/null +++ b/alter_visits_table.php @@ -0,0 +1,12 @@ +exec($sql); + echo "Table 'patient_visits' altered successfully. Column 'id' renamed to 'visit_id'.\n"; +} catch (PDOException $e) { + die("Database error: " . $e->getMessage()); +} +?> \ No newline at end of file diff --git a/billing.php b/billing.php index fea00f0..315cf3d 100644 --- a/billing.php +++ b/billing.php @@ -5,13 +5,12 @@ require_once 'db/config.php'; // Handle status update if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'mark_paid') { - $patient_id_to_update = $_POST['patient_id'] ?? null; - if ($patient_id_to_update) { + $visit_id_to_update = $_POST['visit_id'] ?? null; + if ($visit_id_to_update) { try { $pdo = db(); - $stmt = $pdo->prepare("UPDATE patients SET payment_status = 'paid' WHERE id = ?"); - $stmt->execute([$patient_id_to_update]); - // Redirect to avoid form resubmission + $stmt = $pdo->prepare("UPDATE patient_visits SET payment_status = 'paid' WHERE visit_id = ?"); + $stmt->execute([$visit_id_to_update]); header("Location: billing.php"); exit; } catch (PDOException $e) { @@ -20,15 +19,31 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' } } -// Fetch unpaid patients +// Fetch unpaid visits and calculate total cost try { $pdo = db(); - $stmt = $pdo->prepare("SELECT p.*, u.username as doctor_name FROM patients p JOIN users u ON p.doctor_id = u.id WHERE p.status = 'Completed' AND p.payment_status = 'unpaid' ORDER BY p.updated_at DESC"); + $stmt = $pdo->prepare( + "SELECT + pv.visit_id, + pv.cost as consultation_fee, + p.patient_name, + p.id as patient_id, + u.username as doctor_name, + pv.service_rendered, + COALESCE((SELECT SUM(lt.cost) FROM ordered_tests ot JOIN lab_tests lt ON ot.test_id = lt.test_id WHERE ot.visit_id = pv.visit_id AND ot.test_type = 'lab'), 0) as lab_tests_cost, + COALESCE((SELECT SUM(it.cost) FROM ordered_tests ot JOIN imaging_tests it ON ot.test_id = it.test_id WHERE ot.visit_id = pv.visit_id AND ot.test_type = 'imaging'), 0) as imaging_tests_cost + FROM patient_visits pv + JOIN patients p ON pv.patient_id = p.id + JOIN users u ON pv.doctor_id = u.id + WHERE pv.status = 'Completed' AND pv.payment_status = 'unpaid' + ORDER BY pv.visit_time DESC" + ); $stmt->execute(); - $unpaid_patients = $stmt->fetchAll(PDO::FETCH_ASSOC); + $unpaid_visits = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { - $unpaid_patients = []; - // Log error + $unpaid_visits = []; + // You should log the error in a real application + // error_log($e->getMessage()); } ?> @@ -101,26 +116,27 @@ try { Patient Name Doctor Service Rendered - Cost + Total Bill Action - - - Dr. - - $ + + Dr. + + $
- +
- Invoice + Invoice @@ -141,4 +157,4 @@ try { - + \ No newline at end of file diff --git a/dispense.php b/dispense.php new file mode 100644 index 0000000..3ace9ac --- /dev/null +++ b/dispense.php @@ -0,0 +1,34 @@ + false, 'message' => 'Invalid request.']; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $prescription_id = $_POST['prescription_id'] ?? null; + $user_id = $_SESSION['user_id'] ?? null; + + if ($prescription_id && $user_id) { + try { + $pdo = db(); + $stmt = $pdo->prepare( + "UPDATE prescriptions SET status = 'Dispensed', dispensed_at = CURRENT_TIMESTAMP, dispensed_by = ? WHERE id = ?" + ); + + if ($stmt->execute([$user_id, $prescription_id])) { + $response = ['success' => true, 'message' => 'Prescription marked as dispensed.']; + } else { + $response['message'] = 'Failed to update prescription status.'; + } + } catch (PDOException $e) { + $response['message'] = 'Database error: ' . $e->getMessage(); + } + } else { + $response['message'] = 'Missing prescription ID or user not logged in.'; + } +} + +echo json_encode($response); +?> \ No newline at end of file diff --git a/doctor_dashboard.php b/doctor_dashboard.php index 84f1158..93901a9 100644 --- a/doctor_dashboard.php +++ b/doctor_dashboard.php @@ -4,17 +4,28 @@ require_role('doctor'); require_once 'db/config.php'; // Get doctor ID from session -$doctor_id = $_SESSION['user_id'] ?? 0; // Default to 0 if not set +$doctor_id = $_SESSION['user_id'] ?? 0; -// Fetch patients assigned to the doctor +// Fetch today's visits for the logged-in doctor try { $pdo = db(); - // Corrected to fetch patients for the logged-in doctor based on the user_id which corresponds to the doctor's ID in the `doctors` table - $stmt = $pdo->prepare("SELECT p.* FROM patients p JOIN users u ON p.doctor_id = u.id WHERE u.id = ? AND DATE(p.created_at) = CURDATE() ORDER BY p.created_at DESC"); + $stmt = $pdo->prepare( + "SELECT + pv.id as visit_id, + pv.status, + pv.notes, + p.id as patient_id, + p.patient_id as patient_system_id, + p.patient_name + FROM patient_visits pv + JOIN patients p ON pv.patient_id = p.id + WHERE pv.doctor_id = ? AND DATE(pv.visit_time) = CURDATE() + ORDER BY pv.visit_time DESC" + ); $stmt->execute([$doctor_id]); - $patients = $stmt->fetchAll(PDO::FETCH_ASSOC); + $visits = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { - $patients = []; + $visits = []; // In a real app, you'd want to log this error } @@ -60,6 +71,14 @@ try { Doctor + + + Lab Reports + + + + Pharmacy +