prepare("SELECT hn, fname, lname FROM patient WHERE cid = ?"); $stmt_hn->execute([$cid]); $patient = $stmt_hn->fetch(); } if ($patient) { $hn = $patient['hn']; $fname = $patient['fname']; $lname = $patient['lname']; // Check if CID already registered in line_staff_register $stmt_check = $pdo_bot->prepare("SELECT * FROM line_staff_register WHERE cid = ?"); $stmt_check->execute([$cid]); $existing = $stmt_check->fetch(); if ($existing) { if (!empty($existing['user_id']) && $existing['user_id'] !== $line_uid) { $error = "เลขบัตรประชาชนนี้ถูกผูกกับบัญชี Line อื่นไปแล้ว"; } else { // Update existing $update = $pdo_bot->prepare("UPDATE line_staff_register SET user_id = ?, phone = ?, hn = ?, fname = ?, lname = ?, date = NOW(), ksh_user = 'Y' WHERE cid = ?"); $update->execute([$line_uid, $phone, $hn, $fname, $lname, $cid]); $_SESSION['cid'] = $cid; echo ""; exit; } } else { // Insert new $insert = $pdo_bot->prepare("INSERT INTO line_staff_register (user_id, fname, lname, cid, phone, date, hn, ksh_user, assessment_status) VALUES (?, ?, ?, ?, ?, NOW(), ?, 'Y', 0)"); $insert->execute([$line_uid, $fname, $lname, $cid, $phone, $hn]); $_SESSION['cid'] = $cid; echo ""; exit; } } else { $error = "ไม่พบหมายเลขบัตรประชาชนในระบบข้อมูลผู้ป่วย (HIS) กรุณาติดต่อหน่วยงานที่ดูแล"; } } } ?> ลงทะเบียนเข้าใช้งาน
Logo

ลงทะเบียน KSH-STAFF

กำลังตรวจสอบข้อมูล Line ของคุณ...