• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 31843719412

14 Aug 2026 09:43PM UTC coverage: 64.329% (+0.007%) from 64.322%
31843719412

push

github

ibacher
TRUNK-6717: Replace reflective BeanUtils property access with direct PersonName getters (#6431)

11 of 11 new or added lines in 1 file covered. (100.0%)

60 existing lines in 11 files now uncovered.

24629 of 38286 relevant lines covered (64.33%)

0.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.18
/api/src/main/java/org/openmrs/PatientState.java
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

14
import org.hibernate.annotations.GenericGenerator;
15
import org.hibernate.annotations.Parameter;
16
import org.hibernate.envers.Audited;
17
import org.openmrs.util.OpenmrsUtil;
18

19
import javax.persistence.Column;
20
import javax.persistence.Entity;
21
import javax.persistence.FetchType;
22
import javax.persistence.GeneratedValue;
23
import javax.persistence.GenerationType;
24
import javax.persistence.Id;
25
import javax.persistence.JoinColumn;
26
import javax.persistence.ManyToOne;
27
import javax.persistence.Table;
28

29
/**
30
 * PatientState
31
 */
32
@Entity
33
@Table(name = "patient_state")
34
@Audited
35
public class PatientState extends BaseFormRecordableOpenmrsData implements java.io.Serializable, Comparable<PatientState> {
36
        
37
        public static final long serialVersionUID = 0L;
38
        
39
        // ******************
40
        // Properties
41
        // ******************
42

43
        @Id
44
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "patient_state_id_seq")
45
        @GenericGenerator(
46
                name = "patient_state_id_seq",
47
                strategy = "native",
48
                parameters = @Parameter(name = "sequence", value = "patient_state_patient_state_id_seq")
49
        )
50
        @Column(name = "patient_state_id")
51
        private Integer patientStateId;
52

53
        @ManyToOne(fetch = FetchType.LAZY)
54
        @JoinColumn(name = "patient_program_id", nullable = false)
55
        private PatientProgram patientProgram;
56

57
        @ManyToOne(fetch = FetchType.LAZY)
58
        @JoinColumn(name = "state", nullable = false)
59
        private ProgramWorkflowState state;
60

61
        @Column(name = "start_date", length = 19)
62
        private Date startDate;
63

64
        @Column(name = "end_date", length = 19)
65
        private Date endDate;
66

67
        @ManyToOne(fetch = FetchType.LAZY)
68
        @JoinColumn(name = "encounter_id")
69
        private Encounter encounter;
70
        
71
        // ******************
72
        // Constructors
73
        // ******************
74
        
75
        /** Default Constructor */
76
        public PatientState() {
1✔
77
        }
1✔
78
        
79
        /** Constructor with id */
80
        public PatientState(Integer patientStateId) {
×
81
                setPatientStateId(patientStateId);
×
UNCOV
82
        }
×
83
        
84
        /**
85
         * Does a shallow copy of this PatientState. Does NOT copy patientStateId
86
         * 
87
         * @return a copy of this PatientState
88
         */
89
        public PatientState copy() {
90
                return copyHelper(new PatientState());
1✔
91
        }
92
        
93
        /**
94
         * The purpose of this method is to allow subclasses of PatientState to delegate a portion of
95
         * their copy() method back to the superclass, in case the base class implementation changes.
96
         * 
97
         * @param target a PatientState that will have the state of <code>this</code> copied into it
98
         * @return the PatientState that was passed in, with state copied into it
99
         */
100
        protected PatientState copyHelper(PatientState target) {
101
                target.setPatientProgram(this.getPatientProgram());
1✔
102
                target.setState(this.getState());
1✔
103
                target.setStartDate(this.getStartDate());
1✔
104
                target.setEndDate(this.getEndDate());
1✔
105
                target.setEncounter(this.getEncounter());
1✔
106
                target.setCreator(this.getCreator());
1✔
107
                target.setDateCreated(this.getDateCreated());
1✔
108
                target.setChangedBy(this.getChangedBy());
1✔
109
                target.setDateChanged(this.getDateChanged());
1✔
110
                target.setVoided(this.getVoided());
1✔
111
                target.setVoidedBy(this.getVoidedBy());
1✔
112
                target.setDateVoided(this.getDateVoided());
1✔
113
                target.setVoidReason(this.getVoidReason());
1✔
114
                return target;
1✔
115
        }
116
        
117
        // ******************
118
        // Instance methods
119
        // ******************
120
        
121
        /**
122
         * Returns true if this {@link PatientState} is active as of the passed {@link Date}
123
         * 
124
         * @param onDate - {@link Date} to check for {@link PatientState} enrollment
125
         * @return boolean - true if this {@link PatientState} is active as of the passed {@link Date}
126
         * <strong>Should</strong> return false if voided and date in range
127
         * <strong>Should</strong> return false if voided and date not in range
128
         * <strong>Should</strong> return true if not voided and date in range
129
         * <strong>Should</strong> return false if not voided and date earlier than startDate
130
         * <strong>Should</strong> return false if not voided and date later than endDate
131
         * <strong>Should</strong> return true if not voided and date in range with null startDate
132
         * <strong>Should</strong> return true if not voided and date in range with null endDate
133
         * <strong>Should</strong> return true if not voided and both startDate and endDate nulled
134
         * <strong>Should</strong> compare with current date if date null
135
         */
136
        public boolean getActive(Date onDate) {
137
                if (onDate == null) {
1✔
138
                        onDate = new Date();
1✔
139
                }
140
                return !getVoided() && (OpenmrsUtil.compareWithNullAsEarliest(startDate, onDate) <= 0)
1✔
141
                        && (OpenmrsUtil.compareWithNullAsLatest(endDate, onDate) > 0);
1✔
142
        }
143
        
144
        /**
145
         * Returns true if this {@link PatientState} is currently active
146
         * 
147
         * @return boolean - true if this {@link PatientState} is currently active
148
         */
149
        public boolean getActive() {
UNCOV
150
                return getActive(null);
×
151
        }
152
        
153
        /** @see Object#toString() */
154
        @Override
155
        public String toString() {
156
                return "id=" + getPatientStateId() + ", patientProgram=" + getPatientProgram() + ", state=" + getState()
×
157
                        + ", startDate=" + getStartDate() + ", endDate=" + getEndDate() + ", encounter=" + getEncounter() + ", dateCreated=" + getDateCreated()
×
UNCOV
158
                        + ", dateChanged=" + getDateChanged();
×
159
        }
160
        
161
        // ******************
162
        // Property Access
163
        // ******************
164
        
165
        public PatientProgram getPatientProgram() {
166
                return patientProgram;
1✔
167
        }
168
        
169
        public void setPatientProgram(PatientProgram patientProgram) {
170
                this.patientProgram = patientProgram;
1✔
171
        }
1✔
172
        
173
        public Integer getPatientStateId() {
174
                return patientStateId;
1✔
175
        }
176
        
177
        public void setPatientStateId(Integer patientStatusId) {
178
                this.patientStateId = patientStatusId;
×
UNCOV
179
        }
×
180
        
181
        public ProgramWorkflowState getState() {
182
                return state;
1✔
183
        }
184
        
185
        public void setState(ProgramWorkflowState state) {
186
                this.state = state;
1✔
187
        }
1✔
188
        
189
        public Date getEndDate() {
190
                return endDate;
1✔
191
        }
192
        
193
        public void setEndDate(Date endDate) {
194
                this.endDate = endDate;
1✔
195
        }
1✔
196
        
197
        public Date getStartDate() {
198
                return startDate;
1✔
199
        }
200
        
201
        public void setStartDate(Date startDate) {
202
                this.startDate = startDate;
1✔
203
        }
1✔
204

205
        /**
206
         * @since 2.5
207
         * @return encounter - the associated encounter
208
         */
209
        public Encounter getEncounter() {
210
                return encounter;
1✔
211
        }
212

213
        /**
214
         * @since 2.5
215
         * @param encounter - the encounter to set
216
         */
217
        public void setEncounter(Encounter encounter) {
218
                this.encounter = encounter;
1✔
219
        }
1✔
220

221
        /**
222
         * @since 1.5
223
         * @see org.openmrs.OpenmrsObject#getId()
224
         */
225
        @Override
226
        public Integer getId() {
UNCOV
227
                return getPatientStateId();
×
228
        }
229
        
230
        /**
231
         * @since 1.5
232
         * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
233
         */
234
        @Override
235
        public void setId(Integer id) {
236
                setPatientStateId(id);
×
UNCOV
237
        }
×
238
        
239
        /**
240
         * Compares by startDate with null as earliest and endDate with null as latest.
241
         * 
242
         * @see java.lang.Comparable#compareTo(java.lang.Object)
243
         * <strong>Should</strong> return positive if startDates equal and this endDate null
244
         * <strong>Should</strong> return negative if this startDate null
245
         * <strong>Should</strong> pass if two states have the same start date, end date and uuid
246
         * <strong>Should</strong> return positive or negative if two states have the same start date and end date but different uuids
247
         * Note: this comparator imposes orderings that are inconsistent with equals.
248
         */
249
        @SuppressWarnings("squid:S1210")
250
        @Override
251
        public int compareTo(PatientState o) {
252
                int result = OpenmrsUtil.compareWithNullAsEarliest(getStartDate(), o.getStartDate());
1✔
253
                if (result == 0) {
1✔
254
                        result = OpenmrsUtil.compareWithNullAsLatest(getEndDate(), o.getEndDate());
1✔
255
                }
256
                if (result == 0) {
1✔
257
                        result = OpenmrsUtil.compareWithNullAsGreatest(getUuid(), o.getUuid());
1✔
258
                }
259
                return result;
1✔
260
        }
261
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc