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

Refactor entities

parent 692972e4
No related branches found
No related tags found
1 merge request!19[feature]models-change+authentification+registration
Showing
with 53 additions and 134 deletions
......@@ -21,11 +21,15 @@ public class Appointment {
@ManyToOne
@JoinColumn(name = "patient_id", nullable = false)
private Patient patient; //clé étrangère vers Patient
private Patient patient;
@ManyToOne
@JoinColumn(name = "doctor_id", nullable = false)
private Doctor doctor; //clé étrangère vers Doctor
private Doctor doctor;
@OneToOne
@JoinColumn(name = "invoice_id", nullable = false)
private Invoice invoice;
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
@Column(nullable = false, updatable = false)
......
......@@ -12,36 +12,14 @@ import java.time.LocalDateTime;
@Getter
@Setter
@NoArgsConstructor
public class Doctor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String firstName;
@Column(nullable = false)
private String lastName;
public class Doctor extends User {
private String speciality;
@Column(unique = true, nullable = false)
private String email;
private String phone;
private String address;
@Column(nullable = false, updatable = false)
private LocalDateTime createdAt = LocalDateTime.now();
/// Pour le codage en dur (à retirer ensuite)
public Doctor(String firstName, String lastName, String speciality, String email) {
this.firstName = firstName;
this.lastName = lastName;
public Doctor(String firstName, String lastName, String phoneNumber, String email, String address, String username, String password, Role role) {
super(firstName, lastName, phoneNumber, email, address, username, password, role);
this.speciality = speciality;
this.email = email;
}
}
......@@ -11,15 +11,13 @@ import java.time.LocalDate;
@Data
@NoArgsConstructor
@AllArgsConstructor
class MedicalHistory {
class HealthHistorical {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String history;
private String antecedent;
private String notes;
private LocalDate consultationDate;
@ManyToOne
@JoinColumn(name = "patient_id")
private Patient patient;
}
\ No newline at end of file
......@@ -18,14 +18,6 @@ public class Invoice {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "patient_id", nullable = false)
private Patient patient; //clé étrangère vers Patient
@ManyToOne
@JoinColumn(name = "doctor_id", nullable = false)
private Doctor doctor; //clé étrangère vers Doctor
@Column(nullable = false)
private double amount;
......
......@@ -20,7 +20,4 @@ public class MedicalDocument {
@Column(columnDefinition = "LONGBLOB")
private byte[] fileData;
@ManyToOne
@JoinColumn(name = "medical_file_id")
private MedicalFiles medicalFile;
}
......@@ -20,27 +20,24 @@ public class MedicalFiles {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "patient_id", nullable = false)
private Patient patient; //clé étrangère vers Patient
private String allergy;
private String treatment;
@ManyToOne
@JoinColumn(name = "doctor_id", nullable = false)
private Doctor doctor; //clé étrangère vers Doctor
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<HealthHistorical> healthHistoricalList = new ArrayList<>();
@Column(nullable = false, columnDefinition = "TEXT")
private String history;
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "patient_id", nullable = false)
private Patient patient;
@OneToMany(mappedBy = "medicalFile", cascade = CascadeType.ALL, orphanRemoval = true)
private List<MedicalDocument> documents = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<MedicalDocument> documentList = new ArrayList<>();
@Column(nullable = false, updatable = false)
private LocalDateTime createdAt = LocalDateTime.now();
public MedicalFiles(Patient patient, Doctor doctor, String history) {
public MedicalFiles(Patient patient) {
this.patient = patient;
this.doctor = doctor;
this.history = history;
}
}
package com.projet.projetIndu.entities;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.time.LocalDateTime;
@Entity
@Table(name = "medical_records")
@Getter
@Setter
@NoArgsConstructor
class MedicalRecord {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "patient_id", nullable = false)
private Patient patient;
private String recordType;
private String description;
private LocalDateTime recordDate = LocalDateTime.now();
}
......@@ -18,10 +18,6 @@ public class Notification {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user; //clé étrangère vers User
@Column(columnDefinition = "TEXT")
private String content;
......
......@@ -4,6 +4,7 @@ import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.domain.Auditable;
import java.time.LocalDate;
import java.time.LocalDateTime;
......@@ -15,47 +16,17 @@ import java.util.List;
@Getter
@Setter
@NoArgsConstructor
public class Patient {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String firstName;
@Column(nullable = false)
private String lastName;
public class Patient extends User {
@Column(nullable = false)
private LocalDate dateOfBirth;
private String phoneNumber;
public Patient(String firstName, String lastName, String phoneNumber, String email, String address, String username, String password, Role role) {
super(firstName, lastName, phoneNumber, email, address, username, password, role);
this.dateOfBirth = LocalDate.now();
@Column(unique = true, nullable = false)
private String email;
private String address;
private String allergy;
private String treatment;
@Column(nullable = false, updatable = false)
private LocalDateTime createdAt = LocalDateTime.now();
@OneToMany(mappedBy = "patient", cascade = CascadeType.ALL)
private List<MedicalRecord> medicalRecords;
public Patient(/*Long id,*/ String firstName, String lastName, LocalDate dateOfBirth, String phoneNumber, String email, String address, String allergy, String treatment) {
/*this.id = id;*/
this.firstName = firstName;
this.lastName = lastName;
this.dateOfBirth = dateOfBirth;
this.phoneNumber = phoneNumber;
this.email = email;
this.address = address;
this.allergy = allergy;
this.treatment = treatment;
}
}
......@@ -22,7 +22,7 @@ public class Statistic {
@ManyToOne
@JoinColumn(name = "doctor_id", nullable = false)
private Doctor doctor; //clé étrangère vers Doctor
private Doctor doctor;
@Column(nullable = false)
private LocalDate date;
......
......@@ -6,17 +6,30 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Entity
@Table(name = "users")
@Getter
@Setter
@NoArgsConstructor
public class User {
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "role", discriminatorType = DiscriminatorType.STRING)
abstract class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String firstName;
@Column(nullable = false)
private String lastName;
private String phoneNumber;
@Column(unique = true, nullable = false)
private String email;
private String address;
@Column(nullable = false, unique = true)
private String username;
......@@ -27,18 +40,18 @@ public class User {
@Column(nullable = false)
private Role role;
@ManyToOne
@JoinColumn(name = "medecin_id")
private Doctor doctor;
@ManyToOne
@JoinColumn(name = "patient_id")
private Patient patient;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<Notification> notificationList = new ArrayList<>();
@Column(nullable = false, updatable = false)
private LocalDateTime createdAt = LocalDateTime.now();
public User(String username, String password, Role role) {
protected User(String firstName, String lastName, String phoneNumber, String email, String address, String username, String password, Role role) {
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
this.email = email;
this.address = address;
this.username = username;
this.password = password;
this.role = role;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment