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

openmrs / openmrs-core / 41717837886

03 Nov 2026 08:59PM UTC coverage: 68.971% (+0.05%) from 68.922%
41717837886

push

github

ibacher
TRUNK-6863: Remove the generation token before clearing a node's cache locally (#6791)

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

413 existing lines in 30 files now uncovered.

26445 of 38342 relevant lines covered (68.97%)

0.69 hits per line

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

51.35
/api/src/main/java/org/openmrs/ProgramWorkflow.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.ArrayList;
13
import java.util.Comparator;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Locale;
17
import java.util.Set;
18
import java.util.TreeSet;
19

20
import org.hibernate.envers.Audited;
21
import org.openmrs.util.CollectionUtil;
22
import org.openmrs.util.NaturalStrings;
23

24
/**
25
 * ProgramWorkflow
26
 */
27
@Audited
28
public class ProgramWorkflow extends BaseChangeableOpenmrsMetadata {
29
        
30
        private static final long serialVersionUID = 1L;
31
        
32
        // ******************
33
        // Properties
34
        // ******************
35
        
36
        private Integer programWorkflowId;
37
        
38
        private Program program;
39
        
40
        private Concept concept;
41
        
42
        private Set<ProgramWorkflowState> states = new HashSet<>();
1 ✔
43
        
44
        // ******************
45
        // Constructors
46
        // ******************
47
        
48
        /** Default Constructor */
49
        public ProgramWorkflow() {
1 ✔
50
        }
1 ✔
51
        
52
        /** Constructor with id */
53
        public ProgramWorkflow(Integer programWorkflowId) {
1 ✔
54
                setProgramWorkflowId(programWorkflowId);
1 ✔
55
        }
1 ✔
56
        
57
        // ******************
58
        // Instance methods
59
        // ******************
60
        
61
        /**
62
         * Adds a new {@link ProgramWorkflowState} to this ProgramWorkflow
63
         * 
64
         * @param state - the {@link ProgramWorkflowState} to add
65
         */
66
        public void addState(ProgramWorkflowState state) {
67
                state.setProgramWorkflow(this);
1 ✔
68
                getStates().add(state);
1 ✔
69
        }
1 ✔
70
        
71
        /**
72
         * Removes a {@link ProgramWorkflowState} from this ProgramWorkflow
73
         * 
74
         * @param state - the {@link ProgramWorkflowState} to remove
75
         */
76
        public void removeState(ProgramWorkflowState state) {
77
                if (getStates().contains(state)) {
×
78
                        getStates().remove(state);
×
UNCOV
79
                        state.setProgramWorkflow(null);
×
80
                }
UNCOV
81
        }
×
82
        
83
        /**
84
         * Retires a {@link ProgramWorkflowState}
85
         * 
86
         * @param state - the {@link ProgramWorkflowState} to retire
87
         */
88
        public void retireState(ProgramWorkflowState state) {
89
                state.setRetired(true);
×
UNCOV
90
        }
×
91
        
92
        /**
93
         * Returns a {@link ProgramWorkflowState} whose primary key id matches the input parameter
94
         * 
95
         * @param programWorkflowStateId the primary key {@link Integer} id to match
96
         * @return a {@link ProgramWorkflowState} whose identifier matches the passed
97
         *         <code>programWorkflowStateId</code>
98
         */
99
        public ProgramWorkflowState getState(Integer programWorkflowStateId) {
100
                for (ProgramWorkflowState s : getStates()) {
1 ✔
101
                        if (s.getProgramWorkflowStateId().equals(programWorkflowStateId)) {
1 ✔
102
                                return s;
1 ✔
103
                        }
104
                }
1 ✔
UNCOV
105
                return null;
×
106
        }
107
        
108
        /**
109
         * Returns a {@link ProgramWorkflowState} whose Concept matches the passed concept
110
         * 
111
         * @param concept the Concept to match
112
         * @return Returns a {@link ProgramWorkflowState} whose {@link Concept} matches the passed
113
         *         <code>concept</code>
114
         */
115
        public ProgramWorkflowState getState(Concept concept) {
116
                for (ProgramWorkflowState s : getStates()) {
1 ✔
117
                        if (s.getConcept().equals(concept)) {
1 ✔
118
                                return s;
1 ✔
119
                        }
120
                }
1 ✔
121
                return null;
1 ✔
122
        }
123
        
124
        /**
125
         * Returns a {@link ProgramWorkflowState} whose Concept name matches the passed name in any
126
         * {@link Locale}
127
         * 
128
         * @param name the Concept name to match in any {@link Locale}
129
         * @return a {@link ProgramWorkflowState} whose {@link Concept} name matches the passed
130
         *         <code>name</code>
131
         */
132
        public ProgramWorkflowState getState(String name) {
133
                for (ProgramWorkflowState s : getStates()) {
×
134
                        if (s.getConcept().isNamed(name)) {
×
UNCOV
135
                                return s;
×
136
                        }
137
                }
×
UNCOV
138
                return null;
×
139
        }
140
        
141
        /**
142
         * Returns a {@link ProgramWorkflowState} whose {@link Concept} has any {@link ConceptName} that
143
         * matches the given <code>name</code>
144
         * 
145
         * @param name the {@link ProgramWorkflowState} name, in any {@link Locale}
146
         * @return a {@link ProgramWorkflowState} which has the passed <code>name</code> in any
147
         *         {@link Locale}
148
         */
149
        public ProgramWorkflowState getStateByName(String name) {
150
                for (ProgramWorkflowState s : getStates()) {
×
151
                        if (s.getConcept().isNamed(name)) {
×
UNCOV
152
                                return s;
×
153
                        }
154
                }
×
UNCOV
155
                return null;
×
156
        }
157
        
158
        /**
159
         * Returns a Set&lt;{@link ProgramWorkflowState}&gt; including all non-retired ProgramWorkflowStates
160
         * and all retired ProgramWorkflowStates in this ProgramWorkflow if <code>includeRetired</code>
161
         * is true
162
         * 
163
         * @param includeRetired - if false, returns only non-retired {@link ProgramWorkflowState}
164
         *            objects in this ProgramWorkflow
165
         * @return Set&lt;ProgramWorkflowState&gt; - all ProgramWorkflowStates matching input parameters
166
         */
167
        public Set<ProgramWorkflowState> getStates(boolean includeRetired) {
168
                Set<ProgramWorkflowState> ret = new HashSet<>();
×
169
                for (ProgramWorkflowState s : getStates()) {
×
170
                        if (includeRetired || !s.getRetired()) {
×
UNCOV
171
                                ret.add(s);
×
172
                        }
173
                }
×
UNCOV
174
                return ret;
×
175
        }
176
        
177
        /**
178
         * Returns a Set&lt;{@link ProgramWorkflowState}&gt; including all ProgramWorkflowStates, sorted by
179
         * {@link ConceptName}
180
         * 
181
         * @return Set&lt;ProgramWorkflowState&gt; - all ProgramWorkflowStates, sorted by {@link ConceptName}
182
         * <strong>Should</strong> sort names containing numbers intelligently
183
         */
184
        public Set<ProgramWorkflowState> getSortedStates() {
185
                final Comparator<String> naturalComparator = NaturalStrings.getNaturalComparator();
1 ✔
186
                
187
                Comparator<ProgramWorkflowState> stateComparator = (o1, o2) -> naturalComparator.compare(o1.getConcept().getName().getName(), o2.getConcept().getName().getName());
1 ✔
188
                
189
                Set<ProgramWorkflowState> sorted = new TreeSet<>(stateComparator);
1 ✔
190
                if (getStates() != null) {
1 ✔
191
                        sorted.addAll(getStates());
1 ✔
192
                }
193
                return sorted;
1 ✔
194
        }
195
        
196
        /**
197
         * Returns a List&lt;{@link ProgramWorkflowState}&gt; including all possible next
198
         * ProgramWorkflowStates, for the passed {@link PatientProgram} ordered by {@link ConceptName}
199
         * 
200
         * @param patientProgram - The PatientProgram to check
201
         * @return List&lt;ProgramWorkflowState&gt; - all possible next ProgramWorkflowStates, for the passed
202
         *         {@link PatientProgram} ordered by {@link ConceptName}
203
         */
204
        public List<ProgramWorkflowState> getPossibleNextStates(PatientProgram patientProgram) {
205
                List<ProgramWorkflowState> ret = new ArrayList<>();
×
206
                PatientState currentState = patientProgram.getCurrentState(this);
×
207
                for (ProgramWorkflowState st : getSortedStates()) {
×
208
                        if (isLegalTransition(currentState == null ? null : currentState.getState(), st)) {
×
UNCOV
209
                                ret.add(st);
×
210
                        }
211
                }
×
UNCOV
212
                return ret;
×
213
        }
214
        
215
        /**
216
         * Check whether it is allowable to transition from <code>fromState</code> to
217
         * <code>toState</code>.
218
         * 
219
         * @param fromState {@link ProgramWorkflowState} to check transition from
220
         * @param toState {@link ProgramWorkflowState} to check transition to
221
         * @return boolean true if it is allowable to transition from <code>fromState</code> to
222
         *         <code>toState</code>
223
         */
224
        public boolean isLegalTransition(ProgramWorkflowState fromState, ProgramWorkflowState toState) {
225
                // If there's no current state then we need tom move into an initial state
226
                if (fromState == null) {
1 ✔
UNCOV
227
                        return toState.getInitial();
×
228
                }
229
                
230
                // Does not allow patient to move into the same state
231
                return !fromState.equals(toState);
1 ✔
232
        }
233
        
234
        /** @see Object#toString() */
235
        @Override
236
        public String toString() {
237
                return "ProgramWorkflow(id=" + getProgramWorkflowId() + ")";
1 ✔
238
        }
239
        
240
        // ******************
241
        // Property Access
242
        // ******************
243
        
244
        public Set<ProgramWorkflowState> getStates() {
245
                return states;
1 ✔
246
        }
247
        
248
        public void setStates(Set<ProgramWorkflowState> states) {
UNCOV
249
                this.states = CollectionUtil.setCollection(this.states, states);
×
UNCOV
250
        }
×
251
        
252
        public Concept getConcept() {
253
                return concept;
1 ✔
254
        }
255
        
256
        public void setConcept(Concept concept) {
257
                this.concept = concept;
1 ✔
258
        }
1 ✔
259
        
260
        public Program getProgram() {
261
                return program;
1 ✔
262
        }
263
        
264
        public void setProgram(Program program) {
265
                this.program = program;
1 ✔
266
        }
1 ✔
267
        
268
        public Integer getProgramWorkflowId() {
269
                return programWorkflowId;
1 ✔
270
        }
271
        
272
        public void setProgramWorkflowId(Integer programWorkflowId) {
273
                this.programWorkflowId = programWorkflowId;
1 ✔
274
        }
1 ✔
275
        
276
        /**
277
         * @since 1.5
278
         * @see org.openmrs.OpenmrsObject#getId()
279
         */
280
        @Override
281
        public Integer getId() {
282
                
283
                return getProgramWorkflowId();
1 ✔
284
        }
285
        
286
        /**
287
         * @since 1.5
288
         * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
289
         */
290
        @Override
291
        public void setId(Integer id) {
UNCOV
292
                setProgramWorkflowId(id);
×
293
                
UNCOV
294
        }
×
295
        
296
        /**
297
         * Gets the number of states which are not retired
298
         * 
299
         * @return the total number of non retired states
300
         * @since 1.9
301
         */
302
        public int getNonRetiredStateCount() {
UNCOV
303
                return getStates(false).size();
×
304
        }
305
}
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