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 4.72 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 org.hibernate.annotations.BatchSize;
  13. import org.hibernate.annotations.LazyCollection;
  14. import org.hibernate.annotations.LazyCollectionOption;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17.  
  18. import javax.persistence.Access;
  19. import javax.persistence.AccessType;
  20. import javax.persistence.AttributeOverride;
  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. import java.util.LinkedHashSet;
  33. import java.util.Set;
  34.  
  35. /**
  36. * Represents a person who may provide care to a patient during an encounter
  37. *
  38. * @since 1.9
  39. */
  40. @Entity
  41. @Table(name = "provider")
  42. @AttributeOverride(name = "name", column = @Column(name = "name"))
  43. public class Provider extends BaseCustomizableMetadata<ProviderAttribute> {
  44.  
  45. private static final Logger log = LoggerFactory.getLogger(Provider.class);
  46.  
  47. @Id
  48. @Column(name = "provider_id")
  49. @GeneratedValue(strategy = GenerationType.IDENTITY)
  50. private Integer providerId;
  51.  
  52. @ManyToOne(cascade = CascadeType.ALL)
  53. @JoinColumn(name = "person_id")
  54. private Person person;
  55.  
  56. @Column(name = "identifier", length = 255)
  57. private String identifier;
  58.  
  59. @ManyToOne
  60. @JoinColumn(name = "role_id")
  61. private Concept role;
  62.  
  63. @ManyToOne
  64. @JoinColumn(name = "speciality_id")
  65. private Concept speciality;
  66.  
  67. @Access(AccessType.PROPERTY)
  68. @OneToMany(mappedBy = "provider", cascade = CascadeType.ALL, orphanRemoval = true)
  69. @OrderBy("voided asc")
  70. @LazyCollection(LazyCollectionOption.TRUE)
  71. @BatchSize(size = 100)
  72. private Set<ProviderAttribute> attributes = new LinkedHashSet<>();
  73.  
  74. public Provider() {
  75. }
  76.  
  77. public Provider(Integer providerId) {
  78. this.providerId = providerId;
  79. }
  80.  
  81. /**
  82. * @see org.openmrs.OpenmrsObject#getId()
  83. */
  84. @Override
  85. public Integer getId() {
  86. return getProviderId();
  87. }
  88.  
  89. /**
  90. * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
  91. */
  92. @Override
  93. public void setId(Integer id) {
  94. setProviderId(id);
  95. }
  96.  
  97. /**
  98. * @param providerId the providerId to set
  99. */
  100. public void setProviderId(Integer providerId) {
  101. this.providerId = providerId;
  102. }
  103.  
  104. /**
  105. * @return the providerId
  106. */
  107. public Integer getProviderId() {
  108. return providerId;
  109. }
  110.  
  111. /**
  112. * @param person the person to set
  113. */
  114. public void setPerson(Person person) {
  115. this.person = person;
  116. }
  117.  
  118. /**
  119. * @return the person
  120. */
  121. public Person getPerson() {
  122. return person;
  123. }
  124.  
  125. /**
  126. * @param identifier the identifier to set
  127. */
  128. public void setIdentifier(String identifier) {
  129. this.identifier = identifier;
  130. }
  131.  
  132. /**
  133. * @return the identifier
  134. */
  135. public String getIdentifier() {
  136. return identifier;
  137. }
  138.  
  139. /**
  140. * Sets the role concept
  141. *
  142. * @since 2.2
  143. * @param role the role to set
  144. */
  145. public void setRole(Concept role) {
  146. this.role = role;
  147. }
  148.  
  149. /**
  150. * Gets the role concept
  151. *
  152. * @since 2.2
  153. * @return the role
  154. */
  155. public Concept getRole() {
  156. return role;
  157. }
  158.  
  159. /**
  160. * Sets the speciality concept
  161. *
  162. * @since 2.2
  163. * @param speciality the speciality to set
  164. */
  165. public void setSpeciality(Concept speciality) {
  166. this.speciality = speciality;
  167. }
  168.  
  169. /**
  170. * Gets the speciality concept
  171. *
  172. * @since 2.2
  173. * @return the speciality
  174. */
  175. public Concept getSpeciality() {
  176. return speciality;
  177. }
  178.  
  179. @Override
  180. public String toString() {
  181. String provider = String.valueOf(providerId) + " providerName:" + ((person != null) ? person.getNames() : "");
  182. return "[Provider: providerId:" + provider + " ]";
  183. }
  184.  
  185. /**
  186. * @see org.openmrs.BaseOpenmrsMetadata#getName()
  187. * <strong>Should</strong> return person full name if person is not null or null otherwise
  188. */
  189.  
  190. @Override
  191. public String getName() {
  192. if (getPerson() != null && getPerson().getPersonName() != null) {
  193. return getPerson().getPersonName().getFullName();
  194. } else {
  195. log.warn("We no longer support providers who are not linked to person. Set the name on the linked person");
  196. return null;
  197. }
  198. }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement