36247-vm/pharmacy.php
Flatlogic Bot c8d83e1d5c version 2
2025-11-25 08:14:18 +00:00

165 lines
6.8 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">
</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>
</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.');
});
}
});
</script>
</body>
</html>