Skip to content

Commit

Permalink
FE and BE Exercise reccomendation + fix FE Condition manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewaaa committed Jan 16, 2024
1 parent 04a432e commit 130b2ce
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/main/java/model/DAO/DAOExercise.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model.DAO;

import model.entity.Exercise;
import model.entity.ExerciseGlossary;
import model.entity.Schedule;
import model.entity.SlimmerExercise;

Expand Down Expand Up @@ -173,6 +174,8 @@ public List<Exercise> 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;
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/model/DAO/DAOExerciseGlossary.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


/**
Expand Down Expand Up @@ -82,4 +84,71 @@ public ExerciseGlossary getExerciseByCode(int code) {

return null;
}

public List<ExerciseGlossary> 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<ExerciseGlossary> 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<ExerciseGlossary> 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<ExerciseGlossary> 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;
}
}
4 changes: 4 additions & 0 deletions src/main/java/model/service/exercise/ExerciseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public List<SlimmerExercise> retrieveDoneExercises(int patientId) {
public List<SlimmerExercise> retrieveNotDoneExercises(int patientId) {
return daoE.retrieveNotDoneExercises(patientId);
}

public List<ExerciseGlossary> retrieveAllPatientExerciseGlossaryNotDone(int userID) { return daoEG.retrieveAllPatientExerciseGlossaryNotDone(userID);}

public List<ExerciseGlossary> retrieveAllPatientExerciseGlossaryDone(int userID) { return daoEG.retrieveAllPatientExerciseGlossaryDone(userID);}
}
16 changes: 16 additions & 0 deletions src/main/java/model/service/exercise/ExerciseManagerInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,20 @@ public interface ExerciseManagerInterface {
* @return Una lista di oggetti SlimmerExercise che rappresentano gli esercizi non fatti dal paziente.
*/
public List<SlimmerExercise> 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<ExerciseGlossary> 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<ExerciseGlossary> retrieveAllPatientExerciseGlossaryDone(int userID);
}
18 changes: 18 additions & 0 deletions src/main/webapp/CSS/RecommendationAndConditionManager.css
Original file line number Diff line number Diff line change
@@ -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;
}
93 changes: 93 additions & 0 deletions src/main/webapp/JSP/exerciseRecommendation.jsp
Original file line number Diff line number Diff line change
@@ -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" %>
<html>
<head>
<title>Raccomanda Esercizio</title>
<link rel="stylesheet" href="../CSS/RecommendationAndConditionManager.css" />
</head>
<body>
<%
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<ExerciseGlossary> list_Exercisedone = ExerciseService.retrieveAllPatientExerciseGlossaryDone(userId);
List<ExerciseGlossary> list_ExerciseNOTdone = ExerciseService.retrieveAllPatientExerciseGlossaryNotDone(userId);
%>
<a href="homeTherapist.jsp" align="left">Home</a>
<table border="1" align="center">
<caption><b>Esercizi Fatti</b></caption>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Type</th>
<th>Difficulty</th>
<th>Target</th>
</tr>
</thead>
<tbody>
<% for (ExerciseGlossary exerciseGlossary : list_Exercisedone) { %>
<tr>
<td><%= exerciseGlossary.getIdExercise() %></td>
<td><%= exerciseGlossary.getExerciseName() %></td>
<td><%= exerciseGlossary.getExerciseDescription() %></td>
<td><%= exerciseGlossary.getType() %></td>
<td><%= exerciseGlossary.getDifficulty()%></td>
<td><%= exerciseGlossary.getTarget()%></td>
</tr>
<% } %>
</tbody>
</table>
<hr>
<table border="1">
<caption><b>Raccomanda Esercizi</b></caption>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Type</th>
<th>Difficulty</th>
<th>Target</th>
<th></th>
</tr>
</thead>
<tbody>
<% for (ExerciseGlossary exerciseGlossary : list_ExerciseNOTdone) { %>
<tr>
<td><%= exerciseGlossary.getIdExercise() %></td>
<td><%= exerciseGlossary.getExerciseName() %></td>
<td><%= exerciseGlossary.getExerciseDescription() %></td>
<td><%= exerciseGlossary.getType() %></td>
<td><%= exerciseGlossary.getDifficulty()%></td>
<td><%= exerciseGlossary.getTarget()%></td>
<form action="../Raccomanda" method="post">
<td>
<input type="hidden" name="idCondition" value="<%= exerciseGlossary.getIdExercise() %>">
<input type="hidden" name="idPatient" value="<%= userId %>">
<input type="submit" value="Raccomanda" name="operation">
</td>
</form>
</tr>
<% } %>
</tbody>
</table>
</body>
</html>

9 changes: 4 additions & 5 deletions src/main/webapp/JSP/patientConditionManager.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Condition</title>
<title>Patologie</title>
<link rel="stylesheet" href="../CSS/RecommendationAndConditionManager.css" />
</head>
<body>
<%
Expand All @@ -23,16 +24,14 @@
response.sendRedirect("../errorPage/403.html");
}
}
ConditionManager ConditionService= new ConditionManager();
ArrayList<Condition> list_PatientCondition = ConditionService.getConditionsOfPatient(userId);
ArrayList<Condition> list_NOTPatientCondition = ConditionService.getConditionsNOTOfPatient(userId);
%>
<a href="homeTherapist.jsp" align="left">Home</a>
<table border="1" align="center">
<caption>Condition of patient</caption>
<caption><b>Patologie del paziente</b></caption>
<thead>
<tr>
<th>ID</th>
Expand Down Expand Up @@ -62,7 +61,7 @@
</table>
<hr>
<table border="1">
<caption>Add new condition to patient</caption>
<caption><b>Aggiungi nuova patologia</b></caption>
<thead>
<tr>
<th>ID</th>
Expand Down
5 changes: 4 additions & 1 deletion src/main/webapp/JSP/viewPatient.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<div class="group-5" onclick="redirectToGestioneMalattie()">
<div class="overlap-3"><div class="text-wrapper-2">Modifica patologie</div></div>
</div>
<div class="group-6">
<div class="group-6" onclick="redirectToGestioneRaccomandazioni()">
<div class="overlap-4"><div class="text-wrapper-3">Raccomanda Esercizio</div></div>
</div>
<div class="button-chat"><img class="iconly-light-chat" src="../images/homeTherapist/iconly-light-chat.svg" /></div>
Expand Down Expand Up @@ -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() %>;
}
</script>
<%} %>
</body>
Expand Down

0 comments on commit 130b2ce

Please sign in to comment.