Gitlab@Informatics

Skip to content
Snippets Groups Projects
Select Git revision
  • 3eee1fd8e09ffc56076d3c1b85078e83dd13484f
  • master default
  • main protected
3 results

DentistController.js

Blame
  • DentistController.js 10.40 KiB
    const QueueDetail = require('../models/QueueDetail');
    const TreatmentHistory = require('../models/TreatmentHistory')
    
    
    class DentistController {
        //แสดงหน้า my treatment
        static async showQueueDetailsById(req, res) {
            const searchQuery = req.query.search || ''; // รับคำค้นหาจาก url query
            try{
                const queueDetails = await QueueDetail.getQueueDetails(searchQuery); // ส่งคำค้นหาที่ได้ไปยังเมธอดใน Model
    
                res.render('treatment', { queueDetails }); // แสดงหน้ารักษาพร้อมผลลัพธ์ที่กรองแล้ว
            } catch (error) {
                console.error("Error fetching queue details:", error.message);
                res.status(500).send("Error fetching queue details");
            }
        }
        
    
    
        //แสดงประวัติการรักษา
        static async showTreatmentHistory(req, res) {
            const patientId = req.params.id;
    
            if (!patientId) {
                console.error("Patient ID is missing or invalid.");
                return res.status(400).send("Invalid Patient ID.");
            }
    
            try {
                //ดึงข้อมูลจากตาราง treatmenthistoryและค้นหา
                const treatmentHistory = await TreatmentHistory.getTreatmentHistory(patientId);
    
                if (!treatmentHistory || treatmentHistory.length === 0) {
                    console.log('No treatment history found.');
                    return res.render('treatmenthistory', { 
                        message: "ไม่พบการรักษา", 
                        patientId,
                        treatmentHistory:[] // สำหรับประวัติการรักษาเมื่อไม่พบข้อมูล
                    });
                }
    
                res.render('treatmenthistory', { 
                    treatmentHistory, 
                    patientId,
                    message: null // ไม่มีข้อความเมื่อมีข้อมูล
                });
            } catch (error) {
                console.error("Error fetching treatment history:", error.message);
                res.status(500).send("Error fetching treatment history");
            }
        }
    
    
    
        static async showAddTreatmentForm(req, res) {
            const queuedetail_id = req.params.queuedetail_id;
        
            // ตรวจสอบว่า queuedetail_id ถูกต้องหรือไม่
            if (!queuedetail_id) {
                console.error("queuedetail_id is missing or invalid.");
                return res.status(400).send("Invalid queuedetail_id.");
            }
        
            try {
                // ดึงข้อมูลจาก queuedetail โดยใช้ queuedetail_id
                const queueDetail = await QueueDetail.getQueueDetailById(queuedetail_id);
        
                if (!queueDetail) {
                    return res.status(404).send('ไม่พบข้อมูลการรักษา');