<?php
// todaysPatient.php
require_once __DIR__ . '/../../dripend/includes/db.php';

header('Content-Type: application/json');

// Ensure DB connection
if (!isset($conn) || !$conn) {
    echo json_encode(['count' => 0]);
    exit;
}

// Get current date in YYYY-MM-DD format
$today = date('Y-m-d');

// Prepare statement for safety
$stmt = $conn->prepare("SELECT COUNT(*) AS total FROM patient WHERE DATE(created_at) = ?");
$stmt->bind_param('s', $today);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();

$total = $row ? intval($row['total']) : 0;
$stmt->close();

echo json_encode(['count' => $total]);
?>
