From 130b2ce043de400c02c513120e8824ee019f9797 Mon Sep 17 00:00:00 2001 From: Sewaaa Date: Tue, 16 Jan 2024 20:00:36 +0100 Subject: [PATCH] FE and BE Exercise reccomendation + fix FE Condition manager --- src/main/java/model/DAO/DAOExercise.java | 3 + .../java/model/DAO/DAOExerciseGlossary.java | 69 ++++++++++++++ .../service/exercise/ExerciseManager.java | 4 + .../exercise/ExerciseManagerInterface.java | 16 ++++ .../CSS/RecommendationAndConditionManager.css | 18 ++++ .../webapp/JSP/exerciseRecommendation.jsp | 93 +++++++++++++++++++ .../webapp/JSP/patientConditionManager.jsp | 9 +- src/main/webapp/JSP/viewPatient.jsp | 5 +- 8 files changed, 211 insertions(+), 6 deletions(-) create mode 100644 src/main/webapp/CSS/RecommendationAndConditionManager.css create mode 100644 src/main/webapp/JSP/exerciseRecommendation.jsp diff --git a/src/main/java/model/DAO/DAOExercise.java b/src/main/java/model/DAO/DAOExercise.java index e59658d..b2ae1bf 100644 --- a/src/main/java/model/DAO/DAOExercise.java +++ b/src/main/java/model/DAO/DAOExercise.java @@ -1,6 +1,7 @@ package model.DAO; import model.entity.Exercise; +import model.entity.ExerciseGlossary; import model.entity.Schedule; import model.entity.SlimmerExercise; @@ -173,6 +174,8 @@ public List retrieveAllPatientExerciseDone(int userID) { return exercises; } + + public Blob getExerciseExecution(int userID, int exerciseID, Date insertDate) { String query = "SELECT Execution FROM exercise WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?"; PreparedStatement preparedStatement = null; diff --git a/src/main/java/model/DAO/DAOExerciseGlossary.java b/src/main/java/model/DAO/DAOExerciseGlossary.java index 9f3b64b..e6480d5 100644 --- a/src/main/java/model/DAO/DAOExerciseGlossary.java +++ b/src/main/java/model/DAO/DAOExerciseGlossary.java @@ -6,6 +6,8 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; /** @@ -82,4 +84,71 @@ public ExerciseGlossary getExerciseByCode(int code) { return null; } + + public List retrieveAllPatientExerciseGlossaryNotDone(int userID) { + String query = "SELECT eg.* FROM exercise_glossary eg LEFT JOIN exercise e ON eg.ID_exercise = e.ID_exercise AND e.ID_user = ? WHERE e.ID_user IS NULL;\n"; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + List exercises = new ArrayList<>(); + + try { + connection = connection.isClosed() ? DAOConnection.getConnection() : connection; + preparedStatement = connection.prepareStatement(query); + preparedStatement.setInt(1, userID); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) { + ExerciseGlossary exercise = extractExerciseFromResultSet(resultSet); + exercises.add(exercise); + } + + } 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 exercises; + } + + public List retrieveAllPatientExerciseGlossaryDone(int userID) { + String query = "SELECT eg.* FROM exercise_glossary eg JOIN exercise e ON eg.ID_exercise = e.ID_exercise\n" + + "WHERE e.ID_user = ?;\n"; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + List exercises = new ArrayList<>(); + + try { + connection = connection.isClosed() ? DAOConnection.getConnection() : connection; + preparedStatement = connection.prepareStatement(query); + preparedStatement.setInt(1, userID); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) { + ExerciseGlossary exercise = extractExerciseFromResultSet(resultSet); + exercises.add(exercise); + } + + } 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 exercises; + } } diff --git a/src/main/java/model/service/exercise/ExerciseManager.java b/src/main/java/model/service/exercise/ExerciseManager.java index 317b77f..411aa1d 100644 --- a/src/main/java/model/service/exercise/ExerciseManager.java +++ b/src/main/java/model/service/exercise/ExerciseManager.java @@ -43,4 +43,8 @@ public List retrieveDoneExercises(int patientId) { public List retrieveNotDoneExercises(int patientId) { return daoE.retrieveNotDoneExercises(patientId); } + + public List retrieveAllPatientExerciseGlossaryNotDone(int userID) { return daoEG.retrieveAllPatientExerciseGlossaryNotDone(userID);} + + public List retrieveAllPatientExerciseGlossaryDone(int userID) { return daoEG.retrieveAllPatientExerciseGlossaryDone(userID);} } diff --git a/src/main/java/model/service/exercise/ExerciseManagerInterface.java b/src/main/java/model/service/exercise/ExerciseManagerInterface.java index 6d3ad23..490c1b3 100644 --- a/src/main/java/model/service/exercise/ExerciseManagerInterface.java +++ b/src/main/java/model/service/exercise/ExerciseManagerInterface.java @@ -65,4 +65,20 @@ public interface ExerciseManagerInterface { * @return Una lista di oggetti SlimmerExercise che rappresentano gli esercizi non fatti dal paziente. */ public List retrieveNotDoneExercises(int patientId); + + /** + * Recupera una lista delle info degli esercizi che un paziente non ha ancora fatto. + * + * @param userID L'ID del paziente. + * @return Una lista di oggetti ExerciseGlossary che rappresentano gli esercizi non fatti dal paziente. + */ + public List retrieveAllPatientExerciseGlossaryNotDone(int userID); + + /** + * Recupera una lista delle info degli esercizi che un paziente ha fatto. + * + * @param userID L'ID del paziente. + * @return Una lista di oggetti ExerciseGlossary che rappresentano gli esercizi non fatti dal paziente. + */ + public List retrieveAllPatientExerciseGlossaryDone(int userID); } diff --git a/src/main/webapp/CSS/RecommendationAndConditionManager.css b/src/main/webapp/CSS/RecommendationAndConditionManager.css new file mode 100644 index 0000000..4f10cc5 --- /dev/null +++ b/src/main/webapp/CSS/RecommendationAndConditionManager.css @@ -0,0 +1,18 @@ +table { + width: 80%; + border-collapse: collapse; + margin: 20px auto; +} + +table, th, td { + border: 1px solid black; +} + +th, td { + padding: 10px; + text-align: left; +} + +form { + display: inline; +} \ No newline at end of file diff --git a/src/main/webapp/JSP/exerciseRecommendation.jsp b/src/main/webapp/JSP/exerciseRecommendation.jsp new file mode 100644 index 0000000..c86f8f0 --- /dev/null +++ b/src/main/webapp/JSP/exerciseRecommendation.jsp @@ -0,0 +1,93 @@ +<%@ page import="java.util.ArrayList" %> +<%@ page import="model.service.condition.ConditionManager" %> +<%@ page import="model.service.user.UserData" %> +<%@ page import="model.service.exercise.ExerciseManager" %> +<%@ page import="java.util.List" %> +<%@ page import="model.entity.*" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Raccomanda Esercizio + + + +<% + int userId = 0; + if(session.getAttribute("type")!=null && !session.getAttribute("type").equals("therapist") || request.getParameter("userId")==null) { + response.sendRedirect("../errorPage/403.html"); + }else { + userId = Integer.parseInt((request.getParameter("userId"))); + + int userTherapist = new UserData().getUser(userId).getIdTherapist(); + if (userTherapist != (Integer) session.getAttribute("id")) { + response.sendRedirect("../errorPage/403.html"); + } + } + ExerciseManager ExerciseService= new ExerciseManager(); + + List list_Exercisedone = ExerciseService.retrieveAllPatientExerciseGlossaryDone(userId); + List list_ExerciseNOTdone = ExerciseService.retrieveAllPatientExerciseGlossaryNotDone(userId); +%> +Home + + + + + + + + + + + + + + <% for (ExerciseGlossary exerciseGlossary : list_Exercisedone) { %> + + + + + + + + + <% } %> + +
Esercizi Fatti
IDNameDescriptionTypeDifficultyTarget
<%= exerciseGlossary.getIdExercise() %><%= exerciseGlossary.getExerciseName() %><%= exerciseGlossary.getExerciseDescription() %><%= exerciseGlossary.getType() %><%= exerciseGlossary.getDifficulty()%><%= exerciseGlossary.getTarget()%>
+
+ + + + + + + + + + + + + + + <% for (ExerciseGlossary exerciseGlossary : list_ExerciseNOTdone) { %> + + + + + + + + + + + + <% } %> + +
Raccomanda Esercizi
IDNameDescriptionTypeDifficultyTarget
<%= exerciseGlossary.getIdExercise() %><%= exerciseGlossary.getExerciseName() %><%= exerciseGlossary.getExerciseDescription() %><%= exerciseGlossary.getType() %><%= exerciseGlossary.getDifficulty()%><%= exerciseGlossary.getTarget()%>
+ + + +
+ + + diff --git a/src/main/webapp/JSP/patientConditionManager.jsp b/src/main/webapp/JSP/patientConditionManager.jsp index 571c088..cb0e0d2 100644 --- a/src/main/webapp/JSP/patientConditionManager.jsp +++ b/src/main/webapp/JSP/patientConditionManager.jsp @@ -8,7 +8,8 @@ <%@ page contentType="text/html;charset=UTF-8" language="java" %> - Condition + Patologie + <% @@ -23,8 +24,6 @@ response.sendRedirect("../errorPage/403.html"); } } - - ConditionManager ConditionService= new ConditionManager(); ArrayList list_PatientCondition = ConditionService.getConditionsOfPatient(userId); @@ -32,7 +31,7 @@ %> Home - + @@ -62,7 +61,7 @@
Condition of patientPatologie del paziente
ID

- + diff --git a/src/main/webapp/JSP/viewPatient.jsp b/src/main/webapp/JSP/viewPatient.jsp index 6450cf7..9633ce4 100644 --- a/src/main/webapp/JSP/viewPatient.jsp +++ b/src/main/webapp/JSP/viewPatient.jsp @@ -71,7 +71,7 @@
Modifica patologie
-
+
Raccomanda Esercizio
@@ -101,6 +101,9 @@ function redirectToGestioneMalattie() { window.location.href = 'patientConditionManager.jsp?userId='+<%=user_selected.getIdUser() %>; } + function redirectToGestioneRaccomandazioni() { + window.location.href = 'exerciseRecommendation.jsp?userId='+<%=user_selected.getIdUser() %>; + } <%} %>
Add new condition to patientAggiungi nuova patologia
ID