246 lines
9.6 KiB
PHP
246 lines
9.6 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
require_role('receptionist'); // For now, accessible by receptionists/pharmacists
|
|
require_once 'db/config.php';
|
|
|
|
$pdo = db();
|
|
|
|
// Fetch all prescriptions that have not been dispensed
|
|
$pending_prescriptions_stmt = $pdo->prepare(
|
|
"SELECT
|
|
pr.id as prescription_id,
|
|
pr.prescription_date,
|
|
pr.medication,
|
|
pr.dosage,
|
|
pr.frequency,
|
|
p.patient_name,
|
|
p.id as patient_id,
|
|
u.username as doctor_name
|
|
FROM prescriptions pr
|
|
JOIN patients p ON pr.patient_id = p.id
|
|
JOIN users u ON pr.doctor_id = u.id
|
|
WHERE pr.status = 'Prescribed'
|
|
ORDER BY pr.prescription_date ASC"
|
|
);
|
|
$pending_prescriptions_stmt->execute();
|
|
$pending_prescriptions = $pending_prescriptions_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>Pharmacy Dashboard</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">
|
|
<i class="bi bi-file-earmark-medical"></i>
|
|
<span>Lab Reports</span>
|
|
</a>
|
|
<a href="pharmacy.php" class="nav-link active">
|
|
<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">Pharmacy - Pending Prescriptions</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 Prescribed</th>
|
|
<th>Patient</th>
|
|
<th>Doctor</th>
|
|
<th>Medication</th>
|
|
<th>Dosage</th>
|
|
<th>Frequency</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($pending_prescriptions)): ?>
|
|
<tr>
|
|
<td colspan="7" class="text-center">No pending prescriptions found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($pending_prescriptions as $prescription): ?>
|
|
<tr id="prescription-row-<?= $prescription['prescription_id'] ?>">
|
|
<td><?= date("d M, Y", strtotime($prescription['prescription_date'])) ?></td>
|
|
<td><a href="patient_profile.php?id=<?= $prescription['patient_id'] ?>"><?= htmlspecialchars($prescription['patient_name']) ?></a></td>
|
|
<td>Dr. <?= htmlspecialchars($prescription['doctor_name']) ?></td>
|
|
<td><?= htmlspecialchars($prescription['medication']) ?></td>
|
|
<td><?= htmlspecialchars($prescription['dosage']) ?></td>
|
|
<td><?= htmlspecialchars($prescription['frequency']) ?></td>
|
|
<td>
|
|
<button class="btn btn-sm btn-success dispense-btn" data-prescription-id="<?= $prescription['prescription_id'] ?>">Dispense</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</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('.dispense-btn')) {
|
|
if (!confirm('Are you sure you want to mark this prescription as dispensed?')) {
|
|
return;
|
|
}
|
|
|
|
const prescriptionId = e.target.dataset.prescriptionId;
|
|
const formData = new FormData();
|
|
formData.append('prescription_id', prescriptionId);
|
|
|
|
fetch('dispense.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('Prescription dispensed successfully!');
|
|
// Remove the row from the table
|
|
document.getElementById('prescription-row-' + prescriptionId).remove();
|
|
} 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>
|