package CHAP16;

import javax.swing.*;
import java.awt.*;
import java.sql.*;

public class C16_REALHospitalReservation1 extends JFrame {
    private static final String DB_URL = "jdbc:mysql://localhost:3306/hospital_db";
    private static final String DB_USER = "root"; // MySQL 사용자명
    private static final String DB_PASSWORD = "123456789"; // MySQL 비밀번호

    private JTextField nameField, ageField, genderField, addressField, phoneField, emailField;
    private JTextField doctorNameField, specialtyField, doctorPhoneField, doctorEmailField;
    // 예약관리 탭 관련 필드 (예약 ID 추가)
    private JTextField appointmentIdField, patientIdField, doctorIdField, appointmentDateField;
    
    public C16_REALHospitalReservation1() {
        setTitle("병원 예약 시스템");
        setSize(600, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        initializeDatabase();

        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.addTab("환자 관리", createPatientPanel());
        tabbedPane.addTab("의사 관리", createDoctorPanel());
        tabbedPane.addTab("예약 관리", createAppointmentPanel());
        // 전체 조회 탭 추가
        tabbedPane.addTab("전체 조회", createViewAllPanel());

        add(tabbedPane);
    }
    
    // 1. 환자 관리 패널
    private JPanel createPatientPanel() {
        // 7행 2열 GridLayout
        JPanel panel = new JPanel(new GridLayout(7, 2));
        panel.add(new JLabel("이름:"));
        nameField = new JTextField();
        panel.add(nameField);

        panel.add(new JLabel("나이:"));
        ageField = new JTextField();
        panel.add(ageField);

        panel.add(new JLabel("성별(남/여):"));
        genderField = new JTextField();
        panel.add(genderField);

        panel.add(new JLabel("주소:"));
        addressField = new JTextField();
        panel.add(addressField);

        panel.add(new JLabel("전화번호:"));
        phoneField = new JTextField();
        panel.add(phoneField);

        panel.add(new JLabel("이메일:"));
        emailField = new JTextField();
        panel.add(emailField);

        JButton addButton = new JButton("환자 등록");
        addButton.addActionListener(e -> addPatient());
        JButton clsButton = new JButton("초기화");
        clsButton.addActionListener(e -> clsPatient());
        panel.add(addButton);
        panel.add(clsButton);

        return panel;
    }
    
    // 2. 의사 관리 패널
    private JPanel createDoctorPanel() {
        // 5행 2열 GridLayout
        JPanel panel = new JPanel(new GridLayout(5, 2));
        panel.add(new JLabel("이름:"));
        doctorNameField = new JTextField();
        panel.add(doctorNameField);

        panel.add(new JLabel("전문 과목:"));
        specialtyField = new JTextField();
        panel.add(specialtyField);

        panel.add(new JLabel("전화번호:"));
        doctorPhoneField = new JTextField();
        panel.add(doctorPhoneField);

        panel.add(new JLabel("이메일:"));
        doctorEmailField = new JTextField();
        panel.add(doctorEmailField);

        JButton addButton = new JButton("의사 등록");
        addButton.addActionListener(e -> addDoctor());
        panel.add(addButton);

        JButton clsButton = new JButton("초기화");
        clsButton.addActionListener(e -> clsDoctor());
        panel.add(clsButton);

        return panel;
    }
    
    // 3. 예약 관리 패널 (예약 ID, 환자 ID, 의사 ID, 예약 날짜 입력)
    //     버튼: 예약 등록, 예약 취소, 예약 변경, 초기화
    private JPanel createAppointmentPanel() {
        // 6행 2열 GridLayout
        JPanel panel = new JPanel(new GridLayout(6, 2));
        
        panel.add(new JLabel("예약 ID:"));
        appointmentIdField = new JTextField();
        panel.add(appointmentIdField);
        
        panel.add(new JLabel("환자 ID:"));
        patientIdField = new JTextField();
        panel.add(patientIdField);
        
        panel.add(new JLabel("의사 ID:"));
        doctorIdField = new JTextField();
        panel.add(doctorIdField);
        
        panel.add(new JLabel("예약 날짜(YYYY-MM-DD HH:MM:SS):"));
        appointmentDateField = new JTextField();
        panel.add(appointmentDateField);
        
        JButton bookButton = new JButton("예약 등록");
        bookButton.addActionListener(e -> addAppointment());
        JButton cancelButton = new JButton("예약 취소");
        cancelButton.addActionListener(e -> cancelAppointment());
        panel.add(bookButton);
        panel.add(cancelButton);
        
        JButton updateButton = new JButton("예약 변경");
        updateButton.addActionListener(e -> updateAppointment());
        JButton clsButton = new JButton("초기화");
        clsButton.addActionListener(e -> clsAppointment());
        panel.add(updateButton);
        panel.add(clsButton);
        
        return panel;
    }
    
    // 4. 전체 조회 탭 패널
    private JPanel createViewAllPanel() {
        // BorderLayout을 사용하여 상단에 조회 옵션 패널, 중앙에 결과 출력 영역 배치
        JPanel panel = new JPanel(new BorderLayout());
        
        // 상단 옵션 패널 (콤보박스와 조회 버튼)
        JPanel topPanel = new JPanel();
        String[] options = {"환자 전체 조회", "의사 전체 조회", "예약 전체 조회"};
        JComboBox<String> comboBox = new JComboBox<>(options);
        JButton searchButton = new JButton("조회");
        topPanel.add(comboBox);
        topPanel.add(searchButton);
        panel.add(topPanel, BorderLayout.NORTH);
        
        // 중앙 결과 출력 영역
        JTextArea resultTextArea = new JTextArea();
        resultTextArea.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(resultTextArea);
        scrollPane.setPreferredSize(new Dimension(500, 300));
        panel.add(scrollPane, BorderLayout.CENTER);
        
        // 조회 버튼 액션: 콤보박스 선택에 따라 해당 테이블의 데이터를 조회 후 텍스트 영역에 출력
        searchButton.addActionListener(e -> {
            String selection = (String) comboBox.getSelectedItem();
            StringBuilder sb = new StringBuilder();
            try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
                 Statement stmt = conn.createStatement()) {
                if ("환자 전체 조회".equals(selection)) {
                    String sql = "SELECT * FROM patients";
                    ResultSet rs = stmt.executeQuery(sql);
                    while (rs.next()) {
                        sb.append("ID: ").append(rs.getInt("id"))
                          .append(", 이름: ").append(rs.getString("name"))
                          .append(", 나이: ").append(rs.getInt("age"))
                          .append(", 성별: ").append(rs.getString("gender"))
                          .append(", 주소: ").append(rs.getString("address"))
                          .append(", 전화번호: ").append(rs.getString("phone"))
                          .append(", 이메일: ").append(rs.getString("email"))
                          .append("\n");
                    }
                } else if ("의사 전체 조회".equals(selection)) {
                    String sql = "SELECT * FROM doctors";
                    ResultSet rs = stmt.executeQuery(sql);
                    while (rs.next()) {
                        sb.append("ID: ").append(rs.getInt("id"))
                          .append(", 이름: ").append(rs.getString("name"))
                          .append(", 전문 과목: ").append(rs.getString("specialty"))
                          .append(", 전화번호: ").append(rs.getString("phone"))
                          .append(", 이메일: ").append(rs.getString("email"))
                          .append("\n");
                    }
                } else if ("예약 전체 조회".equals(selection)) {
                    String sql = "SELECT * FROM appointments";
                    ResultSet rs = stmt.executeQuery(sql);
                    while (rs.next()) {
                        sb.append("ID: ").append(rs.getInt("id"))
                          .append(", 환자 ID: ").append(rs.getInt("patient_id"))
                          .append(", 의사 ID: ").append(rs.getInt("doctor_id"))
                          .append(", 예약 날짜: ").append(rs.getString("appointment_date"))
                          .append(", 상태: ").append(rs.getString("status"))
                          .append("\n");
                    }
                }
            } catch (SQLException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(this, "데이터 조회 오류", "오류", JOptionPane.ERROR_MESSAGE);
            }
            resultTextArea.setText(sb.toString());
        });
        
        return panel;
    }
    
    // ------------------ 예약 관련 기능 ------------------
    
    // 예약 등록
    private void addAppointment() {
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD)) {
            // 신규 예약 등록 시 예약 ID는 auto-generated되므로 사용하지 않음
            int patientId = Integer.parseInt(patientIdField.getText());
            int doctorId = Integer.parseInt(doctorIdField.getText());
            String appointmentDate = appointmentDateField.getText();

            // 환자 및 의사 존재 여부 확인
            if (!isPatientExists(conn, patientId)) {
                JOptionPane.showMessageDialog(this, "환자 ID가 존재하지 않습니다!", "오류", JOptionPane.ERROR_MESSAGE);
                return;
            }
            if (!isDoctorExists(conn, doctorId)) {
                JOptionPane.showMessageDialog(this, "의사 ID가 존재하지 않습니다!", "오류", JOptionPane.ERROR_MESSAGE);
                return;
            }
            // 중복 예약 방지 (같은 의사, 같은 시간)
            if (isAppointmentDuplicate(conn, doctorId, appointmentDate)) {
                JOptionPane.showMessageDialog(this, "이미 해당 시간에 예약이 존재합니다!", "오류", JOptionPane.ERROR_MESSAGE);
                return;
            }
            // 예약 등록
            String sql = "INSERT INTO appointments (patient_id, doctor_id, appointment_date) VALUES (?, ?, ?)";
            try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
                pstmt.setInt(1, patientId);
                pstmt.setInt(2, doctorId);
                pstmt.setString(3, appointmentDate);
                pstmt.executeUpdate();
                JOptionPane.showMessageDialog(this, "예약 등록 완료!");
            }
        } catch (SQLException | NumberFormatException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "입력 오류: 올바른 값을 입력하세요.", "오류", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    // 예약 취소 기능
    private void cancelAppointment() {
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD)) {
            int appointmentId = Integer.parseInt(appointmentIdField.getText());
            if (!isAppointmentExists(conn, appointmentId)) {
                JOptionPane.showMessageDialog(this, "예약 ID가 존재하지 않습니다!", "오류", JOptionPane.ERROR_MESSAGE);
                return;
            }
            String sql = "UPDATE appointments SET status = '취소됨' WHERE id = ?";
            try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
                pstmt.setInt(1, appointmentId);
                int updated = pstmt.executeUpdate();
                if (updated > 0) {
                    JOptionPane.showMessageDialog(this, "예약 취소 완료!");
                } else {
                    JOptionPane.showMessageDialog(this, "예약 취소에 실패했습니다.", "오류", JOptionPane.ERROR_MESSAGE);
                }
            }
        } catch (SQLException | NumberFormatException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "입력 오류: 올바른 값을 입력하세요.", "오류", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    // 예약 변경 기능
    private void updateAppointment() {
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD)) {
            int appointmentId = Integer.parseInt(appointmentIdField.getText());
            int patientId = Integer.parseInt(patientIdField.getText());
            int doctorId = Integer.parseInt(doctorIdField.getText());
            String appointmentDate = appointmentDateField.getText();

            // 예약 존재 여부 확인
            if (!isAppointmentExists(conn, appointmentId)) {
                JOptionPane.showMessageDialog(this, "예약 ID가 존재하지 않습니다!", "오류", JOptionPane.ERROR_MESSAGE);
                return;
            }
            // 환자 및 의사 존재 여부 확인
            if (!isPatientExists(conn, patientId)) {
                JOptionPane.showMessageDialog(this, "환자 ID가 존재하지 않습니다!", "오류", JOptionPane.ERROR_MESSAGE);
                return;
            }
            if (!isDoctorExists(conn, doctorId)) {
                JOptionPane.showMessageDialog(this, "의사 ID가 존재하지 않습니다!", "오류", JOptionPane.ERROR_MESSAGE);
                return;
            }
            // 변경하려는 예약시간에 동일 의사의 다른 예약이 있는지 확인 (현재 예약은 제외)
            if (isAppointmentDuplicateForUpdate(conn, appointmentId, doctorId, appointmentDate)) {
                JOptionPane.showMessageDialog(this, "이미 해당 시간에 예약이 존재합니다!", "오류", JOptionPane.ERROR_MESSAGE);
                return;
            }
            String sql = "UPDATE appointments SET patient_id = ?, doctor_id = ?, appointment_date = ?, status = '예약됨' WHERE id = ?";
            try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
                pstmt.setInt(1, patientId);
                pstmt.setInt(2, doctorId);
                pstmt.setString(3, appointmentDate);
                pstmt.setInt(4, appointmentId);
                int updated = pstmt.executeUpdate();
                if (updated > 0) {
                    JOptionPane.showMessageDialog(this, "예약 변경 완료!");
                } else {
                    JOptionPane.showMessageDialog(this, "예약 변경에 실패했습니다.", "오류", JOptionPane.ERROR_MESSAGE);
                }
            }
        } catch (SQLException | NumberFormatException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "입력 오류: 올바른 값을 입력하세요.", "오류", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    // ------------------ 전체조회 기능 ------------------
    
    // 환자 전체 조회
    private void viewAllPatients() {
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
             Statement stmt = conn.createStatement()) {
            String sql = "SELECT * FROM patients";
            ResultSet rs = stmt.executeQuery(sql);
            StringBuilder sb = new StringBuilder();
            while (rs.next()) {
                sb.append("ID: ").append(rs.getInt("id"))
                  .append(", 이름: ").append(rs.getString("name"))
                  .append(", 나이: ").append(rs.getInt("age"))
                  .append(", 성별: ").append(rs.getString("gender"))
                  .append(", 주소: ").append(rs.getString("address"))
                  .append(", 전화번호: ").append(rs.getString("phone"))
                  .append(", 이메일: ").append(rs.getString("email"))
                  .append("\n");
            }
            // 조회 결과를 다이얼로그 창으로 출력
            JTextArea textArea = new JTextArea(sb.toString());
            textArea.setEditable(false);
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(500, 300));
            JOptionPane.showMessageDialog(this, scrollPane, "환자 전체 조회", JOptionPane.INFORMATION_MESSAGE);
        } catch (SQLException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "데이터 조회 오류", "오류", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    // 의사 전체 조회
    private void viewAllDoctors() {
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
             Statement stmt = conn.createStatement()) {
            String sql = "SELECT * FROM doctors";
            ResultSet rs = stmt.executeQuery(sql);
            StringBuilder sb = new StringBuilder();
            while (rs.next()) {
                sb.append("ID: ").append(rs.getInt("id"))
                  .append(", 이름: ").append(rs.getString("name"))
                  .append(", 전문 과목: ").append(rs.getString("specialty"))
                  .append(", 전화번호: ").append(rs.getString("phone"))
                  .append(", 이메일: ").append(rs.getString("email"))
                  .append("\n");
            }
            JTextArea textArea = new JTextArea(sb.toString());
            textArea.setEditable(false);
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(500, 300));
            JOptionPane.showMessageDialog(this, scrollPane, "의사 전체 조회", JOptionPane.INFORMATION_MESSAGE);
        } catch (SQLException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "데이터 조회 오류", "오류", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    // 예약 전체 조회
    private void viewAllAppointments() {
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
             Statement stmt = conn.createStatement()) {
            String sql = "SELECT * FROM appointments";
            ResultSet rs = stmt.executeQuery(sql);
            StringBuilder sb = new StringBuilder();
            while (rs.next()) {
                sb.append("ID: ").append(rs.getInt("id"))
                  .append(", 환자 ID: ").append(rs.getInt("patient_id"))
                  .append(", 의사 ID: ").append(rs.getInt("doctor_id"))
                  .append(", 예약 날짜: ").append(rs.getString("appointment_date"))
                  .append(", 상태: ").append(rs.getString("status"))
                  .append("\n");
            }
            JTextArea textArea = new JTextArea(sb.toString());
            textArea.setEditable(false);
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(500, 300));
            JOptionPane.showMessageDialog(this, scrollPane, "예약 전체 조회", JOptionPane.INFORMATION_MESSAGE);
        } catch (SQLException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "데이터 조회 오류", "오류", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    // ------------------ 존재 및 중복 검사 ------------------
    
    // 환자 존재 여부 확인 메서드
    private boolean isPatientExists(Connection conn, int patientId) throws SQLException {
        String sql = "SELECT id FROM patients WHERE id = ?";
        try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
            pstmt.setInt(1, patientId);
            ResultSet rs = pstmt.executeQuery();
            return rs.next();
        }
    }
    
    // 의사 존재 여부 확인 메서드
    private boolean isDoctorExists(Connection conn, int doctorId) throws SQLException {
        String sql = "SELECT id FROM doctors WHERE id = ?";
        try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
            pstmt.setInt(1, doctorId);
            ResultSet rs = pstmt.executeQuery();
            return rs.next();
        }
    }
    
    // 예약 중복 여부 확인 (등록 시: 같은 의사, 같은 시간)
    private boolean isAppointmentDuplicate(Connection conn, int doctorId, String appointmentDate) throws SQLException {
        String sql = "SELECT id FROM appointments WHERE doctor_id = ? AND appointment_date = ?";
        try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
            pstmt.setInt(1, doctorId);
            pstmt.setString(2, appointmentDate);
            ResultSet rs = pstmt.executeQuery();
            return rs.next();
        }
    }
    
    // 예약 존재 여부 확인 (예약 ID로)
    private boolean isAppointmentExists(Connection conn, int appointmentId) throws SQLException {
        String sql = "SELECT id FROM appointments WHERE id = ?";
        try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
            pstmt.setInt(1, appointmentId);
            ResultSet rs = pstmt.executeQuery();
            return rs.next();
        }
    }
    
    // 예약 변경 시, 현재 예약(ID 제외)과 동일한 의사와 예약시간의 예약이 존재하는지 확인
    private boolean isAppointmentDuplicateForUpdate(Connection conn, int appointmentId, int doctorId, String appointmentDate) throws SQLException {
        String sql = "SELECT id FROM appointments WHERE doctor_id = ? AND appointment_date = ? AND id <> ?";
        try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
            pstmt.setInt(1, doctorId);
            pstmt.setString(2, appointmentDate);
            pstmt.setInt(3, appointmentId);
            ResultSet rs = pstmt.executeQuery();
            return rs.next();
        }
    }
    
    // ------------------ 데이터베이스 초기화 ------------------
    
    private void initializeDatabase() {
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
             Statement stmt = conn.createStatement()) {

            String createPatientsTable = "CREATE TABLE IF NOT EXISTS patients (" +
                    "id INT AUTO_INCREMENT PRIMARY KEY, " +
                    "name VARCHAR(100) NOT NULL, " +
                    "age INT NOT NULL, " +
                    "gender ENUM('남', '여') NOT NULL, " +
                    "address TEXT NOT NULL, " +
                    "phone VARCHAR(20) NOT NULL UNIQUE, " +
                    "email VARCHAR(100) UNIQUE)";

            String createDoctorsTable = "CREATE TABLE IF NOT EXISTS doctors (" +
                    "id INT AUTO_INCREMENT PRIMARY KEY, " +
                    "name VARCHAR(100) NOT NULL, " +
                    "specialty VARCHAR(100) NOT NULL, " +
                    "phone VARCHAR(20) NOT NULL UNIQUE, " +
                    "email VARCHAR(100) UNIQUE)";

            String createAppointmentsTable = "CREATE TABLE IF NOT EXISTS appointments (" +
                    "id INT AUTO_INCREMENT PRIMARY KEY, " +
                    "patient_id INT NOT NULL, " +
                    "doctor_id INT NOT NULL, " +
                    "appointment_date DATETIME NOT NULL, " +
                    "status ENUM('예약됨', '취소됨', '완료') DEFAULT '예약됨', " +
                    "FOREIGN KEY (patient_id) REFERENCES patients(id) ON DELETE CASCADE, " +
                    "FOREIGN KEY (doctor_id) REFERENCES doctors(id) ON DELETE CASCADE)";

            stmt.executeUpdate(createPatientsTable);
            stmt.executeUpdate(createDoctorsTable);
            stmt.executeUpdate(createAppointmentsTable);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
    // ------------------ 등록 기능 ------------------
    
    // 환자 등록
    private void addPatient() {
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
             PreparedStatement pstmt = conn.prepareStatement(
                     "INSERT INTO patients (name, age, gender, address, phone, email) VALUES (?, ?, ?, ?, ?, ?)")) {
            pstmt.setString(1, nameField.getText());
            pstmt.setInt(2, Integer.parseInt(ageField.getText()));
            pstmt.setString(3, genderField.getText());
            pstmt.setString(4, addressField.getText());
            pstmt.setString(5, phoneField.getText());
            pstmt.setString(6, emailField.getText());
            pstmt.executeUpdate();
            JOptionPane.showMessageDialog(this, "환자 등록 완료!");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    // 의사 등록
    private void addDoctor() {
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
             PreparedStatement pstmt = conn.prepareStatement(
                     "INSERT INTO doctors (name, specialty, phone, email) VALUES (?, ?, ?, ?)")) {
            pstmt.setString(1, doctorNameField.getText());
            pstmt.setString(2, specialtyField.getText());
            pstmt.setString(3, doctorPhoneField.getText());
            pstmt.setString(4, doctorEmailField.getText());
            pstmt.executeUpdate();
            JOptionPane.showMessageDialog(this, "의사 등록 완료!");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
    // ------------------ 초기화 기능 ------------------
    
    // 환자 입력 필드 초기화 메서드
    private void clsPatient() {
        nameField.setText("");
        ageField.setText("");
        genderField.setText("");
        addressField.setText("");
        phoneField.setText("");
        emailField.setText("");
    }
    
    // 의사 입력 필드 초기화 메서드
    private void clsDoctor() {
        doctorNameField.setText("");
        specialtyField.setText("");
        doctorPhoneField.setText("");
        doctorEmailField.setText("");
    }
    
    // 예약 입력 필드 초기화 메서드
    private void clsAppointment() {
        appointmentIdField.setText("");
        patientIdField.setText("");
        doctorIdField.setText("");
        appointmentDateField.setText("");
    }
    
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new REAL_HospitalReservation1().setVisible(true));
    }
}
