Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
@@ -0,0 +1,244 @@
<?php
require_once 'includes/db.php';
require_once 'includes/auth.php';
requireLogin();
// Handle Create
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create_incident') {
$call_type = $_POST['call_type'];
$channel = $_POST['channel'];
$case_number = trim($_POST['case_number']);
$ems_refer = $_POST['ems_refer'];
$unit_level = $_POST['unit_level'];
$assigned_unit_id = $_POST['assigned_unit_id'] ?: null;
$symptom_group = $_POST['symptom_group'];
$phone_triage = $_POST['phone_triage'];
$fast_track = $_POST['fast_track'];
$transport_route = $_POST['transport_route'];
$completed_by = $_POST['completed_by'];
$diagnosis = $_POST['diagnosis'];
$stmt = $pdo->prepare("INSERT INTO incidents (case_number, call_type, channel, ems_refer, unit_level, assigned_unit_id, symptom_group, phone_triage, fast_track, transport_route, completed_by, diagnosis, created_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$case_number, $call_type, $channel, $ems_refer, $unit_level, $assigned_unit_id, $symptom_group, $phone_triage, $fast_track, $transport_route, $completed_by, $diagnosis, $_SESSION['user_id']]);
$_SESSION['flash'] = ['type' => 'success', 'title' => 'บันทึกสำเร็จ', 'message' => 'บันทึกการรับสายแจ้งเหตุเรียบร้อยแล้ว'];
header("Location: dashboard.php");
exit;
}
// Fetch Incidents History
$stmt = $pdo->query("
SELECT i.*, creator.full_name as creator_name
FROM incidents i
LEFT JOIN users creator ON i.created_by = creator.id
ORDER BY i.created_at DESC LIMIT 10
");
$incidents = $stmt->fetchAll();
// Fetch Units
$stmt = $pdo->query("SELECT id, name FROM units WHERE is_active = 1 ORDER BY name ASC");
$units = $stmt->fetchAll();
// Fetch Master Data
$md = [
'call_type' => [], 'call_channel' => [], 'ems_refer' => [],
'unit_level' => [], 'cbd_symptom' => [], 'phone_triage' => [],
'fast_track' => [], 'transport_route' => []
];
try {
$stmt = $pdo->query("SELECT category, item_value, item_label FROM master_data WHERE is_active = 1 ORDER BY category ASC, sort_order ASC, id ASC");
if ($stmt) {
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$md[$row['category']][] = $row;
}
}
} catch (PDOException $e) {}
require_once 'includes/header.php';
?>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 h-full">
<!-- Left Column: Form -->
<div class="bg-white rounded-2xl p-5 md:p-6 shadow-sm border border-slate-100 flex flex-col h-full overflow-y-auto">
<div class="mb-4">
<h2 class="text-base font-black text-slate-800 flex items-center gap-2">
<i data-lucide="phone-call" class="w-5 h-5 text-indigo-600"></i> บันทึกการรับสายโทรศัพท์ (รับแจ้งเหตุแรกรับ)
</h2>
<p class="text-xs text-slate-400 mt-0.5">คีย์ข้อมูลผู้เจ็บป่วยฉุกเฉินอย่างรวดเร็ว โดยไม่จำเป็นต้องกรอกครบทุกช่องก็สามารถบันทึกได้</p>
</div>
<form method="POST" action="dashboard.php" class="space-y-4 flex-1">
<input type="hidden" name="action" value="create_incident">
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">ประเภทสายเรียกเข้า</label>
<div class="relative">
<select name="call_type" class="w-full py-2 px-3 pl-8 border border-slate-200 rounded-lg text-sm font-bold text-slate-700 outline-none focus:ring-1 focus:ring-indigo-500 bg-white appearance-none">
<?php foreach($md['call_type'] as $c): ?>
<option value="<?php echo htmlspecialchars($c['item_value']); ?>"><?php echo htmlspecialchars($c['item_label']); ?></option>
<?php endforeach; ?>
</select>
<i data-lucide="phone" class="w-4 h-4 absolute left-3 top-2.5 text-slate-400"></i>
</div>
</div>
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">ช่องทางการแจ้งเหตุ</label>
<select name="channel" class="w-full py-2 px-3 border border-slate-200 rounded-lg text-sm font-bold text-slate-700 outline-none focus:ring-1 focus:ring-indigo-500 bg-white">
<?php foreach($md['call_channel'] as $c): ?>
<option value="<?php echo htmlspecialchars($c['item_value']); ?>"><?php echo htmlspecialchars($c['item_label']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="pt-2">
<h3 class="text-sm font-black text-indigo-600 flex items-center gap-1.5 mb-3">
<i data-lucide="truck" class="w-4 h-4"></i> รายละเอียดปฏิบัติการกู้ชีพ (EMS / REFER)
</h3>
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">เลขปฏิบัติการ (สพฉ.)</label>
<input type="text" name="case_number" placeholder="เช่น 08-2569-1234 (ปล่อยว่างหากยังไม่มี)" class="w-full py-2 px-3 border border-slate-200 rounded-lg text-sm font-bold text-slate-700 outline-none focus:ring-1 focus:ring-indigo-500 bg-white">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">ประเภทปฏิบัติการ</label>
<div class="flex rounded-lg overflow-hidden border border-slate-200 bg-slate-100 p-0.5">
<?php $i=0; foreach($md['ems_refer'] as $c): ?>
<label class="flex-1 cursor-pointer">
<input type="radio" name="ems_refer" value="<?php echo htmlspecialchars($c['item_value']); ?>" class="peer hidden" <?php echo $i===0?'checked':''; ?>>
<div class="text-center py-1.5 text-[10px] font-bold text-slate-500 peer-checked:bg-indigo-600 peer-checked:text-white rounded-md transition-all"><?php echo htmlspecialchars($c['item_label']); ?></div>
</label>
<?php $i++; endforeach; ?>
</div>
</div>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">ระดับหน่วยกู้ชีพ</label>
<div class="flex rounded-lg overflow-hidden border border-slate-200 bg-slate-100 p-0.5">
<?php $i=0; foreach($md['unit_level'] as $c): ?>
<label class="flex-1 cursor-pointer">
<input type="radio" name="unit_level" value="<?php echo htmlspecialchars($c['item_value']); ?>" class="peer hidden" <?php echo $i===0?'checked':''; ?>>
<div class="text-center py-1.5 text-xs font-bold text-slate-500 peer-checked:bg-indigo-600 peer-checked:text-white rounded-md transition-all"><?php echo htmlspecialchars($c['item_label']); ?></div>
</label>
<?php $i++; endforeach; ?>
</div>
</div>
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">หน่วยปฏิบัติการรับมอบ (เฉพาะระดับ ALS)</label>
<select name="assigned_unit_id" class="w-full py-2 px-3 border border-slate-200 rounded-lg text-sm font-bold text-slate-700 outline-none focus:ring-1 focus:ring-indigo-500 bg-white">
<?php foreach($units as $unit): ?>
<option value="<?php echo $unit['id']; ?>" <?php echo $unit['name'] === 'โรงพยาบาลเกาะสมุย' ? 'selected' : ''; ?>><?php echo htmlspecialchars($unit['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="mb-4">
<label class="block text-xs font-bold text-slate-500 mb-1">จำแนกกลุ่มอาการ (25 กลุ่มอาการ สพฉ.)</label>
<select name="symptom_group" class="w-full py-2 px-3 border border-slate-200 rounded-lg text-sm font-bold text-slate-700 outline-none focus:ring-1 focus:ring-indigo-500 bg-white">
<?php foreach($md['cbd_symptom'] as $c): ?>
<option value="<?php echo htmlspecialchars($c['item_value']); ?>"><?php echo htmlspecialchars($c['item_label']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">Phone Triage (ระดับวิกฤตสายแรกรับ)</label>
<select name="phone_triage" class="w-full py-2 px-3 border border-slate-200 rounded-lg text-sm font-bold text-slate-700 outline-none focus:ring-1 focus:ring-indigo-500 bg-white">
<?php foreach($md['phone_triage'] as $c): ?>
<option value="<?php echo htmlspecialchars($c['item_value']); ?>"><?php echo htmlspecialchars($c['item_label']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">รหัสเฉพาะผู้ป่วยวิกฤต (Fast Track)</label>
<select name="fast_track" class="w-full py-2 px-3 border border-slate-200 rounded-lg text-sm font-bold text-slate-700 outline-none focus:ring-1 focus:ring-indigo-500 bg-white">
<?php foreach($md['fast_track'] as $c): ?>
<option value="<?php echo htmlspecialchars($c['item_value']); ?>"><?php echo htmlspecialchars($c['item_label']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">เส้นทางลำเลียงผู้ป่วย</label>
<select name="transport_route" class="w-full py-2 px-3 border border-slate-200 rounded-lg text-sm font-bold text-slate-700 outline-none focus:ring-1 focus:ring-indigo-500 bg-white">
<?php foreach($md['transport_route'] as $c): ?>
<option value="<?php echo htmlspecialchars($c['item_value']); ?>"><?php echo htmlspecialchars($c['item_label']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label class="block text-xs font-bold text-slate-500 mb-1">ผู้รับผิดชอบกรอกข้อมูล (Complete ข้อมูล)</label>
<select name="completed_by" class="w-full py-2 px-3 border border-slate-200 rounded-lg text-sm font-bold text-slate-700 outline-none focus:ring-1 focus:ring-indigo-500 bg-white">
<option value="นพ.เกียรติภูมิ ภูมิใจไทย (ผู้อำนวยการศูนย์)">นพ.เกียรติภูมิ ภูมิใจไทย (ผู้อำนวยการศูนย์)</option>
<option value="<?php echo htmlspecialchars($_SESSION['name']); ?>"><?php echo htmlspecialchars($_SESSION['name']); ?></option>
</select>
</div>
</div>
<div class="mb-4">
<label class="block text-xs font-bold text-slate-500 mb-1">อาการแรกรับ / ผลวินิจฉัย (Diagnosis)</label>
<textarea name="diagnosis" rows="3" placeholder="กรอกเหตุการณ์เบื้องต้น เช่น ผู้ป่วยเพศชายอายุ 45 ปี ประสบอุบัติเหตุล้มหัวฟาดพื้น รู้สึกตัวดีปวดต้นคอ..." class="w-full py-2 px-3 border border-slate-200 rounded-lg text-sm outline-none focus:ring-1 focus:ring-indigo-500 bg-white resize-none text-slate-700"></textarea>
</div>
</div>
<div class="pt-2">
<button type="submit" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-4 rounded-xl shadow-sm transition-all text-sm flex items-center justify-center gap-2">
<i data-lucide="save" class="w-4 h-4"></i> บันทึกและสรุปข้อมูลแรกรับ
</button>
</div>
</form>
</div>
<!-- Right Column: History -->
<div class="bg-white rounded-2xl p-5 md:p-6 shadow-sm border border-slate-100 flex flex-col h-full">
<div class="flex justify-between items-center mb-6">
<h2 class="text-base font-black text-slate-800">สายเรียกเข้าและรายงานล่าสุดในรอบเวร</h2>
<span class="bg-indigo-100 text-indigo-700 text-xs font-bold px-3 py-1 rounded-full"><?php echo count($incidents); ?> สายเรียกเข้า</span>
</div>
<p class="text-xs text-slate-400 mb-4 border-b border-slate-100 pb-3">แสดงรายการประวัติสายเรียกเข้าทั้งหมดที่คุณคีย์ล่าสุด</p>
<div class="flex-1 overflow-y-auto pr-2 space-y-4">
<?php foreach($incidents as $inc):
$dotColor = 'bg-rose-500';
if ($inc['call_type'] == 'สายก่อกวน') $dotColor = 'bg-amber-500';
elseif ($inc['call_type'] == 'โทรผิด') $dotColor = 'bg-slate-400';
elseif ($inc['call_type'] == 'แจ้งเหตุอื่น') $dotColor = 'bg-blue-500';
?>
<div class="flex items-start justify-between group">
<div class="flex items-start gap-3">
<div class="w-2 h-2 rounded-full mt-1.5 <?php echo $dotColor; ?>"></div>
<div>
<p class="text-sm font-bold text-slate-700">
<?php echo htmlspecialchars($inc['call_type']); ?>
<span class="text-xs font-normal text-slate-400 ml-1">(<?php echo date('H:i', strtotime($inc['created_at'])); ?> น.)</span>
</p>
<p class="text-[10px] text-slate-500 font-bold mt-0.5">ช่องทาง: <?php echo htmlspecialchars($inc['channel']); ?></p>
<p class="text-[9px] text-slate-400 mt-0.5">บันทึกโดย: <?php echo htmlspecialchars($inc['creator_name']); ?> (Dispatcher)</p>
</div>
</div>
<button class="text-slate-300 hover:text-rose-500 transition-colors hidden group-hover:block">
<i data-lucide="trash-2" class="w-4 h-4"></i>
</button>
</div>
<?php endforeach; ?>
</div>
<div class="mt-4 bg-amber-50 border border-amber-100 rounded-lg p-3 flex gap-2 items-start">
<i data-lucide="info" class="w-4 h-4 text-amber-500 mt-0.5"></i>
<p class="text-[10px] text-slate-600">
<span class="font-bold">เคล็ดลับปฏิบัติการ:</span> ข้อมูลเคสจะถูกนำเข้าสู่ระบบบัญชี "หน้าเคสปฏิบัติการ" โดยอัตโนมัติ เพื่อให้ผู้รับผิดชอบ (Complete) และทีม ER ดำเนินการคัดแยกสี และปิดเคสอย่างละเอียด
</p>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>