<?php
session_start();
include '../include/config.php';
$patient_id = $_POST['patient_id'];
$nurse_id = $_SESSION['nurse_id'];

$vitals = $conn->query("
    SELECT * FROM vitals 
    WHERE patient_id = $patient_id AND recorded_by_nurse_id = $nurse_id 
    ORDER BY recorded_date DESC
");

if($vitals->num_rows > 0):
?>
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead>
                <tr><th>Date</th><th>BP</th><th>Heart Rate</th><th>Temp</th><th>O2 Sat</th><th>Weight</th><th>BMI</th><th>Notes</th></tr>
            </thead>
            <tbody>
                <?php while($v = $vitals->fetch_assoc()): ?>
                    <tr>
                        <td><?= date('M d, Y H:i', strtotime($v['recorded_date'])) ?></td>
                        <td><?= $v['blood_pressure'] ?? 'N/A' ?></td>
                        <td><?= $v['heart_rate'] ?? 'N/A' ?> bpm</td>
                        <td><?= $v['temperature'] ?? 'N/A' ?> °C</td>
                        <td><?= $v['oxygen_saturation'] ?? 'N/A' ?> %</td>
                        <td><?= $v['weight'] ?? 'N/A' ?> kg</td>
                        <td><?= $v['bmi'] ?? 'N/A' ?></td>
                        <td><?= $v['notes'] ?? '-' ?></td>
                    </tr>
                <?php endwhile; ?>
            </tbody>
        </table>
    </div>
<?php else: ?>
    <div class="alert alert-info mt-3">No vitals recorded for this patient.</div>
<?php endif; ?>