mirror of
https://github.com/tiennm99/BSK-All-in-One-Clinic-Management-System.git
synced 2026-10-15 16:14:14 +00:00
[add] Send checkup update to all client!
This commit is contained in:
1 parent
6adfa9c77b
commit
178795a695
8 files changed
+123
-16
No files matched your search
@@ -12,6 +12,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.jdatepicker.impl.JDatePanelImpl;
|
||||
import org.jdatepicker.impl.JDatePickerImpl;
|
||||
import org.jdatepicker.impl.UtilDateModel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
@@ -28,6 +30,7 @@ import java.util.Properties;
|
||||
|
||||
@Slf4j
|
||||
public class AddDialog extends JDialog {
|
||||
private static final Logger log = LoggerFactory.getLogger(AddDialog.class);
|
||||
private JTextField patientNameField;
|
||||
private JTextField patientYearField;
|
||||
private JTextField patientIdField;
|
||||
@@ -56,11 +59,6 @@ public class AddDialog extends JDialog {
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, response.getError());
|
||||
}
|
||||
ClientHandler.deleteListener(AddCheckupResponse.class);
|
||||
ClientHandler.deleteListener(AddPatientResponse.class);
|
||||
ClientHandler.deleteListener(GetRecentPatientResponse.class);
|
||||
ClientHandler.deleteListener(GetDistrictResponse.class);
|
||||
ClientHandler.deleteListener(GetWardResponse.class);
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
@@ -104,8 +102,19 @@ public class AddDialog extends JDialog {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// Clean up listeners
|
||||
log.info("Cleaning up listeners");
|
||||
ClientHandler.deleteListener(AddCheckupResponse.class);
|
||||
ClientHandler.deleteListener(AddPatientResponse.class);
|
||||
ClientHandler.deleteListener(GetRecentPatientResponse.class);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public AddDialog(Frame parent) {
|
||||
super(parent, "Add Patient", true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
// Set size of the dialog
|
||||
setSize(1000, 400);
|
||||
@@ -436,11 +445,6 @@ public class AddDialog extends JDialog {
|
||||
JPanel ButtonPanel = new JPanel();
|
||||
JButton closeButton = new JButton("Close");
|
||||
closeButton.addActionListener(e -> {
|
||||
ClientHandler.deleteListener(AddCheckupResponse.class);
|
||||
ClientHandler.deleteListener(AddPatientResponse.class);
|
||||
ClientHandler.deleteListener(GetRecentPatientResponse.class);
|
||||
ClientHandler.deleteListener(GetDistrictResponse.class);
|
||||
ClientHandler.deleteListener(GetWardResponse.class);
|
||||
setVisible(false);
|
||||
});
|
||||
ButtonPanel.add(closeButton);
|
||||
|
||||
@@ -40,6 +40,7 @@ public class CheckUpPage extends JPanel {
|
||||
private String[][] history;
|
||||
private DefaultTableModel model, historyModel;
|
||||
private JTable table1, historyTable;
|
||||
private final ResponseListener<GetCheckUpQueueUpdateResponse> checkUpQueueUpdateListener = this::handleGetCheckUpQueueUpdateResponse;
|
||||
private final ResponseListener<GetCheckUpQueueResponse> checkUpQueueListener = this::handleGetCheckUpQueueResponse;
|
||||
private final ResponseListener<GetCustomerHistoryResponse> customerHistoryListener = this::handleGetCustomerHistoryResponse;
|
||||
private final ResponseListener<GetDistrictResponse> districtResponseListener = this::handleGetDistrictResponse;
|
||||
@@ -61,9 +62,13 @@ public class CheckUpPage extends JPanel {
|
||||
|
||||
boolean returnCell = false;
|
||||
public void updateQueue() {
|
||||
ClientHandler.addResponseListener(GetCheckUpQueueResponse.class, checkUpQueueListener);
|
||||
NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueRequest());
|
||||
}
|
||||
|
||||
public void updateUpdateQueue() {
|
||||
NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueUpdateRequest());
|
||||
}
|
||||
|
||||
private int findProvinceIndex(String province) {
|
||||
for (int i = 0; i < LocalStorage.provinces.length; i++) {
|
||||
if (TextUtils.removeAccents(LocalStorage.provinces[i]).equals(TextUtils.removeAccents(province))) {
|
||||
@@ -94,7 +99,9 @@ public class CheckUpPage extends JPanel {
|
||||
public CheckUpPage(MainFrame mainFrame) {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// add history listener
|
||||
|
||||
ClientHandler.addResponseListener(GetCheckUpQueueResponse.class, checkUpQueueListener);
|
||||
ClientHandler.addResponseListener(GetCheckUpQueueUpdateResponse.class, checkUpQueueUpdateListener);
|
||||
ClientHandler.addResponseListener(GetCustomerHistoryResponse.class, customerHistoryListener);
|
||||
ClientHandler.addResponseListener(GetDistrictResponse.class, districtResponseListener);
|
||||
ClientHandler.addResponseListener(GetWardResponse.class, wardResponseListener);
|
||||
@@ -251,7 +258,7 @@ public class CheckUpPage extends JPanel {
|
||||
rightButton.addActionListener(e -> {
|
||||
addDialog = new AddDialog(mainFrame);
|
||||
addDialog.setVisible(true);
|
||||
updateQueue();
|
||||
updateUpdateQueue();
|
||||
});
|
||||
|
||||
topPanel.add(titleText1, BorderLayout.WEST);
|
||||
@@ -835,6 +842,12 @@ public class CheckUpPage extends JPanel {
|
||||
LocalStorage.doctorsName = response.getDoctorsName();
|
||||
}
|
||||
|
||||
private void handleGetCheckUpQueueUpdateResponse(GetCheckUpQueueUpdateResponse response) {
|
||||
log.info("Received checkup update queue");
|
||||
this.queue = response.getQueue();
|
||||
model.setDataVector(this.queue, new String[]{"Mã khám bệnh", "Ngày Tháng", "Họ", "Tên", "Bác Sĩ", "Triệu chứng", "Chẩn đoán", "Ghi chú", "Trạng thái"});
|
||||
}
|
||||
|
||||
private void handleGetCheckUpQueueResponse(GetCheckUpQueueResponse response) {
|
||||
log.info("Received checkup queue");
|
||||
this.queue = response.getQueue();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package BsK.common.packet.req;
|
||||
|
||||
import BsK.common.packet.Packet;
|
||||
|
||||
public class GetCheckUpQueueUpdateRequest implements Packet {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package BsK.common.packet.res;
|
||||
|
||||
import BsK.common.packet.Packet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class GetCheckUpQueueUpdateResponse implements Packet {
|
||||
private String[][] queue;
|
||||
}
|
||||
@@ -112,6 +112,72 @@ public class ServerHandler extends SimpleChannelInboundHandler<TextWebSocketFram
|
||||
String customerDob = rs.getString("customer_dob");
|
||||
|
||||
|
||||
String result = String.join("|", checkupId,
|
||||
checkupDate, customerLastName, customerFirstName,
|
||||
doctorLastName + " " + doctorFirstName, symptoms,
|
||||
diagnosis, notes, status, customerId, customerNumber, customerAddress, customerWeight, customerHeight,
|
||||
customerGender, customerDob
|
||||
);
|
||||
|
||||
resultList.add(result);
|
||||
|
||||
}
|
||||
|
||||
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(user.getSessionId(), new GetCheckUpQueueResponse(resultArray));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (packet instanceof GetCheckUpQueueUpdateRequest) {
|
||||
log.debug("Received GetCheckUpQueueUpdateRequest");
|
||||
try {
|
||||
ResultSet rs = statement.executeQuery(
|
||||
"select a.checkup_id, a.checkup_date, c.customer_last_name, c.customer_first_name,\n" +
|
||||
"d.doctor_first_name, d.doctor_last_name, a.symptoms, a.diagnosis, a.notes, a.status, a.customer_id, \n" +
|
||||
"c.customer_number, c.customer_address, c.customer_weight, c.customer_height, c.customer_gender, c.customer_dob\n" +
|
||||
"from checkup as a\n" +
|
||||
"join customer as c on a.customer_id = c.customer_id\n" +
|
||||
"join Doctor D on a.doctor_id = D.doctor_id\n" +
|
||||
"where a.status = 'PROCESSING'"
|
||||
);
|
||||
|
||||
if (!rs.isBeforeFirst()) {
|
||||
System.out.println("No data found in the checkup table.");
|
||||
|
||||
} else {
|
||||
ArrayList<String> 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()); // Needed to recode
|
||||
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 symptoms = rs.getString("symptoms");
|
||||
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 result = String.join("|", checkupId,
|
||||
checkupDate, customerLastName, customerFirstName,
|
||||
doctorLastName + " " + doctorFirstName, symptoms,
|
||||
@@ -129,9 +195,11 @@ public class ServerHandler extends SimpleChannelInboundHandler<TextWebSocketFram
|
||||
for (int i = 0; i < resultString.length; i++) {
|
||||
resultArray[i] = resultString[i].split("\\|");
|
||||
}
|
||||
|
||||
UserUtil.sendPacket(user.getSessionId(), new GetCheckUpQueueResponse(resultArray));
|
||||
|
||||
//send to all
|
||||
int maxCurId = SessionManager.getMaxSessionId();
|
||||
for (int sessionId = 1; sessionId <= maxCurId; sessionId++) {
|
||||
UserUtil.sendPacket(sessionId, new GetCheckUpQueueUpdateResponse(resultArray));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -32,6 +32,10 @@ public class SessionManager {
|
||||
return SESSION_ID_MAP.get(sessionId);
|
||||
}
|
||||
|
||||
public static int getMaxSessionId() {
|
||||
return SESSION_ID.get();
|
||||
}
|
||||
|
||||
public static int onUserLogin(Channel channel) {
|
||||
int sessionId = SESSION_ID.incrementAndGet();
|
||||
var user = new User(channel, sessionId);
|
||||
|
||||
@@ -11,6 +11,7 @@ import lombok.NoArgsConstructor;
|
||||
public class UserUtil {
|
||||
public static void sendPacket(int sessionId, Packet packet) {
|
||||
String channel = SessionManager.getChannelBySessionId(sessionId);
|
||||
if (channel == null) return;
|
||||
var user = SessionManager.getUserByChannel(channel);
|
||||
if (user == null) return;
|
||||
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user