From a45525aab5a88fd601de25706599f49783dedaa4 Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Wed, 5 Nov 2025 16:41:15 +0100 Subject: [PATCH] Add models --- .../com/project/back_end/models/Admin.java | 37 ---- .../project/back_end/models/Appointment.java | 136 ++++++++------ .../com/project/back_end/models/Doctor.java | 166 ++++++++++++------ .../com/project/back_end/models/Patient.java | 146 ++++++++++----- .../project/back_end/models/Prescription.java | 105 ++++++----- 5 files changed, 360 insertions(+), 230 deletions(-) delete mode 100644 SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Admin.java diff --git a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Admin.java b/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Admin.java deleted file mode 100644 index 58d9862..0000000 --- a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Admin.java +++ /dev/null @@ -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. - -} diff --git a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Appointment.java b/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Appointment.java index b26be0d..89aad66 100644 --- a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Appointment.java +++ b/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Appointment.java @@ -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. + public Appointment() {} -// 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. + public Appointment(Doctor doctor, Patient patient, LocalDateTime appointmentTime) { + this.doctor = doctor; + this.patient = patient; + this.appointmentTime = appointmentTime; + this.status = Status.SCHEDULED; + } -// 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. + public void setAppointmentTime(LocalDateTime appointmentTime) { + this.appointmentTime = appointmentTime; + } -// 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. + public void setStatus(Status status) { + this.status = status; + } -// 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. + public Long getId() { + return id; + } -// 10. Getters and Setters: -// - Standard getter and setter methods are provided for accessing and modifying the fields: id, doctor, patient, appointmentTime, status, etc. + 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 + } +} \ No newline at end of file diff --git a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Doctor.java b/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Doctor.java index 8cb5d79..a0e1bd2 100644 --- a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Doctor.java +++ b/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Doctor.java @@ -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 appointments; + + @NotNull + @Size(min = 1) + @OneToMany(fetch = FetchType.LAZY) + private List officeHours; + + @OneToMany(fetch = FetchType.LAZY) + private List 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. + @NotNull + private Boolean archived; -// 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). + public Doctor() { + } -// 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). + public Doctor(String name, User user, List officeHours) { + this.name = name; + this.user = user; + this.officeHours = officeHours; + } -// 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. + public Long getId() { + return id; + } -// 7. 'availableTimes' field: -// - Type: private List -// - 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. + public String getSpecialization() { + return specialization; + } -// 8. Getters and Setters: -// - Standard getter and setter methods are provided for all fields: id, name, specialty, email, password, phone, and availableTimes. + 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 getAppointments() { + return appointments; + } + + public void setAppointments(List appointments) { + this.appointments = appointments; + } + + public List getOfficeHours() { + return officeHours; + } + + public void setOfficeHours(List officeHours) { + this.officeHours = officeHours; + } + + public List getUnavailabilitySchedules() { + return unavailabilitySchedules; + } + + public void setUnavailabilitySchedules(List 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; + } +} \ No newline at end of file diff --git a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Patient.java b/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Patient.java index 81b8c23..20ab11b 100644 --- a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Patient.java +++ b/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Patient.java @@ -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. + @NotNull + private Boolean archived; + @OneToMany(fetch = FetchType.LAZY) + public List appointments; -// 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. + 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 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 getAppointments() { + return appointments; + } + + @PrePersist + private void save() { + archived = false; + } +} \ No newline at end of file diff --git a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Prescription.java b/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Prescription.java index 89bc1a5..54f97dc 100644 --- a/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Prescription.java +++ b/SmartClinicManagementSystem/app/src/main/java/com/project/back_end/models/Prescription.java @@ -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. + @Size(max = 200) + private String doctorNotes; -// 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. + public Prescription() {} -// 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. + 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; + } -// 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 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; + } +} \ No newline at end of file