diff --git a/src/main/java/controller/AddRemovePatientCondition.java b/src/main/java/controller/AddRemovePatientCondition.java index 8e61ed4..f8675f9 100644 --- a/src/main/java/controller/AddRemovePatientCondition.java +++ b/src/main/java/controller/AddRemovePatientCondition.java @@ -11,7 +11,7 @@ @WebServlet("/AddRemovePatientCondition") public class AddRemovePatientCondition extends HttpServlet { - +//mammt protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { String referer = request.getHeader("Referer"); ConditionManager conditionService= new ConditionManager(); diff --git a/src/main/java/model/DAO/DAOExercise.java b/src/main/java/model/DAO/DAOExercise.java index 5a8aa54..2f9cf06 100644 --- a/src/main/java/model/DAO/DAOExercise.java +++ b/src/main/java/model/DAO/DAOExercise.java @@ -6,7 +6,9 @@ import java.sql.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * The DAOExercise class provides methods for retrieving Exercise information from a database. @@ -464,5 +466,52 @@ public boolean deleteMultipleExercise(int userId){ } } + public Map retrieveAllStatsPatientExerciseDone(int userID) { + String query = "SELECT " + + " eg.Type AS ExerciseType," + + " COUNT(*) AS TotalAssigned," + + " COUNT(e.ID_exercise) AS TotalCompleted," + + " (COUNT(e.ID_exercise) / COUNT(*)) * 100 AS CompletionPercentage " + + "FROM " + + " exercise_glossary eg " + + "LEFT JOIN " + + " exercise e ON eg.ID_exercise = e.ID_exercise " + + " AND e.Recommended <> 0 " + + "WHERE " + + " e.ID_user = ? " + + "GROUP BY " + + " eg.Type;"; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + Map result = new HashMap<>(); + + try { + connection = connection.isClosed() ? DAOConnection.getConnection() : connection; + preparedStatement = connection.prepareStatement(query); + preparedStatement.setInt(1, userID); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) { + String exerciseType = resultSet.getString("ExerciseType"); + int completionPercentage = Math.round((float)resultSet.getDouble("CompletionPercentage")); + + result.put(exerciseType,completionPercentage); + } + + } 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 result; + } } diff --git a/src/main/java/model/service/exercise/ExerciseManager.java b/src/main/java/model/service/exercise/ExerciseManager.java index 341cf00..363c94b 100644 --- a/src/main/java/model/service/exercise/ExerciseManager.java +++ b/src/main/java/model/service/exercise/ExerciseManager.java @@ -9,6 +9,7 @@ import java.sql.Blob; import java.sql.Date; import java.util.List; +import java.util.Map; public class ExerciseManager implements ExerciseManagerInterface { private final DAOExerciseGlossary daoEG = new DAOExerciseGlossary(); @@ -63,4 +64,9 @@ public boolean changeMultipleReccomandation(String action, int userId){ return daoE.deleteMultipleExercise(userId); } } + + public Map retrieveAllStats(int id) + { + return daoE.retrieveAllStatsPatientExerciseDone(id); + } } diff --git a/src/main/webapp/JSP/userReport.jsp b/src/main/webapp/JSP/userReport.jsp new file mode 100644 index 0000000..e5cd03c --- /dev/null +++ b/src/main/webapp/JSP/userReport.jsp @@ -0,0 +1,92 @@ +<%@ page import="model.service.exercise.ExerciseManager" %> +<%@ page import="model.entity.Exercise" %> +<%@ page import="java.util.List" %> +<%@ page import="model.entity.ExerciseGlossary" %> +<%@ page import="java.util.Map" %> + + +<% + Integer userIdp = (Integer) session.getAttribute("id"); + if(userIdp == null) { + response.sendRedirect("../errorPage/403.html"); + } + else { + int userId = (Integer) session.getAttribute("id"); +%> + + <%@page contentType="text/html;charset=UTF-8"%> + + + + + + + +
+
+
+ +

Report del vostro progresso

+
+
+ +
+
+
+ +
+ + <% + ExerciseManager exerciseManager = new ExerciseManager(); + Map dict = exerciseManager.retrieveAllStats((int)session.getAttribute("id")); + if(!dict.isEmpty()){ + int Counter = 0; + for(Map.Entry exercise : dict.entrySet()) { + + %> +
+

<%= exercise.getKey()%>

+ + + Layer 1 + + + <%=exercise.getValue()%>% + + +
+ + + <% + Counter++; + } + } + else { + %> + %> +
Esercizi non disponibili
+ <% + } + %> + +
+
+ + +
+
+
+ + +<% + } +%> \ No newline at end of file