Skip to content

Commit

Permalink
Merge pull request #87 from pastore99/86-merge-all-therapist-related-…
Browse files Browse the repository at this point in the history
…branches-together

86 merge all therapist related branches together
  • Loading branch information
r-monti authored Jan 18, 2024
2 parents b10af02 + 0a6b087 commit 62aa6b1
Show file tree
Hide file tree
Showing 35 changed files with 1,271 additions and 454 deletions.
2 changes: 1 addition & 1 deletion src/main/java/controller/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private String setSessionAttributes(int id, HttpServletRequest request){
else {
session.setAttribute("type", "therapist");
session.setAttribute("surname", personalInfo.getLastname());
return "JSP/homeTherapist.jsp";
return "JSP/homepageTherapist.jsp";
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/controller/ManageAIExercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public class ManageAIExercise extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String referer = request.getHeader("Referer");
String action = request.getParameter("action");
ExerciseManager em = new ExerciseManager();
Gson g = new Gson();
Expand All @@ -31,6 +32,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
}
em.changeMultipleReccomandation(action, Integer.parseInt(request.getParameter("userId")));
}
response.sendRedirect(request.getHeader("Referer"));
response.sendRedirect(referer);
}
}
29 changes: 29 additions & 0 deletions src/main/java/controller/exerciseRecommendation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package controller;

import model.service.condition.ConditionManager;
import model.service.exercise.ExerciseManager;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/exerciseRecommendation")
public class exerciseRecommendation extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String referer = request.getHeader("Referer");
ExerciseManager exerciseService= new ExerciseManager();

int idExercise = Integer.parseInt(request.getParameter("idExercise"));
int idPatient = Integer.parseInt(request.getParameter("idPatient"));

exerciseService.AddExerciseRecommendation(idExercise,idPatient);

response.sendRedirect(referer);

}

}
34 changes: 17 additions & 17 deletions src/main/java/model/DAO/DAOCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ public ArrayList<Condition> getConditionsNOTOfPatient(int id_patient) {

public boolean AddConditionPatient(int ID_condition, int ID_patient, int Severity) {

PreparedStatement preparedStatementPersonalInfo = null;
PreparedStatement preparedStatement = null;

try {
connection = connection.isClosed() ? DAOConnection.getConnection():connection;
connection.setAutoCommit(false); // Start a transaction

// Insert user data into personal_info table
String queryAnagrafica = "INSERT INTO PatientCondition (ID_condition, ID_patient, Severity)\n" +

String query = "INSERT INTO PatientCondition (ID_condition, ID_patient, Severity)\n" +
"VALUES (?, ?, ?)";
preparedStatementPersonalInfo = connection.prepareStatement(queryAnagrafica);
preparedStatementPersonalInfo.setInt(1, ID_condition);
preparedStatementPersonalInfo.setInt(2, ID_patient);
preparedStatementPersonalInfo.setInt(3, Severity);
preparedStatementPersonalInfo.executeUpdate();
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, ID_condition);
preparedStatement.setInt(2, ID_patient);
preparedStatement.setInt(3, Severity);
preparedStatement.executeUpdate();

connection.commit(); // Commit the transaction
return true; // User created successfully
Expand All @@ -157,7 +157,7 @@ public boolean AddConditionPatient(int ID_condition, int ID_patient, int Severit
}
} finally {
try {
if (preparedStatementPersonalInfo != null) preparedStatementPersonalInfo.close();
if (preparedStatement != null) preparedStatement.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
// Handle the exception (e.g., log or throw)
Expand All @@ -170,19 +170,19 @@ public boolean AddConditionPatient(int ID_condition, int ID_patient, int Severit

public boolean RemoveConditionPatient(int ID_condition, int ID_patient) {

PreparedStatement preparedStatementPersonalInfo = null;
PreparedStatement preparedStatement = null;

try {
connection = connection.isClosed() ? DAOConnection.getConnection():connection;
connection.setAutoCommit(false); // Start a transaction

// Insert user data into personal_info table
String queryAnagrafica = "DELETE FROM PatientCondition\n" +

String query = "DELETE FROM PatientCondition\n" +
"WHERE ID_condition = ? AND ID_patient = ?;";
preparedStatementPersonalInfo = connection.prepareStatement(queryAnagrafica);
preparedStatementPersonalInfo.setInt(1, ID_condition);
preparedStatementPersonalInfo.setInt(2, ID_patient);
preparedStatementPersonalInfo.executeUpdate();
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, ID_condition);
preparedStatement.setInt(2, ID_patient);
preparedStatement.executeUpdate();

connection.commit(); // Commit the transaction
return true; // User created successfully
Expand All @@ -199,7 +199,7 @@ public boolean RemoveConditionPatient(int ID_condition, int ID_patient) {
}
} finally {
try {
if (preparedStatementPersonalInfo != null) preparedStatementPersonalInfo.close();
if (preparedStatement != null) preparedStatement.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
// Handle the exception (e.g., log or throw)
Expand Down
76 changes: 76 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 @@ -156,6 +157,39 @@ public List<SlimmerExercise> retrieveDoneExercises(int patientId) {
return exercises;
}

public List<Exercise> retrieveAllPatientExerciseDone(int userID) {
String query = "SELECT * FROM exercise WHERE ID_user = ? AND CompletionDate IS NOT NULL ORDER BY InsertionDate DESC;";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
List<Exercise> exercises = new ArrayList<>();

try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, userID);

resultSet = preparedStatement.executeQuery();

while (resultSet.next()) {
Exercise 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<Exercise> retrievePatientExerciseDone(int patientID) {
String query = "SELECT *\n" +
"FROM exercise\n" +
Expand Down Expand Up @@ -333,6 +367,48 @@ public boolean setExerciseFeedback(int userID, int exerciseID, Date insertDate,
}
}

public boolean AddExerciseRecommendation(int idExercise, int idPatient) {

PreparedStatement preparedStatement= null;

try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
connection.setAutoCommit(false); // Start a transaction


String query = "INSERT INTO exercise (ID_user, ID_exercise, InsertionDate, CompletionDate, Execution, Evaluation, Recommended, Feedback)\n" +
"VALUES (?,?,CURRENT_DATE,NULL,NULL,NULL,2,NULL);";
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, idPatient);
preparedStatement.setInt(2, idExercise);
preparedStatement.executeUpdate();

connection.commit(); // Commit the transaction
return true; // User created successfully

} catch (SQLException e) {
// Handle the exception (e.g., log or throw)
e.printStackTrace();
try {
if (connection != null) {
connection.rollback(); // Rollback the transaction in case of an exception
}
} catch (SQLException ex) {
ex.printStackTrace();
}
} finally {
try {
if (preparedStatement != null) preparedStatement.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
// Handle the exception (e.g., log or throw)
e.printStackTrace();
}
}
return false;
}


public List<SlimmerExercise> getExerciseToApprove(int therapistId){
List<SlimmerExercise> exercises = new ArrayList<>();
try {
Expand Down
69 changes: 68 additions & 1 deletion src/main/java/model/DAO/DAOExerciseGlossary.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,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;
}
}
10 changes: 10 additions & 0 deletions src/main/java/model/service/exercise/ExerciseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public boolean saveEvaluation(int userID, int exerciseId, Date insertDate, int e
return daoE.setExerciseEvaluation(userID, exerciseId, insertDate, evaluation);
}

public List<Exercise> retrieveAllPatientExerciseDone(int userID){
return daoE.retrieveAllPatientExerciseDone(userID);
}

public List<Exercise> retrievePatientExerciseDone(int patientID) {
return daoE.retrievePatientExerciseDone(patientID);
}
Expand Down Expand Up @@ -69,4 +73,10 @@ public Map<String,Integer> retrieveAllStats(int id)
{
return daoE.retrieveAllStatsPatientExerciseDone(id);
}

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

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

public boolean AddExerciseRecommendation(int idExercise, int idPatient) { return daoE.AddExerciseRecommendation(idExercise,idPatient);}
}
32 changes: 32 additions & 0 deletions src/main/java/model/service/exercise/ExerciseManagerInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public interface ExerciseManagerInterface {
*/
public boolean saveEvaluation(int userID, int exerciseId, Date insertDate, int evaluation);

/**
* Recupera una lista di tutti gli esercizi fatti da un paziente specifico.
*
* @param userID L'ID del paziente.
* @return Una lista di oggetti Exercise che rappresentano gli esercizi fatti dal paziente.
*/
public List<Exercise> retrieveAllPatientExerciseDone(int userID);

/**
* Recupera una lista di esercizi che un paziente ha già fatto.
Expand Down Expand Up @@ -74,4 +81,29 @@ public interface ExerciseManagerInterface {
* @return Una Map con chiave il tipo di esercizio e valore la percentaule di esercizi fatti rispetto a quelli non fatti.
*/
public Map<String,Integer> retrieveAllStats(int id);

/**
* 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);

/**
* Raccomanda un esercizio ad un paziente
*
* @param idPatient L'ID dell'utente.
* @param idExercise L'ID dell'esercizio.
* @return true se la raccomandazione viene salvata con successo, false altrimenti.
*/
public boolean AddExerciseRecommendation(int idExercise, int idPatient);
}
Loading

0 comments on commit 62aa6b1

Please sign in to comment.