Advertisement
Guest User

boza2

a guest
Dec 15th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. /**
  2. *
  3. */
  4. package com.dxc.medxc.persistence.jpa.entities;
  5.  
  6. import java.sql.Timestamp;
  7. import java.util.List;
  8. import java.util.Objects;
  9.  
  10. import javax.persistence.Column;
  11. import javax.persistence.Entity;
  12. import javax.persistence.GeneratedValue;
  13. import javax.persistence.Id;
  14. import javax.persistence.JoinColumn;
  15. import javax.persistence.ManyToOne;
  16. import javax.persistence.OneToMany;
  17. import javax.persistence.OneToOne;
  18. import javax.persistence.Table;
  19.  
  20. import com.dxc.medxc.persistence.model.Appointment;
  21. import com.dxc.medxc.persistence.model.Doctor;
  22. import com.dxc.medxc.persistence.model.Patient;
  23. import com.dxc.medxc.persistence.model.Record;
  24. import com.dxc.medxc.persistence.model.Specialty;
  25. import com.dxc.medxc.persistence.model.Status;
  26. import com.dxc.medxc.persistence.model.Test;
  27.  
  28. /**
  29. * Appointment entity
  30. *
  31. * @author yyayya
  32. */
  33. @Entity
  34. @Table(name = "APPOINTMENT")
  35. // @NamedQuery(name="Test", query="SELECT c FROM APPOINTMENT c WHERE ")
  36. public class JpaAppointment implements Appointment {
  37.  
  38. /*
  39. * APP_ID NUMBER (10) GENERATED BY DEFAULT AS IDENTITY, APP_DATE_TIME DATE NOT
  40. * NULL, STATUS_ID NUMBER (1) NOT NULL, PAT_ID NUMBER (10), SPEC_ID NUMBER (4),
  41. * DOC_NUM CHAR (10 CHAR) NOT NULL, PRIMARY KEY(APP_ID), FOREIGN KEY (STATUS_ID)
  42. * REFERENCES STATUS(STATUS_ID), FOREIGN KEY (PAT_ID) REFERENCES
  43. * PATIENT(PAT_ID), FOREIGN KEY (DOC_NUM) REFERENCES DOCTOR(DOC_NUM), FOREIGN
  44. * KEY (SPEC_ID) REFERENCES SPECIALTY(SPEC_ID)
  45. */
  46.  
  47. @Id
  48. @GeneratedValue
  49. @Column(name = "APP_ID", nullable = false)
  50. private int id;
  51.  
  52. @Column(name = "APP_DATE_TIME", nullable = false)
  53. private Timestamp date;
  54.  
  55. @ManyToOne(targetEntity = JpaStatus.class)
  56. @JoinColumn(name = "STATUS_ID")
  57. private Status status;
  58.  
  59. @ManyToOne(targetEntity = JpaSpecialty.class)
  60. @JoinColumn(name = "SPEC_ID")
  61. private Specialty specialty;
  62.  
  63. @ManyToOne(targetEntity = JpaPatient.class)
  64. @JoinColumn(name = "PIN")
  65. private Patient patient;
  66.  
  67. @ManyToOne(targetEntity = JpaDoctor.class)
  68. @JoinColumn(name = "DOC_NUM")
  69. private Doctor doctor;
  70.  
  71. @OneToMany(targetEntity = JpaTest.class, mappedBy = "appointment")
  72. private List<Test> tests;
  73.  
  74. @OneToOne(targetEntity = JpaRecord.class, mappedBy = "appointment")
  75. private Record record;
  76.  
  77. /**
  78. * Needed by JPA
  79. */
  80. public JpaAppointment() {
  81.  
  82. }
  83.  
  84. /**
  85. * @param status
  86. * Status of the appointment
  87. * @param patient
  88. * The patient who scheduled the appointment
  89. * @param doctor
  90. * The doctor the appointment is scheduled with
  91. * @param date
  92. * Date of the appointment
  93. */
  94. public JpaAppointment(final Status status, final Patient patient, final Doctor doctor, final Timestamp date) {
  95. Objects.requireNonNull(status);
  96. Objects.requireNonNull(patient);
  97. Objects.requireNonNull(doctor);
  98. Objects.requireNonNull(date);
  99.  
  100. this.status = status;
  101. this.patient = patient;
  102. this.doctor = doctor;
  103. this.date = (Timestamp) date.clone();
  104. }
  105.  
  106. @Override
  107. public Status getStatus() {
  108. return status;
  109. }
  110.  
  111. @Override
  112. public Patient getPIN() {
  113. return patient;
  114. }
  115.  
  116. @Override
  117. public Doctor getDocNum() {
  118. return doctor;
  119.  
  120. }
  121.  
  122. @Override
  123. public Timestamp getDate() {
  124. return (Timestamp) date.clone();
  125.  
  126. }
  127.  
  128. @Override
  129. public int getId() {
  130. return id;
  131. }
  132.  
  133. @Override
  134. public Patient getPatient() {
  135. return patient;
  136. }
  137.  
  138. @Override
  139. public Specialty getSpecialty() {
  140. return specialty;
  141. }
  142.  
  143. @Override
  144. public Doctor getDoctor() {
  145. return doctor;
  146. }
  147.  
  148. @Override
  149. public List<Test> getTests() {
  150. return null;
  151. }
  152.  
  153. @Override
  154. public Record getRecord() {
  155. return record;
  156. }
  157.  
  158. @Override
  159. public boolean equals(final Object other) {
  160. if (this == other) {
  161. return true;
  162. }
  163. if (other == null) {
  164. return false;
  165. }
  166. if (this.getClass() != other.getClass()) {
  167. return false;
  168. }
  169.  
  170. final JpaAppointment appointmentOther = (JpaAppointment) other;
  171.  
  172. return this.id == appointmentOther.id;
  173.  
  174. }
  175.  
  176. @Override
  177. public int hashCode() {
  178. return Objects.hash(Integer.valueOf(this.id));
  179. }
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement