[add] Send checkup update to all client!

This commit is contained in:
lds217 committed 2025-02-24 01:25:41 -05:00
1 parent 6adfa9c77b
commit 178795a695
8 files changed
+123 -16

No files matched your search

@@ -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);