Add models

This commit is contained in:
2025-11-05 16:41:15 +01:00
parent c0078972c7
commit a45525aab5
5 changed files with 360 additions and 230 deletions

View File

@@ -1,37 +0,0 @@
package com.project.back_end.models;
public class Admin {
// @Entity annotation:
// - Marks the class as a JPA entity, which means it represents a table in the database.
// - It is required for persistence frameworks like Hibernate to map the class to a database table.
// 1. 'id' field:
// - Type: private Long
// - Description:
// - Represents the unique identifier for the Admin entity.
// - This field is auto-generated by the database using @GeneratedValue with strategy GenerationType.IDENTITY.
// - It is the primary key of the entity, identified by @Id annotation.
// 2. 'username' field:
// - Type: private String
// - Description:
// - Represents the username of the admin.
// - Used to log into the system.
// - @NotNull validation ensures that this field cannot be null when creating or updating an Admin.
// 3. 'password' field:
// - Type: private String
// - Description:
// - Represents the password of the admin for authentication.
// - The field is marked with @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) to prevent the password from being exposed in JSON responses.
// - @NotNull validation ensures the password cannot be null when creating or updating an Admin.
// 4. Constructor(s):
// - A no-argument constructor is implicitly provided, required by JPA for entity creation.
// - A parameterized constructor can be added as needed.
// 5. Getters and Setters:
// - Standard getter and setter methods are provided for accessing and modifying the fields.
}

View File

@@ -1,72 +1,96 @@
package com.project.back_end.models;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@Entity
@Table(name = "appointments")
public class Appointment {
// @Entity annotation:
// - Marks the class as a JPA entity, meaning it represents a table in the database.
// - Required for persistence frameworks (e.g., Hibernate) to map the class to a database table.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// 1. 'id' field:
// - Type: private Long
// - Description:
// - Represents the unique identifier for each appointment.
// - The @Id annotation marks it as the primary key.
// - The @GeneratedValue(strategy = GenerationType.IDENTITY) annotation auto-generates the ID value when a new record is inserted into the database.
@NotNull
@ManyToOne
private Doctor doctor;
// 2. 'doctor' field:
// - Type: private Doctor
// - Description:
// - Represents the doctor assigned to this appointment.
// - The @ManyToOne annotation defines the relationship, indicating many appointments can be linked to one doctor.
// - The @NotNull annotation ensures that an appointment must be associated with a doctor when created.
@NotNull
@ManyToOne
private Patient patient;
// 3. 'patient' field:
// - Type: private Patient
// - Description:
// - Represents the patient assigned to this appointment.
// - The @ManyToOne annotation defines the relationship, indicating many appointments can be linked to one patient.
// - The @NotNull annotation ensures that an appointment must be associated with a patient when created.
@NotNull
@Future
private LocalDateTime appointmentTime;
// 4. 'appointmentTime' field:
// - Type: private LocalDateTime
// - Description:
// - Represents the date and time when the appointment is scheduled to occur.
// - The @Future annotation ensures that the appointment time is always in the future when the appointment is created.
// - It uses LocalDateTime, which includes both the date and time for the appointment.
@NotNull
@Enumerated(EnumType.ORDINAL)
private Status status;
// 5. 'status' field:
// - Type: private int
// - Description:
// - Represents the current status of the appointment. It is an integer where:
// - 0 means the appointment is scheduled.
// - 1 means the appointment has been completed.
// - The @NotNull annotation ensures that the status field is not null.
// 6. 'getEndTime' method:
// - Type: private LocalDateTime
// - Description:
// - This method is a transient field (not persisted in the database).
// - It calculates the end time of the appointment by adding one hour to the start time (appointmentTime).
// - It is used to get an estimated appointment end time for display purposes.
// 7. 'getAppointmentDate' method:
// - Type: private LocalDate
// - Description:
// - This method extracts only the date part from the appointmentTime field.
// - It returns a LocalDate object representing just the date (without the time) of the scheduled appointment.
// 8. 'getAppointmentTimeOnly' method:
// - Type: private LocalTime
// - Description:
// - This method extracts only the time part from the appointmentTime field.
// - It returns a LocalTime object representing just the time (without the date) of the scheduled appointment.
// 9. Constructor(s):
// - A no-argument constructor is implicitly provided by JPA for entity creation.
// - A parameterized constructor can be added as needed to initialize fields.
// 10. Getters and Setters:
// - Standard getter and setter methods are provided for accessing and modifying the fields: id, doctor, patient, appointmentTime, status, etc.
public Appointment() {}
public Appointment(Doctor doctor, Patient patient, LocalDateTime appointmentTime) {
this.doctor = doctor;
this.patient = patient;
this.appointmentTime = appointmentTime;
this.status = Status.SCHEDULED;
}
public void setAppointmentTime(LocalDateTime appointmentTime) {
this.appointmentTime = appointmentTime;
}
public void setStatus(Status status) {
this.status = status;
}
public Long getId() {
return id;
}
public Doctor getDoctor() {
return doctor;
}
public Patient getPatient() {
return patient;
}
public LocalDateTime getAppointmentTime() {
return appointmentTime;
}
public Status getStatus() {
return status;
}
public LocalDateTime getEndTime() {
return appointmentTime.plusHours(1);
}
public LocalDate getAppointmentDate() {
return appointmentTime.toLocalDate();
}
public LocalTime getAppointmentTimeOnly() {
return appointmentTime.toLocalTime();
}
public enum Status {
SCHEDULED,
COMPLETED,
CANCELLED
}
}

View File

@@ -1,65 +1,131 @@
package com.project.back_end.models;
import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.util.List;
@Entity
@Table(name = "doctors")
public class Doctor {
// @Entity annotation:
// - Marks the class as a JPA entity, meaning it represents a table in the database.
// - Required for persistence frameworks (e.g., Hibernate) to map the class to a database table.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// 1. 'id' field:
// - Type: private Long
// - Description:
// - Represents the unique identifier for each doctor.
// - The @Id annotation marks it as the primary key.
// - The @GeneratedValue(strategy = GenerationType.IDENTITY) annotation auto-generates the ID value when a new record is inserted into the database.
@NotNull
@OneToOne
private User user;
// 2. 'name' field:
// - Type: private String
// - Description:
// - Represents the doctor's name.
// - The @NotNull annotation ensures that the doctor's name is required.
// - The @Size(min = 3, max = 100) annotation ensures that the name length is between 3 and 100 characters.
// - Provides validation for correct input and user experience.
@NotNull
@Size(min = 3, max = 100)
private String name;
@NotNull
@Size(min = 3, max = 50)
private String specialization;
@NotNull
@Email
private String email_address;
@NotNull
@Pattern(regexp = "^[0-9]{10}$")
private String phone_number;
@OneToMany(fetch = FetchType.LAZY)
private List<Appointment> appointments;
@NotNull
@Size(min = 1)
@OneToMany(fetch = FetchType.LAZY)
private List<OfficeHour> officeHours;
@OneToMany(fetch = FetchType.LAZY)
private List<UnavailabilitySchedule> unavailabilitySchedules;
// 3. 'specialty' field:
// - Type: private String
// - Description:
// - Represents the medical specialty of the doctor.
// - The @NotNull annotation ensures that a specialty must be provided.
// - The @Size(min = 3, max = 50) annotation ensures that the specialty name is between 3 and 50 characters long.
// 4. 'email' field:
// - Type: private String
// - Description:
// - Represents the doctor's email address.
// - The @NotNull annotation ensures that an email address is required.
// - The @Email annotation validates that the email address follows a valid email format (e.g., doctor@example.com).
// 5. 'password' field:
// - Type: private String
// - Description:
// - Represents the doctor's password for login authentication.
// - The @NotNull annotation ensures that a password must be provided.
// - The @Size(min = 6) annotation ensures that the password must be at least 6 characters long.
// - The @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) annotation ensures that the password is not serialized in the response (hidden from the frontend).
// 6. 'phone' field:
// - Type: private String
// - Description:
// - Represents the doctor's phone number.
// - The @NotNull annotation ensures that a phone number must be provided.
// - The @Pattern(regexp = "^[0-9]{10}$") annotation validates that the phone number must be exactly 10 digits long.
// 7. 'availableTimes' field:
// - Type: private List<String>
// - Description:
// - Represents the available times for the doctor in a list of time slots.
// - Each time slot is represented as a string (e.g., "09:00-10:00", "10:00-11:00").
// - The @ElementCollection annotation ensures that the list of time slots is stored as a separate collection in the database.
// 8. Getters and Setters:
// - Standard getter and setter methods are provided for all fields: id, name, specialty, email, password, phone, and availableTimes.
@NotNull
private Boolean archived;
public Doctor() {
}
public Doctor(String name, User user, List<OfficeHour> officeHours) {
this.name = name;
this.user = user;
this.officeHours = officeHours;
}
public Long getId() {
return id;
}
public String getSpecialization() {
return specialization;
}
public void setSpecialization(String specialization) {
this.specialization = specialization;
}
public String getEmail_address() {
return email_address;
}
public void setEmail_address(String email_address) {
this.email_address = email_address;
}
public String getPhone_number() {
return phone_number;
}
public void setPhone_number(String phone_number) {
this.phone_number = phone_number;
}
public List<Appointment> getAppointments() {
return appointments;
}
public void setAppointments(List<Appointment> appointments) {
this.appointments = appointments;
}
public List<OfficeHour> getOfficeHours() {
return officeHours;
}
public void setOfficeHours(List<OfficeHour> officeHours) {
this.officeHours = officeHours;
}
public List<UnavailabilitySchedule> getUnavailabilitySchedules() {
return unavailabilitySchedules;
}
public void setUnavailabilitySchedules(List<UnavailabilitySchedule> unavailabilitySchedules) {
this.unavailabilitySchedules = unavailabilitySchedules;
}
public User getUser() {
return user;
}
public Boolean getArchived() {
return archived;
}
public void setArchived(Boolean archived) {
this.archived = archived;
}
@PrePersist
private void save() {
archived = false;
}
}

View File

@@ -1,59 +1,115 @@
package com.project.back_end.models;
import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.util.List;
@Entity
@Table(name = "patients")
public class Patient {
// @Entity annotation:
// - Marks the class as a JPA entity, meaning it represents a table in the database.
// - Required for persistence frameworks (e.g., Hibernate) to map the class to a database table.
// 1. 'id' field:
// - Type: private Long
// - Description:
// - Represents the unique identifier for each patient.
// - The @Id annotation marks it as the primary key.
// - The @GeneratedValue(strategy = GenerationType.IDENTITY) annotation auto-generates the ID value when a new record is inserted into the database.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// 2. 'name' field:
// - Type: private String
// - Description:
// - Represents the patient's full name.
// - The @NotNull annotation ensures that the patient's name is required.
// - The @Size(min = 3, max = 100) annotation ensures that the name length is between 3 and 100 characters.
// - Provides validation for correct input and user experience.
@NotNull
@OneToOne
private User user;
@NotNull
@Size(min = 3, max = 100)
private String name;
// 3. 'email' field:
// - Type: private String
// - Description:
// - Represents the patient's email address.
// - The @NotNull annotation ensures that an email address must be provided.
// - The @Email annotation validates that the email address follows a valid email format (e.g., patient@example.com).
@NotNull
@Email
private String emailAddress;
// 4. 'password' field:
// - Type: private String
// - Description:
// - Represents the patient's password for login authentication.
// - The @NotNull annotation ensures that a password must be provided.
// - The @Size(min = 6) annotation ensures that the password must be at least 6 characters long.
@NotNull
@Pattern(regexp = "^[0-9]{10}$")
private String phoneNumber;
// 5. 'phone' field:
// - Type: private String
// - Description:
// - Represents the patient's phone number.
// - The @NotNull annotation ensures that a phone number must be provided.
// - The @Pattern(regexp = "^[0-9]{10}$") annotation validates that the phone number must be exactly 10 digits long.
@NotNull
@Size(max = 255)
private String homeAddress;
// 6. 'address' field:
// - Type: private String
// - Description:
// - Represents the patient's address.
// - The @NotNull annotation ensures that the address must be provided.
// - The @Size(max = 255) annotation ensures that the address does not exceed 255 characters in length, providing validation for the address input.
// 7. Getters and Setters:
// - Standard getter and setter methods are provided for all fields: id, name, email, password, phone, and address.
// - These methods allow access and modification of the fields of the Patient class.
@NotNull
private Boolean archived;
@OneToMany(fetch = FetchType.LAZY)
public List<Appointment> appointments;
public Patient(){}
public Patient(User user, String name, String emailAddress, String phoneNumber, String homeAddress) {
this.user = user;
this.name = name;
this.emailAddress = emailAddress;
this.phoneNumber = phoneNumber;
this.homeAddress = homeAddress;
}
public void setName(String name) {
this.name = name;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public void setHomeAddress(String homeAddress) {
this.homeAddress = homeAddress;
}
public void setArchived(Boolean archived) {
this.archived = archived;
}
public void setAppointments(List<Appointment> appointments) {
this.appointments = appointments;
}
public Long getId() {
return id;
}
public User getUser() {
return user;
}
public String getName() {
return name;
}
public String getEmailAddress() {
return emailAddress;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getHomeAddress() {
return homeAddress;
}
public Boolean getArchived() {
return archived;
}
public List<Appointment> getAppointments() {
return appointments;
}
@PrePersist
private void save() {
archived = false;
}
}

View File

@@ -1,56 +1,77 @@
package com.project.back_end.models;
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import org.springframework.data.mongodb.core.mapping.Document;
import static java.util.Objects.requireNonNull;
@Document(collation = "prescriptions")
public class Prescription {
// @Document annotation:
// - Marks the class as a MongoDB document (a collection in MongoDB).
// - The collection name is specified as "prescriptions" to map this class to the "prescriptions" collection in MongoDB.
@Id
private String id;
// 1. 'id' field:
// - Type: private String
// - Description:
// - Represents the unique identifier for each prescription.
// - The @Id annotation marks it as the primary key in the MongoDB collection.
// - The id is of type String, which is commonly used for MongoDB's ObjectId as it stores IDs as strings in the database.
@NotNull
private Long patientId;
// 2. 'patientName' field:
// - Type: private String
// - Description:
// - Represents the name of the patient receiving the prescription.
// - The @NotNull annotation ensures that the patient name is required.
// - The @Size(min = 3, max = 100) annotation ensures that the name length is between 3 and 100 characters, ensuring a reasonable name length.
@NotNull
private Long appointmentId;
// 3. 'appointmentId' field:
// - Type: private Long
// - Description:
// - Represents the ID of the associated appointment where the prescription was given.
// - The @NotNull annotation ensures that the appointment ID is required for the prescription.
@NotNull
@Size(min = 3, max = 100)
private String medication;
// 4. 'medication' field:
// - Type: private String
// - Description:
// - Represents the medication prescribed to the patient.
// - The @NotNull annotation ensures that the medication name is required.
// - The @Size(min = 3, max = 100) annotation ensures that the medication name is between 3 and 100 characters, which ensures meaningful medication names.
@NotNull
private String dosage;
// 5. 'dosage' field:
// - Type: private String
// - Description:
// - Represents the dosage information for the prescribed medication.
// - The @NotNull annotation ensures that the dosage information is provided.
// 6. 'doctorNotes' field:
// - Type: private String
// - Description:
// - Represents any additional notes or instructions from the doctor regarding the prescription.
// - The @Size(max = 200) annotation ensures that the doctor's notes do not exceed 200 characters, providing a reasonable limit for additional notes.
// 7. Constructors:
// - The class includes a no-argument constructor (default constructor) and a parameterized constructor that initializes the fields: patientName, medication, dosage, doctorNotes, and appointmentId.
// 8. Getters and Setters:
// - Standard getter and setter methods are provided for all fields: id, patientName, medication, dosage, doctorNotes, and appointmentId.
// - These methods allow access and modification of the fields of the Prescription class.
@Size(max = 200)
private String doctorNotes;
public Prescription() {}
public Prescription(Patient patient, Appointment appointment, String medication, String dosage, String doctorNotes) {
this.patientId = requireNonNull(patient).getId();
this.appointmentId = requireNonNull(appointment).getId();
this.medication = medication;
this.dosage = dosage;
this.doctorNotes = doctorNotes;
}
public String getId() {
return id;
}
public String getMedication() {
return medication;
}
public void setMedication(String medication) {
this.medication = medication;
}
public String getDosage() {
return dosage;
}
public void setDosage(String dosage) {
this.dosage = dosage;
}
public String getDoctorNotes() {
return doctorNotes;
}
public void setDoctorNotes(String doctorNotes) {
this.doctorNotes = doctorNotes;
}
public Long getAppointmentId() {
return appointmentId;
}
public Long getPatientId() {
return patientId;
}
}