Skip to content

Commit

Permalink
Merge pull request #84 from pastore99/81-userreport
Browse files Browse the repository at this point in the history
81 userreport
  • Loading branch information
panuozzo77 authored Jan 18, 2024
2 parents e2646cb + db9aa0d commit eb82645
Show file tree
Hide file tree
Showing 6 changed files with 644 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/controller/AddRemovePatientCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/model/DAO/DAOExercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -464,5 +466,46 @@ public boolean deleteMultipleExercise(int userId){
}
}

public Map<String, Integer> retrieveAllStatsPatientExerciseDone(int userID) {
String query = "SELECT eg.Type, " +
"COUNT(CASE WHEN e.CompletionDate IS NOT NULL THEN e.ID_exercise END) as CompletedCount, " +
"COUNT(e.ID_exercise) as TotalAssignedCount, " +
"IFNULL(COUNT(CASE WHEN e.CompletionDate IS NOT NULL THEN e.ID_exercise END) / NULLIF(COUNT(e.ID_exercise), 0) * 100, 0) as CompletionPercentage " +
"FROM exercise_glossary eg " +
"LEFT JOIN exercise e ON eg.ID_exercise = e.ID_exercise AND e.ID_user = ? " +
"GROUP BY eg.Type; ";

PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
Map<String, Integer> 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("Type"); // Fix: Use "Type" instead of "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;
}

}
6 changes: 6 additions & 0 deletions src/main/java/model/service/exercise/ExerciseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -63,4 +64,9 @@ public boolean changeMultipleReccomandation(String action, int userId){
return daoE.deleteMultipleExercise(userId);
}
}

public Map<String,Integer> retrieveAllStats(int id)
{
return daoE.retrieveAllStatsPatientExerciseDone(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.sql.Blob;
import java.sql.Date;
import java.util.List;
import java.util.Map;

public interface ExerciseManagerInterface {

Expand Down Expand Up @@ -66,4 +67,11 @@ public interface ExerciseManagerInterface {
*/
public List<SlimmerExercise> retrieveNotDoneExercises(int patientId);

/**
* Recupera i dati riguardanti gli esercizi proposti dal paziente all'utente.
*
* @param id L'ID del paziente.
* @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);
}
Loading

0 comments on commit eb82645

Please sign in to comment.