From 29bc22eb95d8365dd67a385dabecb20b235fa100 Mon Sep 17 00:00:00 2001 From: Mirna Gama Date: Sat, 13 Jan 2024 17:24:46 -0300 Subject: [PATCH] [R9] Create consultations table and entity --- .../domain/entities/Consultation.java | 118 ++++++++++++++++++ .../V7__create-table-consultations.sql | 12 ++ 2 files changed, 130 insertions(+) create mode 100644 src/main/java/com/mirna/hospitalmanagementapi/domain/entities/Consultation.java create mode 100644 src/main/resources/db/migration/V7__create-table-consultations.sql diff --git a/src/main/java/com/mirna/hospitalmanagementapi/domain/entities/Consultation.java b/src/main/java/com/mirna/hospitalmanagementapi/domain/entities/Consultation.java new file mode 100644 index 0000000..760cf4d --- /dev/null +++ b/src/main/java/com/mirna/hospitalmanagementapi/domain/entities/Consultation.java @@ -0,0 +1,118 @@ +package com.mirna.hospitalmanagementapi.domain.entities; + +import java.time.LocalDateTime; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; + +/** +* +* @author Mirna Gama +* @version 1.0 +*/ +@Table(name="consultations") +@Entity(name="Consultation") +public class Consultation { + + /** + * Constructor for class Consultation + * @param patient Patient who scheduled the consultation + * @param doctor Doctor who will be at the consultation + * @param consultationDate Scheduled date for the consultation + */ + public Consultation(Patient patient, Doctor doctor, LocalDateTime consultationDate) { + this.patient=patient; + this.doctor=doctor; + this.consultationDate=consultationDate; + } + + public Consultation() {} + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @NotNull(message="consultationDate cannot be null") + @Column(name="consultation_date") + private LocalDateTime consultationDate; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="patient_id") + private Patient patient; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="doctor_id") + private Doctor doctor; + + /** + * Returns the consultation id. + * @return A Long representing the consultation id. + */ + public Long getId() { + return id; + } + + /** + * Sets the consultation id. + * @param id The consultation's unique identifier. + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Returns the consultation date + * @return A local date time object representing the consultation date + */ + public LocalDateTime getConsultationDate() { + return consultationDate; + } + + /** + * Sets the consultation date. + * @param consultationDate Scheduled date for the consultation + */ + public void setConsultationDate(LocalDateTime consultationDate) { + this.consultationDate = consultationDate; + } + + /** + * Returns the patient + * @return A Patient entity representing the patient + */ + public Patient getPatient() { + return patient; + } + + /** + * Sets the patient. + * @param patient Patient who scheduled the consultation + */ + public void setPatient(Patient patient) { + this.patient = patient; + } + + /** + * Returns the doctor + * @return A Doctor entity representing the doctor + */ + public Doctor getDoctor() { + return doctor; + } + + /** + * Sets the doctor. + * @param doctor Doctor who will be at the consultation + */ + public void setDoctor(Doctor doctor) { + this.doctor = doctor; + } + +} diff --git a/src/main/resources/db/migration/V7__create-table-consultations.sql b/src/main/resources/db/migration/V7__create-table-consultations.sql new file mode 100644 index 0000000..ee5fffa --- /dev/null +++ b/src/main/resources/db/migration/V7__create-table-consultations.sql @@ -0,0 +1,12 @@ +create table consultations ( + + id bigint not null auto_increment, + patient_id bigint not null, + doctor_id bigint not null, + consultation_date datetime not null, + + primary key(id), + constraint fk_doctor_id foreign key(doctor_id) references doctors(id), + constraint fk_patient_id foreign key(patient_id) references patients(id) +); +