[R9] Create consultations table and entity
This commit is contained in:
parent
283ac4d3e8
commit
29bc22eb95
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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)
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user