diff --git a/src/main/java/controller/ScheduleServlet.java b/src/main/java/controller/ScheduleServlet.java new file mode 100644 index 0000000..eb36d6b --- /dev/null +++ b/src/main/java/controller/ScheduleServlet.java @@ -0,0 +1,19 @@ +package controller; + +import java.io.IOException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +@WebServlet("/ScheduleServlet") +public class ScheduleServlet extends HttpServlet { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + HttpSession session = request.getSession(); + } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { + + } +} \ No newline at end of file diff --git a/src/main/java/model/DAO/DAOSchedule.java b/src/main/java/model/DAO/DAOSchedule.java new file mode 100644 index 0000000..763a1c7 --- /dev/null +++ b/src/main/java/model/DAO/DAOSchedule.java @@ -0,0 +1,283 @@ +package model.DAO; + +import model.entity.Schedule; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; +import java.sql.Date; + +public class DAOSchedule { + + private Schedule getScheduleFromResultSet(ResultSet resultSet) throws SQLException { + Schedule schedule = new Schedule(); + + schedule.setIdTherapist(resultSet.getInt("ID_therapist")); + schedule.setDate(resultSet.getDate("Date")); + schedule.setTimeSlot(resultSet.getString("TimeSlot")); + schedule.setReserved(resultSet.getInt("Reserved")); + + return schedule; + } + public void createNewSchedule(int idTherapist, Date date, String timeSlot) { + Connection conn = null; + PreparedStatement pstmt = null; + + try { + conn = DAOConnection.getConnection(); + + String sql = "INSERT INTO schedule (ID_therapist, Date, TimeSlot) VALUES (?, ?, ?);"; + + pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, idTherapist); + pstmt.setDate(2, date); + pstmt.setString(3, timeSlot); + + pstmt.executeUpdate(); + + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + if (pstmt != null) pstmt.close(); + DAOConnection.releaseConnection(conn); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + public void modifySchedule(int idTherapist, Date date, String timeSlot, int reserved, Date ndate, String ntimeSlot) { + Connection conn = null; + PreparedStatement pstmt = null; + + try { + conn = DAOConnection.getConnection(); + + String sql = "UPDATE schedule SET Date = ?, TimeSlot = ?, Reserved = ? WHERE ID_therapist = ? AND Date = ? AND TimeSlot = ?;"; + + pstmt = conn.prepareStatement(sql); + pstmt.setDate(1, ndate); + pstmt.setString(2, ntimeSlot); + pstmt.setInt(3, reserved); + pstmt.setInt(4, idTherapist); + pstmt.setDate(5, date); + pstmt.setString(6, timeSlot); + + pstmt.executeUpdate(); + + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + if (pstmt != null) pstmt.close(); + DAOConnection.releaseConnection(conn); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + public void deleteSchedule(int idTherapist, Date date, String timeSlot) { + Connection conn = null; + PreparedStatement pstmt = null; + + try { + conn = DAOConnection.getConnection(); + + String sql = "DELETE FROM schedule WHERE ID_therapist = ? AND Date = ? AND TimeSlot = ?;"; + + pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, idTherapist); + pstmt.setDate(2, date); + pstmt.setString(3, timeSlot); + + pstmt.executeUpdate(); + + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + if (pstmt != null) pstmt.close(); + DAOConnection.releaseConnection(conn); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + public List retrieveAllPatientSchedules(int reserved) { + Connection connection = null; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + + List schedules = new ArrayList<>(); + + try { + connection = DAOConnection.getConnection(); + + String query = "SELECT * FROM schedule WHERE Reserved = ?;"; + + preparedStatement = connection.prepareStatement(query); + preparedStatement.setInt(1, reserved); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) { + Schedule schedule = getScheduleFromResultSet(resultSet); + schedules.add(schedule); + } + + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + if (resultSet != null) resultSet.close(); + if (preparedStatement != null) preparedStatement.close(); + DAOConnection.releaseConnection(connection); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + return schedules; + } + public List retrieveAllTherapistSchedules(int idTherapist) { + Connection connection = null; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + + List schedules = new ArrayList<>(); + + try { + connection = DAOConnection.getConnection(); + + String query = "SELECT * FROM schedule WHERE ID_therapist = ?;"; + + preparedStatement = connection.prepareStatement(query); + preparedStatement.setInt(1, idTherapist); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) { + Schedule schedule = getScheduleFromResultSet(resultSet); + schedules.add(schedule); + } + + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + if (resultSet != null) resultSet.close(); + if (preparedStatement != null) preparedStatement.close(); + DAOConnection.releaseConnection(connection); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + return schedules; + } + public List retrieveAllPrenotedSchedules(int idTherapist) { + Connection connection = null; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + + List schedules = new ArrayList<>(); + + try { + connection = DAOConnection.getConnection(); + + String query = "SELECT * FROM schedule WHERE Reserved != 0 AND ID_therapist =?;"; + + preparedStatement = connection.prepareStatement(query); + preparedStatement.setInt(1, idTherapist); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) { + Schedule schedule = getScheduleFromResultSet(resultSet); + schedules.add(schedule); + } + + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + if (resultSet != null) resultSet.close(); + if (preparedStatement != null) preparedStatement.close(); + DAOConnection.releaseConnection(connection); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + return schedules; + } + public List retrieveAllNotPrenotedSchedules(int idTherapist) { + Connection connection = null; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + + List schedules = new ArrayList<>(); + + try { + connection = DAOConnection.getConnection(); + + String query = "SELECT * FROM schedule WHERE Reserved = 0 AND ID_therapist =?;"; + + preparedStatement = connection.prepareStatement(query); + preparedStatement.setInt(1, idTherapist); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) { + Schedule schedule = getScheduleFromResultSet(resultSet); + schedules.add(schedule); + } + + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + if (resultSet != null) resultSet.close(); + if (preparedStatement != null) preparedStatement.close(); + DAOConnection.releaseConnection(connection); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + return schedules; + } + public int retrieveAllPrenotedSchedulesCount(int idTherapist) { + Connection conn = null; + PreparedStatement pstmt = null; + ResultSet rs = null; + int count = 0; + + try { + conn = DAOConnection.getConnection(); + + String sql = "SELECT COUNT(*) FROM schedule WHERE Reserved != 0 AND ID_therapist =?;"; + + pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, idTherapist); + + rs = pstmt.executeQuery(); + if (rs.next()) { + count = rs.getInt(1); + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + if (rs != null) rs.close(); + if (pstmt != null) pstmt.close(); + DAOConnection.releaseConnection(conn); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return count; + } +} diff --git a/src/main/java/model/service/schedule/ScheduleManager.java b/src/main/java/model/service/schedule/ScheduleManager.java new file mode 100644 index 0000000..2657657 --- /dev/null +++ b/src/main/java/model/service/schedule/ScheduleManager.java @@ -0,0 +1,49 @@ +package model.service.schedule; + +import model.DAO.DAOSchedule; +import model.entity.Schedule; +import java.sql.Date; + +import java.util.List; + +public class ScheduleManager implements ScheduleManagerInterface { + DAOSchedule db = new DAOSchedule(); + + public ScheduleManager(){} + + public Date convStoD(String Date){ + return java.sql.Date.valueOf(Date); + } + + public void createNewSchedule(int idTherapist, String date, String timeSlot){ + db.createNewSchedule(idTherapist, convStoD(date), timeSlot); + } + + public void modifySchedule(int idTherapist, String date, String timeSlot, String ndate,String ntimeSlot, int reserved){ + db.modifySchedule(idTherapist, convStoD(date), timeSlot, reserved, convStoD(ndate), ntimeSlot); + } + + public void deleteSchedule(int idTherapist, String date, String timeSlot){ + db.deleteSchedule(idTherapist, convStoD(date), timeSlot); + } + + public List retrieveAllPatientSchedules(int reserved){ + return db.retrieveAllPatientSchedules(reserved); + } + + public List retrieveAllTherapistSchedules(int idTherapist){ + return db.retrieveAllTherapistSchedules(idTherapist); + } + + public List retrieveAllPrenotedSchedules(int idTherapist){ + return db.retrieveAllPrenotedSchedules(idTherapist); + } + + public List retrieveAllNotPrenotedSchedules(int idTherapist){ + return db.retrieveAllNotPrenotedSchedules(idTherapist); + } + + public int retrieveAllPrenotedSchedulesCount(int idTherapist){ + return db.retrieveAllPrenotedSchedulesCount(idTherapist); + } +} diff --git a/src/main/java/model/service/schedule/ScheduleManagerInterface.java b/src/main/java/model/service/schedule/ScheduleManagerInterface.java new file mode 100644 index 0000000..36e76b1 --- /dev/null +++ b/src/main/java/model/service/schedule/ScheduleManagerInterface.java @@ -0,0 +1,74 @@ +package model.service.schedule; + +import model.entity.Schedule; + +import java.util.List; + +public interface ScheduleManagerInterface { + + /** + * Creation of a new schedule slot from the therapist. + * + * @param idTherapist the ID of the therapist; + * @param date the date for the schedule; + * @param timeSlot the timeslot for the schedule. + */ + void createNewSchedule(int idTherapist, String date, String timeSlot); + + /** + * Modification of a existing schedule slot from the therapist. + * + * @param idTherapist the ID of the therapist; + * @param date the date for the schedule; + * @param timeSlot the timeslot for the schedule; + * @param ndate the new date for the schedule; + * @param ntimeSlot the new timeslot for the schedule; + * @param reserved the ID of the patient, if 0 the prenotation is not reserved. + */ + void modifySchedule(int idTherapist, String date, String timeSlot, String ndate,String ntimeSlot, int reserved); + + + /** + * Elimination of a existing schedule slot from the therapist. + * + * @param idTherapist the ID of the therapist; + * @param date the date for the schedule; + * @param timeSlot the timeslot for the schedule. + */ + void deleteSchedule(int idTherapist, String date, String timeSlot); + + /** + * Retrieves all the schedules of a patient. + * @param reserved the ID of the patient, if 0 the prenotation is not reserved; + * @return a list of schedule that the patient has signed on. + */ + List retrieveAllPatientSchedules(int reserved); + + /** + * Retrieves all the schedules from a therapist. + * @param idTherapist the ID of the therapist; + * @return a list of schedule that the therapist has created. + */ + List retrieveAllTherapistSchedules(int idTherapist); + + /** + * Retrieves all the schedules from a therapist that are prenoted. + * @param idTherapist the ID of the therapist; + * @return a list of schedule that the therapist has created. + */ + List retrieveAllPrenotedSchedules(int idTherapist); + + /** + * Retrieves all the schedules from a therapist that are not prenoted. + * @param idTherapist the ID of the therapist; + * @return a list of schedule that the therapist has created. + */ + List retrieveAllNotPrenotedSchedules(int idTherapist); + + /** + * Retrieves the number of schedules from a therapist that are prenoted. + * @param idTherapist the ID of the therapist; + * @return a list of schedule that the therapist has created. + */ + int retrieveAllPrenotedSchedulesCount(int idTherapist); +} diff --git a/src/main/webapp/CSS/schedule.css b/src/main/webapp/CSS/schedule.css new file mode 100644 index 0000000..0344c17 --- /dev/null +++ b/src/main/webapp/CSS/schedule.css @@ -0,0 +1,60 @@ +body { + font-family: Georgia, sans-serif; + width: 100%; + max-width: 800px; + margin: 0 auto; + padding: 20px; + font-size:1.5em; +} + +#calendar { + text-align: center; +} + +#calendarTable { + width: 100%; + border-collapse: collapse; + margin-top: 20px; + margin-bottom: 20px; + display: flex; + overflow-x: auto; + white-space: nowrap; +} + +#calendarTable th, #calendarTable td { + border: 1px solid black; + padding: 10px; +} + +#calendarTable tr:nth-child(even) { + background-color: #f2f2f2; +} + +#calendarTable td.selected { + background-color: #ddd; /* Change this to your preferred color */ +} + + + +#timeTable { + width: 100%; + border-collapse: collapse; + margin-top: 20px; + margin-bottom: 20px; + display: flex; + overflow-x: auto; + white-space: nowrap; +} + +#timeTable th, #timeTable td { + border: 1px solid black; + padding: 10px; +} + +#timeTable tr:nth-child(even) { + background-color: #f2f2f2; +} + +#timeTable td.selected { + background-color: #ddd; /* Change this to your preferred color */ +} \ No newline at end of file diff --git a/src/main/webapp/JS/schedule.js b/src/main/webapp/JS/schedule.js new file mode 100644 index 0000000..0dce656 --- /dev/null +++ b/src/main/webapp/JS/schedule.js @@ -0,0 +1,104 @@ +let currentDate = new Date(); +let currentMonth = currentDate.getMonth(); +let currentYear = currentDate.getFullYear(); + +document.getElementById('calendarTitle').textContent = `${new Date().toLocaleString('default', { month: 'long' })} ${currentYear}`; + + + + + +function createCalendar() { + const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + document.getElementById('calendarTitle').textContent = `${monthNames[currentMonth]} ${currentYear}`; + + let firstDayOfMonth = new Date(currentYear, currentMonth, 1).getDay(); + let daysInMonth = 32 - new Date(currentYear, currentMonth, 32).getDate(); + + let calendarBody = ''; + + // Fill in the days of the month + for(let x = 1; x <= daysInMonth; x++) { + calendarBody += `${x}`; + } + + // Append the calendar to the DOM + document.getElementById('calendarTable').innerHTML = `${calendarBody}`; + + // Add click event listeners to each date cell + document.querySelectorAll('#calendarTable td').forEach((cell, index) => { + cell.addEventListener('click', () => { + // Remove the 'selected' class from all cells + document.querySelectorAll('#calendarTable td').forEach(cell => cell.classList.remove('selected')); + + // Add the 'selected' class to the clicked cell + cell.classList.add('selected'); + + // Calculate the selected date and time + let selectedDate = new Date(currentYear, currentMonth, index + 1); + + // Update the hidden input fields + document.getElementById('selectedDate').value = selectedDate.toISOString().split('T')[0]; + }); + }); +} + + + + + +function createTimeTable() { + let timeTableBody = ''; + + // Fill in the hours of the day + for(let x = 0; x < 24; x++) { + timeTableBody += `${x}:00`; + } + + // Append the time table to the DOM + document.getElementById('timeTable').innerHTML = `${timeTableBody}`; + + // Add click event listeners to each date cell + document.querySelectorAll('#timeTable td').forEach((cell, index) => { + cell.addEventListener('click', () => { + // Remove the 'selected' class from all cells + document.querySelectorAll('#timeTable td').forEach(cell => cell.classList.remove('selected')); + + // Add the 'selected' class to the clicked cell + cell.classList.add('selected'); + + // Get the selected time + let selectedTime = document.querySelectorAll('#timeTable td')[index].textContent; + + // Update the hidden input field + document.getElementById('selectedTime').value = selectedTime; + }); + }); + +} + + + + + +createTimeTable(); + +createCalendar(); + +document.getElementById('prevMonth').addEventListener('click', () => { + currentMonth--; + if(currentMonth < 0) { + currentMonth = 11; + currentYear--; + } + createCalendar(); +}); + +document.getElementById('nextMonth').addEventListener('click', () => { + currentMonth++; + if(currentMonth > 11) { + currentMonth = 0; + currentYear++; + } + createCalendar(); +}); diff --git a/src/main/webapp/JSP/schedule.jsp b/src/main/webapp/JSP/schedule.jsp new file mode 100644 index 0000000..1939431 --- /dev/null +++ b/src/main/webapp/JSP/schedule.jsp @@ -0,0 +1,22 @@ + + + + Simple Calendar + + + +
+

+ + +
+
+
+ + + +
+
+ + +