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

321 lines
14 KiB
PHP

<?php
require_once 'auth.php';
require_once 'db/config.php';
// Check if patient ID is provided
if (!isset($_GET['id'])) {
header("Location: reception.php");
exit();
}
$patient_id = $_GET['id'];
// Fetch patient details
$stmt = db()->prepare("SELECT * FROM patients WHERE id = ?");
$stmt->execute([$patient_id]);
$patient = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$patient) {
die("Patient not found.");
}
// Fetch all visits for this patient
$visit_history_stmt = db()->prepare(
"SELECT pv.*, u.username as doctor_name
FROM patient_visits pv
LEFT JOIN users u ON pv.doctor_id = u.id
WHERE pv.patient_id = ?
ORDER BY pv.visit_time DESC"
);
$visit_history_stmt->execute([$patient_id]);
$visit_history = $visit_history_stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch all prescriptions for this patient
$prescriptions_stmt = db()->prepare(
"SELECT pr.*, u.username as doctor_name
FROM prescriptions pr
LEFT JOIN users u ON pr.doctor_id = u.id
WHERE pr.patient_id = ?
ORDER BY pr.prescription_date DESC"
);
$prescriptions_stmt->execute([$patient_id]);
$prescriptions = $prescriptions_stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch all ordered tests for this patient
$ordered_tests_stmt = db()->prepare(
"SELECT
ot.ordered_at,
ot.test_type,
ot.status,
ot.results,
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 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 pv.patient_id = ?
ORDER BY ot.ordered_at DESC"
);
$ordered_tests_stmt->execute([$patient_id]);
$ordered_tests = $ordered_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>Patient Profile - <?= htmlspecialchars($patient['patient_name']) ?></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 active">
<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>
</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">Patient Profile</h1>
<a href="reception.php" class="btn btn-sm btn-outline-primary">
<i class="bi bi-arrow-left me-2"></i>Back to Dashboard
</a>
</header>
<!-- Patient Details Card -->
<div class="card shadow-sm mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">
<i class="bi bi-person-badge me-2"></i>
<?= htmlspecialchars($patient['patient_name']) ?>
</h6>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-4">
<p><strong>Patient ID:</strong> <?= htmlspecialchars($patient['patient_id']) ?></p>
</div>
<div class="col-md-4">
<p><strong>Phone:</strong> <?= htmlspecialchars($patient['phone_number']) ?></p>
</div>
<div class="col-md-4">
<p><strong>Address:</strong> <?= htmlspecialchars($patient['address']) ?></p>
</div>
</div>
</div>
</div>
<!-- Prescription History -->
<div class="card shadow-sm mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">
<i class="bi bi-file-earmark-medical me-2"></i>
Prescription History
</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Date</th>
<th>Doctor</th>
<th>Medication</th>
<th>Dosage</th>
<th>Frequency</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (empty($prescriptions)): ?>
<tr>
<td colspan="7" class="text-center">No prescription history found.</td>
</tr>
<?php else: ?>
<?php foreach ($prescriptions as $prescription): ?>
<tr>
<td><?= date("d M, Y", strtotime($prescription['prescription_date'])) ?></td>
<td>Dr. <?= htmlspecialchars($prescription['doctor_name'] ?? 'N/A') ?></td>
<td><?= htmlspecialchars($prescription['medication']) ?></td>
<td><?= htmlspecialchars($prescription['dosage']) ?></td>
<td><?= htmlspecialchars($prescription['frequency']) ?></td>
<td>
<span class="badge bg-<?php echo $prescription['status'] === 'Dispensed' ? 'success' : 'warning'; ?>-soft"><?= htmlspecialchars($prescription['status']) ?></span>
</td>
<td>
<a href="prescription_view.php?id=<?= $prescription['id'] ?>" class="btn btn-sm btn-outline-primary" target="_blank">
<i class="bi bi-printer me-1"></i> View/Print
</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Ordered Tests History -->
<div class="card shadow-sm mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">
<i class="bi bi-eyedropper me-2"></i>
Ordered Tests History
</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Date Ordered</th>
<th>Test Name</th>
<th>Type</th>
<th>Ordered By</th>
<th>Status</th>
<th>Results</th>
</tr>
</thead>
<tbody>
<?php if (empty($ordered_tests)): ?>
<tr>
<td colspan="6" class="text-center">No tests have been ordered for this patient.</td>
</tr>
<?php else: ?>
<?php foreach ($ordered_tests as $index => $test): ?>
<tr>
<td><?= date("d M, Y", strtotime($test['ordered_at'])) ?></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-<?php echo $test['status'] === 'Completed' ? 'success' : 'info'; ?>-soft"><?= htmlspecialchars($test['status']) ?></span>
</td>
<td>
<?php if ($test['status'] === 'Completed' && !empty($test['results'])): ?>
<button class="btn btn-sm btn-outline-secondary view-results-btn" data-bs-toggle="modal" data-bs-target="#viewResultsModal" data-results="<?= htmlspecialchars($test['results']) ?>">View Results</button>
<?php else: ?>
<span class="text-muted">N/A</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Visit History -->
<div class="card shadow-sm">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">
<i class="bi bi-clock-history me-2"></i>
Visit History
</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Visit Date</th>
<th>Assigned Doctor</th>
<th>Status</th>
<th>Consultation Notes</th>
</tr>
</thead>
<tbody>
<?php if (empty($visit_history)): ?>
<tr>
<td colspan="4" class="text-center">No visit history found.</td>
</tr>
<?php else: ?>
<?php foreach ($visit_history as $visit): ?>
<tr>
<td><?= date("d M, Y h:i A", strtotime($visit['visit_time'])) ?></td>
<td>Dr. <?= htmlspecialchars($visit['doctor_name'] ?? 'N/A') ?></td>
<td>
<span class="badge bg-primary-soft"><?= htmlspecialchars($visit['status']) ?></span>
</td>
<td><?= nl2br(htmlspecialchars($visit['notes'] ?? 'No notes added.')) ?></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>
<!-- View Results Modal -->
<div class="modal fade" id="viewResultsModal" tabindex="-1" aria-labelledby="viewResultsModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="viewResultsModalLabel">Test Results</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="resultsModalBody">
<!-- Results will be injected here by JS -->
</div>
</div>
</div>
</div>
<script>
document.addEventListener('click', function(e) {
if (e.target.matches('.view-results-btn')) {
const results = e.target.dataset.results;
document.getElementById('resultsModalBody').innerText = results;
}
});
</script>
</body>
</html>