From 790e8aada99fc4eb3e02cb04699ba7826dafdbce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Th=C3=A0nh=20=C4=90=E1=BA=A1t?= <91755733+lds217@users.noreply.github.com> Date: Thu, 3 Jul 2025 02:23:42 +0700 Subject: [PATCH] [update] Enhance CheckUpPage and HistoryViewDialog by integrating order information retrieval for checkups, improving data handling and user experience. Update patient history response structure and refine database query for better performance. Adjust QueueManagementPage to function as a modal dialog for improved user interaction. --- .../ui/component/CheckUpPage/CheckUpPage.java | 41 ++++++--- .../HistoryViewDialog/HistoryViewDialog.java | 52 ++++++++++- src/main/java/BsK/common/entity/Patient.java | 4 +- .../server/network/handler/ServerHandler.java | 86 ++++++++++-------- src/main/resources/database/BSK.db | Bin 1175552 -> 1175552 bytes 5 files changed, 128 insertions(+), 55 deletions(-) diff --git a/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java b/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java index 9eb41cd..9cc1cd8 100644 --- a/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java +++ b/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java @@ -342,6 +342,7 @@ public class CheckUpPage extends JPanel { openQueueButton.setBorder(BorderFactory.createEmptyBorder(8, 15, 8, 15)); // Reduced vertical padding from 10 to 8 openQueueButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); openQueueButton.addActionListener(e -> { + updateQueue(); queueManagementPage.setVisible(true); queueManagementPage.toFront(); }); @@ -1104,12 +1105,14 @@ public class CheckUpPage extends JPanel { if (selectedRow >= 0 && selectedRow < history.length) { // Get selected history data String[] selectedHistory = history[selectedRow]; - String checkupId = selectedHistory[0]; // Assuming first column is checkup ID - String patientName = customerFirstNameField.getText() + " " + customerLastNameField.getText(); - String checkupDate = selectedHistory.length > 1 ? selectedHistory[1] : ""; // Assuming second column is date - - // Open history view dialog - openHistoryViewDialog(checkupId, patientName, checkupDate); + if (selectedHistory.length > 1) { + String checkupId = selectedHistory[1]; // Corrected: Index 1 is the checkup ID + String patientName = customerFirstNameField.getText() + " " + customerLastNameField.getText(); + String checkupDate = selectedHistory[0]; // Corrected: Index 0 is the date + + // Open history view dialog + openHistoryViewDialog(checkupId, patientName, checkupDate); + } } } } @@ -1694,12 +1697,21 @@ public class CheckUpPage extends JPanel { private void handleGetPatientHistoryResponse(GetPatientHistoryResponse response) { SwingUtilities.invokeLater(() -> { log.info("Received patient history"); - this.history = response.getHistory(); + this.history = response.getHistory(); // Keep original 6-column data for the dialog - // Access PatientHistory objects if needed - List patientHistories = response.getPatientHistoryList(); + // Prepare data specifically for the 5-column table view + String[][] tableData = new String[this.history.length][5]; + for (int i = 0; i < this.history.length; i++) { + if (this.history[i] != null && this.history[i].length >= 6) { + tableData[i][0] = this.history[i][0]; // "Ngày Tháng" (Date) + tableData[i][1] = this.history[i][1]; // "Mã khám bệnh" (ID) + tableData[i][2] = this.history[i][2]; // "Triệu chứng" (Suggestion) + tableData[i][3] = this.history[i][3]; // "Chẩn đoán" (Diagnosis) + tableData[i][4] = this.history[i][5]; // "Ghi chú" (Notes) - was incorrectly showing prescription_id + } + } - historyModel.setDataVector(this.history, new String[]{"Ngày Tháng","Mã khám bệnh", "Triệu chứng", "Chẩn đoán", "Ghi chú"}); + historyModel.setDataVector(tableData, new String[]{"Ngày Tháng","Mã khám bệnh", "Triệu chứng", "Chẩn đoán", "Ghi chú"}); }); } @@ -2641,12 +2653,13 @@ public class CheckUpPage extends JPanel { * A separate window (JFrame) to manage and display the patient queue. * It communicates with the main CheckUpPage to handle patient selection. */ - private class QueueManagementPage extends JFrame { + private class QueueManagementPage extends JDialog { private JTable queueTable; private DefaultTableModel queueTableModel; public QueueManagementPage() { - setTitle("Danh sách chờ khám"); + super(mainFrame, "Danh sách chờ khám", true); // Set as modal dialog + setIconImage(new ImageIcon("src/main/java/BsK/client/ui/assets/icon/database.png").getImage()); setSize(800, 600); setLayout(new BorderLayout()); @@ -2713,6 +2726,8 @@ public class CheckUpPage extends JPanel { } // Call the parent class's method to handle the selection CheckUpPage.this.handleRowSelection(selectedRow); + // Hide the dialog after selection + QueueManagementPage.this.setVisible(false); } }); } @@ -2724,7 +2739,7 @@ public class CheckUpPage extends JPanel { add(scrollPane, BorderLayout.CENTER); setLocationRelativeTo(mainFrame); - setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); } private int findRowByCheckupId(String checkupId) { diff --git a/src/main/java/BsK/client/ui/component/CheckUpPage/HistoryViewDialog/HistoryViewDialog.java b/src/main/java/BsK/client/ui/component/CheckUpPage/HistoryViewDialog/HistoryViewDialog.java index cca6ac1..f75e403 100644 --- a/src/main/java/BsK/client/ui/component/CheckUpPage/HistoryViewDialog/HistoryViewDialog.java +++ b/src/main/java/BsK/client/ui/component/CheckUpPage/HistoryViewDialog/HistoryViewDialog.java @@ -23,6 +23,11 @@ import java.util.Date; import java.util.List; import javax.imageio.ImageIO; import lombok.extern.slf4j.Slf4j; +import BsK.client.network.handler.ClientHandler; +import BsK.client.network.handler.ResponseListener; +import BsK.common.packet.req.GetOrderInfoByCheckupReq; +import BsK.common.packet.res.GetOrderInfoByCheckupRes; +import BsK.common.util.network.NetworkUtil; @Slf4j public class HistoryViewDialog extends JDialog { @@ -60,6 +65,7 @@ public class HistoryViewDialog extends JDialog { // Current selected image private BufferedImage currentSelectedImage; private List imageFiles; + private ResponseListener orderInfoListener; public HistoryViewDialog(Frame parent, String checkupId, String patientName, String checkupDate) { super(parent, "Xem chi tiết lịch sử khám - " + patientName, true); @@ -68,13 +74,16 @@ public class HistoryViewDialog extends JDialog { this.checkupDate = checkupDate; this.imageFiles = new ArrayList<>(); - // Initialize sample data for demonstration + // Initialize sample data for demonstration (will be overwritten by network response) initializeSampleData(); initializeDialog(parent); setupUI(); loadImagesForCheckup(); updatePrescriptionTree(); + + // Fetch real data from server + fetchOrderInformation(); } private void initializeSampleData() { @@ -96,6 +105,39 @@ public class HistoryViewDialog extends JDialog { }; } + private void fetchOrderInformation() { + try { + orderInfoListener = new ResponseListener<>() { + @Override + public void onResponse(GetOrderInfoByCheckupRes response) { + SwingUtilities.invokeLater(() -> { + try { + setMedicinePrescription(response.getMedicinePrescription()); + setServicePrescription(response.getServicePrescription()); + log.info("Successfully updated history order tree for checkupId: {}", checkupId); + } finally { + // Remove listener after execution to prevent memory leaks + if (orderInfoListener != null) { + ClientHandler.deleteListener(GetOrderInfoByCheckupRes.class, orderInfoListener); + orderInfoListener = null; + } + } + }); + } + }; + + ClientHandler.addResponseListener(GetOrderInfoByCheckupRes.class, orderInfoListener); + NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetOrderInfoByCheckupReq(this.checkupId)); + log.info("Sent GetOrderInfoByCheckupReq for checkupId: {}", this.checkupId); + } catch (Exception e) { + log.error("Error sending GetOrderInfoByCheckupReq for checkupId: {}", this.checkupId, e); + if (orderInfoListener != null) { + ClientHandler.deleteListener(GetOrderInfoByCheckupRes.class, orderInfoListener); + orderInfoListener = null; + } + } + } + private void initializeDialog(Frame parent) { setDefaultCloseOperation(DISPOSE_ON_CLOSE); setSize(1200, 800); @@ -117,6 +159,14 @@ public class HistoryViewDialog extends JDialog { parent.setState(Frame.NORMAL); } } + + @Override + public void windowClosed(WindowEvent e) { + // Clean up listener when dialog is closed, just in case + if (orderInfoListener != null) { + ClientHandler.deleteListener(GetOrderInfoByCheckupRes.class, orderInfoListener); + } + } }); } diff --git a/src/main/java/BsK/common/entity/Patient.java b/src/main/java/BsK/common/entity/Patient.java index 5152ee0..16f4192 100644 --- a/src/main/java/BsK/common/entity/Patient.java +++ b/src/main/java/BsK/common/entity/Patient.java @@ -49,8 +49,8 @@ public class Patient { // New constructor for a single patient data row public Patient(String[] data) { - if (data.length < 17) { - throw new IllegalArgumentException("Patient data array must contain at least 17 elements."); + if (data.length < 18) { + throw new IllegalArgumentException("Patient data array must contain at least 18 elements to include a conclusion."); } this.checkupId = data[0]; this.checkupDate = data[1]; diff --git a/src/main/java/BsK/server/network/handler/ServerHandler.java b/src/main/java/BsK/server/network/handler/ServerHandler.java index 582633f..3f430a0 100644 --- a/src/main/java/BsK/server/network/handler/ServerHandler.java +++ b/src/main/java/BsK/server/network/handler/ServerHandler.java @@ -272,49 +272,57 @@ public class ServerHandler extends SimpleChannelInboundHandler resultList = new ArrayList<>(); - while (rs.next()) { - String checkupDate = rs.getString("checkup_date"); - long checkupDateLong = Long.parseLong(checkupDate); - Timestamp timestamp = new Timestamp(checkupDateLong); - Date date = new Date(timestamp.getTime()); // Needed to recode - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); - checkupDate = sdf.format(date); - String checkupId = rs.getString("checkup_id"); - String suggestion = rs.getString("suggestion"); - String diagnosis = rs.getString("diagnosis"); - String prescriptionId = rs.getString("prescription_id"); - String notes = rs.getString("notes"); - String result = String.join("|", checkupDate, checkupId, suggestion, diagnosis, prescriptionId, notes); - resultList.add(result); - // log.info(result); + try (PreparedStatement historyStmt = Server.connection.prepareStatement(sql)) { + + historyStmt.setString(1, "ĐÃ KHÁM"); + historyStmt.setInt(2, getPatientHistoryRequest.getPatientId()); + + try (ResultSet rs = historyStmt.executeQuery()) { + if (!rs.isBeforeFirst()) { + log.info("No history data found for patientId: {}", getPatientHistoryRequest.getPatientId()); + UserUtil.sendPacket(currentUser.getSessionId(), new GetPatientHistoryResponse(new String[0][0])); + } else { + ArrayList resultList = new ArrayList<>(); + while (rs.next()) { + String[] historyEntry = new String[6]; + + String checkupDateStr = rs.getString("checkup_date"); + try { + long checkupDateLong = Long.parseLong(checkupDateStr); + Timestamp timestamp = new Timestamp(checkupDateLong); + Date date = new Date(timestamp.getTime()); + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + historyEntry[0] = sdf.format(date); + } catch (Exception e) { + historyEntry[0] = checkupDateStr; // Fallback to raw string if not a timestamp + } + + historyEntry[1] = rs.getString("checkup_id"); + historyEntry[2] = rs.getString("suggestion"); + historyEntry[3] = rs.getString("diagnosis"); + historyEntry[4] = rs.getString("prescription_id"); + historyEntry[5] = rs.getString("notes"); + + resultList.add(historyEntry); + } + + String[][] resultArray = resultList.toArray(new String[0][]); + UserUtil.sendPacket(currentUser.getSessionId(), new GetPatientHistoryResponse(resultArray)); + log.info("Sent patient history for patientId: {}", getPatientHistoryRequest.getPatientId()); } - - String[] resultString = resultList.toArray(new String[0]); - String[][] resultArray = new String[resultString.length][]; - for (int i = 0; i < resultString.length; i++) { - resultArray[i] = resultString[i].split("\\|"); - } - - UserUtil.sendPacket(currentUser.getSessionId(), new GetPatientHistoryResponse(resultArray)); } - } catch (SQLException e) { + log.error("Error fetching patient history for patientId: " + getPatientHistoryRequest.getPatientId(), e); throw new RuntimeException(e); } } diff --git a/src/main/resources/database/BSK.db b/src/main/resources/database/BSK.db index bc1feac77ea2c7af629c3bdce6194d36f0de6de4..f1bc837c5f6dddf0da3c2b104ab8149c6007a052 100644 GIT binary patch delta 786 zcmYk2O-K}B7{}+CncdlO=6z=#WzlWdk8LQ@kX_f*E(MF(`az;dWnZTB0d?@uB4rTh z?x9m;7`{YE1s%i|!Zut&OiT}f5UoajlqhuR5J==9BC2<14te-p-rxKD`9IIVW^7~ zj+p8BuG3MIRO^5AQ{+3DCyZRx@A9!NZMZlUCqWGaQLQJU2$q>1P4!+dI_MUirgvyN z4H+Y(fR&g~=;|=ul52cyT4z53&;u2jAelDtY1lE~!kA#FG6U zUWmW=|F@AuVXm#Mq4h{pYm9v@g>rStm@>W?bH-E}yPp_rDg;C_iFtb=1RRkgab%8* zW+~)-^#3f^fj=OK_DTr$g`bE!QWm}mQA1Hl! z``mk6syre0%Td`Qy_25v1*2djEEjbN08*bvp3|(JCs=4QQf}IE`{;k&P~4 z4b-yiGLEyZMO4|t4MbMDhWU8*ay$`mJD)G*a@fEc9%Af0&N^2)syHQ2+9eOKVOZNy SGL!m@ZjibAnVDS2=KO!UA=q#L delta 795 zcmXw#O-NKx7>3Vx?_BTPnS0KeGj{zO%~5HgA$J`ARv}_xrdT#bR%D8_NJPl679rRj z!d0mmo>fth6*Ukx;2=wrBA-_tMR-#Cpq?h|9%{>h@mO`PusBxy}plAugaK28ku9-XBzvP~AqebPZp zI)$@wjArXQco0|9YC`cg{!DM-8T=3rikto?XwP=lMiq0kuL|L_r$J*9;a{OZd4A+vSlA3sNhO3I{;$ zF_7)#ePw_59aVFk76VzsC0t%(zj*H|3lb}c-L#mU#_QHuEkq};F5ThXo6MYAXNHrI zdb`3d0}1-wm=1UKt7Z1bu>(W>{Z#}z%j?BS4Icf*N|}A&CSAy)?G;D1R#{EZmc1V! z;5_dzs5Q)AF0&e_KiGQ~SNQBHO|EpNKCZG*wmsz=L=E-_TZCMO5Leb%c}{w~vAsFm zY8~;qzSuwRr6*q6l bxn|1x!aQzXDzU+`z;ky