Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 3eee1fd8 authored by 65160130's avatar 65160130
Browse files

add showAddTreatmentForm

parent caf37599
Branches master
No related tags found
No related merge requests found
......@@ -16,6 +16,8 @@ class DentistController {
}
}
//แสดงประวัติการรักษา
static async showTreatmentHistory(req, res) {
const patientId = req.params.id;
......@@ -49,30 +51,84 @@ class DentistController {
}
}
// แสดงหน้าฟอร์มเพิ่มประวัติการรักษา
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('ไม่พบข้อมูลการรักษา');
}
// ส่งข้อมูลที่ดึงมาให้หน้า EJS
// ใช้ patient_id ที่ได้จาก queueDetail
const patientId = queueDetail.patient_id;
if (!patientId) {
console.error("Patient ID is missing.");
return res.status(400).send("Patient ID is missing.");
}
// ตรวจสอบว่า `patient_id` นี้มีการจองใหม่ที่ยังไม่ได้บันทึกการรักษาหรือไม่
const treatmentHistory = await TreatmentHistory.getTreatmentHistory(patientId);
// ถ้าการบันทึกของ queuedetail_id อยู่ใน treatmentHistory
if (treatmentHistory && treatmentHistory.length > 0) {
// ตรวจสอบการจองล่าสุดจาก patient_id
const newQueueDetail = await QueueDetail.getQueueDetailsByPatientId(patientId);
if (!newQueueDetail) {
// ถ้าไม่มีการจองใหม่
return res.render('addtreatmenthis', {
message: 'ไม่พบการจองใหม่สำหรับผู้ป่วยนี้',
patient_id: patientId,
});
}
// เปรียบเทียบว่า newQueueDetail ถูกบันทึกใน treatmentHistory หรือไม่
const isAlreadyBooked = treatmentHistory.some(th =>
th.queuedetail_id === newQueueDetail.queuedetail_id
);
if (isAlreadyBooked) {
// ถ้าการจองนี้ถูกบันทึกแล้วใน `treatmenthistory`
return res.render('addtreatmenthis', {
message: 'ไม่พบการจองใหม่สำหรับผู้ป่วยนี้',
patient_id: patientId,
});
}
// ถ้ามีการจองใหม่ที่ยังไม่ได้บันทึก ให้แสดงข้อมูลการจอง
res.render('addtreatmenthis', {
queuedetail_id: queueDetail.queuedetail_id,
treatment_date: queueDetail.treatment_date,
patient_name: queueDetail.patient_name,
treatment_name: queueDetail.treatment_name,
queuedetail_id: newQueueDetail.queuedetail_id,
treatment_date: newQueueDetail.treatment_date,
patient_name: newQueueDetail.patient_name,
treatment_name: newQueueDetail.treatment_name,
});
} else {
// หากไม่มีการจองใหม่ที่ยังไม่ได้บันทึกการรักษา
return res.render('addtreatmenthis', {
message: 'ไม่พบการจองใหม่สำหรับผู้ป่วยนี้',
patient_id: patientId,
});
}
} catch (error) {
console.error("Error fetching queue details:", error.message);
res.status(500).send("Error fetching queue details");
}
}
// เพิ่มประวัติการรักษาใหม่
static async addTreatmentHistory(req, res) {
const { queuedetail_id, dentist_name, tm_details, followUpdate } = req.body;
......@@ -88,6 +144,8 @@ class DentistController {
}
}
//แสดงฟอร์มแก้ไขข้อมูล
static async showEditTreatmentForm(req, res) {
const treatmenthistoryId = req.params.id;
......@@ -107,6 +165,7 @@ class DentistController {
}
//อัปเดตข้อมูล
static async updateTreatmentHistory(req, res) {
const { treatmenthistory_id, dentist_name, tm_details, followUpdate } = req.body;
......@@ -129,6 +188,8 @@ class DentistController {
}
}
// ลบประวัติการรักษา
static async deleteTreatmentHistory(req, res) {
const treatmenthistoryId = req.params.id;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment