Add models
This commit is contained in:
@@ -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.
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,72 +1,96 @@
|
|||||||
package com.project.back_end.models;
|
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 {
|
public class Appointment {
|
||||||
|
|
||||||
// @Entity annotation:
|
@Id
|
||||||
// - Marks the class as a JPA entity, meaning it represents a table in the database.
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
// - Required for persistence frameworks (e.g., Hibernate) to map the class to a database table.
|
private Long id;
|
||||||
|
|
||||||
// 1. 'id' field:
|
@NotNull
|
||||||
// - Type: private Long
|
@ManyToOne
|
||||||
// - Description:
|
private Doctor doctor;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 2. 'doctor' field:
|
@NotNull
|
||||||
// - Type: private Doctor
|
@ManyToOne
|
||||||
// - Description:
|
private Patient patient;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 3. 'patient' field:
|
@NotNull
|
||||||
// - Type: private Patient
|
@Future
|
||||||
// - Description:
|
private LocalDateTime appointmentTime;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 4. 'appointmentTime' field:
|
@NotNull
|
||||||
// - Type: private LocalDateTime
|
@Enumerated(EnumType.ORDINAL)
|
||||||
// - Description:
|
private Status status;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 5. 'status' field:
|
public Appointment() {}
|
||||||
// - 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(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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,65 +1,131 @@
|
|||||||
package com.project.back_end.models;
|
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 {
|
public class Doctor {
|
||||||
|
|
||||||
// @Entity annotation:
|
@Id
|
||||||
// - Marks the class as a JPA entity, meaning it represents a table in the database.
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
// - Required for persistence frameworks (e.g., Hibernate) to map the class to a database table.
|
private Long id;
|
||||||
|
|
||||||
// 1. 'id' field:
|
@NotNull
|
||||||
// - Type: private Long
|
@OneToOne
|
||||||
// - Description:
|
private User user;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 2. 'name' field:
|
@NotNull
|
||||||
// - Type: private String
|
@Size(min = 3, max = 100)
|
||||||
// - Description:
|
private String name;
|
||||||
// - Represents the doctor's name.
|
|
||||||
// - The @NotNull annotation ensures that the doctor's name is required.
|
@NotNull
|
||||||
// - The @Size(min = 3, max = 100) annotation ensures that the name length is between 3 and 100 characters.
|
@Size(min = 3, max = 50)
|
||||||
// - Provides validation for correct input and user experience.
|
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:
|
@NotNull
|
||||||
// - Type: private String
|
private Boolean archived;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,59 +1,115 @@
|
|||||||
package com.project.back_end.models;
|
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 {
|
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:
|
@Id
|
||||||
// - Type: private Long
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
// - Description:
|
private Long id;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 2. 'name' field:
|
@NotNull
|
||||||
// - Type: private String
|
@OneToOne
|
||||||
// - Description:
|
private User user;
|
||||||
// - 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
|
||||||
|
@Size(min = 3, max = 100)
|
||||||
|
private String name;
|
||||||
|
|
||||||
// 3. 'email' field:
|
@NotNull
|
||||||
// - Type: private String
|
@Email
|
||||||
// - Description:
|
private String emailAddress;
|
||||||
// - 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).
|
|
||||||
|
|
||||||
// 4. 'password' field:
|
@NotNull
|
||||||
// - Type: private String
|
@Pattern(regexp = "^[0-9]{10}$")
|
||||||
// - Description:
|
private String phoneNumber;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 5. 'phone' field:
|
@NotNull
|
||||||
// - Type: private String
|
@Size(max = 255)
|
||||||
// - Description:
|
private String homeAddress;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 6. 'address' field:
|
@NotNull
|
||||||
// - Type: private String
|
private Boolean archived;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,56 +1,77 @@
|
|||||||
package com.project.back_end.models;
|
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 {
|
public class Prescription {
|
||||||
|
|
||||||
// @Document annotation:
|
@Id
|
||||||
// - Marks the class as a MongoDB document (a collection in MongoDB).
|
private String id;
|
||||||
// - The collection name is specified as "prescriptions" to map this class to the "prescriptions" collection in MongoDB.
|
|
||||||
|
|
||||||
// 1. 'id' field:
|
@NotNull
|
||||||
// - Type: private String
|
private Long patientId;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 2. 'patientName' field:
|
@NotNull
|
||||||
// - Type: private String
|
private Long appointmentId;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 3. 'appointmentId' field:
|
@NotNull
|
||||||
// - Type: private Long
|
@Size(min = 3, max = 100)
|
||||||
// - Description:
|
private String medication;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 4. 'medication' field:
|
@NotNull
|
||||||
// - Type: private String
|
private String dosage;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
// 5. 'dosage' field:
|
@Size(max = 200)
|
||||||
// - Type: private String
|
private String doctorNotes;
|
||||||
// - 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.
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user