Skip to content
Snippets Groups Projects
Commit cc651fbf authored by Jessie Ragot's avatar Jessie Ragot
Browse files

Merge branch 'main' into aichatou

# Conflicts:
#	src/main/resources/application.properties
parents 72ec4c49 4ca99591
No related branches found
No related tags found
1 merge request!18Aichatou
Showing
with 260 additions and 18 deletions
......@@ -2,7 +2,6 @@
.vscode
*.iml
.idea
.lock
.bin
.probe
/build
.gradle
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();
}
}
}
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";
}
}
......@@ -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();
}
}
......@@ -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")
......
......@@ -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);
}
......@@ -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);
}
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);
}
}
......@@ -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);
}
......
<!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>
<!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>
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment