[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.

This commit is contained in:
Lê Thành Đạt committed 2025-07-03 02:23:42 +07:00
1 parent 66793f0fc1
commit 790e8aada9
5 files changed
+128 -55

No files matched your search

@@ -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<PatientHistory> 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) {
@@ -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<File> imageFiles;
private ResponseListener<GetOrderInfoByCheckupRes> 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);
}
}
});
}
+2 -2
View File
@@ -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];
@@ -272,49 +272,57 @@ public class ServerHandler extends SimpleChannelInboundHandler<TextWebSocketFram
}
if (packet instanceof GetPatientHistoryRequest getPatientHistoryRequest) {
log.debug("Received GetPatientHistoryRequest");
try {
ResultSet rs = statement.executeQuery(
"select Checkup.checkup_date, Checkup.checkup_id, Checkup.suggestion, Checkup.diagnosis, Checkup.prescription_id, Checkup.notes\n" +
"from Customer\n" +
"join Checkup on Customer.customer_id = Checkup.customer_id\n" +
"where Checkup.status = \"DONE\" and Customer.customer_id = " +
getPatientHistoryRequest.getPatientId() +
" order by checkup_date"
);
log.debug("Received GetPatientHistoryRequest for patientId: {}", getPatientHistoryRequest.getPatientId());
String sql = """
SELECT
C.checkup_date, C.checkup_id, C.suggestion, C.diagnosis, C.prescription_id, C.notes
FROM Checkup C
WHERE C.status = ? AND C.customer_id = ?
ORDER BY C.checkup_date DESC
""";
if (!rs.isBeforeFirst()) {
System.out.println("No history data found in the checkup table.");
UserUtil.sendPacket(currentUser.getSessionId(), new GetPatientHistoryResponse(new String[0][0]));
} else {
ArrayList<String> 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<String[]> 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);
}
}
Binary file not shown.