<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

function e($value) {
    return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
}

function redirect($url) {
    header('Location: ' . $url);
    exit;
}

function current_user_id() {
    return $_SESSION['user_id'] ?? null;
}

function current_user_name() {
    return $_SESSION['user_name'] ?? '';
}

function current_patient_id() {
    return $_SESSION['patient_id'] ?? null;
}

function current_patient_name() {
    return $_SESSION['patient_name'] ?? '';
}

function require_user() {
    if (!current_user_id() || !current_patient_id()) {
        redirect('/ficha_medica/auth/login.php');
    }
}
?>
