diff --git a/.gitignore b/.gitignore index 10c970982f0123c900dd9bcd36badbb5333d76dc..6fe4751a9ad62c2f38a11833e6dfee66eb65e2b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ .vscode *.iml .idea -.lock -.bin -.probe +/build +.gradle diff --git a/src/main/java/com/projet/projetIndu/bootstrap/DatabaseSeeder.java b/src/main/java/com/projet/projetIndu/bootstrap/DatabaseSeeder.java index b059ac304181ad75e8a03650f967d479ff558e6b..122c87f153c787b5527c8e5869a0cb6603a98adf 100644 --- a/src/main/java/com/projet/projetIndu/bootstrap/DatabaseSeeder.java +++ b/src/main/java/com/projet/projetIndu/bootstrap/DatabaseSeeder.java @@ -1,17 +1,16 @@ package com.projet.projetIndu.bootstrap; +import com.projet.projetIndu.entities.*; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; import org.springframework.boot.CommandLineRunner; -import com.projet.projetIndu.entities.Doctor; -import com.projet.projetIndu.entities.MedicalFiles; -import com.projet.projetIndu.entities.Patient; -import com.projet.projetIndu.entities.MedicalDocument; import com.projet.projetIndu.repositories.DoctorRepository; import com.projet.projetIndu.repositories.MedicalFilesRepository; import com.projet.projetIndu.repositories.PatientRepository; import com.projet.projetIndu.repositories.MedicalDocumentRepository; +import com.projet.projetIndu.repositories.AppointmentRepository; +import java.time.LocalDateTime; import java.io.IOException; import java.nio.file.Files; import java.time.LocalDate; @@ -24,21 +23,24 @@ public class DatabaseSeeder implements CommandLineRunner { private final PatientRepository patientRepository; private final MedicalFilesRepository medicalFilesRepository; private final MedicalDocumentRepository medicalDocumentRepository; + private final AppointmentRepository appointmentRepository; // Ajout du repository des rendez-vous public DatabaseSeeder(DoctorRepository doctorRepository, PatientRepository patientRepository, MedicalFilesRepository medicalFilesRepository, - MedicalDocumentRepository medicalDocumentRepository) { + MedicalDocumentRepository medicalDocumentRepository, + AppointmentRepository appointmentRepository) { // Injection du repository this.doctorRepository = doctorRepository; this.patientRepository = patientRepository; this.medicalFilesRepository = medicalFilesRepository; this.medicalDocumentRepository = medicalDocumentRepository; + this.appointmentRepository = appointmentRepository; } @Override public void run(String... args) { if (medicalFilesRepository.count() == 0) { - Doctor doctor1 = new Doctor("Jean", "Dupont", "Generaliste", "jean.dupont@example.com"); + Doctor doctor1 = new Doctor("Jean", "Dupont", "Généraliste", "jean.dupont@example.com"); Doctor doctor2 = new Doctor("Sophie", "Martin", "Cardiologue", "sophie.martin@example.com"); doctorRepository.saveAll(List.of(doctor1, doctor2)); @@ -58,11 +60,17 @@ public class DatabaseSeeder implements CommandLineRunner { addDefaultDocument(file1, "documents/exemple1.pdf", "Rapport Médical.pdf"); addDefaultDocument(file2, "documents/exemple2.pdf", "Résultat Analyse.pdf"); + Appointment appointment1 = new Appointment(patient1, doctor1, LocalDateTime.now().plusDays(2), AppointmentStatus.CONFIRMED, "Consultation de suivi"); + Appointment appointment2 = new Appointment(patient2, doctor2, LocalDateTime.now().plusDays(7), AppointmentStatus.PENDING, "Bilan annuel"); + + appointmentRepository.saveAll(List.of(appointment1, appointment2)); + System.out.println("Données insérées : "); System.out.println("Médecins : " + doctorRepository.count()); System.out.println("Patients : " + patientRepository.count()); System.out.println("Dossiers médicaux : " + medicalFilesRepository.count()); System.out.println("Documents médicaux : " + medicalDocumentRepository.count()); + System.out.println("Rendez-vous : " + appointmentRepository.count()); } } @@ -83,4 +91,5 @@ public class DatabaseSeeder implements CommandLineRunner { e.printStackTrace(); } } + } diff --git a/src/main/java/com/projet/projetIndu/controllers/AppointmentController.java b/src/main/java/com/projet/projetIndu/controllers/AppointmentController.java new file mode 100644 index 0000000000000000000000000000000000000000..a5213cd392752819445d9b024dbc3eb78790ec2b --- /dev/null +++ b/src/main/java/com/projet/projetIndu/controllers/AppointmentController.java @@ -0,0 +1,95 @@ +package com.projet.projetIndu.controllers; + +import com.projet.projetIndu.entities.Appointment; +import com.projet.projetIndu.entities.AppointmentStatus; +import com.projet.projetIndu.entities.Doctor; +import com.projet.projetIndu.entities.Patient; +import com.projet.projetIndu.services.AppointmentService; +import com.projet.projetIndu.services.DoctorService; +import com.projet.projetIndu.services.PatientService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDateTime; +import java.util.List; + +@Controller +@RequestMapping("/appointments") // Toutes les routes commenceront par /appointments +public class AppointmentController { + + private final AppointmentService appointmentService; + private final DoctorService doctorService; + private final PatientService patientService; + + + public AppointmentController(AppointmentService appointmentService, DoctorService doctorService, PatientService patientService) { + this.appointmentService = appointmentService; + this.doctorService = doctorService; + this.patientService = patientService; + } + + @GetMapping + public String showAppointments(Model model) { + List<Appointment> appointments = appointmentService.getAllAppointments(); + model.addAttribute("appointments", appointments); + return "appointments"; + } + + @GetMapping("/doctor/{doctorId}") + public String listAppointmentsForDoctor(@PathVariable Long doctorId, Model model) { + List<Appointment> appointments = appointmentService.getAppointmentsByDoctor(doctorId); + model.addAttribute("appointments", appointments); + return "appointments"; + } + + + @GetMapping("/create") + public String showCreateForm(Model model) { + model.addAttribute("appointment", new Appointment()); + + List<Patient> patients = patientService.getAllPatients(); + List<Doctor> doctors = doctorService.getAllDoctors(); + + model.addAttribute("patients", patients); + model.addAttribute("doctors", doctors); + + return "create-appointment"; + } + + + @PostMapping("/create") + public String createAppointment(@RequestParam("doctorId") Long doctorId, + @RequestParam("patientId") Long patientId, + @RequestParam("dateTime") String dateTime, + @RequestParam("reason") String reason) { + + Doctor doctor = doctorService.getDoctorById(doctorId) + .orElseThrow(() -> new RuntimeException("Médecin introuvable")); + Patient patient = patientService.getPatientById(patientId) + .orElseThrow(() -> new RuntimeException("Patient introuvable")); + + LocalDateTime parsedDateTime = LocalDateTime.parse(dateTime); + + Appointment appointment = new Appointment(); + appointment.setDoctor(doctor); + appointment.setPatient(patient); + appointment.setDateTime(parsedDateTime); + appointment.setStatus(AppointmentStatus.PENDING); + appointment.setReason(reason); + + appointmentService.saveAppointment(appointment); + + return "redirect:/appointments"; + } + + + + + @PostMapping("/{id}/cancel") + public String cancelAppointment(@PathVariable Long id) { + appointmentService.cancelAppointment(id); + return "redirect:/appointments"; + } +} + diff --git a/src/main/java/com/projet/projetIndu/entities/Appointment.java b/src/main/java/com/projet/projetIndu/entities/Appointment.java index 52c7c71dcaa744e7f429735e40f10ee8687e383d..0b8fead5e0b789ec4592dc6e769fb56d38b793e5 100644 --- a/src/main/java/com/projet/projetIndu/entities/Appointment.java +++ b/src/main/java/com/projet/projetIndu/entities/Appointment.java @@ -4,6 +4,7 @@ import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; @@ -26,6 +27,7 @@ public class Appointment { @JoinColumn(name = "doctor_id", nullable = false) private Doctor doctor; //clé étrangère vers Doctor + @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") @Column(nullable = false, updatable = false) private LocalDateTime dateTime; @@ -38,4 +40,16 @@ public class Appointment { @Column(nullable = false, updatable = false) private LocalDateTime createdAt = LocalDateTime.now(); + + public Appointment(Patient patient, Doctor doctor, LocalDateTime dateTime, AppointmentStatus status, String reason) { + this.patient = patient; + this.doctor = doctor; + this.dateTime = dateTime; + this.status = status; + this.reason = reason; + this.createdAt = LocalDateTime.now(); + } + + + } diff --git a/src/main/java/com/projet/projetIndu/entities/HistoriqueMedical.java b/src/main/java/com/projet/projetIndu/entities/HistoriqueMedical.java index 3949deb2ecc6bafbaf41e4839663bb5f8124763b..dd369e544c5d260d6319d70c2fe4f88e00bd55de 100644 --- a/src/main/java/com/projet/projetIndu/entities/HistoriqueMedical.java +++ b/src/main/java/com/projet/projetIndu/entities/HistoriqueMedical.java @@ -4,7 +4,8 @@ import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.Date; + +import java.time.LocalDate; @Entity @Data @@ -16,7 +17,7 @@ class HistoriqueMedical { private Long id; private String antecedents; private String notes; - private Date dateConsultation; + private LocalDate dateConsultation; @ManyToOne @JoinColumn(name = "patient_id") diff --git a/src/main/java/com/projet/projetIndu/repositories/AppointmentRepository.java b/src/main/java/com/projet/projetIndu/repositories/AppointmentRepository.java index 35ca45e8c61ffa01b9b6ee90324eeb56575be195..e30256390d482a2aa43779b434d3c2abf4d5e1d7 100644 --- a/src/main/java/com/projet/projetIndu/repositories/AppointmentRepository.java +++ b/src/main/java/com/projet/projetIndu/repositories/AppointmentRepository.java @@ -4,9 +4,12 @@ import com.projet.projetIndu.entities.Appointment; import org.springframework.data.jpa.repository.JpaRepository; import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; public interface AppointmentRepository extends JpaRepository<Appointment, Long> { Optional<Appointment> findByDateTime(LocalDateTime dateTime); + + List<Appointment> findByDoctorId(Long doctorId); } diff --git a/src/main/java/com/projet/projetIndu/repositories/PatientRepository.java b/src/main/java/com/projet/projetIndu/repositories/PatientRepository.java index 83877b3ef444bd01e14ee30fb496c38a46c0a34d..d62be3764b45e7804ba028378a058b1176a213f9 100644 --- a/src/main/java/com/projet/projetIndu/repositories/PatientRepository.java +++ b/src/main/java/com/projet/projetIndu/repositories/PatientRepository.java @@ -9,6 +9,6 @@ import java.util.Optional; public interface PatientRepository extends JpaRepository<Patient, Long> { Optional<Patient> findByEmail(String email); - List<Patient> findByNomContainingIgnoreCase(String nom); - List<Patient> findByTelephone(String telephone); + List<Patient> findBylastNameContainingIgnoreCase(String lastName); + List<Patient> findByphoneNumber(String phoneNumber); } diff --git a/src/main/java/com/projet/projetIndu/services/AppointmentService.java b/src/main/java/com/projet/projetIndu/services/AppointmentService.java index c4e9b4d53c80b614f39c7f7a260f5cd710875fa7..c3c99b04737481453b060f3bb93f351a7097f660 100644 --- a/src/main/java/com/projet/projetIndu/services/AppointmentService.java +++ b/src/main/java/com/projet/projetIndu/services/AppointmentService.java @@ -1,6 +1,7 @@ package com.projet.projetIndu.services; import com.projet.projetIndu.entities.Appointment; +import com.projet.projetIndu.entities.AppointmentStatus; import com.projet.projetIndu.repositories.AppointmentRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -35,7 +36,22 @@ public class AppointmentService { return appointmentRepository.save(appointment); } - public void deleteAppointmentById(Appointment appointment) { - appointmentRepository.delete(appointment); + public void deleteAppointmentById(Long id) { + appointmentRepository.deleteById(id); } + + public void cancelAppointment(Long id) { + Optional<Appointment> optionalAppointment = appointmentRepository.findById(id); + if (optionalAppointment.isPresent()) { + Appointment appointment = optionalAppointment.get(); + appointment.setStatus(AppointmentStatus.valueOf("CANCELLED")); + appointmentRepository.save(appointment); + } + } + + public List<Appointment> getAppointmentsByDoctor(Long doctorId) { + return appointmentRepository.findByDoctorId(doctorId); + } + + } diff --git a/src/main/java/com/projet/projetIndu/services/UserService.java b/src/main/java/com/projet/projetIndu/services/UserService.java index 8215891b0e0cfdc7d6f242ee7cff59e2fcd447da..f0cf7237d51bffa0efb488745030cb576f8bfbe4 100644 --- a/src/main/java/com/projet/projetIndu/services/UserService.java +++ b/src/main/java/com/projet/projetIndu/services/UserService.java @@ -46,9 +46,9 @@ public class UserService implements UserDetailsService{ userRepository.deleteById(id); } - public User registerUser(String username, String password, String role) { + public User registerUser(String username, String password, Role role) { String encodedPassword = passwordEncoder.encode(password); - User user = new User(username, encodedPassword, Role.valueOf(role.toUpperCase())); + User user = new User(username, encodedPassword, role); return userRepository.save(user); } diff --git a/src/main/resources/templates/appointments.html b/src/main/resources/templates/appointments.html new file mode 100644 index 0000000000000000000000000000000000000000..427ef001f1c6c8c4b17eebe81553884130379c7e --- /dev/null +++ b/src/main/resources/templates/appointments.html @@ -0,0 +1,47 @@ +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Rendez-vous du médecin</title> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> +</head> +<body class="bg-light"> + +<div class="container mt-5"> + <h1 class="text-center mb-4">Liste des rendez-vous</h1> + + <table class="table table-bordered table-striped"> + <thead class="table-dark"> + <tr> + <th>Patient</th> + <th>Date et heure</th> + <th>Statut</th> + <th>Actions</th> + </tr> + </thead> + <tbody> + <tr th:each="appointment : ${appointments}"> + <td th:text="${appointment.patient.firstName + ' ' + appointment.patient.lastName}"></td> + <td th:text="${#temporals.format(appointment.dateTime, 'dd/MM/yyyy HH:mm')}"></td> + <td th:text="${appointment.status}"></td> + <td> + <form method="post" th:action="@{/appointments/{id}/cancel(id=${appointment.id})}" class="d-inline"> + <input type="hidden" name="_method" value="post"/> + <button type="submit" class="btn btn-danger btn-sm" + onclick="return confirm('Voulez-vous annuler ce rendez-vous ?');"> + Annuler + </button> + </form> + </td> + </tr> + </tbody> + </table> + + <a href="/appointments/create" class="btn btn-primary mt-3">Créer un nouveau rendez-vous</a> + <a href="/doctors/dashboard" class="btn btn-secondary mt-3">Retour au tableau de bord</a> +</div> + +<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> +</body> +</html> diff --git a/src/main/resources/templates/create-appointment.html b/src/main/resources/templates/create-appointment.html new file mode 100644 index 0000000000000000000000000000000000000000..4ab3f6a2203235beef84ea19646723b2ec442dca --- /dev/null +++ b/src/main/resources/templates/create-appointment.html @@ -0,0 +1,58 @@ +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Créer un rendez-vous</title> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> +</head> +<body class="bg-light"> + +<div class="container mt-5"> + <h1 class="text-center mb-4">Créer un rendez-vous</h1> + + <form method="post" th:action="@{/appointments/create}"> + <!-- Sélecteur du Patient --> + <div class="mb-3"> + <label class="form-label">Patient :</label> + <select class="form-select" name="patientId" required> + <option value="">Sélectionner un patient</option> + <option th:each="patient : ${patients}" + th:value="${patient.id}" + th:text="${patient.firstName + ' ' + patient.lastName}"> + </option> + </select> + </div> + + <!-- Sélecteur du Médecin --> + <div class="mb-3"> + <label class="form-label">Médecin :</label> + <select class="form-select" name="doctorId" required> + <option value="">Sélectionner un médecin</option> + <option th:each="doctor : ${doctors}" + th:value="${doctor.id}" + th:text="${doctor.firstName + ' ' + doctor.lastName}"> + </option> + </select> + </div> + + <!-- Champ Date et Heure --> + <div class="mb-3"> + <label class="form-label">Date et heure :</label> + <input type="datetime-local" class="form-control" name="dateTime" required> + </div> + + <!-- Champ Motif --> + <div class="mb-3"> + <label class="form-label">Motif :</label> + <input type="text" class="form-control" name="reason" required> + </div> + + <button type="submit" class="btn btn-success">Créer le rendez-vous</button> + <a href="/appointments" th:href="@{/appointments}" class="btn btn-secondary">Annuler</a> + </form> +</div> + +<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> +</body> +</html> diff --git a/src/main/resources/templates/doctor-dashboard.html b/src/main/resources/templates/doctor-dashboard.html index b42eeff138c83bfc9f9fcd3743b03965cb530461..b5115573e560ce0816588d9c867a22c2767d8f4d 100644 --- a/src/main/resources/templates/doctor-dashboard.html +++ b/src/main/resources/templates/doctor-dashboard.html @@ -35,7 +35,7 @@ <p class="mt-2 text-gray-600">Accéder aux dossiers médicaux de vos patients.</p> </a> - <a href="#" class="p-6 bg-white shadow-md rounded-lg hover:shadow-lg transition"> + <a href="/appointments" class="p-6 bg-white shadow-md rounded-lg hover:shadow-lg transition"> <h3 class="text-xl font-semibold text-gray-800">Rendez-vous</h3> <p class="mt-2 text-gray-600">Gérer votre planning et vos rendez-vous.</p> </a>