Mini Kabibi Habibi
| Current Path : C:/xampp/htdocs/clinic/ |
|
|
| Current File : C:/xampp/htdocs/clinic/edit_consultation.php |
<?php
session_start();
include 'includes/db.php';
// Access control: only admin (or physician) can edit
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: login.php");
exit();
}
if (!isset($_GET['id'])) {
echo "No consultation selected.";
exit();
}
$health_id = $_GET['id'];
// Fetch the existing consultation record (join with logs for patient info)
$stmt = $pdo->prepare("
SELECT
hr.*,
l.patient_name,
l.client_type,
l.school,
l.age,
l.sex,
l.address,
l.contact_number,
l.attended_by
FROM health_records hr
JOIN logs l ON l.id = hr.log_id
WHERE hr.id = :health_id
");
$stmt->execute([':health_id' => $health_id]);
$record = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$record) {
echo "Consultation record not found.";
exit();
}
$success = "";
$error = "";
// Handle form submission for updates
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// You may allow updating all or some fields
$date = $_POST['date'];
$chief_complaint = $_POST['chief_complaint'];
$bp = $_POST['bp'];
$cr = $_POST['cr'];
$rr = $_POST['rr'];
$o2sat = $_POST['o2sat'];
$temp = $_POST['temp'];
$physical_examination = $_POST['physical_examination'] ?? null;
$diagnosis = $_POST['diagnosis'] ?? null;
$treatment = $_POST['treatment'];
// Update query
$upd = $pdo->prepare("
UPDATE health_records
SET date = :date,
chief_complaint = :chief_complaint,
findings_bp = :bp,
findings_cr = :cr,
findings_rr = :rr,
findings_o2sat = :o2sat,
findings_temp = :temp,
physical_examination = :physical_examination,
diagnosis = :diagnosis,
treatment = :treatment
WHERE id = :health_id
");
$res = $upd->execute([
':date' => $date,
':chief_complaint' => $chief_complaint,
':bp' => $bp,
':cr' => $cr,
':rr' => $rr,
':o2sat' => $o2sat,
':temp' => $temp,
':physical_examination' => $physical_examination,
':diagnosis' => $diagnosis,
':treatment' => $treatment,
':health_id' => $health_id
]);
if ($res) {
// Redirect to consultations page after successful update
header("Location: consultations.php");
exit();
} else {
$error = "Failed to update. Please try again.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit Consultation</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" />
<style>
body {
display: flex;
flex-direction: column;
min-height: 100vh;
background-color: #f8f9fa;
}
.sidebar {
width: 250px;
background-color: #2c3e50;
color: white;
position: fixed;
top: 0;
bottom: 0;
left: 0;
}
.sidebar a {
color: #ccc;
text-decoration: none;
padding: 15px;
display: block;
transition: 0.3s;
}
.sidebar a:hover {
background-color: #34495e;
color: #fff;
}
.sidebar .collapse a {
font-size: 0.95rem;
padding-left: 30px;
}
.main-content {
margin-left: 250px;
padding: 40px;
flex: 1;
}
.form-card {
background-color: #fff;
border-radius: 10px;
padding: 30px;
box-shadow: 0 0 15px rgba(0,0,0,0.05);
}
h2.page-title {
font-weight: 600;
margin-bottom: 30px;
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
</head>
<body>
<!-- Sidebar -->
<?php include 'sidebar.php'; ?>
<!-- Main Content -->
<div class="main-content">
<h3>Edit Consultation</h3>
<?php if ($success): ?>
<div class="alert alert-success"><?= htmlspecialchars($success) ?></div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<!-- Patient Info -->
<div class="mb-4">
<p><strong>Name:</strong> <?= htmlspecialchars($record['patient_name']) ?></p>
<p><strong>Type:</strong> <?= htmlspecialchars($record['client_type']) ?></p>
<p><strong>Age:</strong> <?= htmlspecialchars($record['age']) ?></p>
<p><strong>Sex:</strong> <?= htmlspecialchars($record['sex']) ?></p>
<p><strong>Attended by:</strong> <?= htmlspecialchars($record['attended_by']) ?></p>
</div>
<form method="post">
<div class="table-responsive">
<table class="table table-bordered align-middle">
<thead class="table-dark">
<tr>
<th>Date</th>
<th>Chief Complaint</th>
<th>Findings</th>
<th>Treatment / Recommendation</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="date" name="date" class="form-control" required
value="<?= htmlspecialchars($record['date']) ?>">
</td>
<td>
<textarea name="chief_complaint" class="form-control" rows="3" required><?= htmlspecialchars($record['chief_complaint']) ?></textarea>
</td>
<td>
<div class="row g-2">
<div class="col-md-6">
<label class="form-label small">BP</label>
<input type="text" name="bp" class="form-control"
value="<?= htmlspecialchars($record['findings_bp']) ?>">
</div>
<div class="col-md-6">
<label class="form-label small">CR</label>
<input type="text" name="cr" class="form-control"
value="<?= htmlspecialchars($record['findings_cr']) ?>">
</div>
<div class="col-md-6">
<label class="form-label small">RR</label>
<input type="text" name="rr" class="form-control"
value="<?= htmlspecialchars($record['findings_rr']) ?>">
</div>
<div class="col-md-6">
<label class="form-label small">O₂ Sat</label>
<input type="text" name="o2sat" class="form-control"
value="<?= htmlspecialchars($record['findings_o2sat']) ?>">
</div>
<div class="col-md-12">
<label class="form-label small">Temp</label>
<input type="text" name="temp" class="form-control"
value="<?= htmlspecialchars($record['findings_temp']) ?>">
</div>
<div class="col-md-12">
<label class="form-label small">Physical Examination</label>
<textarea name="physical_examination" class="form-control" rows="2"><?= htmlspecialchars($record['physical_examination']) ?></textarea>
</div>
<div class="col-md-12">
<label class="form-label small">Diagnosis</label>
<textarea name="diagnosis" class="form-control" rows="2"><?= htmlspecialchars($record['diagnosis']) ?></textarea>
</div>
</div>
</td>
<td>
<label for="treatment" class="form-label small">Select Treatment</label>
<select name="treatment" id="treatment" class="form-select" required>
<option value="">-- Select --</option>
<option value="Treated" <?= $record['treatment'] === 'Treated' ? 'selected' : '' ?>>Treated</option>
<option value="Referred" <?= $record['treatment'] === 'Referred' ? 'selected' : '' ?>>Referred</option>
<option value="For Follow-up" <?= $record['treatment'] === 'For Follow-up' ? 'selected' : '' ?>>For follow-up</option>
</select>
</td>
</tr>
</tbody>
</table>
</div>
<div class="text-center mt-3">
<button type="submit" class="btn btn-primary">Update Consultation</button>
</div>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>