diff --git a/pom.xml b/pom.xml index a0e0e49..6e9084f 100644 --- a/pom.xml +++ b/pom.xml @@ -39,12 +39,6 @@ - - com.google.code.gson - gson - 2.10.1 - - mysql mysql-connector-java @@ -96,6 +90,12 @@ test + + com.google.code.gson + gson + 2.10.1 + + com.mockrunner mockrunner-servlet @@ -119,12 +119,27 @@ javax.servlet-api 3.1.0 + org.mockito mockito-junit-jupiter 5.3.1 test + + + com.microsoft.cognitiveservices.speech + client-sdk + 1.34.0 + + + + + info.debatty + java-string-similarity + 2.0.0 + + @@ -213,6 +228,7 @@ org.apache.maven.plugins maven-compiler-plugin + 3.12.1 21 21 diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 7ae023e..e1216ba 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -17,9 +17,10 @@ public static void main(String[] args) { //r.invitePatient(9, "thenicrodeath@gmail.com", "Raffaele", "Monti"); ScheduleManager manager = new ScheduleManager(); - String date = "2024-01-11"; + String date = "2024-02-10"; String time = "10:00-11:00"; if(manager.checkData(9, date, time)) { + System.out.println("inif"); manager.createNewSchedule(9, date, time); //funziona } } diff --git a/src/main/java/controller/ChangeUserInfo.java b/src/main/java/controller/ChangeUserInfo.java index e23399f..d64feb7 100644 --- a/src/main/java/controller/ChangeUserInfo.java +++ b/src/main/java/controller/ChangeUserInfo.java @@ -23,7 +23,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) } else { risultato = "Dati personali non aggiornati, email gia' utilizzata"; } - response.sendRedirect("/TalkAID_war_exploded/JSP/Cambio_dati.jsp?risultato=" + risultato); + response.sendRedirect("JSP/userInfoChange.jsp?risultato=" + risultato); } private boolean updatePersonalInfo(HttpServletRequest request, int userId, UserRegistry userRegistry) { diff --git a/src/main/java/controller/ExerciseController.java b/src/main/java/controller/ExerciseController.java index d8706d3..eaa2226 100644 --- a/src/main/java/controller/ExerciseController.java +++ b/src/main/java/controller/ExerciseController.java @@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.sql.Date; @WebServlet("/exerciseController") @@ -15,7 +16,10 @@ public class ExerciseController extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { ExerciseManager em = new ExerciseManager(); String id = request.getParameter("exerciseID"); - //TODO: Aggiungi alla sessione insertion date @michele + String insertionDate = request.getParameter("insertionDate"); + request.getSession().setAttribute("insertionDate", Date.valueOf(insertionDate)); + request.getSession().setAttribute("exerciseID", Integer.parseInt(id)); + ExerciseGlossary ex = em.getExercise(Integer.parseInt(id)); request.getSession().setAttribute("exercise", ex); response.sendRedirect(request.getContextPath() + "/JSP/exercise.jsp"); diff --git a/src/main/java/controller/ExerciseEvaluator.java b/src/main/java/controller/ExerciseEvaluator.java new file mode 100644 index 0000000..40f50af --- /dev/null +++ b/src/main/java/controller/ExerciseEvaluator.java @@ -0,0 +1,210 @@ +package controller; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import info.debatty.java.stringsimilarity.Levenshtein; +import model.entity.ExerciseGlossary; +import model.service.exercise.ExerciseManager; +import model.service.exercise.SpeechRecognition; + +import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.*; +import java.io.*; +import java.lang.reflect.Type; +import java.sql.Blob; +import java.sql.Date; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutionException; + + +@WebServlet("/exerciseEvaluator") +@MultipartConfig +public class ExerciseEvaluator extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + HttpSession s = request.getSession(); + String contentType = request.getContentType(); + ExerciseManager em = new ExerciseManager(); + + int exerciseId = (int) s.getAttribute("exerciseID"); + int userId = (int) s.getAttribute("id"); + Date d = (Date) s.getAttribute("insertionDate"); + + int score; + + if ("application/json".equals(contentType)) { + score = evaluateNoAudio(exerciseId, userId, d); + } else { + try { + score = evaluateAudio(exerciseId, userId, d); + } catch (ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + } + em.saveEvaluation(userId, exerciseId, d, score); + } + + + private int evaluateNoAudio(int exerciseId, int userId, Date date){ + Gson gson = new Gson(); + + ExerciseGlossary baseExercise = new ExerciseManager().getExercise(exerciseId); + String executionJSON = getJSONfromBlob(exerciseId, userId, date); + String type = baseExercise.getType(); + + int score; + + switch (type) { + case "CROSSWORD" -> { + String[][] solution = gson.fromJson(baseExercise.getSolution(), String[][].class); + String[][] execution = gson.fromJson(executionJSON, String[][].class); + + score = evaluateCrossword(execution, solution); + } + case "IMAGESTOTEXT", "TEXTTOIMAGES" -> { + Type solutionType = new TypeToken>() {}.getType(); + Map solution = gson.fromJson(baseExercise.getSolution(), solutionType); + Map execution = gson.fromJson(executionJSON, solutionType); + + score = evaluateITTnTTI(execution, solution); + } + case "RIGHTTEXT" -> { + Type solutionType = new TypeToken>(){}.getType(); + Set solution = gson.fromJson(baseExercise.getSolution(), solutionType); + Set execution = gson.fromJson(executionJSON, solutionType); + + score = evaluateRightText(execution, solution); + } + default -> throw new IllegalStateException("Unexpected value: " + type); + } + + return score; + } + + private String getJSONfromBlob(int exerciseId, int userId, Date d){ + Blob executionBlob = new ExerciseManager().getExecution(exerciseId, userId, d); + StringBuilder stringBuilder = new StringBuilder(); + + try (InputStream binaryStream = executionBlob.getBinaryStream(); + InputStreamReader inputStreamReader = new InputStreamReader(binaryStream); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { + + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + + } catch (SQLException | IOException e) { + e.printStackTrace(); + } + + return stringBuilder.toString(); + } + + private int evaluateRightText(Set execution, Set solution) { + double right = 0; + int total = solution.size(); + for (String s : solution) { + if (execution.contains(s.toUpperCase())){ + right++; + } + } + return (int)((right /total)*100); + } + + private int evaluateITTnTTI(Map execution, Map solution) { + double right = 0; + int total = solution.size(); + + for (Map.Entry entry : execution.entrySet()) { + String k = entry.getKey(); + String executionValue = entry.getValue(); + String solutionValue = solution.get(k); + + if (executionValue != null) { + if (executionValue.equals(solutionValue.toUpperCase())) { + right++; + } + } + } + return (int)((right /total)*100); + } + + private int evaluateCrossword(String[][] execution, String[][] solution) { + double right = 0; + int total = 0; + + for (int i = 0; i < execution.length; i++) { + for (int j = 0; j < execution[0].length; j++) { + if (!execution[i][j].equals("#")){ + if (execution[i][j].equals(solution[i][j].toUpperCase())) { + right++; + } + total++; + } + } + } + return (int)((right /total)*100); + } + + private int evaluateAudio(int exerciseId, int userId, Date d) throws IOException, ExecutionException, InterruptedException { + InputStream audioExecution = getAudiofromBlob(exerciseId, userId, d); + String audioText = null; + if (audioExecution!=null){ + SpeechRecognition s = new SpeechRecognition(); + audioText = s.azureSTT(audioExecution); + } + + if(audioText != null) { + ExerciseGlossary baseExercise = new ExerciseManager().getExercise(exerciseId); + String exerciseType = baseExercise.getType(); + Gson g = new Gson(); + + if (baseExercise.getType().equals("READTEXT")){ + Levenshtein l = new Levenshtein(); + String solution = g.fromJson(baseExercise.getInitialState(), String.class); + double distance = l.distance(solution, audioText); + double result = ((solution.length()-distance)/solution.length())*100; + + return (int) Math.round(result); + + }else if(exerciseType.equals("READIMAGES")){ + Type solutionType = new TypeToken>(){}.getType(); + Set solution = g.fromJson(baseExercise.getSolution(), solutionType); + String execution = audioText.toLowerCase().replaceAll("[^a-zA-Z0-9\\s]", ""); + + double right = 0; + double total = solution.size(); + + String[] wordsArray = execution.split("\\s+"); + Set wordSet = new HashSet<>(Arrays.asList(wordsArray)); + + for(String w: wordSet){ + if(solution.contains(w)){ + right++; + } + } + + double result = ((right/total)*100); + + return (int) Math.round(result); + } + } + + return 0; + } + + private InputStream getAudiofromBlob(int exerciseId, int userId, Date d){ + Blob executionBlob = new ExerciseManager().getExecution(exerciseId, userId, d); + try (InputStream audioInputStream = executionBlob.getBinaryStream()) { + return audioInputStream; + } catch (SQLException | IOException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/src/main/java/controller/ExerciseLogger.java b/src/main/java/controller/ExerciseLogger.java index fd5b02a..6d170fd 100644 --- a/src/main/java/controller/ExerciseLogger.java +++ b/src/main/java/controller/ExerciseLogger.java @@ -3,6 +3,7 @@ import model.service.exercise.ExerciseManager; import org.apache.commons.io.IOUtils; +import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; @@ -21,12 +22,13 @@ public class ExerciseLogger extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String contentType = request.getContentType(); - if ("application/json".equals(contentType)) { handleNoAudioExercise(request); } else { handleAudioExercise(request); } + RequestDispatcher d = request.getRequestDispatcher("/exerciseEvaluator"); + d.forward(request, response); } private void handleNoAudioExercise(HttpServletRequest request) throws IOException { @@ -49,13 +51,13 @@ private void handleNoAudioExercise(HttpServletRequest request) throws IOExceptio } private void handleAudioExercise(HttpServletRequest request) throws ServletException, IOException { - InputStream audioInputStream; try { Part audioPart = request.getPart("audioFile"); - audioInputStream = audioPart.getInputStream(); - Blob audioBlob = new SerialBlob(IOUtils.toByteArray(audioInputStream)); - saveInDB(request, audioBlob); + try (InputStream audioInputStream = audioPart.getInputStream()) { + Blob audioBlob = new SerialBlob(IOUtils.toByteArray(audioInputStream)); + saveInDB(request, audioBlob); + } } catch (SQLException e) { throw new RuntimeException(e); } @@ -64,10 +66,10 @@ private void handleAudioExercise(HttpServletRequest request) throws ServletExcep private boolean saveInDB(HttpServletRequest request, Blob execution){ ExerciseManager em = new ExerciseManager(); HttpSession session = request.getSession(); - int userId = Integer.parseInt((String) session.getAttribute("userId")); - int exerciseId = Integer.parseInt((String) session.getAttribute("exerciseId")); - Date insertDate = Date.valueOf((String) session.getAttribute("insertDate")); - //TODO: pulisci la sessione @michele + int userId = (int) session.getAttribute("id"); + int exerciseId = (int) session.getAttribute("exerciseID"); + Date insertDate = (Date) session.getAttribute("insertionDate"); + return em.saveExecution(userId, exerciseId, insertDate, execution); } } \ No newline at end of file diff --git a/src/main/java/controller/InvitePatient.java b/src/main/java/controller/InvitePatient.java new file mode 100644 index 0000000..dbf9dc9 --- /dev/null +++ b/src/main/java/controller/InvitePatient.java @@ -0,0 +1,24 @@ +package controller; + +import model.service.condition.ConditionManager; +import model.service.registration.Registration; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; + + +@WebServlet("/invitePatient") +public class InvitePatient extends HttpServlet { + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { + HttpSession session = request.getSession(); + model.service.registration.Registration registration=new Registration(); + registration.invitePatient((Integer) session.getAttribute("id"), request.getParameter("email"), request.getParameter("nome"), request.getParameter("cognome")); + response.sendRedirect(request.getContextPath() + "/JSP/homepageTherapist.jsp"); + } + +} \ No newline at end of file diff --git a/src/main/java/controller/Login.java b/src/main/java/controller/Login.java index 8a199ad..b4fef2f 100644 --- a/src/main/java/controller/Login.java +++ b/src/main/java/controller/Login.java @@ -59,7 +59,7 @@ private String setSessionAttributes(int id, HttpServletRequest request){ session.setAttribute("type", "patient"); session.setAttribute("therapist", user.getIdTherapist()); - return "JSP/homepagepatient.jsp"; + return "JSP/homePagePatient.jsp"; } else { session.setAttribute("type", "therapist"); diff --git a/src/main/java/controller/ScheduleManager.java b/src/main/java/controller/ScheduleManager.java index 668e225..0a8760b 100644 --- a/src/main/java/controller/ScheduleManager.java +++ b/src/main/java/controller/ScheduleManager.java @@ -23,10 +23,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) scheduleManager.createNewSchedule(userId, request.getParameter("date"), request.getParameter("timeslot")); response.sendRedirect("JSP/schedule.jsp"); } else { - String errorMessage = "La data selezionata non è valida. Seleziona una data non esistente perfavore."; - request.setAttribute("errorMessage", errorMessage); - //request.getRequestDispatcher("JSP/schedule.jsp").forward(request, response); - response.sendRedirect("JSP/schedule.jsp"); + String errorMessage = "Seleziona una data non esistente perfavore."; + response.sendRedirect("JSP/schedule.jsp?errorMessage=" + errorMessage); } } else if (action.equalsIgnoreCase("deleteSchedule")) { diff --git a/src/main/java/model/DAO/DAOExercise.java b/src/main/java/model/DAO/DAOExercise.java index 7644295..ae2f755 100644 --- a/src/main/java/model/DAO/DAOExercise.java +++ b/src/main/java/model/DAO/DAOExercise.java @@ -1,8 +1,11 @@ package model.DAO; import model.entity.Exercise; +import model.entity.Schedule; import java.sql.*; +import java.util.ArrayList; +import java.util.List; /** * The DAOExercise class provides methods for retrieving Exercise information from a database. @@ -52,7 +55,7 @@ private static Exercise extractExerciseFromResultSet(ResultSet resultSet) throws * @return the Exercise if it is found, else null. */ public Exercise getExerciseByPk(int userID, int exerciseID, Date insertDate) { - String query = "SELECT * FROM exercise WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?"; + String query = "SELECT * FROM exercise WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?;"; PreparedStatement preparedStatement = null; ResultSet resultSet = null; @@ -84,6 +87,138 @@ public Exercise getExerciseByPk(int userID, int exerciseID, Date insertDate) { return null; } + public List retrieveAllNewPatientExercise(int userID) { + String query = "SELECT * FROM exercise WHERE ID_user = ? ORDER BY InsertionDate DESC;"; + 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()) { + 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 retrieveAllNewPatientExerciseNotDone(int userID) { + String query = "SELECT * FROM exercise WHERE ID_user = ? AND CompletionDate IS NULL ORDER BY InsertionDate DESC;"; + 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()) { + 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 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 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 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; + ResultSet resultSet = null; + + try { + connection = connection.isClosed() ? DAOConnection.getConnection() : connection; + preparedStatement = connection.prepareStatement(query); + preparedStatement.setInt(1, userID); + preparedStatement.setInt(2, exerciseID); + preparedStatement.setDate(3, insertDate); + + resultSet = preparedStatement.executeQuery(); + + if (resultSet.next()) { + return resultSet.getBlob("Execution"); + } + + } 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 null; + } + public boolean setExerciseExecution(int userID, int exerciseID, Date insertDate, Blob execution) { String query = "UPDATE exercise SET Execution = ? WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?;"; PreparedStatement preparedStatement = null; @@ -112,7 +247,7 @@ public boolean setExerciseExecution(int userID, int exerciseID, Date insertDate, } public boolean setExerciseEvaluation(int userID, int exerciseID, Date insertDate, int evaluation) { - String query = "UPDATE exercise SET Evaluation = ? WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?;"; + String query = "UPDATE exercise SET Evaluation = ? , CompletionDate = CURRENT_DATE WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?;"; PreparedStatement preparedStatement = null; try { diff --git a/src/main/java/model/entity/Exercise.java b/src/main/java/model/entity/Exercise.java index 33b3aae..bd35b8c 100644 --- a/src/main/java/model/entity/Exercise.java +++ b/src/main/java/model/entity/Exercise.java @@ -78,5 +78,17 @@ public int getFeedback() { public void setFeedback(int feedback) { this.feedback = feedback; } + @Override + public String toString() { + return "Exercise{" + + "idUser=" + idUser + + ", idExercise=" + idExercise + + ", insertionDate=" + insertionDate + + ", completionDate=" + completionDate + + ", evaluation=" + evaluation + + ", recommended=" + recommended + + ", feedback=" + feedback + + '}'; + } } diff --git a/src/main/java/model/service/exercise/ExerciseManager.java b/src/main/java/model/service/exercise/ExerciseManager.java index 7509b56..3733a96 100644 --- a/src/main/java/model/service/exercise/ExerciseManager.java +++ b/src/main/java/model/service/exercise/ExerciseManager.java @@ -2,24 +2,44 @@ import model.DAO.DAOExercise; import model.DAO.DAOExerciseGlossary; +import model.entity.Exercise; import model.entity.ExerciseGlossary; import java.sql.Blob; import java.sql.Date; +import java.util.List; public class ExerciseManager implements ExerciseManagerInterface { private final DAOExerciseGlossary daoEG = new DAOExerciseGlossary(); private final DAOExercise daoE = new DAOExercise(); + public ExerciseGlossary getExercise(int exerciseID) { return daoEG.getExerciseByCode(exerciseID); } - public Blob getExecution(int exerciseID, int userID) { - return null; + public Blob getExecution(int exerciseID, int userID, Date insertionDate) { + return daoE.getExerciseExecution(userID, exerciseID, insertionDate); } public boolean saveExecution(int userID, int exerciseId, Date insertDate, Blob execution) { return daoE.setExerciseExecution(userID, exerciseId, insertDate, execution); } + + public boolean saveEvaluation(int userID, int exerciseId, Date insertDate, int evaluation) { + + return daoE.setExerciseEvaluation(userID, exerciseId, insertDate, evaluation); + } + + public List retrieveAllNewPatientExercise(int userID){ + return daoE.retrieveAllNewPatientExercise(userID); + } + + public List retrieveAllPatientExerciseDone(int userID){ + return daoE.retrieveAllPatientExerciseDone(userID); + } + + public List retrieveAllNewPatientExerciseNotDone(int userID){ + return daoE.retrieveAllNewPatientExerciseNotDone(userID); + } } diff --git a/src/main/java/model/service/exercise/ExerciseManagerInterface.java b/src/main/java/model/service/exercise/ExerciseManagerInterface.java index 62d675d..243030e 100644 --- a/src/main/java/model/service/exercise/ExerciseManagerInterface.java +++ b/src/main/java/model/service/exercise/ExerciseManagerInterface.java @@ -18,9 +18,10 @@ public interface ExerciseManagerInterface { * Preleva un'esecuzione di un esercizio * @param exerciseID l'id dell'esercizio * @param userID l'id dell'utente che ha svolto l'esercizio + * @param insertionDate la data in cui l'esercizio è stata assegnata all'utente * @return un BLOB contenente l'esecuzione dell'esercizio */ - Blob getExecution(int exerciseID, int userID); + Blob getExecution(int exerciseID, int userID, Date insertionDate); /** * Salva l'esecuzione di un esercizio diff --git a/src/main/java/model/service/exercise/SpeechRecognition.java b/src/main/java/model/service/exercise/SpeechRecognition.java new file mode 100644 index 0000000..0f5a677 --- /dev/null +++ b/src/main/java/model/service/exercise/SpeechRecognition.java @@ -0,0 +1,121 @@ +package model.service.exercise; + +import com.microsoft.cognitiveservices.speech.*; +import com.microsoft.cognitiveservices.speech.audio.AudioConfig; +import java.io.*; +import java.nio.file.*; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + + +public class SpeechRecognition { + private static final String AZURE_PROPERTIES = "/azure.properties"; + private static String speechKey; + private static String speechRegion; + + public SpeechRecognition(){ + Properties azureProps = loadProps(); + speechRegion = azureProps.getProperty("azure.region"); + speechKey = azureProps.getProperty("azure.key"); + } + + + public String azureSTT(InputStream audio) throws InterruptedException, ExecutionException, IOException { + SpeechConfig speechConfig = SpeechConfig.fromSubscription(speechKey, speechRegion); + speechConfig.setSpeechRecognitionLanguage("it-It"); + + AudioConfig audioConfig = AudioConfig.fromWavFileInput(generateFile(audio)); + SpeechRecognizer speechRecognizer = new SpeechRecognizer(speechConfig, audioConfig); + + Future task = speechRecognizer.recognizeOnceAsync(); + SpeechRecognitionResult speechRecognitionResult = task.get(); + + String result = null; + + if (speechRecognitionResult.getReason() == ResultReason.RecognizedSpeech) { + result = speechRecognitionResult.getText(); + } + else if (speechRecognitionResult.getReason() == ResultReason.NoMatch){ + System.err.println("NOMATCH: Speech could not be recognized."); + }else if (speechRecognitionResult.getReason() == ResultReason.Canceled) { + CancellationDetails cancellation = CancellationDetails.fromResult(speechRecognitionResult); + System.out.println("CANCELED: Reason=" + cancellation.getReason()); + + if (cancellation.getReason() == CancellationReason.Error) { + System.out.println("CANCELED: ErrorCode=" + cancellation.getErrorCode()); + System.out.println("CANCELED: ErrorDetails=" + cancellation.getErrorDetails()); + System.out.println("CANCELED: Did you set the speech resource key and region values?"); + } + } + + return result; + } + + public String generateFile(InputStream inputAudio) throws IOException { + //Crea temporaneamente il file creato dal DB + File tempFile = File.createTempFile("tempAudio", ".opus"); + try (FileOutputStream fos = new FileOutputStream(tempFile)) { + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = inputAudio.read(buffer)) != -1) { + fos.write(buffer, 0, bytesRead); + } + } + //Ottieni il path dell'output basandoti sul file creato + Path outputPath = Paths.get(tempFile.getPath()).getParent().resolve("outputJava.wav"); + String path = outputPath.toString(); + + //Controlla che non esista già un file + try { + // Use the delete method from Files class to delete the file + Files.delete(Paths.get(path)); + } catch (FileNotFoundException e){ + System.err.println("File not found"); + } catch (IOException e) { + System.err.println("Error deleting the file: " + e.getMessage()); + } + + + List command = Arrays.asList( + "ffmpeg", + "-i", tempFile.getPath(), + "-ar", "16000", + "-ac", "1", + "-acodec", "pcm_s16le", + path + ); + + try { + ProcessBuilder processBuilder = new ProcessBuilder(command); + Process process = processBuilder.start(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + int exitCode = process.waitFor(); + if(exitCode != 0){ + System.err.println("\nExited with error code : " + exitCode); + } + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + + return path; + } + + private Properties loadProps() { + Properties props = new Properties(); + try (InputStream input = SpeechRecognition.class.getResourceAsStream(AZURE_PROPERTIES)) { + props.load(input); + } catch (IOException e) { + System.out.println(e.getMessage()); + } + + return props; + } +} \ No newline at end of file diff --git a/src/main/java/model/service/registration/Registration.java b/src/main/java/model/service/registration/Registration.java index 9b8dd41..358d95d 100644 --- a/src/main/java/model/service/registration/Registration.java +++ b/src/main/java/model/service/registration/Registration.java @@ -84,7 +84,7 @@ public boolean invitePatient(int therapistId, String patientEmail, String patien String pin = la.generatePin(therapistId); if(pin!=null){ - String body = "Salve "+ patientSurname+ " " + patientName + ". Il tuo logopedista ti ha invitato a TalkAid! Ecco il tuo codice per registrarti a TalkAid: "+ pin; + String body = "Salve "+ patientSurname+ " " + patientName + "\n. il tuo logopedista ti ha invitato a TalkAID! Ecco il tuo codice per registrarti al sito: "+ pin; tool.sendEmail(patientEmail, "Sei stato invitato a TalkAID!", body); return true; diff --git a/src/main/resources/azure.properties b/src/main/resources/azure.properties new file mode 100644 index 0000000..73bf85a --- /dev/null +++ b/src/main/resources/azure.properties @@ -0,0 +1,2 @@ +azure.key=4dc85598a1f64a54a190c8e6e0eddb0b +azure.region=westeurope \ No newline at end of file diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index a84ca9d..d23b563 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -1,3 +1,3 @@ -db.url=jdbc:mysql://81.56.127.184:16400/TalkAID +db.url=jdbc:mysql://81.56.127.184:16400/TalkAID2 db.username=dbauthority db.password=password \ No newline at end of file diff --git a/src/main/webapp/CSS/homepagepatient.css b/src/main/webapp/CSS/homepagepatient.css index dcc26aa..9a30511 100644 --- a/src/main/webapp/CSS/homepagepatient.css +++ b/src/main/webapp/CSS/homepagepatient.css @@ -22,6 +22,18 @@ margin-right: 20px; /* Spazio tra i div */ } +.divbar{ + background-color: #199a8e; + width: 100%; + border-collapse: collapse; + margin-top: 1.3em; + margin-bottom: 1.3em; + border-radius: 50px; + overflow-x: auto; + white-space: nowrap; + height: 1.3em; +} + .cards { margin-top: 20px; margin-bottom: 20px; @@ -29,6 +41,16 @@ overflow-x: auto; white-space: nowrap; } +.acards { + margin-top: 20px; + margin-bottom: 20px; + display: flex; + justify-content: center; + flex-wrap: wrap; + overflow-x: auto; + white-space: nowrap; +} + .card2 { display: flex; @@ -47,6 +69,12 @@ display: flex; overflow-x: scroll; } + +.challenges .acards { + display: flex; + overflow-x: scroll; +} + .card .img { position: absolute; width: 105px; @@ -57,6 +85,50 @@ +.errorcard { + display: flex; + flex-direction: column; + align-items: flex-direction; + gap: 16px; + padding: 20px; + position: relative; + flex: 0 0 auto; + background-color: #ffffff; + border-radius: 32px; + margin-right: 20px; /* Spazio tra i div */ +} +.errorcard .img { + position: absolute; + width: 105px; + height: 115px; + top: 4px; + left: 600px; +} +.errorcard .chapter { + position: relative; + width: fit-content; + margin-top: -1px; + font-family: Georgia, serif; + font-size: 1.5em; + white-space: nowrap; +} + +.card .eimg { + position: absolute; + top: 4px; + left: 600px; +} + +.eillustration-wrapper { + display: flex; + align-items: center; + justify-content: center; + padding: 8px; + position: relative; + flex: 0 0 auto; + border-radius: 900px; + margin-bottom:2em; +} @@ -91,6 +163,7 @@ position: relative; align-self: stretch; width: 100%; + height: 150px; flex: 0 0 auto; } @@ -217,13 +290,19 @@ font-size: 2.5em; } -.notification{ - float: right; - height: 1.3em; + + +.circle_animation { + stroke-dasharray: 440; /* this value is the pixel circumference of the circle */ + stroke-dashoffset: 440; } -.profile{ - float: left; - height: 1.3em; +.html .circle_animation { + animation: html 1s ease-out forwards; } +@keyframes html { + to { + stroke-dashoffset: 80; /* 50% would be 220 (half the initial value specified above) */ + } +} diff --git a/src/main/webapp/CSS/invitePatient.css b/src/main/webapp/CSS/invitePatient.css new file mode 100644 index 0000000..dd2befa --- /dev/null +++ b/src/main/webapp/CSS/invitePatient.css @@ -0,0 +1,127 @@ +* { + margin: 0; + padding: 0; + font-family: Georgia, sans-serif; +} + +body { + height: 100%; + width: 100%; + display: flex; + flex-direction: column; +} + +a { + color: #199a8e; + text-decoration: none; + font-size: 13px; +} + +/* Aggiunta di stili per il pop-up */ +#InvitePopupOverlay { + display: none; + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0, 0, 0, 0.5); + z-index: 1000; + justify-content: center; + align-items: center; +} + +#InvitePage { + width: 154px; + background-color: #fff; + padding: 80px; + border-radius: 10px; + text-align: center; + position: fixed; + top: 43%; + left: 50%; + transform: translate(-50%, -50%); + z-index: 1001; + border: 2px solid #000; +} + + +.homeTherapistOverlay { + transition: opacity 0.3s ease; +} + +#InvitePopupOverlay.visible .homeTherapistOverlay { + opacity: 0.5; +} + +#InviteTitle{ + margin-top: -16%; + font-size: 20px;; +} + + +#InviteForm{ + margin-top: 5%; + width: 70%; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; +} + +.inputDiv{ + width: 217%; + display: flex; + flex-direction: row; + justify-content: space-between; + background-color: #f9fafb; + border: 2px solid #e8eaed; + border-radius: 500px; + margin-bottom: -1%; +} + +.icon{ + display: flex; + justify-content: center; + align-items: center; + text-align: center; + width: 10%; +} + +.iconLeft{ + margin-left: 3%; +} + + + +.icon > img{ + width: 50%; +} + +.formInput{ + padding: 5% 7%; + height: 90%; + width: 80%; + border: none; + border-radius: 27px; + background-color: #f9fafb; + font-size: 15px; +} + +.formInput:focus{ + border: none; + outline: none; +} + + +#InviteButton{ + color: white; + width: 100%; + background-color: #199a8e; + border: none; + padding: 5% 10%; + border-radius: 500px; + margin-bottom: 20px; + display: inline-block; + font-size: 21px; +} \ No newline at end of file diff --git a/src/main/webapp/CSS/schedule.css b/src/main/webapp/CSS/schedule.css index 8ea0cfe..a7dec26 100644 --- a/src/main/webapp/CSS/schedule.css +++ b/src/main/webapp/CSS/schedule.css @@ -168,6 +168,12 @@ body { box-sizing: border-box; } +#popup{ + color:red; + font-weight: 500; + font-size: .7em; +} + h2{ color:#199a8e; font-weight: 700; diff --git a/src/main/webapp/JS/exercise.js b/src/main/webapp/JS/exercise.js index 799e59a..139e120 100644 --- a/src/main/webapp/JS/exercise.js +++ b/src/main/webapp/JS/exercise.js @@ -10,9 +10,7 @@ const IMAGESINAROW = 2 const exerciseInfo = $("#exerciseInfo"); const EXERCISETYPE = exerciseInfo.data("type"); -const EXERCISEID = exerciseInfo.data("exerciseId"); -const USERTYPE = exerciseInfo.data("userType"); -const USERID = exerciseInfo.data("userId"); +const USERTYPE = exerciseInfo.data("usertype"); const exerciseDiv = $("#exerciseDiv"); @@ -29,10 +27,11 @@ function startUp(exerciseIS){ let mediaRecorder; let audioChunks = []; +let timeoutID; function micPreparation(){ if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { - navigator.mediaDevices.getUserMedia({ audio: true }) + navigator.mediaDevices.getUserMedia({ audio: true }) .then(function(stream) { mediaRecorder = new MediaRecorder(stream); @@ -43,7 +42,7 @@ function micPreparation(){ }; mediaRecorder.onstop = function() { - let audioBlob = new Blob(audioChunks, { type: 'audio/wav' }); + let audioBlob = new Blob(audioChunks, { type: 'audio/opus' }); let audioUrl = URL.createObjectURL(audioBlob); $("#audioPlayer").attr("src", audioUrl); @@ -77,9 +76,15 @@ function micPreparation(){ mediaRecorder.start(); $("#startRecord").hide(); $("#stopRecord").show(); + + // Set a timeout to stop recording after 33 seconds + timeoutID = setTimeout(() => { + $("#stopRecord").click(); + }, 33000); }); $("#stopRecord").click(function() { + clearTimeout(timeoutID); mediaRecorder.stop(); $("#stopRecord").hide(); $("#audioDiv").show(); @@ -116,9 +121,9 @@ function parseJSON(json) { function redirect(where){ if (where === "home"){ if (USERTYPE === "patient"){ - window.location.href = "homepagepatient.jsp"; + window.location.href = "homePagePatient.jsp"; }else if (USERTYPE === "therapist"){ - window.location.href = "homepagelogopedist.jsp"; + window.location.href = "homeTherapist.jsp"; } } else{ @@ -514,25 +519,26 @@ function saveCT(n){ function saveExecution(execution){ $("#buttonDiv > button").prop("disabled", true).text("Esercizio Inviato!"); - $.post({ + + $.ajax({ + type: "POST", url: "../exerciseLogger", + data: JSON.stringify(execution), contentType: "application/json", - data: JSON.stringify(execution) - }).done(() => { - redirect("home"); - }).fail((error) => { - console.log("Errore durante la chiamata Post:"+error); - redirect("500.html") - }) + error: function (error) { + console.error("Errore durante l'invio dell'esecuzione alla servlet:", error); + redirect("500.html") + } + }); + redirect("home"); } function saveAudioExecution(execution){ if(execution != null){ let formData = new FormData(); - formData.append("audioFile", execution, "User"+USERID+"exercise"+EXERCISEID+".wav"); - + formData.append("audioFile", execution); $.ajax({ type: "POST", @@ -541,13 +547,13 @@ function saveAudioExecution(execution){ processData: false, contentType: false, cache: false, - success: function (){ - redirect("home"); - }, - error: function (error) { + error: function(xhr, status, error) { console.error("Errore durante l'invio dell'audio alla servlet:", error); - redirect("500.html") + console.log(xhr.responseText); + redirect("500.html"); } }); + + redirect("home"); } } \ No newline at end of file diff --git a/src/main/webapp/JS/homeTherapist.js b/src/main/webapp/JS/homeTherapist.js new file mode 100644 index 0000000..5e169b0 --- /dev/null +++ b/src/main/webapp/JS/homeTherapist.js @@ -0,0 +1,35 @@ +//search bar for name and surname +$(document).ready(function () { + var tableContainer = document.getElementById('tableContainer'); + + // Aggiungi un gestore di eventi all'input di ricerca + $('#searchInput').on('input', function () { + var searchText = $(this).val().toLowerCase(); + + // Nascondi tutte le righe + tableContainer.getElementsByTagName('tbody')[0].style.marginTop = '0'; + + // Filtra e mostra solo le righe che corrispondono alla ricerca + $('tbody tr').each(function () { + var name = $(this).find('td:eq(1)').text().toLowerCase(); + var lastName = $(this).find('td:eq(2)').text().toLowerCase(); + + if (name.includes(searchText) || lastName.includes(searchText)) { + $(this).show(); + } else { + $(this).hide(); + } + }); + }); +}); +/*POPUP INVITE PATIENT*/ +function openInvitePopup() { + document.getElementById("invitePopup").style.display = "block"; +} +function InvitePatient(){ + window.location.href = "invitePatient.jsp"; +} +/*VIEW PATIENT*/ +function viewPatient(i){ + window.location.href = "viewPatient.jsp?patientID="+i; +} \ No newline at end of file diff --git a/src/main/webapp/JSP/changepassw.jsp b/src/main/webapp/JSP/changePassw.jsp similarity index 100% rename from src/main/webapp/JSP/changepassw.jsp rename to src/main/webapp/JSP/changePassw.jsp diff --git a/src/main/webapp/JSP/exercise.jsp b/src/main/webapp/JSP/exercise.jsp index f8c4a5b..5862cc7 100644 --- a/src/main/webapp/JSP/exercise.jsp +++ b/src/main/webapp/JSP/exercise.jsp @@ -5,7 +5,6 @@ <% ExerciseGlossary exercise = (ExerciseGlossary) session.getAttribute("exercise"); - //session.removeAttribute("exercise"); TODO: @michele fallo nella homepage questa cosa, ovviamente controlla se prima esiste poi nel caso elimini %> Esercizio <%= exercise.getIdExercise()%> @@ -30,8 +29,6 @@ diff --git a/src/main/webapp/JSP/exerciseTest.jsp b/src/main/webapp/JSP/exerciseTest.jsp index 1374171..9c31aa3 100644 --- a/src/main/webapp/JSP/exerciseTest.jsp +++ b/src/main/webapp/JSP/exerciseTest.jsp @@ -27,9 +27,9 @@ -
+ - +
diff --git a/src/main/webapp/JSP/homePagePatient.jsp b/src/main/webapp/JSP/homePagePatient.jsp new file mode 100644 index 0000000..12675d8 --- /dev/null +++ b/src/main/webapp/JSP/homePagePatient.jsp @@ -0,0 +1,226 @@ +<%@ page import="model.service.exercise.ExerciseManager" %> +<%@ page import="model.entity.Exercise" %> +<%@ page import="java.util.List" %> +<%@ page import="model.entity.ExerciseGlossary" %> +<%@ page import="model.entity.PersonalInfo" %> +<%@ page import="model.service.user.UserRegistry" %> + + +<% + Integer userIdp = (Integer) session.getAttribute("id"); + if(userIdp == null) { + response.sendRedirect("../errorPage/403.html"); + } + else { + int userId = (Integer) session.getAttribute("id"); + UserRegistry ur = new UserRegistry(); + PersonalInfo data= ur.getPersonalInfo(userIdp); +%> + + <%@page contentType="text/html;charset=UTF-8"%> + + + + + +<% + if(session.getAttribute("exercise") !=null){ + session.removeAttribute("exercise"); + } +%> + + +
+
+
+
+ Ciao <%=data.getFirstname()%> <%=data.getLastname()%> +
+
+
+ + + + +
+
+
+ +
+ +
+
+ + +
+ + +
+
+
+ +
+
+ + <% + ExerciseManager exerciseManager1 = new ExerciseManager(); + List list1 = exerciseManager1.retrieveAllNewPatientExerciseNotDone(userId); + ExerciseGlossary exerciseGlossary1 = new ExerciseGlossary(); + if(!list1.isEmpty()){ + int maxCardsToShow = 5; + int cardCounter = 0; + for(Exercise exercise : list1) { + exerciseGlossary1 = exerciseManager1.getExercise(exercise.getIdExercise()); + %> +
+
+
+
+ +
+
<%=exerciseGlossary1.getExerciseName()%>
+
+ + + +
+
+ <% + cardCounter++; + if (cardCounter >= maxCardsToShow) { + break; // Interrompi il ciclo se il numero massimo di cards è stato raggiunto + } + } + } + else { + %> + %> +
Esercizi non disponibili
+ <% + } + %> +
+
+
+ + +
+ + +
+
+
+ +
+
+ + <% + ExerciseManager exerciseManager2 = new ExerciseManager(); + List list2 = exerciseManager2.retrieveAllPatientExerciseDone(userId); + ExerciseGlossary exerciseGlossary2 = new ExerciseGlossary(); + if(!list2.isEmpty()){ + int maxCardsToShow = 5; + int cardCounter = 0; + for(Exercise exercise : list2) { + exerciseGlossary2 = exerciseManager2.getExercise(exercise.getIdExercise()); + %> +
+
+
+
+ +
+
<%=exerciseGlossary2.getExerciseName()%>
+
+ + + +
+
+ <% + cardCounter++; + if (cardCounter >= maxCardsToShow) { + break; // Interrompi il ciclo se il numero massimo di cards è stato raggiunto + } + } + } + else { + %> + %> +
Esercizi non disponibili
+ <% + } + %> +
+
+
+
+ + + + + + + + + +<% + } +%> \ No newline at end of file diff --git a/src/main/webapp/JSP/homeTherapist.jsp b/src/main/webapp/JSP/homeTherapist.jsp index bb7231f..3e40016 100644 --- a/src/main/webapp/JSP/homeTherapist.jsp +++ b/src/main/webapp/JSP/homeTherapist.jsp @@ -17,27 +17,27 @@
PAZIENTI
-
+
- - - - - - - - - - - <% - if(session.getAttribute("type")!=null && session.getAttribute("type").equals("therapist")){ - @SuppressWarnings("unchecked") - ArrayList list_user= new UserData().getUsersAndPersonalInfoByIdTherapist((Integer) session.getAttribute("id")); - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); +
Inizio Terapia Progressi
+ + + + + + + + + + <% + if(session.getAttribute("type")!=null && session.getAttribute("type").equals("therapist")){ + @SuppressWarnings("unchecked") + ArrayList list_user= new UserData().getUsersAndPersonalInfoByIdTherapist((Integer) session.getAttribute("id")); + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); - for(UserInfo u: list_user){ - %> - + for(UserInfo u: list_user){ + %> + @@ -51,16 +51,14 @@ Visualizza - - <% + + <% + } } - } else { - response.sendRedirect("../errorPage/403.html"); - } - %> - -
Inizio Terapia Progressi
<%=u.getFirstname()%> <%=u.getLastname()%>
-
+ %> + + +
@@ -84,15 +82,14 @@
-
+
- - + + + \ No newline at end of file diff --git a/src/main/webapp/JSP/homepagepatient.jsp b/src/main/webapp/JSP/homepagepatient.jsp deleted file mode 100644 index c98fa6e..0000000 --- a/src/main/webapp/JSP/homepagepatient.jsp +++ /dev/null @@ -1,151 +0,0 @@ - - - - <%@page contentType="text/html;charset=UTF-8"%> - - - - - -
-
-
-
- - Benvenuto Utente - -
-
-
-
- -
- -
-
-
-
- - -
-
Tipo Esercizio
-
Nome Esercizio
-
- -
-
- -
-
-
- -
- - -
- -
-
-
- - -
-
Tipo Esercizio
-
Nome Esercizio
-
- -
- -
-
-
- - -
-
Tipo Esercizio
-
Nome Esercizio
-
- -
- -
-
-
- - -
-
Tipo Esercizio
-
Nome Esercizio
-
- -
- -
- - -
-
- -
-
-
- -
- - -
- -
-
-
- - -
-
Tipo Esercizio
-
Nome Esercizio
-
- -
- -
-
-
- - -
-
Tipo Esercizio
-
Nome Esercizio
-
- -
- -
-
-
- - -
-
Tipo Esercizio
-
Nome Esercizio
-
- -
- -
- - -
-
- -
- - diff --git a/src/main/webapp/JSP/invitePatient.jsp b/src/main/webapp/JSP/invitePatient.jsp new file mode 100644 index 0000000..a0603c9 --- /dev/null +++ b/src/main/webapp/JSP/invitePatient.jsp @@ -0,0 +1,46 @@ + + + + Invita Paziente + + +<% + if(session.getAttribute("type")==null || !session.getAttribute("type").equals("therapist")) { + response.sendRedirect("../errorPage/403.html"); + } +%> +
+
+

Invita Paziente

+
+
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+ + < Torna alla home +
+
+ + + \ No newline at end of file diff --git a/src/main/webapp/JSP/PatientConditionManager.jsp b/src/main/webapp/JSP/patientConditionManager.jsp similarity index 100% rename from src/main/webapp/JSP/PatientConditionManager.jsp rename to src/main/webapp/JSP/patientConditionManager.jsp diff --git a/src/main/webapp/JSP/patientReport.jsp b/src/main/webapp/JSP/patientReport.jsp new file mode 100644 index 0000000..e3d53cf --- /dev/null +++ b/src/main/webapp/JSP/patientReport.jsp @@ -0,0 +1,107 @@ +<%@ page import="model.service.exercise.ExerciseManager" %> +<%@ page import="model.entity.Exercise" %> +<%@ page import="java.util.List" %> +<%@ page import="model.entity.ExerciseGlossary" %> + + +<% + 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"%> + + + + + + + + +
+
+ +
+ + <% + ExerciseManager exerciseManager = new ExerciseManager(); + List list = exerciseManager.retrieveAllPatientExerciseDone(userId); + ExerciseGlossary exerciseGlossary = new ExerciseGlossary(); + if(!list.isEmpty()){ + int Counter = 0; + for(Exercise exercise : list) { + exerciseGlossary = exerciseManager.getExercise(exercise.getIdExercise()); + %> +
+
+
+
+ + + + + Layer 1 + + <%=exercise.getEvaluation()%>% + + + +
+
<%=exerciseGlossary.getExerciseName()%>
+
+ +
+ + + +
+ <% + Counter++; + } + } + else { + %> + %> +
Esercizi non disponibili
+ <% + } + %> + + + +
+ + +<% + } +%> \ No newline at end of file diff --git a/src/main/webapp/JSP/schedule.jsp b/src/main/webapp/JSP/schedule.jsp index 8fb5062..b613da7 100644 --- a/src/main/webapp/JSP/schedule.jsp +++ b/src/main/webapp/JSP/schedule.jsp @@ -20,23 +20,10 @@ TalkAId - Schedule Prenotazioni - -<% - String errorMessage = (String) request.getAttribute("errorMessage"); - if (errorMessage != null && !errorMessage.isEmpty()) { -%> - -<% - } -%> +
- Agenda -
<% if (session.getAttribute("type") == "therapist"){ @@ -57,6 +44,15 @@ + +
@@ -278,6 +274,26 @@
+ + + diff --git a/src/main/webapp/JSP/User_Area.jsp b/src/main/webapp/JSP/userArea.jsp similarity index 96% rename from src/main/webapp/JSP/User_Area.jsp rename to src/main/webapp/JSP/userArea.jsp index cb4aafb..4cceaf1 100644 --- a/src/main/webapp/JSP/User_Area.jsp +++ b/src/main/webapp/JSP/userArea.jsp @@ -1,10 +1,3 @@ -<%-- - Created by IntelliJ IDEA. - User: petri - Date: 22/12/2023 - Time: 11:11 - To change this template use File | Settings | File Templates. ---%> <%@ page import="model.service.user.UserData" %> <%@ page import="model.entity.User" %> <%@ page import="model.entity.PersonalInfo" %> @@ -90,7 +83,7 @@
-
+ diff --git a/src/main/webapp/JSP/Cambio_dati.jsp b/src/main/webapp/JSP/userInfoChange.jsp similarity index 95% rename from src/main/webapp/JSP/Cambio_dati.jsp rename to src/main/webapp/JSP/userInfoChange.jsp index 9ebddf2..85d356a 100644 --- a/src/main/webapp/JSP/Cambio_dati.jsp +++ b/src/main/webapp/JSP/userInfoChange.jsp @@ -1,13 +1,7 @@ <%@ page import="model.entity.PersonalInfo" %> <%@ page import="model.entity.User" %> <%@ page import="model.service.user.UserData" %> -<%@ page import="model.service.user.UserRegistry" %><%-- - Created by IntelliJ IDEA. - User: petri - Date: 23/12/2023 - Time: 11:23 - To change this template use File | Settings | File Templates. ---%> +<%@ page import="model.service.user.UserRegistry" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> @@ -87,7 +81,7 @@ <%} %> diff --git a/src/main/webapp/images/homepagepatient/attention.png b/src/main/webapp/images/homepagepatient/attention.png new file mode 100644 index 0000000..9f4887e Binary files /dev/null and b/src/main/webapp/images/homepagepatient/attention.png differ diff --git a/src/main/webapp/images/homepagepatient/check.png b/src/main/webapp/images/homepagepatient/check.png new file mode 100644 index 0000000..1ca641f Binary files /dev/null and b/src/main/webapp/images/homepagepatient/check.png differ diff --git a/src/main/webapp/images/homepagepatient/exerc.png b/src/main/webapp/images/homepagepatient/exerc.png new file mode 100644 index 0000000..55365d4 Binary files /dev/null and b/src/main/webapp/images/homepagepatient/exerc.png differ diff --git a/src/test/java/controller/LoginTest.java b/src/test/java/controller/LoginTest.java index ccf63a6..1039e8f 100644 --- a/src/test/java/controller/LoginTest.java +++ b/src/test/java/controller/LoginTest.java @@ -48,7 +48,7 @@ void testDoPostWithValidCredentials() throws Exception { verify(mockSession).setAttribute("type", "patient"); // Verify redirection - verify(response).sendRedirect("JSP/homepagepatient.jsp"); + verify(response).sendRedirect("JSP/homePagePatient.jsp"); } //ACCESSO LOGOPEDISTA CORRETTO