รายการยา

รหัสยา ชื่อยา กลุ่มยา HAD สถานะ การจัดการ
กำลังโหลดข้อมูล...
0
รายการยาทั้งหมด
0
High Alert Drug
0
ยาที่ใช้งาน
0
ยาที่ไม่ใช้งาน

ตั้งค่า Google Sheets

รับ API key จาก Google Cloud Console
พบใน URL ของ Google Sheet ของคุณ
Sheet นี้ใช้สำหรับดึงรายชื่อผู้ใช้ในระบบ
Sheet นี้ใช้สำหรับดึงรายชื่อรายการยาในระบบ
⚠️ หมายเหตุ CORS:
• หากเกิด CORS error ให้ deploy Apps Script ใหม่
• ตั้งค่า Execute as: "Me", Who has access: "Anyone"
• หรือใช้ Google Chrome ด้วย --disable-web-security flag
• หรือใช้ Live Server extension แทน file:// protocol
จำเป็นสำหรับการบันทึกข้อมูล (ดูคำแนะนำด้านล่าง)

คำแนะนำการตั้งค่า:

  1. สร้าง Google Sheet พร้อม 2 tabs:
    • Predispensing_Errors พร้อมคอลัมน์: วันที่, เลขที่รายงาน, เวร, ประเภท, สถานที่, กระบวนการ, ข้อผิดพลาด, รายการถูกต้อง, รายการผิด, สาเหตุ, รายละเอียดเพิ่มเติม, ผู้รายงาน
    • Users พร้อมคอลัมน์: PS Code, ID 13 หลัก, ชื่อ-นามสกุล, กลุ่ม, ระดับ, อีเมล, รหัสผ่าน, status
  2. แชร์ Google Sheet: คลิก "แชร์" → เปลี่ยนเป็น "ทุกคนที่มีลิงก์สามารถดูได้"
  3. สร้าง Google Apps Script สำหรับบันทึกข้อมูล:
    1. ใน Google Sheet ไปที่ Extensions → Apps Script
    2. ลบโค้ดเดิม และคัดลอกโค้ดด้านล่างใส่แทน
    3. บันทึก → Deploy → New deployment
    4. Type: Web app → Execute as: Me → Who has access: Anyone
    5. คัดลอก Web app URL มาใส่ในช่องด้านบน
    6. หมายเหตุ: หากอัปเดตโค้ด Apps Script ต้อง Deploy ใหม่
  4. ไปที่ Google Cloud Console
  5. เปิดใช้งาน Google Sheets API: APIs & Services → Library → ค้นหา "Google Sheets API" → เปิดใช้งาน
  6. สร้าง API Key: APIs & Services → Credentials → Create Credentials → API Key
  7. คัดลอกข้อมูลผู้ใช้จากไฟล์ users.csv ไปใส่ใน Sheet Users
  8. ทดสอบ: คลิก "รีเฟรชรายชื่อผู้ใช้" เพื่อตรวจสอบการเชื่อมต่อ

Google Apps Script Code:

// Minimal ตัวอย่าง (อัปเดต): Apps Script ไม่รองรับ setHeaders กับ ContentService
                        function jsonResponse(o){return ContentService.createTextOutput(JSON.stringify(o)).setMimeType(ContentService.MimeType.JSON);} 
                        function doPost(e){
                            try{
                                let data;
                                if(e.parameter && e.parameter.action){ data = e.parameter; }
                                else if(e.postData && e.postData.contents){ data = JSON.parse(e.postData.contents); }
                                else { return jsonResponse({error:'No data'}); }
                                const ss = SpreadsheetApp.openById('YOUR_SPREADSHEET_ID');
                                if(data.action==='append'){
                                    const sheet = ss.getSheetByName(data.sheetName || 'Predispensing_Errors');
                                    if(!sheet) return jsonResponse({error:'Sheet not found'});
                                    if(data.timestamp){
                                        sheet.appendRow([
                                            data.timestamp,
                                            data.reportId,
                                            data.shift,
                                            data.errorType,
                                            data.location,
                                            data.process,
                                            data.errorDetail,
                                            data.correctItem,
                                            data.incorrectItem,
                                            data.cause,
                                            data.additionalDetails||'',
                                            data.reporter
                                        ]);
                                        return jsonResponse({success:true});
                                    }
                                }
                                return jsonResponse({error:'Invalid action'});
                            }catch(err){return jsonResponse({error:err.toString()});}
                        }

หมายเหตุสำคัญ:

  • API Key ใช้สำหรับอ่านข้อมูลเท่านั้น (Users list)
  • Web App URL จำเป็นสำหรับการบันทึกข้อมูล
  • หากไม่ตั้งค่า Web App จะไม่สามารถบันทึกข้อผิดพลาดได้