Advertisement
Guest User

Untitled

a guest
Jul 10th, 2020
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. /**
  2. * This Source Code Form is subject to the terms of the Mozilla Public License,
  3. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  4. * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
  5. * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
  6. *
  7. * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
  8. * graphic logo is a trademark of OpenMRS Inc.
  9. */
  10. package org.openmrs;
  11.  
  12. import java.util.Date;
  13. import java.util.HashSet;
  14. import java.util.LinkedHashSet;
  15. import java.util.List;
  16. import java.util.Set;
  17. import java.util.stream.Collectors;
  18.  
  19. import javax.persistence.Access;
  20. import javax.persistence.AccessType;
  21. import javax.persistence.CascadeType;
  22. import javax.persistence.Column;
  23. import javax.persistence.Entity;
  24. import javax.persistence.GeneratedValue;
  25. import javax.persistence.GenerationType;
  26. import javax.persistence.Id;
  27. import javax.persistence.JoinColumn;
  28. import javax.persistence.ManyToOne;
  29. import javax.persistence.OneToMany;
  30. import javax.persistence.OrderBy;
  31. import javax.persistence.Table;
  32.  
  33. import org.hibernate.annotations.BatchSize;
  34. import org.openmrs.customdatatype.Customizable;
  35.  
  36. /**
  37. * A 'visit' is a contiguous time period where encounters occur between patients and healthcare
  38. * providers. This can function as a grouper for encounters
  39. *
  40. * @since 1.9
  41. */
  42. @Entity
  43. @Table(name = "visit")
  44. public class Visit extends BaseCustomizableData<VisitAttribute> implements Auditable, Customizable<VisitAttribute> {
  45.  
  46. @Id
  47. @GeneratedValue(strategy = GenerationType.IDENTITY)
  48. @Column(name = "visit_id")
  49. private Integer visitId;
  50.  
  51. @ManyToOne(optional = false)
  52. @JoinColumn(name = "patient_id")
  53. private Patient patient;
  54.  
  55. @ManyToOne(optional = false)
  56. @JoinColumn(name = "visit_type_id")
  57. private VisitType visitType;
  58.  
  59. @ManyToOne
  60. @JoinColumn(name = "indication_concept_id")
  61. private Concept indication;
  62.  
  63. @ManyToOne
  64. @JoinColumn(name = "location_id")
  65. private Location location;
  66.  
  67. @Column(name = "date_started", nullable = false, length = 19)
  68. private Date startDatetime;
  69.  
  70. @Column(name = "date_stopped", length = 19)
  71. private Date stopDatetime;
  72.  
  73. @OneToMany(mappedBy = "visit")
  74. @OrderBy("encounter_datetime desc, encounter_id desc")
  75. private Set<Encounter> encounters;
  76.  
  77. @Access(AccessType.PROPERTY)
  78. @OneToMany(mappedBy = "visit", cascade = CascadeType.ALL, orphanRemoval = true)
  79. @OrderBy("voided asc")
  80. @BatchSize(size = 100)
  81. private Set<VisitAttribute> attributes = new LinkedHashSet<>();
  82.  
  83. /**
  84. * Default Constructor
  85. */
  86. public Visit() {
  87. }
  88.  
  89. /**
  90. * Constructor that takes in a visitId
  91. *
  92. * @param visitId
  93. */
  94. public Visit(Integer visitId) {
  95. this.visitId = visitId;
  96. }
  97.  
  98. /**
  99. * Convenience constructor that takes in the required fields i.e {@link Patient},
  100. * {@link VisitType} and dateStarted
  101. *
  102. * @see VisitType
  103. * @param patient the patient associated to this visit
  104. * @param visitType The type of visit
  105. * @param startDatetime the date this visit was started
  106. */
  107. public Visit(Patient patient, VisitType visitType, Date startDatetime) {
  108. this.patient = patient;
  109. this.visitType = visitType;
  110. this.startDatetime = startDatetime;
  111. }
  112.  
  113. /**
  114. * @return the visitId
  115. */
  116. public Integer getVisitId() {
  117. return visitId;
  118. }
  119.  
  120. /**
  121. * @param visitId the visitId to set
  122. */
  123. public void setVisitId(Integer visitId) {
  124. this.visitId = visitId;
  125. }
  126.  
  127. /**
  128. * @return the patient
  129. */
  130. public Patient getPatient() {
  131. return patient;
  132. }
  133.  
  134. /**
  135. * @param patient the patient to set
  136. */
  137. public void setPatient(Patient patient) {
  138. this.patient = patient;
  139. }
  140.  
  141. /**
  142. * @return the visitType
  143. */
  144. public VisitType getVisitType() {
  145. return visitType;
  146. }
  147.  
  148. /**
  149. * @param visitType the visitType to set
  150. */
  151. public void setVisitType(VisitType visitType) {
  152. this.visitType = visitType;
  153. }
  154.  
  155. /**
  156. * @return the indication
  157. */
  158. public Concept getIndication() {
  159. return indication;
  160. }
  161.  
  162. /**
  163. * @param indication the indication to set
  164. */
  165. public void setIndication(Concept indication) {
  166. this.indication = indication;
  167. }
  168.  
  169. /**
  170. * @return the location
  171. */
  172. public Location getLocation() {
  173. return location;
  174. }
  175.  
  176. /**
  177. * @param location the location to set
  178. */
  179. public void setLocation(Location location) {
  180. this.location = location;
  181. }
  182.  
  183. /**
  184. * @return the startDatetime
  185. */
  186. public Date getStartDatetime() {
  187. return startDatetime;
  188. }
  189.  
  190. /**
  191. * @param startDatetime the startDatetime to set
  192. */
  193. public void setStartDatetime(Date startDatetime) {
  194. this.startDatetime = startDatetime;
  195. }
  196.  
  197. /**
  198. * @return the stopDatetime
  199. */
  200. public Date getStopDatetime() {
  201. return stopDatetime;
  202. }
  203.  
  204. /**
  205. * @param stopDatetime the stopDatetime to set
  206. */
  207. public void setStopDatetime(Date stopDatetime) {
  208. this.stopDatetime = stopDatetime;
  209. }
  210.  
  211. /**
  212. * @see org.openmrs.OpenmrsObject#getId()
  213. */
  214. @Override
  215. public Integer getId() {
  216. return visitId;
  217. }
  218.  
  219. /**
  220. * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
  221. */
  222. @Override
  223. public void setId(Integer id) {
  224. visitId = id;
  225. }
  226.  
  227. /**
  228. * @see java.lang.Object#toString()
  229. */
  230. @Override
  231. public String toString() {
  232. return "Visit #" + visitId;
  233. }
  234.  
  235. /**
  236. * @return the encounters
  237. */
  238. public Set<Encounter> getEncounters() {
  239. if (encounters == null) {
  240. encounters = new HashSet<>();
  241. }
  242. return encounters;
  243. }
  244.  
  245. /**
  246. * @param encounters the encounters to set
  247. */
  248. public void setEncounters(Set<Encounter> encounters) {
  249. this.encounters = encounters;
  250. }
  251.  
  252. /**
  253. * Gets a list of non voided encounters
  254. *
  255. * @return the non voided encounter list
  256. * @since 1.11.0, 1.12.0
  257. */
  258. public List<Encounter> getNonVoidedEncounters() {
  259. return getEncounters().stream().filter(e -> !e.getVoided()).collect(Collectors.toList());
  260. }
  261.  
  262. /**
  263. * adds an individual encounter to a visit
  264. *
  265. * @param encounter the encounter to add
  266. * @since 1.9.2, 1.10.0
  267. */
  268. public void addEncounter(Encounter encounter) {
  269. if (encounter != null) {
  270. encounter.setVisit(this);
  271. getEncounters().add(encounter);
  272. }
  273. }
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement