185 lines
12 KiB
PHP
185 lines
12 KiB
PHP
<?php
|
|
// views/jobs/request.php
|
|
?>
|
|
<div class="max-w-3xl mx-auto">
|
|
<div class="mb-6">
|
|
<h2 class="text-2xl font-bold text-slate-800 dark:text-white">ร้องของานเปล (Request Job)</h2>
|
|
<p class="text-slate-500 dark:text-slate-400">กรอกข้อมูลผู้ป่วยและสถานที่ให้ครบถ้วน</p>
|
|
</div>
|
|
|
|
<div class="glass-card p-6 md:p-8">
|
|
<form id="requestForm">
|
|
<input type="hidden" name="action" value="create_job">
|
|
<input type="hidden" name="csrf_token" value="<?= generateCSRFToken() ?>">
|
|
|
|
<h4 class="text-lg font-semibold text-emerald-600 dark:text-emerald-400 mb-4 border-b border-emerald-100 dark:border-emerald-900 pb-2">1. ข้อมูลผู้ป่วย</h4>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-5 mb-6">
|
|
<div>
|
|
<label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">HN (ถ้ามี)</label>
|
|
<input type="text" class="glass-input w-full px-4 py-2" name="hn" placeholder="เช่น 6601234">
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">ชื่อ-สกุลผู้ป่วย <span class="text-red-500">*</span></label>
|
|
<input type="text" class="glass-input w-full px-4 py-2" name="patient_name" required placeholder="ชื่อ นามสกุล">
|
|
</div>
|
|
</div>
|
|
|
|
<h4 class="text-lg font-semibold text-emerald-600 dark:text-emerald-400 mb-4 border-b border-emerald-100 dark:border-emerald-900 pb-2">2. เส้นทางและอุปกรณ์</h4>
|
|
|
|
<?php
|
|
require_once dirname(__DIR__, 2) . '/models/Department.php';
|
|
require_once dirname(__DIR__, 2) . '/models/Setting.php';
|
|
$deptModel = new Department();
|
|
$departments = $deptModel->getAllActive();
|
|
|
|
$settingModel = new Setting();
|
|
|
|
$equipmentsJson = $settingModel->get('equipment_types');
|
|
$equipments = $equipmentsJson ? json_decode($equipmentsJson, true) : [
|
|
['id' => 'wheelchair', 'name' => 'รถนั่ง (Wheelchair)', 'icon' => 'fa-wheelchair'],
|
|
['id' => 'stretcher', 'name' => 'รถนอน (Stretcher)', 'icon' => 'fa-bed'],
|
|
['id' => 'bed', 'name' => 'เตียง (Bed)', 'icon' => 'fa-bed-pulse']
|
|
];
|
|
|
|
$prioritiesJson = $settingModel->get('job_priorities');
|
|
$priorities = $prioritiesJson ? json_decode($prioritiesJson, true) : [
|
|
['id' => 'normal', 'name' => 'ทั่วไป (Normal)', 'color' => 'blue'],
|
|
['id' => 'urgent', 'name' => 'ด่วน (Urgency)', 'color' => 'amber'],
|
|
['id' => 'emergency', 'name' => 'ฉุกเฉิน (Emergency)', 'color' => 'red']
|
|
];
|
|
?>
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-5 mb-5">
|
|
<div>
|
|
<label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">จุดรับผู้ป่วย <span class="text-red-500">*</span></label>
|
|
<select class="glass-input w-full px-4 py-2" name="from_department_id" required>
|
|
<option value="">-- เลือกจุดรับ --</option>
|
|
<?php foreach($departments as $dept): ?>
|
|
<option value="<?= $dept['id'] ?>"><?= escape($dept['name']) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">จุดส่งผู้ป่วย <span class="text-red-500">*</span></label>
|
|
<select class="glass-input w-full px-4 py-2" name="to_department_id" required>
|
|
<option value="">-- เลือกจุดส่ง --</option>
|
|
<?php foreach($departments as $dept): ?>
|
|
<option value="<?= $dept['id'] ?>"><?= escape($dept['name']) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
|
|
<div class="mt-2 flex items-center bg-blue-50 dark:bg-blue-900/20 p-2 rounded-lg border border-blue-100 dark:border-blue-800">
|
|
<input type="checkbox" id="is_round_trip" name="is_round_trip" value="1" class="w-4 h-4 text-blue-600 rounded border-blue-300 focus:ring-blue-500 cursor-pointer">
|
|
<label for="is_round_trip" class="ml-2 text-sm font-medium text-blue-800 dark:text-blue-300 cursor-pointer">
|
|
<i class="fa-solid fa-rotate-left me-1"></i> ไป-กลับ (รอรับกลับทันที)
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-6">
|
|
<label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">ประเภทอุปกรณ์ <span class="text-red-500">*</span></label>
|
|
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3">
|
|
<?php foreach($equipments as $index => $eq): ?>
|
|
<label class="relative flex items-center p-3 border border-slate-200 dark:border-slate-700 rounded-xl cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-800 transition-colors">
|
|
<input type="radio" name="equipment_type" value="<?= escape($eq['id']) ?>" class="w-4 h-4 text-emerald-600 border-gray-300 focus:ring-emerald-500 dark:bg-slate-700 dark:border-slate-600" <?= $index === 0 ? 'required checked' : '' ?>>
|
|
<span class="ml-3 flex flex-col">
|
|
<span class="text-sm font-medium text-slate-900 dark:text-white flex items-center gap-2">
|
|
<i class="fa-solid <?= escape($eq['icon']) ?> text-emerald-500"></i> <?= escape($eq['name']) ?>
|
|
</span>
|
|
</span>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-5">
|
|
<label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">ระดับความฉุกเฉิน (Priority) <span class="text-red-500">*</span></label>
|
|
<select class="glass-input w-full px-4 py-2" name="priority" required>
|
|
<?php foreach($priorities as $index => $pri): ?>
|
|
<option value="<?= escape($pri['id']) ?>" class="text-<?= escape($pri['color']) ?>-600 font-medium" <?= $index === 0 ? 'selected' : '' ?>>
|
|
<?= escape($pri['name']) ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-5 flex items-center gap-2 bg-red-50 dark:bg-red-900/20 p-4 rounded-xl border border-red-200 dark:border-red-800">
|
|
<input type="checkbox" id="infection_control" name="infection_control" value="1" class="w-5 h-5 text-red-600 rounded border-red-300 focus:ring-red-500">
|
|
<label for="infection_control" class="text-sm font-medium text-red-800 dark:text-red-300">
|
|
<i class="fa-solid fa-biohazard me-1"></i> ผู้ป่วยโรคติดต่อ / ต้องการการแยกกักโรค (Infection Control)
|
|
</label>
|
|
</div>
|
|
|
|
<div class="mb-5">
|
|
<label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">เวลาที่ต้องการให้มารับ (Booking)</label>
|
|
<div class="flex gap-4 mb-2">
|
|
<label class="flex items-center gap-2 cursor-pointer">
|
|
<input type="radio" name="is_scheduled" value="0" checked class="text-emerald-500 focus:ring-emerald-500" onchange="document.getElementById('scheduleTimeDiv').classList.add('hidden')">
|
|
<span class="text-sm dark:text-slate-300">ด่วนทันที</span>
|
|
</label>
|
|
<label class="flex items-center gap-2 cursor-pointer">
|
|
<input type="radio" name="is_scheduled" value="1" class="text-emerald-500 focus:ring-emerald-500" onchange="document.getElementById('scheduleTimeDiv').classList.remove('hidden')">
|
|
<span class="text-sm dark:text-slate-300">จองเวลาล่วงหน้า</span>
|
|
</label>
|
|
</div>
|
|
<div id="scheduleTimeDiv" class="hidden">
|
|
<input type="datetime-local" class="glass-input w-full px-4 py-2" name="scheduled_time">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-8">
|
|
<label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">หมายเหตุ (ถ้ามี)</label>
|
|
<textarea class="glass-input w-full px-4 py-2" name="notes" rows="2" placeholder="เช่น ผู้ป่วยให้ออกซิเจน, ระวังสายน้ำเกลือ"></textarea>
|
|
</div>
|
|
|
|
<div class="flex justify-end gap-3 pt-4 border-t border-slate-200 dark:border-slate-700">
|
|
<button type="reset" class="btn-secondary-glass py-2 px-6">
|
|
ล้างข้อมูล
|
|
</button>
|
|
<button type="submit" class="btn-primary-glass py-2 px-8 flex items-center">
|
|
<span class="text"><i class="fa-solid fa-paper-plane me-2"></i> ส่งคำขอ</span>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
$('#requestForm').submit(function(e) {
|
|
e.preventDefault();
|
|
const btn = $(this).find('button[type="submit"]');
|
|
const originalText = btn.html();
|
|
|
|
btn.addClass('btn-loading');
|
|
|
|
$.ajax({
|
|
url: 'api/jobs.php',
|
|
type: 'POST',
|
|
data: $(this).serialize(),
|
|
success: function(response) {
|
|
if (response.status === 'success') {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'บันทึกสำเร็จ',
|
|
text: 'หมายเลขงาน: ' + response.job_number,
|
|
background: document.documentElement.classList.contains('dark') ? '#1e293b' : '#fff',
|
|
color: document.documentElement.classList.contains('dark') ? '#f1f5f9' : '#1e293b'
|
|
}).then(() => {
|
|
window.location.href = '?page=dashboard';
|
|
});
|
|
} else {
|
|
btn.removeClass('btn-loading').html(originalText);
|
|
Swal.fire('ผิดพลาด', response.message, 'error');
|
|
}
|
|
},
|
|
error: function() {
|
|
btn.removeClass('btn-loading').html(originalText);
|
|
Swal.fire('ผิดพลาด', 'เกิดข้อผิดพลาดในการเชื่อมต่อ', 'error');
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|