diff --git a/database/BSK.db-shm b/database/BSK.db-shm index 0194ae2..4d7a7fc 100644 Binary files a/database/BSK.db-shm and b/database/BSK.db-shm differ diff --git a/database/BSK.db-wal b/database/BSK.db-wal index 38aee3c..dcc7d2d 100644 Binary files a/database/BSK.db-wal and b/database/BSK.db-wal differ diff --git a/src/main/java/BsK/client/LocalStorage.java b/src/main/java/BsK/client/LocalStorage.java index e2481b4..fe59ab0 100644 --- a/src/main/java/BsK/client/LocalStorage.java +++ b/src/main/java/BsK/client/LocalStorage.java @@ -24,6 +24,7 @@ public class LocalStorage { public static String pathToProject = ""; public static int currentMaxQueueNumber = 0; + public static int currentShift = 0; // 0 for morning, 1 for afternoon public static String dataDialogSearchTerm = ""; public static Date dataDialogFromDate = new Date(); public static Date dataDialogToDate = new Date(); 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 b206df2..ea7ada4 100644 --- a/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java +++ b/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java @@ -291,7 +291,7 @@ public class CheckUpPage extends JPanel { public void updateQueue() { - NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueRequest()); + NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueRequest(LocalStorage.currentShift)); } @@ -300,7 +300,7 @@ public class CheckUpPage extends JPanel { } public void updateUpdateQueue() { - NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueUpdateRequest()); + NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueUpdateRequest(LocalStorage.currentShift)); } private String[][] preprocessPatientDataForTable(List patients) { @@ -602,8 +602,6 @@ public class CheckUpPage extends JPanel { driveButton.setBackground(new Color(26, 115, 232)); // Google Blue color driveButton.setForeground(Color.WHITE); driveButton.setFocusPainted(false); - driveButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); - driveButton.setEnabled(false); // Disabled by default driveButton.setBorder(BorderFactory.createEmptyBorder(8, 15, 8, 15)); // Load and set the icon @@ -4851,7 +4849,8 @@ public class CheckUpPage extends JPanel { (Integer) patientHeartRateSpinner.getValue(), bloodPressureSystolicSpinner.getValue() + "/" + bloodPressureDiastolicSpinner.getValue(), medicinePrescription, - servicePrescription + servicePrescription, + LocalStorage.currentShift ); NetworkUtil.sendPacket(ClientHandler.ctx.channel(), request); saved = true; diff --git a/src/main/java/BsK/client/ui/component/DashboardPage/DashboardPage.java b/src/main/java/BsK/client/ui/component/DashboardPage/DashboardPage.java index 20abfbe..3066b5d 100644 --- a/src/main/java/BsK/client/ui/component/DashboardPage/DashboardPage.java +++ b/src/main/java/BsK/client/ui/component/DashboardPage/DashboardPage.java @@ -53,7 +53,12 @@ public class DashboardPage extends JPanel { private void handleGetCheckUpQueueUpdateResponse(GetCheckUpQueueUpdateResponse response) { SwingUtilities.invokeLater(() -> { - log.info("Received dashboard queue update from server."); + if (response.getShift() != LocalStorage.currentShift) { + log.info("Ignored dashboard queue update for different shift. Current: {}, Received: {}", LocalStorage.currentShift, response.getShift()); + return; + } + + log.info("Received dashboard queue update from server for shift {}.", response.getShift()); this.patientQueue.clear(); if (response.getQueue() != null) { for (String[] patientData : response.getQueue()) { @@ -128,7 +133,7 @@ public class DashboardPage extends JPanel { ClientHandler.addResponseListener(TodayPatientCountResponse.class, todayPatientCountListener); ClientHandler.addResponseListener(RecheckCountResponse.class, recheckCountListener); log.info("DashboardPage listeners registered. Requesting initial data."); - NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueUpdateRequest()); + NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueUpdateRequest(LocalStorage.currentShift)); } private void startRealTimeClock() { diff --git a/src/main/java/BsK/client/ui/component/LoginPage/LoginPage.java b/src/main/java/BsK/client/ui/component/LoginPage/LoginPage.java index 2eafcf2..a623921 100644 --- a/src/main/java/BsK/client/ui/component/LoginPage/LoginPage.java +++ b/src/main/java/BsK/client/ui/component/LoginPage/LoginPage.java @@ -78,6 +78,21 @@ public class LoginPage extends JPanel { gbc.anchor = GridBagConstraints.WEST; JPasswordField passwordField = new JPasswordField(20); formPanel.add(passwordField, gbc); + + gbc.gridx = 0; + gbc.gridy++; + gbc.anchor = GridBagConstraints.EAST; + JLabel shiftLabel = new JLabel("Chọn ca:"); + shiftLabel.setForeground(Color.WHITE); + shiftLabel.setFont(new Font("Arial", Font.PLAIN, 14)); + formPanel.add(shiftLabel, gbc); + + gbc.gridx = 1; + gbc.anchor = GridBagConstraints.WEST; + String[] shifts = {"Chọn ca", "Ca sáng", "Ca chiều"}; + JComboBox shiftComboBox = new JComboBox<>(shifts); + formPanel.add(shiftComboBox, gbc); + // --- BUTTON PANEL START --- gbc.gridx = 0; @@ -120,10 +135,15 @@ public class LoginPage extends JPanel { passwordField.addActionListener(e -> loginButton.doClick()); loginButton.addActionListener(e -> { + if (shiftComboBox.getSelectedIndex() == 0) { + JOptionPane.showMessageDialog(this, "Vui lòng chọn ca làm việc.", "Lỗi", JOptionPane.ERROR_MESSAGE); + return; + } char[] passwordChars = passwordField.getPassword(); String password = new String(passwordChars); String username = loginField.getText(); - var loginRequest = new LoginRequest(username, password); + int shift = shiftComboBox.getSelectedIndex() - 1; + var loginRequest = new LoginRequest(username, password, shift); NetworkUtil.sendPacket(ClientHandler.ctx.channel(), loginRequest); }); @@ -131,6 +151,7 @@ public class LoginPage extends JPanel { log.info("Login successful, UserId: {}, Role: {}", response.getUserId(), response.getRole()); LocalStorage.username = loginField.getText(); LocalStorage.userId = response.getUserId(); + LocalStorage.currentShift = shiftComboBox.getSelectedIndex() - 1; // 0 for morning, 1 for afternoon NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new ClinicInfoRequest()); NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetDoctorGeneralInfo()); NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetProvinceRequest()); diff --git a/src/main/java/BsK/client/ui/component/common/AddDialog/AddDialog.java b/src/main/java/BsK/client/ui/component/common/AddDialog/AddDialog.java index 8c08044..1679b16 100644 --- a/src/main/java/BsK/client/ui/component/common/AddDialog/AddDialog.java +++ b/src/main/java/BsK/client/ui/component/common/AddDialog/AddDialog.java @@ -644,8 +644,8 @@ public class AddDialog extends JDialog { // Send -1 to let the server know to auto-increment the queue number queueNumber = -1; } - log.info("Sending AddCheckupRequest with queue number: {}", queueNumber); - NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new AddCheckupRequest(patientId, doctorId, LocalStorage.userId, selectedCheckupType, "CHỜ KHÁM", queueNumber)); + log.info("Sending AddCheckupRequest with queue number: {} for shift {}", queueNumber, LocalStorage.currentShift); + NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new AddCheckupRequest(patientId, doctorId, LocalStorage.userId, selectedCheckupType, "CHỜ KHÁM", queueNumber, LocalStorage.currentShift)); }); checkupInfoPanel.add(saveButton, gbc); @@ -1105,7 +1105,7 @@ private void setupDebounceSearch() { // Now that the JOptionPane is closed, the connection is still alive. // This packet will be sent successfully. - NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueUpdateRequest()); + NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueUpdateRequest(LocalStorage.currentShift)); patientIdField.setText(String.valueOf(response.getPatientId())); addPatientButton.setEnabled(false); // Disable add patient button diff --git a/src/main/java/BsK/client/ui/component/common/NavBar.java b/src/main/java/BsK/client/ui/component/common/NavBar.java index 1d26419..a8fd8fa 100644 --- a/src/main/java/BsK/client/ui/component/common/NavBar.java +++ b/src/main/java/BsK/client/ui/component/common/NavBar.java @@ -31,6 +31,7 @@ import java.awt.event.MouseEvent; import java.awt.event.ActionListener; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Calendar; @Slf4j public class NavBar extends JPanel { @@ -41,6 +42,7 @@ public class NavBar extends JPanel { private RoundedPanel messageButtonPanel; // NEW: Reference to message button panel for repainting private JSpinner counterSpinner; // NEW: Spinner for current number private boolean isUpdatingSpinner = false; // Flag to prevent recursive updates + private int currentShift = 0; // 0 for morning, 1 for afternoon // Listener for incoming emergency alerts private final ResponseListener emergencyResponseListener = this::handleEmergencyResponse; @@ -285,7 +287,9 @@ public class NavBar extends JPanel { this.add(Box.createHorizontalGlue()); this.add(userPanel); - NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCounterRequest()); + // Determine current shift and request counter + currentShift = LocalStorage.currentShift; + NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCounterRequest(currentShift)); } private int findNavItemIndex(String text, String[] items) { @@ -297,7 +301,7 @@ public class NavBar extends JPanel { // NEW: Create counter spinner component private Component createCounterSpinner() { - JPanel counterPanel = new JPanel(new BorderLayout(5, 0)); + JPanel counterPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); counterPanel.setBackground(this.getBackground()); counterPanel.setAlignmentY(Component.CENTER_ALIGNMENT); @@ -309,7 +313,7 @@ public class NavBar extends JPanel { // Create spinner with initial value of 1, minimum 1, maximum 999, step 1 SpinnerNumberModel spinnerModel = new SpinnerNumberModel(1, 1, 999, 1); counterSpinner = new JSpinner(spinnerModel); - counterSpinner.setPreferredSize(new Dimension(80, 30)); + counterSpinner.setPreferredSize(new Dimension(60, 30)); counterSpinner.setFont(new Font("Arial", Font.BOLD, 14)); counterSpinner.setEnabled(false); // Style the spinner @@ -330,13 +334,21 @@ public class NavBar extends JPanel { log.info("Counter spinner changed to: {}", newValue); // Send SetCounterRequest to server - NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new SetCounterRequest(newValue)); + NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new SetCounterRequest(newValue, currentShift)); } } }); - counterPanel.add(counterLabel, BorderLayout.WEST); - counterPanel.add(counterSpinner, BorderLayout.EAST); + counterPanel.add(counterLabel); + counterPanel.add(counterSpinner); + + String shiftText = (LocalStorage.currentShift == 0) ? "Ca sáng" : "Ca chiều"; + JLabel shiftLabel = new JLabel(shiftText); + shiftLabel.setFont(new Font("Arial", Font.BOLD, 12)); + shiftLabel.setForeground(new Color(60, 60, 60)); + + counterPanel.add(new JLabel("Ca:")); + counterPanel.add(shiftLabel); return counterPanel; } @@ -344,16 +356,21 @@ public class NavBar extends JPanel { // NEW: Handle SetCounterResponse private void handleSetCounterResponse(SetCounterResponse response) { SwingUtilities.invokeLater(() -> { - log.info("Received SetCounterResponse with value: {}", response.getCounter()); - LocalStorage.currentMaxQueueNumber = response.getCounter(); - // Update spinner value without triggering change event - isUpdatingSpinner = true; - try { - counterSpinner.setValue(response.getCounter()); - } catch (Exception e) { - log.error("Error updating counter spinner: {}", e.getMessage()); - } finally { - isUpdatingSpinner = false; + // Only update if the response is for the currently selected shift + if (response.getShift() == currentShift) { + log.info("Received SetCounterResponse with value: {} for shift {}", response.getCounter(), response.getShift()); + LocalStorage.currentMaxQueueNumber = response.getCounter(); + // Update spinner value without triggering change event + isUpdatingSpinner = true; + try { + counterSpinner.setValue(response.getCounter()); + } catch (Exception e) { + log.error("Error updating counter spinner: {}", e.getMessage()); + } finally { + isUpdatingSpinner = false; + } + } else { + log.info("Ignored SetCounterResponse for different shift. Current: {}, Received: {}", currentShift, response.getShift()); } }); } @@ -705,17 +722,21 @@ public class NavBar extends JPanel { private void handleGetCounterResponse(GetCounterResponse response) { SwingUtilities.invokeLater(() -> { - log.info("Received GetCounterResponse with initial value: {}", response.getCounter()); - LocalStorage.currentMaxQueueNumber = response.getCounter(); - // Update spinner value without triggering change event - isUpdatingSpinner = true; - try { - counterSpinner.setValue(response.getCounter()); - log.info("Counter spinner initialized to: {}", response.getCounter()); - } catch (Exception e) { - log.error("Error initializing counter spinner: {}", e.getMessage()); - } finally { - isUpdatingSpinner = false; + if (response.getShift() == currentShift) { + log.info("Received GetCounterResponse with initial value: {} for shift {}", response.getCounter(), response.getShift()); + LocalStorage.currentMaxQueueNumber = response.getCounter(); + // Update spinner value without triggering change event + isUpdatingSpinner = true; + try { + counterSpinner.setValue(response.getCounter()); + log.info("Counter spinner initialized to: {} for shift {}", response.getCounter(), response.getShift()); + } catch (Exception e) { + log.error("Error initializing counter spinner: {}", e.getMessage()); + } finally { + isUpdatingSpinner = false; + } + } else { + log.info("Ignored GetCounterResponse for different shift. Current: {}, Received: {}", currentShift, response.getShift()); } }); } diff --git a/src/main/java/BsK/common/packet/req/AddCheckupRequest.java b/src/main/java/BsK/common/packet/req/AddCheckupRequest.java index 701cd67..920c558 100644 --- a/src/main/java/BsK/common/packet/req/AddCheckupRequest.java +++ b/src/main/java/BsK/common/packet/req/AddCheckupRequest.java @@ -14,4 +14,5 @@ public class AddCheckupRequest implements Packet { private String checkupType; private String status; private int queueNumber; + private int shift; // 0 for morning, 1 for afternoon } diff --git a/src/main/java/BsK/common/packet/req/DeleteCheckupRequest.java b/src/main/java/BsK/common/packet/req/DeleteCheckupRequest.java index c618ee5..d283093 100644 --- a/src/main/java/BsK/common/packet/req/DeleteCheckupRequest.java +++ b/src/main/java/BsK/common/packet/req/DeleteCheckupRequest.java @@ -6,9 +6,11 @@ import lombok.Data; @Data public class DeleteCheckupRequest implements Packet { private long checkupId; + private int shift; - public DeleteCheckupRequest(long checkupId) { + public DeleteCheckupRequest(long checkupId, int shift) { this.checkupId = checkupId; + this.shift = shift; } } diff --git a/src/main/java/BsK/common/packet/req/GetCheckUpQueueRequest.java b/src/main/java/BsK/common/packet/req/GetCheckUpQueueRequest.java index 38d365b..70c2881 100644 --- a/src/main/java/BsK/common/packet/req/GetCheckUpQueueRequest.java +++ b/src/main/java/BsK/common/packet/req/GetCheckUpQueueRequest.java @@ -1,5 +1,11 @@ package BsK.common.packet.req; import BsK.common.packet.Packet; +import lombok.AllArgsConstructor; +import lombok.Data; -public class GetCheckUpQueueRequest implements Packet {} +@AllArgsConstructor +@Data +public class GetCheckUpQueueRequest implements Packet { + private int shift; +} diff --git a/src/main/java/BsK/common/packet/req/GetCheckUpQueueUpdateRequest.java b/src/main/java/BsK/common/packet/req/GetCheckUpQueueUpdateRequest.java index 5bf5bf8..031db74 100644 --- a/src/main/java/BsK/common/packet/req/GetCheckUpQueueUpdateRequest.java +++ b/src/main/java/BsK/common/packet/req/GetCheckUpQueueUpdateRequest.java @@ -1,6 +1,11 @@ package BsK.common.packet.req; import BsK.common.packet.Packet; +import lombok.AllArgsConstructor; +import lombok.Getter; +@AllArgsConstructor +@Getter public class GetCheckUpQueueUpdateRequest implements Packet { + private int shift; } diff --git a/src/main/java/BsK/common/packet/req/GetCounterRequest.java b/src/main/java/BsK/common/packet/req/GetCounterRequest.java index 440e3e9..4f6eac0 100644 --- a/src/main/java/BsK/common/packet/req/GetCounterRequest.java +++ b/src/main/java/BsK/common/packet/req/GetCounterRequest.java @@ -2,7 +2,10 @@ package BsK.common.packet.req; import BsK.common.packet.Packet; import lombok.AllArgsConstructor; +import lombok.Getter; + @AllArgsConstructor -public class GetCounterRequest implements Packet{ - +@Getter +public class GetCounterRequest implements Packet { + private int shift; // 0 for morning, 1 for afternoon } diff --git a/src/main/java/BsK/common/packet/req/SaveCheckupRequest.java b/src/main/java/BsK/common/packet/req/SaveCheckupRequest.java index 7f5a408..b5780e0 100644 --- a/src/main/java/BsK/common/packet/req/SaveCheckupRequest.java +++ b/src/main/java/BsK/common/packet/req/SaveCheckupRequest.java @@ -40,4 +40,5 @@ public class SaveCheckupRequest implements Packet { // Prescriptions String[][] medicinePrescription; String[][] servicePrescription; + int shift; } \ No newline at end of file diff --git a/src/main/java/BsK/common/packet/req/SetCounterRequest.java b/src/main/java/BsK/common/packet/req/SetCounterRequest.java index f2e14c7..b30d47a 100644 --- a/src/main/java/BsK/common/packet/req/SetCounterRequest.java +++ b/src/main/java/BsK/common/packet/req/SetCounterRequest.java @@ -8,4 +8,5 @@ import lombok.Data; @AllArgsConstructor public class SetCounterRequest implements Packet { private int counter; + private int shift; // 0 for morning, 1 for afternoon } diff --git a/src/main/java/BsK/common/packet/res/GetCheckUpQueueUpdateResponse.java b/src/main/java/BsK/common/packet/res/GetCheckUpQueueUpdateResponse.java index e436195..0311b0c 100644 --- a/src/main/java/BsK/common/packet/res/GetCheckUpQueueUpdateResponse.java +++ b/src/main/java/BsK/common/packet/res/GetCheckUpQueueUpdateResponse.java @@ -8,4 +8,5 @@ import lombok.Data; @Data public class GetCheckUpQueueUpdateResponse implements Packet { private String[][] queue; + private int shift; } \ No newline at end of file diff --git a/src/main/java/BsK/common/packet/res/GetCounterResponse.java b/src/main/java/BsK/common/packet/res/GetCounterResponse.java index 0404e43..0d4e379 100644 --- a/src/main/java/BsK/common/packet/res/GetCounterResponse.java +++ b/src/main/java/BsK/common/packet/res/GetCounterResponse.java @@ -8,4 +8,5 @@ import lombok.Data; @Data public class GetCounterResponse implements Packet{ private int counter; + private int shift; } diff --git a/src/main/java/BsK/common/packet/res/SetCounterResponse.java b/src/main/java/BsK/common/packet/res/SetCounterResponse.java index d0e4723..f5ec2bb 100644 --- a/src/main/java/BsK/common/packet/res/SetCounterResponse.java +++ b/src/main/java/BsK/common/packet/res/SetCounterResponse.java @@ -8,4 +8,5 @@ import lombok.Data; @AllArgsConstructor public class SetCounterResponse implements Packet{ private int counter; + private int shift; // 0 for morning, 1 for afternoon } diff --git a/src/main/java/BsK/server/network/handler/ServerHandler.java b/src/main/java/BsK/server/network/handler/ServerHandler.java index 9fe88c1..f5ce101 100644 --- a/src/main/java/BsK/server/network/handler/ServerHandler.java +++ b/src/main/java/BsK/server/network/handler/ServerHandler.java @@ -119,9 +119,9 @@ public class ServerHandler extends SimpleChannelInboundHandler currentMax) { String upsertSql = """ - INSERT INTO DailyQueueCounter (date, current_count) - VALUES (date('now', 'localtime'), ?) - ON CONFLICT(date) DO UPDATE SET current_count = ? + INSERT INTO DailyQueueCounter (date, shift, current_count) + VALUES (date('now', 'localtime'), ?, ?) + ON CONFLICT(date, shift) DO UPDATE SET current_count = ? """; try (PreparedStatement stmt = conn.prepareStatement(upsertSql)) { - stmt.setInt(1, queueNumber); + stmt.setInt(1, shift); stmt.setInt(2, queueNumber); + stmt.setInt(3, queueNumber); stmt.executeUpdate(); } shouldBroadcastCounter = true; @@ -675,13 +681,14 @@ public class ServerHandler extends SimpleChannelInboundHandler currentMax) { String upsertSql = """ - INSERT INTO DailyQueueCounter (date, current_count) - VALUES (date('now', 'localtime'), ?) - ON CONFLICT(date) DO UPDATE SET current_count = ? + INSERT INTO DailyQueueCounter (date, shift, current_count) + VALUES (date('now', 'localtime'), ?, ?) + ON CONFLICT(date, shift) DO UPDATE SET current_count = ? """; try (PreparedStatement stmt = conn.prepareStatement(upsertSql)) { - stmt.setInt(1, newCounter); + stmt.setInt(1, shift); stmt.setInt(2, newCounter); + stmt.setInt(3, newCounter); stmt.executeUpdate(); } int maxCurId = SessionManager.getMaxSessionId(); for (int sessionId = 1; sessionId <= maxCurId; sessionId++) { - UserUtil.sendPacket(sessionId, new SetCounterResponse(newCounter)); + UserUtil.sendPacket(sessionId, new SetCounterResponse(newCounter, shift)); } } } catch (SQLException e) { @@ -791,13 +802,18 @@ public class ServerHandler extends SimpleChannelInboundHandler resultList = new ArrayList<>(); - while (rs.next()) { - String checkupId = rs.getString("checkup_id"); - String checkupDate = rs.getString("checkup_date"); - long checkupDateLong = Long.parseLong(checkupDate); - Timestamp timestamp = new Timestamp(checkupDateLong); - Date date = new Date(timestamp.getTime()); - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); - checkupDate = sdf.format(date); - String customerLastName = rs.getString("customer_last_name"); - String customerFirstName = rs.getString("customer_first_name"); - String doctorFirstName = rs.getString("doctor_first_name"); - String doctorLastName = rs.getString("doctor_last_name"); - String suggestion = rs.getString("suggestion"); - String diagnosis = rs.getString("diagnosis"); - String notes = rs.getString("notes"); - String status = rs.getString("status"); - String customerId = rs.getString("customer_id"); - String customerNumber = rs.getString("customer_number"); - String customerAddress = rs.getString("customer_address"); - String customerWeight = rs.getString("customer_weight"); - String customerHeight = rs.getString("customer_height"); - String customerGender = rs.getString("customer_gender"); - String customerDob = rs.getString("customer_dob"); - String checkupType = rs.getString("checkup_type"); - String conclusion = rs.getString("conclusion"); - String reCheckupDate = rs.getString("reCheckupDate"); - String cccdDdcn = rs.getString("cccd_ddcn"); - String heartBeat = rs.getString("heart_beat"); - String bloodPressure = rs.getString("blood_pressure"); - String driveUrl = rs.getString("drive_url"); - String doctorUltrasoundId = rs.getString("doctor_ultrasound_id"); - String queueNumber = String.format("%02d", rs.getInt("queue_number")); - if (driveUrl == null) { driveUrl = ""; } - String result = String.join("|", checkupId, checkupDate, customerLastName, customerFirstName, - doctorLastName + " " + doctorFirstName, suggestion, diagnosis, notes, status, customerId, customerNumber, customerAddress, customerWeight, customerHeight, - customerGender, customerDob, checkupType, conclusion, reCheckupDate, cccdDdcn, heartBeat, bloodPressure, - driveUrl, doctorUltrasoundId, queueNumber - ); - resultList.add(result); - } - String[] resultString = resultList.toArray(new String[0]); - resultArray = new String[resultString.length][]; - for (int i = 0; i < resultString.length; i++) { - resultArray[i] = resultString[i].split("\\|"); + if (!rs.isBeforeFirst()) { + log.warn("No data found in the checkup table for today's shift {}.", shift); + resultArray = new String[0][0]; + } else { + // ... (rest of the logic is the same) + ArrayList resultList = new ArrayList<>(); + while (rs.next()) { + String checkupId = rs.getString("checkup_id"); + String checkupDate = rs.getString("checkup_date"); + long checkupDateLong = Long.parseLong(checkupDate); + Timestamp timestamp = new Timestamp(checkupDateLong); + Date date = new Date(timestamp.getTime()); + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + checkupDate = sdf.format(date); + String customerLastName = rs.getString("customer_last_name"); + String customerFirstName = rs.getString("customer_first_name"); + String doctorFirstName = rs.getString("doctor_first_name"); + String doctorLastName = rs.getString("doctor_last_name"); + String suggestion = rs.getString("suggestion"); + String diagnosis = rs.getString("diagnosis"); + String notes = rs.getString("notes"); + String status = rs.getString("status"); + String customerId = rs.getString("customer_id"); + String customerNumber = rs.getString("customer_number"); + String customerAddress = rs.getString("customer_address"); + String customerWeight = rs.getString("customer_weight"); + String customerHeight = rs.getString("customer_height"); + String customerGender = rs.getString("customer_gender"); + String customerDob = rs.getString("customer_dob"); + String checkupType = rs.getString("checkup_type"); + String conclusion = rs.getString("conclusion"); + String reCheckupDate = rs.getString("reCheckupDate"); + String cccdDdcn = rs.getString("cccd_ddcn"); + String heartBeat = rs.getString("heart_beat"); + String bloodPressure = rs.getString("blood_pressure"); + String driveUrl = rs.getString("drive_url"); + String doctorUltrasoundId = rs.getString("doctor_ultrasound_id"); + String queueNumber = String.format("%02d", rs.getInt("queue_number")); + if (driveUrl == null) { + driveUrl = ""; } + String result = String.join("|", checkupId, checkupDate, customerLastName, customerFirstName, + doctorLastName + " " + doctorFirstName, suggestion, diagnosis, notes, status, customerId, customerNumber, customerAddress, customerWeight, customerHeight, + customerGender, customerDob, checkupType, conclusion, reCheckupDate, cccdDdcn, heartBeat, bloodPressure, + driveUrl, doctorUltrasoundId, queueNumber + ); + resultList.add(result); + } + String[] resultString = resultList.toArray(new String[0]); + resultArray = new String[resultString.length][]; + for (int i = 0; i < resultString.length; i++) { + resultArray[i] = resultString[i].split("\\|"); } } - + // --- LOGIC GỐC ĐẾM SỐ BỆNH NHÂN TRONG NGÀY --- ZoneId zoneId = ZoneId.of("Asia/Ho_Chi_Minh"); LocalDate today = LocalDate.now(zoneId); @@ -2733,7 +2747,6 @@ public class ServerHandler extends SimpleChannelInboundHandler