Mini Kabibi Habibi

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

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

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

if (!isset($_GET['id'])) {
    echo "No patient selected.";
    exit();
}

$log_id = $_GET['id'];

// Fetch patient info from logs
$stmt = $pdo->prepare("SELECT * FROM logs WHERE id = :id");
$stmt->execute([':id' => $log_id]);
$patient = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$patient) {
    echo "Patient not found.";
    exit();
}

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $date = $_POST['date'];
    $chief_complaint = $_POST['chief_complaint'];
    $bp = $_POST['bp'];
    $cr = $_POST['cr'];
    $rr = $_POST['rr'];
    $o2sat = $_POST['o2sat'];
    $temp = $_POST['temp'];

    $insert = $pdo->prepare("INSERT INTO health_records 
        (log_id, date, chief_complaint, findings_bp, findings_cr, findings_rr, findings_o2sat, findings_temp) 
        VALUES 
        (:log_id, :date, :chief_complaint, :bp, :cr, :rr, :o2sat, :temp)");

    $insert->execute([
        ':log_id' => $log_id,
        ':date' => $date,
        ':chief_complaint' => $chief_complaint,
        ':bp' => $bp,
        ':cr' => $cr,
        ':rr' => $rr,
        ':o2sat' => $o2sat,
        ':temp' => $temp
    ]);

    // Redirect to consultations page for physician input
    header("Location: initial_assessment.php?from=view_patient&id=" . $log_id);
    exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>View Patient</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 class="mb-3">HEALTH RECORD (Initial)</h3>

    <!-- Patient Info -->
    <div class="mb-4">
        <p><strong>Name:</strong> <?= htmlspecialchars($patient['patient_name']) ?></p>
        <p><strong>School:</strong> <?= htmlspecialchars($patient['school']) ?></p>
        <p><strong>Age:</strong> <?= htmlspecialchars($patient['age']) ?></p>
    </div>

    <!-- Health Record Form -->
    <form method="POST">
        <div class="table-responsive">
            <table class="table table-bordered align-middle">
                <thead style="background-color: #004d00; color: white;">
                    <tr>
                        <th style="width: 15%;">Date</th>
                        <th style="width: 25%;">Chief Complaint</th>
                        <th style="width: 60%;">Findings (BP, CR, RR, O₂ Sat, Temp)</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <!-- Date -->
                        <td>
                            <input type="date" name="date" class="form-control" required>
                        </td>

                        <!-- Chief Complaint -->
                        <td>
                            <textarea name="chief_complaint" class="form-control" rows="3" required></textarea>
                        </td>

                        <!-- Findings -->
                        <td>
                            <div class="row g-2">
                                <div class="col-md-4">
                                    <label class="form-label small">BP</label>
                                    <input type="text" name="bp" class="form-control" placeholder="e.g. 120/80">
                                </div>
                                <div class="col-md-4">
                                    <label class="form-label small">CR</label>
                                    <input type="text" name="cr" class="form-control" placeholder="e.g. 72">
                                </div>
                                <div class="col-md-4">
                                    <label class="form-label small">RR</label>
                                    <input type="text" name="rr" class="form-control" placeholder="e.g. 18">
                                </div>
                                <div class="col-md-4">
                                    <label class="form-label small">O₂ Sat</label>
                                    <input type="text" name="o2sat" class="form-control" placeholder="e.g. 98%">
                                </div>
                                <div class="col-md-4">
                                    <label class="form-label small">Temp</label>
                                    <input type="text" name="temp" class="form-control" placeholder="e.g. 36.5°C">
                                </div>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>

        <!-- Submit Button -->
        <div class="text-center mt-4">
            <button type="submit" class="btn btn-primary px-5">Save Health Record</button>
        </div>
    </form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>