280 lines
11 KiB
PHP
280 lines
11 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
require_role('receptionist'); // For now, accessible by receptionists
|
|
require_once 'db/config.php';
|
|
|
|
$pdo = db();
|
|
|
|
// Fetch all ordered tests that are not yet completed
|
|
$pending_tests_stmt = $pdo->prepare(
|
|
"SELECT
|
|
ot.order_id,
|
|
ot.ordered_at,
|
|
ot.test_type,
|
|
ot.status,
|
|
p.patient_name,
|
|
p.id as patient_id,
|
|
CASE
|
|
WHEN ot.test_type = 'lab' THEN lt.test_name
|
|
WHEN ot.test_type = 'imaging' THEN it.test_name
|
|
END as test_name,
|
|
u.username as doctor_name
|
|
FROM ordered_tests ot
|
|
JOIN patient_visits pv ON ot.visit_id = pv.visit_id
|
|
JOIN patients p ON pv.patient_id = p.id
|
|
JOIN users u ON pv.doctor_id = u.id
|
|
LEFT JOIN lab_tests lt ON ot.test_type = 'lab' AND ot.test_id = lt.test_id
|
|
LEFT JOIN imaging_tests it ON ot.test_type = 'imaging' AND ot.test_id = it.test_id
|
|
WHERE ot.status = 'Ordered'
|
|
ORDER BY ot.ordered_at ASC"
|
|
);
|
|
$pending_tests_stmt->execute();
|
|
$pending_tests = $pending_tests_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Lab & Imaging Reports</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
<style>
|
|
.search-container {
|
|
position: relative;
|
|
width: 100%;
|
|
max-width: 400px;
|
|
}
|
|
.search-results {
|
|
position: absolute;
|
|
top: 100%;
|
|
left: 0;
|
|
right: 0;
|
|
z-index: 1000;
|
|
border: 1px solid #ccc;
|
|
background-color: #fff;
|
|
border-radius: 0 0 5px 5px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
display: none;
|
|
}
|
|
.search-results a {
|
|
display: block;
|
|
padding: 10px;
|
|
text-decoration: none;
|
|
color: #333;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
.search-results a:hover {
|
|
background-color: #f5f5f5;
|
|
}
|
|
.search-results a:last-child {
|
|
border-bottom: none;
|
|
}
|
|
</style>
|
|
</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">
|
|
<i class="bi bi-person-fill"></i>
|
|
<span>Doctor</span>
|
|
</a>
|
|
<a href="lab_reports.php" class="nav-link active">
|
|
<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 text-white text-decoration-none 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 dropdown-menu-dark 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">
|
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h3 mb-0 text-gray-800">Pending Lab & Imaging Reports</h1>
|
|
<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>
|
|
</header>
|
|
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Date Ordered</th>
|
|
<th>Patient</th>
|
|
<th>Test Name</th>
|
|
<th>Type</th>
|
|
<th>Ordered By</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($pending_tests)): ?>
|
|
<tr>
|
|
<td colspan="7" class="text-center">No pending tests found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($pending_tests as $test): ?>
|
|
<tr>
|
|
<td><?= date("d M, Y", strtotime($test['ordered_at'])) ?></td>
|
|
<td><a href="patient_profile.php?id=<?= $test['patient_id'] ?>"><?= htmlspecialchars($test['patient_name']) ?></a></td>
|
|
<td><?= htmlspecialchars($test['test_name']) ?></td>
|
|
<td><?= htmlspecialchars(ucfirst($test['test_type'])) ?></td>
|
|
<td>Dr. <?= htmlspecialchars($test['doctor_name'] ?? 'N/A') ?></td>
|
|
<td><span class="badge bg-warning-soft"><?= htmlspecialchars($test['status']) ?></span></td>
|
|
<td>
|
|
<button class="btn btn-sm btn-primary enter-results-btn" data-bs-toggle="modal" data-bs-target="#resultsModal" data-order-id="<?= $test['order_id'] ?>">Enter Results</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<!-- Enter Results Modal -->
|
|
<div class="modal fade" id="resultsModal" tabindex="-1" aria-labelledby="resultsModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="resultsModalLabel">Enter Test Results</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="resultsForm">
|
|
<input type="hidden" id="orderId" name="order_id">
|
|
<div class="mb-3">
|
|
<label for="resultsText" class="form-label">Results</label>
|
|
<textarea class="form-control" id="resultsText" name="results" rows="5" required></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save Results & Complete</button>
|
|
</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('.enter-results-btn')) {
|
|
const orderId = e.target.dataset.orderId;
|
|
document.getElementById('orderId').value = orderId;
|
|
}
|
|
});
|
|
|
|
document.addEventListener('submit', function(e) {
|
|
if (e.target.matches('#resultsForm')) {
|
|
e.preventDefault();
|
|
const formData = new FormData(e.target);
|
|
const orderId = formData.get('order_id');
|
|
|
|
fetch('enter_results.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('Results submitted successfully!');
|
|
const modal = bootstrap.Modal.getInstance(document.getElementById('resultsModal'));
|
|
modal.hide();
|
|
e.target.reset();
|
|
// Remove the row from the table
|
|
document.querySelector(`[data-order-id="${orderId}"]`).closest('tr').remove();
|
|
} else {
|
|
alert('Error: ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('An unexpected error occurred while submitting the results.');
|
|
});
|
|
}
|
|
});
|
|
|
|
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>
|