496 lines
22 KiB
PHP
496 lines
22 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
require_role('doctor');
|
|
require_once 'db/config.php';
|
|
|
|
// Get doctor ID from session
|
|
$doctor_id = $_SESSION['user_id'] ?? 0;
|
|
|
|
// Fetch today's visits for the logged-in doctor
|
|
try {
|
|
$pdo = db();
|
|
$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]);
|
|
$visits = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$visits = [];
|
|
// In a real app, you'd want to log this error
|
|
}
|
|
|
|
// Fetch doctor's details from users table
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->execute([$doctor_id]);
|
|
$doctor = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$doctor = null;
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Doctor's Dashboard</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
|
|
</head>
|
|
<body>
|
|
|
|
<div class="page-wrapper">
|
|
<!-- Sidebar -->
|
|
<aside class="sidebar">
|
|
<div class="sidebar-header">
|
|
<a href="index.php" class="sidebar-brand">
|
|
<i class="bi bi-heart-pulse-fill"></i>
|
|
<span>ClinicFlow</span>
|
|
</a>
|
|
</div>
|
|
<nav class="sidebar-nav">
|
|
<a href="reception.php" class="nav-link">
|
|
<i class="bi bi-people-fill"></i>
|
|
<span>Reception</span>
|
|
</a>
|
|
<a href="doctor_dashboard.php" class="nav-link active">
|
|
<i class="bi bi-person-fill"></i>
|
|
<span>Doctor</span>
|
|
</a>
|
|
<a href="lab_reports.php" class="nav-link">
|
|
<i class="bi bi-file-earmark-medical"></i>
|
|
<span>Lab Reports</span>
|
|
</a>
|
|
<a href="pharmacy.php" class="nav-link">
|
|
<i class="bi bi-capsule-pill"></i>
|
|
<span>Pharmacy</span>
|
|
</a>
|
|
</nav>
|
|
<div class="sidebar-footer">
|
|
<div class="dropdown">
|
|
<a href="#" class="d-flex align-items-center dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle me-2"></i>
|
|
<strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
|
</a>
|
|
<ul class="dropdown-menu text-small shadow" aria-labelledby="dropdownUser1">
|
|
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
|
|
<!-- Main Content -->
|
|
<main class="main-content">
|
|
<div class="header d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<h1 class="header-title">Doctor's Dashboard</h1>
|
|
<p class="header-subtitle mb-0">Welcome, Dr. <?php echo htmlspecialchars($doctor['username'] ?? 'Doctor'); ?>!</p>
|
|
</div>
|
|
<div class="search-container">
|
|
<input type="text" id="patientSearch" class="form-control" placeholder="Search Patient by Name or ID...">
|
|
<div id="searchResults" class="search-results"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Today's Patients -->
|
|
<div class="content-card">
|
|
<div class="card-header">
|
|
<h5 class="card-title-text"><i class="bi bi-list-ul me-2"></i>Today's Appointments</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Patient ID</th>
|
|
<th>Name</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!empty($visits)):
|
|
foreach ($visits as $visit):
|
|
?>
|
|
<tr id="patient-row-<?php echo $visit['visit_id']; ?>">
|
|
<td><?php echo htmlspecialchars($visit['patient_system_id']); ?></td>
|
|
<td>
|
|
<a href="patient_profile.php?id=<?php echo $visit['patient_id']; ?>"><?php echo htmlspecialchars($visit['patient_name']); ?></a>
|
|
</td>
|
|
<td><span class="badge bg-<?php echo get_status_badge_class($visit['status']); ?>-soft" id="status-<?php echo $visit['visit_id']; ?>"><?php echo htmlspecialchars($visit['status']); ?></span></td>
|
|
<td id="action-cell-<?php echo $visit['visit_id']; ?>">
|
|
<?php echo get_action_buttons($visit); ?>
|
|
</td>
|
|
</tr>
|
|
<tr class="notes-row" id="notes-row-<?php echo $visit['visit_id']; ?>" style="<?php echo $visit['status'] !== 'In Progress' ? 'display: none;' : ''; ?>">
|
|
<td colspan="4">
|
|
<form class="notes-form" data-visit-id="<?php echo $visit['visit_id']; ?>">
|
|
<div class="mb-3">
|
|
<label for="notes-<?php echo $visit['visit_id']; ?>" class="form-label">Consultation Notes</label>
|
|
<textarea class="form-control" id="notes-<?php echo $visit['visit_id']; ?>" rows="3"><?php echo htmlspecialchars($visit['notes'] ?? ''); ?></textarea>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-8 mb-3">
|
|
<label for="service-<?php echo $visit['visit_id']; ?>" class="form-label">Service Rendered</label>
|
|
<input type="text" class="form-control" id="service-<?php echo $visit['visit_id']; ?>" placeholder="e.g., General Consultation">
|
|
</div>
|
|
<div class="col-md-4 mb-3">
|
|
<label for="cost-<?php echo $visit['visit_id']; ?>" class="form-label">Cost ($)</label>
|
|
<input type="number" class="form-control" id="cost-<?php echo $visit['visit_id']; ?>" placeholder="e.g., 75.00" step="0.01">
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="btn btn-sm btn-success">
|
|
<i class="bi bi-check-circle me-1"></i>Complete Consultation & Bill
|
|
</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php else:
|
|
?>
|
|
<tr>
|
|
<td colspan="4" class="text-center text-muted">No patients assigned for today.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<!-- Prescription Modal -->
|
|
<div class="modal fade" id="prescriptionModal" tabindex="-1" aria-labelledby="prescriptionModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="prescriptionModalLabel">Add Prescription</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="prescriptionForm">
|
|
<input type="hidden" id="prescriptionVisitId" name="visit_id">
|
|
<div class="mb-3">
|
|
<label for="medication" class="form-label">Medication</label>
|
|
<input type="text" class="form-control" id="medication" name="medication" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="dosage" class="form-label">Dosage</label>
|
|
<input type="text" class="form-control" id="dosage" name="dosage" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="frequency" class="form-label">Frequency</label>
|
|
<input type="text" class="form-control" id="frequency" name="frequency" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="prescriptionNotes" class="form-label">Notes</label>
|
|
<textarea class="form-control" id="prescriptionNotes" name="notes" rows="3"></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save Prescription</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Order Tests Modal -->
|
|
<div class="modal fade" id="orderTestsModal" tabindex="-1" aria-labelledby="orderTestsModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="orderTestsModalLabel">Order Tests</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="orderTestsForm">
|
|
<input type="hidden" id="orderVisitId" name="visit_id">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<h5>Lab Tests</h5>
|
|
<div id="lab-tests-list" class="list-group" style="max-height: 300px; overflow-y: auto;">
|
|
<!-- JS will populate this -->
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h5>Imaging Tests</h5>
|
|
<div id="imaging-tests-list" class="list-group" style="max-height: 300px; overflow-y: auto;">
|
|
<!-- JS will populate this -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="mt-3">
|
|
<button type="submit" class="btn btn-primary">Order Selected Tests</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
document.addEventListener('click', function(e) {
|
|
if (e.target.matches('.start-consultation-btn')) {
|
|
const visitId = e.target.dataset.visitId;
|
|
updatePatientStatus(visitId, 'In Progress');
|
|
}
|
|
|
|
if (e.target.matches('.prescribe-btn')) {
|
|
const visitId = e.target.dataset.visitId;
|
|
document.getElementById('prescriptionVisitId').value = visitId;
|
|
}
|
|
|
|
if (e.target.matches('.order-tests-btn')) {
|
|
const visitId = e.target.dataset.visitId;
|
|
document.getElementById('orderVisitId').value = visitId;
|
|
loadTestsForModal();
|
|
}
|
|
});
|
|
|
|
document.addEventListener('submit', function(e) {
|
|
if (e.target.matches('.notes-form')) {
|
|
e.preventDefault();
|
|
const visitId = e.target.dataset.visitId;
|
|
const notes = document.getElementById('notes-' + visitId).value;
|
|
const service = document.getElementById('service-' + visitId).value;
|
|
const cost = document.getElementById('cost-' + visitId).value;
|
|
updatePatientStatus(visitId, 'Completed', notes, service, cost);
|
|
}
|
|
|
|
if (e.target.matches('#prescriptionForm')) {
|
|
e.preventDefault();
|
|
const formData = new FormData(e.target);
|
|
|
|
fetch('add_prescription.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('Prescription saved successfully!');
|
|
const modal = bootstrap.Modal.getInstance(document.getElementById('prescriptionModal'));
|
|
modal.hide();
|
|
e.target.reset();
|
|
} else {
|
|
alert('Error: ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('An unexpected error occurred while saving the prescription.');
|
|
});
|
|
}
|
|
|
|
if (e.target.matches('#orderTestsForm')) {
|
|
e.preventDefault();
|
|
const formData = new FormData(e.target);
|
|
|
|
fetch('order_tests.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('Tests ordered successfully!');
|
|
const modal = bootstrap.Modal.getInstance(document.getElementById('orderTestsModal'));
|
|
modal.hide();
|
|
e.target.reset();
|
|
} else {
|
|
alert('Error: ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('An unexpected error occurred while ordering tests.');
|
|
});
|
|
}
|
|
});
|
|
|
|
function loadTestsForModal() {
|
|
fetch('get_tests.php')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
const labList = document.getElementById('lab-tests-list');
|
|
const imagingList = document.getElementById('imaging-tests-list');
|
|
labList.innerHTML = '';
|
|
imagingList.innerHTML = '';
|
|
|
|
data.lab_tests.forEach(test => {
|
|
labList.innerHTML += `
|
|
<label class="list-group-item">
|
|
<input class="form-check-input me-1" type="checkbox" name="lab_tests[]" value="${test.test_id}">
|
|
${test.test_name}
|
|
</label>`;
|
|
});
|
|
|
|
data.imaging_tests.forEach(test => {
|
|
imagingList.innerHTML += `
|
|
<label class="list-group-item">
|
|
<input class="form-check-input me-1" type="checkbox" name="imaging_tests[]" value="${test.test_id}">
|
|
${test.test_name}
|
|
</label>`;
|
|
});
|
|
} else {
|
|
alert('Could not load tests: ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error loading tests:', error);
|
|
alert('An error occurred while fetching tests.');
|
|
});
|
|
}
|
|
|
|
function updatePatientStatus(visitId, status, notes = null, service = null, cost = null) {
|
|
const formData = new FormData();
|
|
formData.append('visit_id', visitId);
|
|
formData.append('status', status);
|
|
if (notes !== null) {
|
|
formData.append('notes', notes);
|
|
}
|
|
if (service !== null) {
|
|
formData.append('service_rendered', service);
|
|
}
|
|
if (cost !== null) {
|
|
formData.append('cost', cost);
|
|
}
|
|
|
|
fetch('update_patient_status.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Update status badge
|
|
const statusBadge = document.getElementById('status-' + visitId);
|
|
statusBadge.textContent = status;
|
|
statusBadge.className = 'badge bg-' + data.status_class + '-soft';
|
|
|
|
// Update action buttons/form
|
|
const actionCell = document.getElementById('action-cell-' + visitId);
|
|
const notesRow = document.getElementById('notes-row-' + visitId);
|
|
if (status === 'In Progress') {
|
|
actionCell.innerHTML = get_action_buttons({ status: 'In Progress', visit_id: visitId });
|
|
notesRow.style.display = 'table-row';
|
|
} else if (status === 'Completed') {
|
|
actionCell.innerHTML = get_action_buttons({ status: 'Completed', visit_id: visitId });
|
|
notesRow.style.display = 'none';
|
|
}
|
|
} else {
|
|
alert('Error: ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('An unexpected error occurred.');
|
|
});
|
|
}
|
|
|
|
document.getElementById('patientSearch').addEventListener('input', function() {
|
|
const searchTerm = this.value;
|
|
const resultsContainer = document.getElementById('searchResults');
|
|
|
|
if (searchTerm.length < 2) {
|
|
resultsContainer.innerHTML = '';
|
|
resultsContainer.style.display = 'none';
|
|
return;
|
|
}
|
|
|
|
fetch(`search_patient.php?term=${encodeURIComponent(searchTerm)}`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
resultsContainer.innerHTML = '';
|
|
if (data.length > 0) {
|
|
data.forEach(patient => {
|
|
const patientLink = document.createElement('a');
|
|
patientLink.href = `patient_profile.php?id=${patient.id}`;
|
|
patientLink.textContent = `${patient.patient_name} (${patient.patient_id})`;
|
|
resultsContainer.appendChild(patientLink);
|
|
});
|
|
resultsContainer.style.display = 'block';
|
|
} else {
|
|
resultsContainer.innerHTML = '<a href="#" class="disabled">No patients found</a>';
|
|
resultsContainer.style.display = 'block';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
resultsContainer.innerHTML = '<a href="#" class="disabled">Search error</a>';
|
|
resultsContainer.style.display = 'block';
|
|
});
|
|
});
|
|
|
|
// Hide results when clicking outside
|
|
document.addEventListener('click', function(e) {
|
|
const searchContainer = document.querySelector('.search-container');
|
|
if (searchContainer && !searchContainer.contains(e.target)) {
|
|
const resultsContainer = document.getElementById('searchResults');
|
|
if (resultsContainer) {
|
|
resultsContainer.style.display = 'none';
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|
|
<?php
|
|
function get_status_badge_class($status) {
|
|
switch ($status) {
|
|
case 'Pending':
|
|
return 'warning';
|
|
case 'In Progress':
|
|
return 'info';
|
|
case 'Completed':
|
|
return 'success';
|
|
default:
|
|
return 'secondary';
|
|
}
|
|
}
|
|
|
|
function get_action_buttons($visit) {
|
|
$status = $visit['status'];
|
|
$visit_id = $visit['visit_id'];
|
|
$patient_id = $visit['patient_id'] ?? 0;
|
|
|
|
$buttons = '';
|
|
|
|
switch ($status) {
|
|
case 'Pending':
|
|
$buttons .= '<button class="btn btn-sm btn-primary start-consultation-btn" data-visit-id="' . $visit_id . '"><i class="bi bi-play-circle me-1"></i>Start Consultation</button>';
|
|
break;
|
|
case 'In Progress':
|
|
// The form is shown, but we can add a prescribe button here too
|
|
$buttons .= '<button class="btn btn-sm btn-info prescribe-btn" data-bs-toggle="modal" data-bs-target="#prescriptionModal" data-visit-id="' . $visit_id . '" data-patient-id="' . $patient_id . '"><i class="bi bi-pen me-1"></i>Prescribe</button>';
|
|
$buttons .= ' <button class="btn btn-sm btn-secondary order-tests-btn" data-bs-toggle="modal" data-bs-target="#orderTestsModal" data-visit-id="' . $visit_id . '"><i class="bi bi-eyedropper me-1"></i>Order Tests</button>';
|
|
break;
|
|
case 'Completed':
|
|
$buttons .= '<span class="text-success"><i class="bi bi-check-circle-fill me-1"></i>Completed</span>';
|
|
$buttons .= ' <button class="btn btn-sm btn-outline-primary prescribe-btn" data-bs-toggle="modal" data-bs-target="#prescriptionModal" data-visit-id="' . $visit_id . '" data-patient-id="' . $patient_id . '"><i class="bi bi-pen me-1"></i>Add/View Prescription</button>';
|
|
$buttons .= ' <button class="btn btn-sm btn-outline-secondary order-tests-btn" data-bs-toggle="modal" data-bs-target="#orderTestsModal" data-visit-id="' . $visit_id . '"><i class="bi bi-eyedropper me-1"></i>Order/View Tests</button>';
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return $buttons;
|
|
}
|
|
?>
|