Mini Kabibi Habibi

Current Path : C:/xampp/htdocs/clinic/
Upload File :
Current File : C:/xampp/htdocs/clinic/consultations.php

<?php
session_start();
include 'includes/db.php';

// Access control
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
    header("Location: login.php");
    exit();
}

// Today's date
$today = date('Y-m-d');

// Fetch today's consultations
$stmt = $pdo->prepare("
    SELECT 
        l.id AS log_id,+
        l.patient_name,
        l.client_type,
        l.school,
        l.age,
        l.sex,
        l.attended_by,
        hr.id AS health_id,
        hr.date,
        hr.chief_complaint,
        hr.findings_bp,
        hr.findings_cr,
        hr.findings_rr,
        hr.findings_o2sat,
        hr.findings_temp,
        hr.physical_examination,
        hr.diagnosis,
        hr.treatment
    FROM logs l
    INNER JOIN health_records hr ON hr.log_id = l.id
    WHERE hr.date = :today AND (hr.diagnosis IS NULL OR hr.diagnosis = '')
    ORDER BY hr.date DESC
");
$stmt->execute([':today' => $today]);
$consultations = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Highlight recently redirected patient
$highlight_id = $_GET['id'] ?? null;
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Consultations</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" />
    <style>
        body {
            display: flex;
            min-height: 100vh;
            background-color: #f8f9fa;
        }
        .sidebar {
            width: 250px;
            background-color: #2c3e50;
            color: white;
        }
        .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 {
            flex-grow: 1;
            padding: 40px;
        }
        .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">
    <h2>Today's Consultations</h2>
    <?php if (isset($_GET['from']) && $_GET['from'] === 'view_patient'): ?>
        <div class="alert alert-success">
            Initial consultation saved. Please complete physician's notes if needed.
        </div>
    <?php endif; ?>

    <?php if (count($consultations) > 0): ?>
        <div class="table-responsive mt-3">
            <table class="table table-bordered table-striped align-middle">
                <thead class="table-dark">
                    <tr>
                        <th>Date</th>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Sex</th>
                        <th>Chief Complaint</th>
                        <th>Findings</th>
                        <th>Diagnosis</th>
                        <th>Treatment</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($consultations as $row): ?>
                        <tr class="<?= $highlight_id == $row['log_id'] ? 'highlight-row' : '' ?>">
                            <td><?= htmlspecialchars(date('m/d/Y', strtotime($row['date']))) ?></td>
                            <td><?= htmlspecialchars($row['patient_name']) ?></td>
                            <td><?= htmlspecialchars($row['client_type']) ?></td>
                            <td><?= htmlspecialchars($row['sex']) ?></td>
                            <td><?= nl2br(htmlspecialchars($row['chief_complaint'])) ?></td>
                            <td>
                                <strong>BP:</strong> <?= htmlspecialchars($row['findings_bp']) ?><br>
                                <strong>CR:</strong> <?= htmlspecialchars($row['findings_cr']) ?><br>
                                <strong>RR:</strong> <?= htmlspecialchars($row['findings_rr']) ?><br>
                                <strong>O₂ Sat:</strong> <?= htmlspecialchars($row['findings_o2sat']) ?><br>
                                <strong>Temp:</strong> <?= htmlspecialchars($row['findings_temp']) ?><br>
                                <strong>PE:</strong> <?= nl2br(htmlspecialchars($row['physical_examination'])) ?>
                            </td>
                            <td><?= nl2br(htmlspecialchars($row['diagnosis'])) ?></td>
                            <td><?= nl2br(htmlspecialchars($row['treatment'])) ?></td>
                            <td>
                                <a href="edit_consultation.php?id=<?= $row['health_id'] ?>" class="btn btn-sm btn-primary">Edit</a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    <?php else: ?>
        <div class="alert alert-info mt-3">No initial consultations found for today.</div>
    <?php endif; ?>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>