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

openmrs / openmrs-core / 41717832711

30 Oct 2026 04:16PM UTC coverage: 66.75% (+0.003%) from 66.747%
41717832711

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%)

419 existing lines in 31 files now uncovered.

26279 of 39369 relevant lines covered (66.75%)

0.67 hits per line

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

85.71
/api/src/main/java/org/openmrs/OrderGroup.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.List;
14
import java.util.Set;
15

16
import org.hibernate.envers.Audited;
17
import org.openmrs.api.APIException;
18
import org.openmrs.util.CollectionUtil;
19

20
/**
21
 * Contains a group of {@link org.openmrs.Order}s that are ordered together within a single encounter,often driven by an {@link org.openmrs.OrderSet}. 
22
 * Not all orders in an encounter need to be grouped this way, only those that have a specific connection to each other 
23
 * (e.g. several orders that together make up a treatment protocol for some diagnosis could be grouped).
24
 * 
25
 * @since 1.12
26
 */
27
@Audited
28
public class OrderGroup extends BaseCustomizableData<OrderGroupAttribute> {
1 ✔
29
        
30
        public static final long serialVersionUID = 72232L;
31
        
32
        private Integer orderGroupId;
33
        
34
        private Patient patient;
35
        
36
        private Encounter encounter;
37
        
38
        private List<Order> orders;
39
        
40
        private OrderSet orderSet;
41
        
42
        private OrderGroup parentOrderGroup;
43

44
        private Concept orderGroupReason;
45

46
        private OrderGroup previousOrderGroup;
47
        
48
        private Set<OrderGroup> nestedOrderGroups;
49

50
        /**
51
         * Gets the orderGroupId
52
         *
53
         * @return the orderGroupId
54
         */
55
        public Integer getOrderGroupId() {
56
                return orderGroupId;
1 ✔
57
        }
58
        
59
        /**
60
         * Sets the orderGroupId
61
         *
62
         * @param orderGroupId the orderGroupId to set
63
         */
64
        public void setOrderGroupId(Integer orderGroupId) {
65
                this.orderGroupId = orderGroupId;
1 ✔
66
        }
1 ✔
67
        
68
        /**
69
         * Gets the patient
70
         *
71
         * @return the patient
72
         */
73
        public Patient getPatient() {
74
                return patient;
1 ✔
75
        }
76
        
77
        /**
78
         * Sets the patient
79
         *
80
         * @param patient the patient to set
81
         */
82
        public void setPatient(Patient patient) {
83
                this.patient = patient;
1 ✔
84
        }
1 ✔
85
        
86
        /**
87
         * Gets the encounter
88
         *
89
         * @return the encounter
90
         */
91
        public Encounter getEncounter() {
92
                return encounter;
1 ✔
93
        }
94
        
95
        /**
96
         * Sets the encounter
97
         *
98
         * @param encounter the encounter to set
99
         */
100
        public void setEncounter(Encounter encounter) {
101
                this.encounter = encounter;
1 ✔
102
        }
1 ✔
103
        
104
        /**
105
         * Gets the orders
106
         *
107
         * @return the orders
108
         */
109
        public List<Order> getOrders() {
110
                if (orders == null) {
1 ✔
111
                        orders = new ArrayList<>();
1 ✔
112
                }
113
                return orders;
1 ✔
114
        }
115
        
116
        /**
117
         * Sets the orders
118
         *
119
         * @param orders the orders to set
120
         */
121
        public void setOrders(List<Order> orders) {
122
                this.orders = CollectionUtil.setCollection(this.orders, orders);
1 ✔
123
        }
1 ✔
124
        
125
        /**
126
         * Adds a new order to the existing list of orders
127
         * 
128
         * @param order the new order to be added
129
         */
130
        public void addOrder(Order order) {
131
                this.addOrder(order, null);
1 ✔
132
        }
1 ✔
133
        
134
        /**
135
         * Adds {@link Order}s to existing Order list
136
         * 
137
         * @param orders
138
         * @since 2.2
139
         */
140
        public void addOrders(List<Order> orders) {
141
                for (Order order : orders) {
×
142
                        addOrder(order);
×
143
                }
×
UNCOV
144
        }
×
145
        
146
        /**
147
         * Adds a new order to the existing list of orders.
148
         * The <tt>sortWeight</tt> for the order is auto calculated based on the given position.
149
         * 
150
         * @param order the new order to be added
151
         * @param position the position where the order has to be added
152
         */
153
        public void addOrder(Order order, Integer position) {
154
                if (order == null || getOrders().contains(order)) {
1 ✔
UNCOV
155
                        return;
×
156
                }
157
                
158
                order.setOrderGroup(this);  
1 ✔
159
                 
160
                Integer listIndex = findListIndexForGivenPosition(position);
1 ✔
161
                getOrders().add(listIndex, order);
1 ✔
162
                if (order.getSortWeight() == null) {
1 ✔
163
                        order.setSortWeight(findSortWeight(listIndex));
1 ✔
164
                }
165
        }
1 ✔
166
        
167
        private Integer findListIndexForGivenPosition(Integer position) {
168
                Integer size = getOrders().size();
1 ✔
169
                if (position != null) {
1 ✔
170
                        if (position < 0 && position >= (-1 - size)) {
1 ✔
171
                                position = position + size + 1;
1 ✔
172
                        } else if (position > size) {
1 ✔
173
                                throw new APIException("Cannot add a member which is out of range of the list");
1 ✔
174
                        }
175
                } else {
176
                        position = size;
1 ✔
177
                }
178
                return position;
1 ✔
179
        }
180
        
181
        private double findSortWeight(int index) {
182
                int size = getOrders().size();
1 ✔
183
                if (size == 1) {
1 ✔
184
                        return 10.0;
1 ✔
185
                }
186
                if (index == 0) {
1 ✔
187
                        return getOrders().get(1).getSortWeight() / 2;
1 ✔
188
                }
189
                if (index == size - 1) {
1 ✔
190
                        return getOrders().get(index - 1).getSortWeight() + 10.0;
1 ✔
191
                }
192
                return (getOrders().get(index - 1).getSortWeight() + getOrders().get(index + 1).getSortWeight()) / 2;
1 ✔
193
        }
194
        
195
        /**
196
         * Gets the orderSet
197
         *
198
         * @return the orderSet
199
         */
200
        public OrderSet getOrderSet() {
201
                return orderSet;
1 ✔
202
        }
203
        
204
        /**
205
         * Sets the orderSet
206
         *
207
         * @param orderSet the orderSet to set
208
         */
209
        public void setOrderSet(OrderSet orderSet) {
210
                this.orderSet = orderSet;
1 ✔
211
        }
1 ✔
212
        
213
        @Override
214
        public Integer getId() {
215
                return getOrderGroupId();
1 ✔
216
        }
217
        
218
        @Override
219
        public void setId(Integer id) {
220
                setOrderGroupId(id);
×
UNCOV
221
        }
×
222
        
223
        /**
224
         * Gets the parent order group to maintain linkages between groups and support group nesting
225
         * 
226
         * @return the parent order group
227
         * @since 2.4.0
228
         */
229
        public OrderGroup getParentOrderGroup() {
230
                return parentOrderGroup;
1 ✔
231
        }
232
        
233
        /**
234
         * Sets the parent order group to maintain linkages between groups and support group nesting
235
         * 
236
         * @param parentOrderGroup the parent order group to set.
237
         * @since 2.4.0
238
         */
239
        public void setParentOrderGroup(OrderGroup parentOrderGroup) {
240
                this.parentOrderGroup = parentOrderGroup;
1 ✔
241
        }
1 ✔
242

243
        /**
244
         * Gets the order group reason which denotes the reason why the group was
245
         * ordered
246
         * 
247
         * @return the order group reason
248
         * @since 2.4.0
249
         */
250
        public Concept getOrderGroupReason() {
251
                return orderGroupReason;
1 ✔
252
        }
253

254
        /**
255
         * Sets the order group reason which denotes the reason why the group was
256
         * ordered
257
         * 
258
         * @param orderGroupReason, the order group reason to set
259
         * @since 2.4.0
260
         */
261
        public void setOrderGroupReason(Concept orderGroupReason) {
262
                this.orderGroupReason = orderGroupReason;
1 ✔
263
        }
1 ✔
264
        
265
        /**
266
         * Gets the previous order group to other order groups, to maintain linkages
267
         * between groups and support group nesting
268
         * 
269
         * @param returns the previous order group
270
         * @since 2.4.0
271
         */
272
        public OrderGroup getPreviousOrderGroup() {
273
                return previousOrderGroup;
1 ✔
274
        }
275

276
        /**
277
         * Sets the previous order group to other order groups, to maintain linkages
278
         * between groups and support group nesting
279
         * 
280
         * @param previousOrderGroup The previous order group to set
281
         * @since 2.4.0
282
         */
283
        public void setPreviousOrderGroup(OrderGroup previousOrderGroup) {
284
                this.previousOrderGroup = previousOrderGroup;
1 ✔
285
        }
1 ✔
286
        
287
        /**
288
         * Gets the nested order groups to other order groups, to maintain linkages
289
         * between groups and support group nesting
290
         * 
291
         * @param returns the nested order groups
292
         * @since 2.4.0
293
         */
294
        public Set<OrderGroup> getNestedOrderGroups() {
295
                return this.nestedOrderGroups;
1 ✔
296
        }
297
        
298
        /**
299
         * Sets the nested order groups to other order groups, to maintain linkages
300
         * between groups and support group nesting.
301
         * 
302
         * @param nestedOrderGroup The nested order groups to set
303
         * @since 2.4.0
304
         */
305
        public void setNestedOrderGroups(Set<OrderGroup> nestedOrderGroups) {
306
                this.nestedOrderGroups = CollectionUtil.setCollection(this.nestedOrderGroups, nestedOrderGroups);
×
UNCOV
307
        }
×
308
}
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