Gitlab@Informatics

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

add showAddTreatmentForm

parent caf37599
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,8 @@ class DentistController { ...@@ -16,6 +16,8 @@ class DentistController {
} }
} }
//แสดงประวัติการรักษา //แสดงประวัติการรักษา
static async showTreatmentHistory(req, res) { static async showTreatmentHistory(req, res) {
const patientId = req.params.id; const patientId = req.params.id;
...@@ -49,30 +51,84 @@ class DentistController { ...@@ -49,30 +51,84 @@ class DentistController {
} }
} }
// แสดงหน้าฟอร์มเพิ่มประวัติการรักษา
static async showAddTreatmentForm(req, res) { static async showAddTreatmentForm(req, res) {
const queuedetail_id = req.params.queuedetail_id; 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 { try {
// ดึงข้อมูลจาก queuedetail โดยใช้ queuedetail_id // ดึงข้อมูลจาก queuedetail โดยใช้ queuedetail_id
const queueDetail = await QueueDetail.getQueueDetailById(queuedetail_id); const queueDetail = await QueueDetail.getQueueDetailById(queuedetail_id);
if (!queueDetail) { if (!queueDetail) {
return res.status(404).send('ไม่พบข้อมูลการรักษา'); 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', { res.render('addtreatmenthis', {
queuedetail_id: queueDetail.queuedetail_id, queuedetail_id: newQueueDetail.queuedetail_id,
treatment_date: queueDetail.treatment_date, treatment_date: newQueueDetail.treatment_date,
patient_name: queueDetail.patient_name, patient_name: newQueueDetail.patient_name,
treatment_name: queueDetail.treatment_name, treatment_name: newQueueDetail.treatment_name,
});
} else {
// หากไม่มีการจองใหม่ที่ยังไม่ได้บันทึกการรักษา
return res.render('addtreatmenthis', {
message: 'ไม่พบการจองใหม่สำหรับผู้ป่วยนี้',
patient_id: patientId,
}); });
}
} catch (error) { } catch (error) {
console.error("Error fetching queue details:", error.message); console.error("Error fetching queue details:", error.message);
res.status(500).send("Error fetching queue details"); res.status(500).send("Error fetching queue details");
} }
} }
// เพิ่มประวัติการรักษาใหม่ // เพิ่มประวัติการรักษาใหม่
static async addTreatmentHistory(req, res) { static async addTreatmentHistory(req, res) {
const { queuedetail_id, dentist_name, tm_details, followUpdate } = req.body; const { queuedetail_id, dentist_name, tm_details, followUpdate } = req.body;
...@@ -88,6 +144,8 @@ class DentistController { ...@@ -88,6 +144,8 @@ class DentistController {
} }
} }
//แสดงฟอร์มแก้ไขข้อมูล //แสดงฟอร์มแก้ไขข้อมูล
static async showEditTreatmentForm(req, res) { static async showEditTreatmentForm(req, res) {
const treatmenthistoryId = req.params.id; const treatmenthistoryId = req.params.id;
...@@ -107,6 +165,7 @@ class DentistController { ...@@ -107,6 +165,7 @@ class DentistController {
} }
//อัปเดตข้อมูล //อัปเดตข้อมูล
static async updateTreatmentHistory(req, res) { static async updateTreatmentHistory(req, res) {
const { treatmenthistory_id, dentist_name, tm_details, followUpdate } = req.body; const { treatmenthistory_id, dentist_name, tm_details, followUpdate } = req.body;
...@@ -129,6 +188,8 @@ class DentistController { ...@@ -129,6 +188,8 @@ class DentistController {
} }
} }
// ลบประวัติการรักษา // ลบประวัติการรักษา
static async deleteTreatmentHistory(req, res) { static async deleteTreatmentHistory(req, res) {
const treatmenthistoryId = req.params.id; 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