Advertisement
Guest User

Untitled

a guest
Aug 15th, 2013
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14. package org.openmrs;
  15.  
  16. import java.util.Date;
  17.  
  18. import org.openmrs.util.OpenmrsUtil;
  19.  
  20. /**
  21. * PatientState
  22. */
  23. public class PatientState extends BaseOpenmrsData implements java.io.Serializable, Comparable<PatientState> {
  24.  
  25. public static final long serialVersionUID = 0L;
  26.  
  27. // ******************
  28. // Properties
  29. // ******************
  30.  
  31. private Integer patientStateId;
  32.  
  33. private PatientProgram patientProgram;
  34.  
  35. private ProgramWorkflowState state;
  36.  
  37. private Date startDate;
  38.  
  39. private Date endDate;
  40.  
  41. // ******************
  42. // Constructors
  43. // ******************
  44.  
  45. /** Default Constructor */
  46. public PatientState() {
  47. }
  48.  
  49. /** Constructor with id */
  50. public PatientState(Integer patientStateId) {
  51. setPatientStateId(patientStateId);
  52. }
  53.  
  54. /**
  55. * Does a shallow copy of this PatientState. Does NOT copy patientStateId
  56. *
  57. * @return a copy of this PatientState
  58. */
  59. public PatientState copy() {
  60. return copyHelper(new PatientState());
  61. }
  62.  
  63. /**
  64. * The purpose of this method is to allow subclasses of PatientState to delegate a portion of
  65. * their copy() method back to the superclass, in case the base class implementation changes.
  66. *
  67. * @param target a PatientState that will have the state of <code>this</code> copied into it
  68. * @return the PatientState that was passed in, with state copied into it
  69. */
  70. protected PatientState copyHelper(PatientState target) {
  71. target.setPatientProgram(this.getPatientProgram());
  72. target.setState(this.getState());
  73. target.setStartDate(this.getStartDate());
  74. target.setEndDate(this.getEndDate());
  75. target.setCreator(this.getCreator());
  76. target.setDateCreated(this.getDateCreated());
  77. target.setChangedBy(this.getChangedBy());
  78. target.setDateChanged(this.getDateChanged());
  79. target.setVoided(this.getVoided());
  80. target.setVoidedBy(this.getVoidedBy());
  81. target.setDateVoided(this.getDateVoided());
  82. target.setVoidReason(this.getVoidReason());
  83. return target;
  84. }
  85.  
  86. // ******************
  87. // Instance methods
  88. // ******************
  89.  
  90. /**
  91. * Returns true if this {@link PatientState} is active as of the passed {@link Date}
  92. *
  93. * @param onDate - {@link Date} to check for {@link PatientState} enrollment
  94. * @return boolean - true if this {@link PatientState} is active as of the passed {@link Date}
  95. * @should return false if voided and date in range
  96. * @should return false if voided and date not in range
  97. * @should return true if not voided and date in range
  98. * @should return false if not voided and date earlier than startDate
  99. * @should return false if not voided and date later than endDate
  100. * @should return true if not voided and date in range with null startDate
  101. * @should return true if not voided and date in range with null endDate
  102. * @should return true if not voided and both startDate and endDate nulled
  103. * @should compare with current date if date null
  104. */
  105. public boolean getActive(Date onDate) {
  106. if (onDate == null) {
  107. onDate = new Date();
  108. }
  109. return !getVoided() && (OpenmrsUtil.compareWithNullAsEarliest(startDate, onDate) <= 0)
  110. && (OpenmrsUtil.compareWithNullAsLatest(endDate, onDate) > 0);
  111. }
  112.  
  113. /**
  114. * Returns true if this {@link PatientState} is currently active
  115. *
  116. * @return boolean - true if this {@link PatientState} is currently active
  117. */
  118. public boolean getActive() {
  119. return getActive(null);
  120. }
  121.  
  122. /** @see Object#toString() */
  123. public String toString() {
  124. return "id=" + getPatientStateId() + ", patientProgram=" + getPatientProgram() + ", state=" + getState()
  125. + ", startDate=" + getStartDate() + ", endDate=" + getEndDate() + ", dateCreated=" + getDateCreated()
  126. + ", dateChanged=" + getDateChanged();
  127. }
  128.  
  129. // ******************
  130. // Property Access
  131. // ******************
  132.  
  133. public PatientProgram getPatientProgram() {
  134. return patientProgram;
  135. }
  136.  
  137. public void setPatientProgram(PatientProgram patientProgram) {
  138. this.patientProgram = patientProgram;
  139. }
  140.  
  141. public Integer getPatientStateId() {
  142. return patientStateId;
  143. }
  144.  
  145. public void setPatientStateId(Integer patientStatusId) {
  146. this.patientStateId = patientStatusId;
  147. }
  148.  
  149. public ProgramWorkflowState getState() {
  150. return state;
  151. }
  152.  
  153. public void setState(ProgramWorkflowState state) {
  154. this.state = state;
  155. }
  156.  
  157. public Date getEndDate() {
  158. return endDate;
  159. }
  160.  
  161. public void setEndDate(Date endDate) {
  162. this.endDate = endDate;
  163. }
  164.  
  165. public Date getStartDate() {
  166. return startDate;
  167. }
  168.  
  169. public void setStartDate(Date startDate) {
  170. this.startDate = startDate;
  171. }
  172.  
  173. /**
  174. * @since 1.5
  175. * @see org.openmrs.OpenmrsObject#getId()
  176. */
  177. public Integer getId() {
  178. return getPatientStateId();
  179. }
  180.  
  181. /**
  182. * @since 1.5
  183. * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
  184. */
  185. public void setId(Integer id) {
  186. setPatientStateId(id);
  187. }
  188.  
  189. /**
  190. * Compares by startDate with null as earliest and endDate with null as latest.
  191. *
  192. * @see java.lang.Comparable#compareTo(java.lang.Object)
  193. * @should return positive if startDates equal and this endDate null
  194. * @should return negative if this startDate null
  195. * @should pass if two states have the same start date, end date and uuid
  196. * @should return positive or negative if two states have the same start date and end date but
  197. * different uuids
  198. */
  199. @Override
  200. public int compareTo(PatientState o) {
  201. if ((OpenmrsUtil.compareWithNullAsEarliest(this.getStartDate(), o.getStartDate())) == 0) {
  202. if ((OpenmrsUtil.compareWithNullAsEarliest(this.getEndDate(), o.getEndDate())) == 0) {
  203. return java.util.UUID.fromString(this.getUuid()).compareTo(java.util.UUID.fromString(o.getUuid()));
  204. } else {
  205. System.out.println(o.getEndDate());
  206. System.out.println(o.getStartDate());
  207. System.out.println(this.getEndDate());
  208. System.out.println(this.getStartDate());
  209.  
  210. return this.getEndDate().compareTo(o.getEndDate());
  211. }
  212. } else {
  213. return this.getStartDate().compareTo(o.getStartDate());
  214. }
  215. }
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement