178 lines
9.4 KiB
PHP
178 lines
9.4 KiB
PHP
<?php
|
|
require_once 'includes/db.php';
|
|
require_once 'includes/auth.php';
|
|
|
|
requireLogin();
|
|
|
|
// 1. Fetch counts for the 4 summary cards
|
|
$currentShiftCalls = 0;
|
|
$activeCasesCount = 0;
|
|
$pendingCasesCount = 0;
|
|
$notReadyUnitsCount = 0;
|
|
|
|
try {
|
|
// Current Shift Calls (using today's date as a proxy for 'current shift')
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM incidents WHERE DATE(created_at) = CURDATE() AND channel = 'First Call'");
|
|
if ($stmt) $currentShiftCalls = $stmt->fetchColumn();
|
|
|
|
// Active cases (Not 'ปิดเคส' and not 'ค้างปรับปรุงข้อมูล')
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM incidents WHERE status != 'ปิดเคส' AND status != 'ค้างปรับปรุงข้อมูล'");
|
|
if ($stmt) $activeCasesCount = $stmt->fetchColumn();
|
|
|
|
// Pending cases ('ค้างปรับปรุงข้อมูล')
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM incidents WHERE status = 'ค้างปรับปรุงข้อมูล'");
|
|
if ($stmt) $pendingCasesCount = $stmt->fetchColumn();
|
|
|
|
// Units not ready
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM units WHERE status = 'not_ready'");
|
|
if ($stmt) $notReadyUnitsCount = $stmt->fetchColumn();
|
|
} catch (Exception $e) {}
|
|
|
|
// 2. Fetch Active Cases list (Left column)
|
|
$activeCases = [];
|
|
try {
|
|
// Since we don't have unit names directly in incidents in our mock, we will mock the unit name if empty, or join if unit table has it.
|
|
// Our mock data didn't have unit names in `incidents`, so we'll just show it using assigned_unit_id or a fallback.
|
|
$query = "
|
|
SELECT
|
|
i.id, i.case_number, i.call_type, i.status, i.diagnosis, i.created_at,
|
|
u.name as unit_name
|
|
FROM incidents i
|
|
LEFT JOIN units u ON i.assigned_unit_id = u.id
|
|
WHERE i.status != 'ปิดเคส'
|
|
ORDER BY i.created_at DESC
|
|
";
|
|
$stmt = $pdo->query($query);
|
|
if ($stmt) $activeCases = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (Exception $e) {}
|
|
|
|
// 3. Fetch Pending Cases Details (Right column)
|
|
$pendingCases = [];
|
|
try {
|
|
// Join with users to get the name of the dispatcher who created it, since we don't have a 'responsible_dispatcher' column explicitly in our mock. We'll use created_by or completed_by.
|
|
$query = "
|
|
SELECT
|
|
i.case_number, i.created_at, i.status,
|
|
u.name as responsible_name
|
|
FROM incidents i
|
|
LEFT JOIN users u ON i.created_by = u.id
|
|
WHERE i.status = 'ค้างปรับปรุงข้อมูล'
|
|
ORDER BY i.created_at ASC
|
|
";
|
|
$stmt = $pdo->query($query);
|
|
if ($stmt) $pendingCases = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (Exception $e) {}
|
|
|
|
// Function to calculate time diff
|
|
function getPendingTime($datetime) {
|
|
$now = new DateTime();
|
|
$past = new DateTime($datetime);
|
|
$diff = $now->diff($past);
|
|
|
|
$parts = [];
|
|
if ($diff->d > 0) $parts[] = $diff->d . ' วัน';
|
|
if ($diff->h > 0) $parts[] = $diff->h . ' ชม.';
|
|
if ($diff->i > 0) $parts[] = $diff->i . ' นาที';
|
|
|
|
return empty($parts) ? 'เพิ่งเกิดขึ้น' : implode(' ', $parts);
|
|
}
|
|
?>
|
|
|
|
<?php require_once 'includes/header.php'; ?>
|
|
|
|
<div class="space-y-6 animate-fadeIn pb-10">
|
|
|
|
<!-- 4 Summary Cards -->
|
|
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
|
<div class="bg-indigo-600 p-4 rounded-2xl shadow-sm text-white">
|
|
<div class="text-xs font-bold opacity-80">สายแรกรับเวรปัจจุบัน</div>
|
|
<div class="text-2xl font-black mt-1"><?php echo $currentShiftCalls; ?> <span class="text-sm font-bold opacity-80">สาย</span></div>
|
|
</div>
|
|
<div class="bg-white p-4 rounded-2xl shadow-sm border border-slate-100">
|
|
<div class="text-xs text-slate-400 font-bold">เคสผู้ป่วยที่กำลังออก ว.4</div>
|
|
<div class="text-2xl font-black text-slate-800 mt-1"><?php echo $activeCasesCount; ?> <span class="text-sm font-bold text-slate-500">เคส</span></div>
|
|
</div>
|
|
<div class="bg-white p-4 rounded-2xl shadow-sm border border-slate-100">
|
|
<div class="text-xs text-slate-400 font-bold">เคสตกค้างข้อมูล</div>
|
|
<div class="text-2xl font-black text-rose-600 mt-1"><?php echo $pendingCasesCount; ?> <span class="text-sm font-bold text-rose-500">เคสค้าง</span></div>
|
|
</div>
|
|
<div class="bg-white p-4 rounded-2xl shadow-sm border border-slate-100">
|
|
<div class="text-xs text-slate-400 font-bold">หน่วยในข่ายไม่พร้อมทำงาน</div>
|
|
<div class="text-2xl font-black text-orange-500 mt-1"><?php echo $notReadyUnitsCount; ?> <span class="text-sm font-bold text-orange-400">สถานี</span></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 2 Column Layout -->
|
|
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
|
|
|
<!-- Left Panel: Active Cases -->
|
|
<div class="lg:col-span-2 bg-white rounded-2xl shadow-sm border border-slate-100 overflow-hidden">
|
|
<div class="p-4 md:p-5 border-b border-slate-100 bg-slate-50/50 flex items-center justify-between">
|
|
<h3 class="text-sm font-bold text-slate-800">ขบวนกู้ชีพกำลังออกปฏิบัติงานหลัก</h3>
|
|
<span class="bg-indigo-100 text-indigo-700 text-[10px] font-bold px-2 py-0.5 rounded-full">Realtime</span>
|
|
</div>
|
|
<div class="p-4 md:p-5 space-y-3">
|
|
<?php if (empty($activeCases)): ?>
|
|
<div class="text-center py-6 text-slate-400 text-sm font-semibold">ไม่มีเคสกำลังดำเนินการ</div>
|
|
<?php else: ?>
|
|
<?php foreach ($activeCases as $case):
|
|
$badgeClass = 'bg-amber-100 text-amber-700'; // Default yellow
|
|
if ($case['status'] === 'รอรับเรื่อง') $badgeClass = 'bg-slate-100 text-slate-600';
|
|
if ($case['status'] === 'กำลังดำเนินการ') $badgeClass = 'bg-blue-100 text-blue-700';
|
|
?>
|
|
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 p-3.5 border border-slate-100 rounded-xl hover:bg-slate-50 transition-colors">
|
|
<div>
|
|
<div class="text-sm font-bold text-slate-800">
|
|
<?php echo htmlspecialchars($case['case_number']); ?>
|
|
<?php if (!empty($case['call_type'])): ?>
|
|
<span class="text-slate-500 font-semibold">(<?php echo htmlspecialchars($case['call_type']); ?>)</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="text-xs text-slate-500 mt-1 truncate max-w-xl">
|
|
หน่วย: <?php echo htmlspecialchars($case['unit_name'] ?? 'ไม่ระบุหน่วย'); ?> | อาการ: <?php echo htmlspecialchars($case['diagnosis'] ?? 'ไม่ระบุอาการ'); ?>
|
|
</div>
|
|
</div>
|
|
<div class="shrink-0">
|
|
<span class="<?php echo $badgeClass; ?> text-[10px] font-bold px-2 py-1 rounded">
|
|
<?php echo htmlspecialchars($case['status']); ?>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Right Panel: Pending Cases -->
|
|
<div class="lg:col-span-1 bg-white rounded-2xl shadow-sm border border-slate-100 overflow-hidden">
|
|
<div class="p-4 md:p-5 border-b border-slate-100 bg-slate-50/50">
|
|
<h3 class="text-sm font-bold text-slate-800">เคสตกค้างการกรอกข้อมูล (ค้างกับใคร)</h3>
|
|
</div>
|
|
<div class="p-4 md:p-5 space-y-3">
|
|
<?php if (empty($pendingCases)): ?>
|
|
<div class="text-center py-6 text-slate-400 text-sm font-semibold">ไม่มีเคสตกค้าง</div>
|
|
<?php else: ?>
|
|
<?php foreach ($pendingCases as $pCase): ?>
|
|
<div class="flex items-center justify-between gap-3 p-3 border border-rose-200 bg-rose-50/40 rounded-xl">
|
|
<div>
|
|
<div class="text-sm font-bold text-slate-800">เลข: <?php echo htmlspecialchars($pCase['case_number']); ?></div>
|
|
<div class="text-xs text-slate-500 mt-0.5">ผู้รับผิดชอบหลัก: <?php echo htmlspecialchars($pCase['responsible_name'] ?? 'ไม่ระบุ'); ?></div>
|
|
</div>
|
|
<div class="text-xs font-bold text-rose-600 shrink-0">
|
|
ค้าง: <?php echo getPendingTime($pCase['created_at']); ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
lucide.createIcons();
|
|
</script>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|