[add] read doctors list on dashboard

This commit is contained in:
lethanhdat committed 2025-01-02 22:59:27 -06:00
1 parent 7575992b7e
commit 725dfa421f
6 files changed
+177 -43

No files matched your search

+8
View File
@@ -104,5 +104,13 @@
<artifactId>sqlite-jdbc</artifactId>
<version>3.47.1.0</version>
</dependency>
<dependency>
<groupId>org.jdatepicker</groupId>
<artifactId>jdatepicker</artifactId>
<version>1.3.4</version>
</dependency>
</dependencies>
</project>
@@ -3,18 +3,29 @@ package BsK.client.ui.component.CheckUpPage;
import BsK.client.LocalStorage;
import BsK.client.network.handler.ClientHandler;
import BsK.client.ui.component.MainFrame;
import BsK.client.ui.component.common.DateLabelFormatter;
import BsK.client.ui.component.common.RoundedPanel;
import BsK.common.packet.req.GetCheckUpQueueRequest;
import BsK.common.packet.req.GetDoctorGeneralInfo;
import BsK.common.packet.res.ErrorResponse;
import BsK.common.packet.res.GetCheckUpQueueResponse;
import BsK.common.packet.res.GetDoctorGeneralInfoResponse;
import BsK.common.util.network.NetworkUtil;
import lombok.extern.slf4j.Slf4j;
import org.jdatepicker.impl.JDatePanelImpl;
import org.jdatepicker.impl.JDatePickerImpl;
import org.jdatepicker.impl.UtilDateModel;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
@Slf4j
public class CheckUpPage extends JPanel {
@@ -30,11 +41,21 @@ public class CheckUpPage extends JPanel {
NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCheckUpQueueRequest());
}
private String[] doctorOptions;
public void getDoctors() {
// listener
ClientHandler.addResponseListener(GetDoctorGeneralInfoResponse.class, this::handleGetDoctorGeneralInfoResponse);
ClientHandler.addResponseListener(ErrorResponse.class, this::handleErrorResponse);
NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetDoctorGeneralInfo());
}
public CheckUpPage(MainFrame mainFrame) {
setLayout(new BorderLayout());
updateQueue();
getDoctors();
// Sidebar panel
JPanel sidebar = new JPanel() {
@Override
@@ -133,7 +154,7 @@ public class CheckUpPage extends JPanel {
rightPanel.add(titleText2, BorderLayout.NORTH);
rightPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 10));
String[] columns = {"Ngày Tháng", "Họ", "Tên", "Tên BS", "Họ BS", "Triệu chứng", "Chẩn đoán", "Ghi chú", "Trạng thái"};
String[] columns = {"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"};
this.queue = new String[][]{}; // Initialize with empty data
model = new DefaultTableModel(this.queue, columns) {
@@ -156,60 +177,72 @@ public class CheckUpPage extends JPanel {
tableScroll1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // Inner padding
leftPanel.add(tableScroll1, BorderLayout.CENTER);
// "Ngày Tháng", "Họ", "Tên", "Ten BS", "Họ BS", "Triệu chứng", "Chẩn đoán", "Ghi chú", "Trạng thái"
RoundedPanel inputPanel = new RoundedPanel(20, Color.WHITE, false);
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5); // Add some padding between components
gbc.fill = GridBagConstraints.HORIZONTAL;
// Username label and text field
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
inputPanel.add(new JLabel("Ngày tháng:"), gbc);
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.NORTHWEST;
inputPanel.add(new JLabel("Mã khám bệnh:"), gbc);
gbc.gridx = 1;
JTextField usernameField = new JTextField(20);
inputPanel.add(usernameField, gbc);
JTextField checkupIdField = new JTextField();
checkupIdField.setEditable(false);
inputPanel.add(checkupIdField, gbc);
UtilDateModel model = new UtilDateModel();
Properties p = new Properties();
p.put("text.today", "Today");
p.put("text.month", "Month");
p.put("text.year", "Year");
JDatePanelImpl datePanel = new JDatePanelImpl(model, p);
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter());
datePicker.setPreferredSize(new Dimension(150, 30));
gbc.gridx = 2;
inputPanel.add(new JLabel("Ngày tháng:"), gbc);
gbc.gridx = 3;
inputPanel.add(datePicker, gbc);
// Sex label and option field
gbc.gridx = 0;
gbc.gridy++;
inputPanel.add(new JLabel("Họ"), gbc);
gbc.gridx = 1;
JTextField customerLastNameField = new JTextField(20);
JTextField customerLastNameField = new JTextField(5);
inputPanel.add(customerLastNameField, gbc);
gbc.gridx = 0;
gbc.gridy++;
gbc.gridx = 2;
inputPanel.add(new JLabel("Tên"), gbc);
gbc.gridx = 1;
JTextField customerFirstNameField = new JTextField(20);
gbc.gridx = 3;
JTextField customerFirstNameField = new JTextField(5);
inputPanel.add(customerFirstNameField, gbc);
gbc.gridwidth = 4;
gbc.gridx = 0;
gbc.gridy++;
inputPanel.add(new JLabel("Tên BS"), gbc);
inputPanel.add(new JLabel("Bác Sĩ"), gbc);
gbc.gridx = 1;
JTextField doctorFirstNameField = new JTextField(20);
inputPanel.add(doctorFirstNameField, gbc);
JComboBox<String> doctorComboBox = new JComboBox<>(doctorOptions);
inputPanel.add(doctorComboBox, gbc);
gbc.gridx = 0;
gbc.gridy++;
inputPanel.add(new JLabel("Họ BS"), gbc);
gbc.gridx = 1;
JTextField doctorLastNameField = new JTextField(20);
inputPanel.add(doctorLastNameField, gbc);
gbc.gridx = 0;
gbc.gridy++;
inputPanel.add(new JLabel("Triệu chứng"), gbc);
gbc.gridx = 1;
JTextField symptomsField = new JTextField(20);
JTextArea symptomsField = new JTextArea(3, 20);
inputPanel.add(symptomsField, gbc);
gbc.gridx = 0;
@@ -217,7 +250,7 @@ public class CheckUpPage extends JPanel {
inputPanel.add(new JLabel("Chẩn đoán"), gbc);
gbc.gridx = 1;
JTextField diagnosisField = new JTextField(20);
JTextArea diagnosisField = new JTextArea(3, 20);
inputPanel.add(diagnosisField, gbc);
gbc.gridx = 0;
@@ -225,7 +258,7 @@ public class CheckUpPage extends JPanel {
inputPanel.add(new JLabel("Ghi chú"), gbc);
gbc.gridx = 1;
JTextField notesField = new JTextField(20);
JTextArea notesField = new JTextArea(3, 20);
inputPanel.add(notesField, gbc);
gbc.gridx = 0;
@@ -243,27 +276,40 @@ public class CheckUpPage extends JPanel {
public void mouseClicked(MouseEvent e) {
int selectedRow = table1.getSelectedRow();
if (selectedRow != -1) {
String date = (String) table1.getValueAt(selectedRow, 0);
String customerLastName = (String) table1.getValueAt(selectedRow, 1);
String customerFirstName = (String) table1.getValueAt(selectedRow, 2);
String doctorFirstName = (String) table1.getValueAt(selectedRow, 3);
String doctorLastName = (String) table1.getValueAt(selectedRow, 4);
String checkupId = (String) table1.getValueAt(selectedRow, 0);
String date = (String) table1.getValueAt(selectedRow, 1);
String customerLastName = (String) table1.getValueAt(selectedRow, 2);
String customerFirstName = (String) table1.getValueAt(selectedRow, 3);
String doctor = (String) table1.getValueAt(selectedRow, 4);
String symptoms = (String) table1.getValueAt(selectedRow, 5);
String diagnosis = (String) table1.getValueAt(selectedRow, 6);
String notes = (String) table1.getValueAt(selectedRow, 7);
String status = (String) table1.getValueAt(selectedRow, 8);
usernameField.setText(date);
checkupIdField.setText(checkupId);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
try {
Date parsedDate = dateFormat.parse(date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(parsedDate);
datePicker.getModel().setDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
datePicker.getModel().setSelected(true);
} catch (ParseException exception) {
exception.printStackTrace();
}
customerLastNameField.setText(customerLastName);
customerFirstNameField.setText(customerFirstName);
doctorFirstNameField.setText(doctorFirstName);
doctorLastNameField.setText(doctorLastName);
doctorComboBox.setSelectedItem(doctor);
symptomsField.setText(symptoms);
diagnosisField.setText(diagnosis);
notesField.setText(notes);
statusComboBox.setSelectedItem(status);
}
}
});
JPanel iconPanel = new JPanel();
@@ -333,8 +379,6 @@ public class CheckUpPage extends JPanel {
add(sidebarScrollPane, BorderLayout.WEST);
add(topbar, BorderLayout.NORTH);
add(splitPane, BorderLayout.CENTER);
}
@Override
@@ -345,10 +389,15 @@ public class CheckUpPage extends JPanel {
ClientHandler.removeResponseListener(ErrorResponse.class, this::handleErrorResponse);
}
private void handleGetDoctorGeneralInfoResponse(GetDoctorGeneralInfoResponse response) {
log.info("Received doctor general info");
this.doctorOptions = response.getDoctorsName();
}
private void handleGetCheckUpQueueResponse(GetCheckUpQueueResponse response) {
log.info("Received checkup queue");
this.queue = response.getQueue();
model.setDataVector(this.queue, new String[]{"Ngày Tháng", "Họ", "Tên", "Ten BS", "Họ BS", "Triệu chứng", "Chẩn đoán", "Ghi chú", "Trạng thái"});
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 handleErrorResponse(ErrorResponse response) {
@@ -0,0 +1,31 @@
package BsK.client.ui.component.common;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import org.jdatepicker.*;
import javax.swing.*;
public class DateLabelFormatter extends JFormattedTextField.AbstractFormatter {
private String datePattern = "dd/MM/yyyy";
private SimpleDateFormat dateFormatter = new SimpleDateFormat(datePattern, Locale.ENGLISH);
@Override
public Object stringToValue(String text) throws ParseException {
return dateFormatter.parseObject(text);
}
@Override
public String valueToString(Object value) throws ParseException {
if (value != null) {
Calendar cal = (Calendar) value;
return dateFormatter.format(cal.getTime());
}
return "";
}
}
@@ -0,0 +1,6 @@
package BsK.common.packet.req;
import BsK.common.packet.Packet;
public class GetDoctorGeneralInfo implements Packet {
}
@@ -0,0 +1,13 @@
package BsK.common.packet.res;
import BsK.common.packet.Packet;
import lombok.AllArgsConstructor;
import lombok.Data;
@AllArgsConstructor
@Data
public class GetDoctorGeneralInfoResponse implements Packet {
String[] doctorsName;
}
@@ -3,6 +3,7 @@ package BsK.server.network.handler;
import BsK.common.packet.Packet;
import BsK.common.packet.PacketSerializer;
import BsK.common.packet.req.GetCheckUpQueueRequest;
import BsK.common.packet.req.GetDoctorGeneralInfo;
import BsK.common.packet.req.LoginRequest;
import BsK.common.packet.req.RegisterRequest;
import BsK.common.packet.res.*;
@@ -69,13 +70,12 @@ public class ServerHandler extends SimpleChannelInboundHandler<TextWebSocketFram
log.debug("Received GetCheckUpQueueRequest");
try {
ResultSet rs = statement.executeQuery(
"select a.checkup_date, c.customer_last_name, c.customer_first_name, " +
"select a.checkup_id, a.checkup_date, c.customer_last_name, c.customer_first_name, " +
"d.doctor_first_name, d.doctor_last_name, a.symptoms, a.diagnosis, a.notes, a.status " +
"from checkup as a " +
"join customer as c on a.customer_id = c.customer_id " +
"join Doctor D on a.doctor_id = D.doctor_id " +
"where a.status = 'PROCESSING' " +
"order by a.checkup_date"
"where a.status = 'PROCESSING'"
);
if (!rs.isBeforeFirst()) {
@@ -83,6 +83,7 @@ public class ServerHandler extends SimpleChannelInboundHandler<TextWebSocketFram
} 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);
@@ -99,9 +100,9 @@ public class ServerHandler extends SimpleChannelInboundHandler<TextWebSocketFram
String status = rs.getString("status");
String result = String.join("|",
String result = String.join("|", checkupId,
checkupDate, customerLastName, customerFirstName,
doctorFirstName, doctorLastName, symptoms,
doctorLastName + " " + doctorFirstName, symptoms,
diagnosis, notes, status
);
@@ -121,6 +122,32 @@ public class ServerHandler extends SimpleChannelInboundHandler<TextWebSocketFram
throw new RuntimeException(e);
}
}
// Get general doctor info
if (packet instanceof GetDoctorGeneralInfo) {
log.debug("Received GetDoctorGeneralInfo");
try {
ResultSet rs = statement.executeQuery(
"select concat(doctor_last_name, ' ', doctor_first_name) from Doctor"
);
if (!rs.isBeforeFirst()) {
System.out.println("No data found in the doctor table.");
} else {
ArrayList<String> resultList = new ArrayList<>();
while (rs.next()) {
String doctorName = rs.getString(1);
resultList.add(doctorName);
}
String[] resultString = resultList.toArray(new String[0]);
UserUtil.sendPacket(user.getSessionId(), new GetDoctorGeneralInfoResponse(resultString));
}
}
catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}