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

openmrs / openmrs-core / 18842842547

27 Oct 2025 01:35PM UTC coverage: 64.894% (+0.008%) from 64.886%
18842842547

push

github

web-flow
TRUNK-6448: Orders: Allow setting Order Number and Stopping Inactive Orders Based On Global Property (#5418)

17 of 23 new or added lines in 4 files covered. (73.91%)

1 existing line in 1 file now uncovered.

23435 of 36113 relevant lines covered (64.89%)

0.65 hits per line

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

95.93
/api/src/main/java/org/openmrs/Order.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 org.hibernate.envers.Audited;
13
import org.openmrs.api.APIException;
14
import org.openmrs.api.db.hibernate.HibernateUtil;
15
import org.openmrs.order.OrderUtil;
16
import org.openmrs.util.ConfigUtil;
17
import org.openmrs.util.OpenmrsConstants;
18
import org.openmrs.util.OpenmrsUtil;
19

20
import java.util.Date;
21

22
/**
23
 * Encapsulates information about the clinical action of a provider requesting something for a
24
 * patient e.g requesting a test to be performed, prescribing a medication, requesting the patient
25
 * to enroll on a specific diet etc. There is the notion of effective dates, these are used to
26
 * determine the span of an order's schedule i.e its effective start and stop dates therefore dates
27
 * should be interpreted as follows: The effective start of the schedule is the scheduledDate if
28
 * urgency is set to ON_SCHEDULED_DATE otherwise it is the dateActivated; the effective end date is
29
 * dateStopped, if it is null then it is the autoExpireDate. For DrugOrders, if the autoExpireDate
30
 * is not specified then it will be calculated and set by the API based on the duration and
31
 * frequency, note that frequency is only used in case duration is specified as a recurring interval
32
 * e.g. 3 times.
33
 * 
34
 * @version 1.0
35
 */
36
@Audited
37
public class Order extends BaseCustomizableData<OrderAttribute> implements FormRecordable {
38
        
39
        public static final long serialVersionUID = 4334343L;
40

41
        /**
42
         * @since 1.9.2, 1.10
43
         */
44
        public enum Urgency {
1✔
45
                ROUTINE,
1✔
46
                STAT,
1✔
47
                ON_SCHEDULED_DATE
1✔
48
        }
49
        
50
        /**
51
         * @since 1.10
52
         */
53
        public enum Action {
1✔
54
                NEW,
1✔
55
                REVISE,
1✔
56
                DISCONTINUE,
1✔
57
                RENEW
1✔
58
        }
59
        
60
        /**
61
         * Valid values for the status of an order that is received from a filler
62
         * @since 2.2.0
63
         * @since 2.6.1 added ON_HOLD & DECLINED
64
         */
65
        public enum FulfillerStatus {
1✔
66
                RECEIVED,
1✔
67
                IN_PROGRESS,
1✔
68
                EXCEPTION,
1✔
69
                ON_HOLD,
1✔
70
                DECLINED,
1✔
71
                COMPLETED
1✔
72
        }
73
        
74
        private Integer orderId;
75
        
76
        private Patient patient;
77
        
78
        private OrderType orderType;
79
        
80
        private Concept concept;
81
        
82
        private String instructions;
83
        
84
        private Date dateActivated;
85
        
86
        private Date autoExpireDate;
87
        
88
        private Encounter encounter;
89
        
90
        private Provider orderer;
91
        
92
        private Date dateStopped;
93
        
94
        private Concept orderReason;
95
        
96
        private String accessionNumber;
97
        
98
        private String orderReasonNonCoded;
99
        
100
        private Urgency urgency = Urgency.ROUTINE;
1✔
101
        
102
        private String orderNumber;
103
        
104
        private String commentToFulfiller;
105
        
106
        private CareSetting careSetting;
107
        
108
        private Date scheduledDate;
109
        
110
        private String formNamespaceAndPath;
111
        
112
        /**
113
         * Allows the orders if ordered as an orderGroup, to maintain a sequence of how members are
114
         * added in the group ex - for two orders of isoniazid and ampicillin, the sequence of 1 and 2
115
         * needed to be maintained
116
         */
117
        private Double sortWeight;
118
        
119
        /**
120
         * Allows orders to be linked to a previous order - e.g., an order discontinue ampicillin linked
121
         * to the original ampicillin order (the D/C gets its own order number)
122
         */
123
        private Order previousOrder;
124
        
125
        /**
126
         * Represents the action being taken on an order.
127
         * 
128
         * @see org.openmrs.Order.Action
129
         */
130
        private Action action = Action.NEW;
1✔
131
        
132
        /**
133
         * {@link org.openmrs.OrderGroup}
134
         */
135
        private OrderGroup orderGroup;
136
        
137
        /**
138
         * Represents the status of an order received from a fulfiller 
139
         * @see FulfillerStatus
140
         */
141
        private FulfillerStatus fulfillerStatus;
142
        
143
        /**
144
         * Represents the comment that goes along with with fulfiller status
145
         */        
146
        private String fulfillerComment;
147

148
        // Constructors
149
        
150
        /** default constructor */
151
        public Order() {
1✔
152
        }
1✔
153
        
154
        /** constructor with id */
155
        public Order(Integer orderId) {
1✔
156
                this.orderId = orderId;
1✔
157
        }
1✔
158
        
159
        /**
160
         * Performs a shallow copy of this Order. Does NOT copy orderId.
161
         * 
162
         * @return a shallow copy of this Order
163
         * <strong>Should</strong> copy all fields
164
         */
165
        public Order copy() {
166
                return copyHelper(new Order());
1✔
167
        }
168
        
169
        /**
170
         * The purpose of this method is to allow subclasses of Order to delegate a portion of their
171
         * copy() method back to the superclass, in case the base class implementation changes.
172
         * 
173
         * @param target an Order that will have the state of <code>this</code> copied into it
174
         * @return Returns the Order that was passed in, with state copied into it
175
         */
176
        protected Order copyHelper(Order target) {
177
                target.setPatient(getPatient());
1✔
178
                target.setOrderType(getOrderType());
1✔
179
                target.setConcept(getConcept());
1✔
180
                target.setInstructions(getInstructions());
1✔
181
                target.setDateActivated(getDateActivated());
1✔
182
                target.setAutoExpireDate(getAutoExpireDate());
1✔
183
                target.setEncounter(getEncounter());
1✔
184
                target.setOrderer(getOrderer());
1✔
185
                target.setCreator(getCreator());
1✔
186
                target.setDateCreated(getDateCreated());
1✔
187
                target.dateStopped = getDateStopped();
1✔
188
                target.setOrderReason(getOrderReason());
1✔
189
                target.setOrderReasonNonCoded(getOrderReasonNonCoded());
1✔
190
                target.setAccessionNumber(getAccessionNumber());
1✔
191
                target.setVoided(getVoided());
1✔
192
                target.setVoidedBy(getVoidedBy());
1✔
193
                target.setDateVoided(getDateVoided());
1✔
194
                target.setVoidReason(getVoidReason());
1✔
195
                target.setUrgency(getUrgency());
1✔
196
                target.setCommentToFulfiller(getCommentToFulfiller());
1✔
197
                target.previousOrder = getPreviousOrder();
1✔
198
                target.action = getAction();
1✔
199
                target.orderNumber = getOrderNumber();
1✔
200
                target.setCareSetting(getCareSetting());
1✔
201
                target.setChangedBy(getChangedBy());
1✔
202
                target.setDateChanged(getDateChanged());
1✔
203
                target.setScheduledDate(getScheduledDate());
1✔
204
                target.setOrderGroup(getOrderGroup());
1✔
205
                target.setSortWeight(getSortWeight());
1✔
206
                target.setFulfillerComment(getFulfillerComment());
1✔
207
                target.setFulfillerStatus(getFulfillerStatus());
1✔
208
                target.setFormNamespaceAndPath(getFormNamespaceAndPath());
1✔
209
                return target;
1✔
210
        }
211
        
212
        // Property accessors
213
        
214
        /**
215
         * @return Returns the autoExpireDate.
216
         */
217
        public Date getAutoExpireDate() {
218
                return autoExpireDate;
1✔
219
        }
220
        
221
        /**
222
         * @param autoExpireDate The autoExpireDate to set.
223
         */
224
        public void setAutoExpireDate(Date autoExpireDate) {
225
                this.autoExpireDate = autoExpireDate;
1✔
226
        }
1✔
227
        
228
        /**
229
         * @return Returns the concept.
230
         */
231
        public Concept getConcept() {
232
                return concept;
1✔
233
        }
234
        
235
        /**
236
         * @param concept The concept to set.
237
         */
238
        public void setConcept(Concept concept) {
239
                this.concept = concept;
1✔
240
        }
1✔
241
        
242
        /**
243
         * @return the scheduledDate
244
         * @since 1.10
245
         */
246
        public Date getScheduledDate() {
247
                return scheduledDate;
1✔
248
        }
249
        
250
        /**
251
         * @param scheduledDate the date to set
252
         * @since 1.10
253
         */
254
        public void setScheduledDate(Date scheduledDate) {
255
                this.scheduledDate = scheduledDate;
1✔
256
        }
1✔
257
        
258
        /**
259
         * @return Returns the dateStopped.
260
         * @since 1.10
261
         */
262
        public Date getDateStopped() {
263
                return dateStopped;
1✔
264
        }
265
        
266
        /**
267
         * Set the dateStopped
268
         *  
269
         * @since 2.7.8, 2.8.2
270
         * @param dateStopped
271
         */
272
        public void setDateStopped(Date dateStopped) {
NEW
273
                this.dateStopped = dateStopped;
×
NEW
274
        }
×
275

276
        /**
277
         * @return Returns the orderReason.
278
         */
279
        public Concept getOrderReason() {
280
                return orderReason;
1✔
281
        }
282
        
283
        /**
284
         * @param orderReason The orderReason to set.
285
         */
286
        public void setOrderReason(Concept orderReason) {
287
                this.orderReason = orderReason;
1✔
288
        }
1✔
289
        
290
        /**
291
         * @return Returns the encounter.
292
         */
293
        public Encounter getEncounter() {
294
                return encounter;
1✔
295
        }
296
        
297
        /**
298
         * @param encounter The encounter to set.
299
         */
300
        public void setEncounter(Encounter encounter) {
301
                this.encounter = encounter;
1✔
302
        }
1✔
303
        
304
        /**
305
         * @return Returns the instructions.
306
         */
307
        public String getInstructions() {
308
                return instructions;
1✔
309
        }
310
        
311
        /**
312
         * @param instructions The instructions to set.
313
         */
314
        public void setInstructions(String instructions) {
315
                this.instructions = instructions;
1✔
316
        }
1✔
317
        
318
        /**
319
         * @return Returns the accessionNumber.
320
         */
321
        public String getAccessionNumber() {
322
                return accessionNumber;
1✔
323
        }
324
        
325
        /**
326
         * @param accessionNumber The accessionNumber to set.
327
         */
328
        public void setAccessionNumber(String accessionNumber) {
329
                this.accessionNumber = accessionNumber;
1✔
330
        }
1✔
331
        
332
        /**
333
         * @return Returns the orderer.
334
         */
335
        public Provider getOrderer() {
336
                return orderer;
1✔
337
        }
338
        
339
        /**
340
         * @param orderer The orderer to set.
341
         */
342
        public void setOrderer(Provider orderer) {
343
                this.orderer = orderer;
1✔
344
        }
1✔
345
        
346
        /**
347
         * @return Returns the orderId.
348
         */
349
        public Integer getOrderId() {
350
                return orderId;
1✔
351
        }
352
        
353
        /**
354
         * @param orderId The orderId to set.
355
         */
356
        public void setOrderId(Integer orderId) {
357
                this.orderId = orderId;
1✔
358
        }
1✔
359
        
360
        /**
361
         * @return Returns the dateActivated.
362
         */
363
        public Date getDateActivated() {
364
                return dateActivated;
1✔
365
        }
366
        
367
        /**
368
         * @param dateActivated The dateActivated to set.
369
         */
370
        public void setDateActivated(Date dateActivated) {
371
                this.dateActivated = dateActivated;
1✔
372
        }
1✔
373
        
374
        /**
375
         * @return Returns the orderReasonNonCoded.
376
         */
377
        public String getOrderReasonNonCoded() {
378
                return orderReasonNonCoded;
1✔
379
        }
380
        
381
        /**
382
         * @param orderReasonNonCoded The orderReasonNonCoded to set.
383
         */
384
        public void setOrderReasonNonCoded(String orderReasonNonCoded) {
385
                this.orderReasonNonCoded = orderReasonNonCoded;
1✔
386
        }
1✔
387
        
388
        /**
389
         * @return the commentToFulfiller
390
         * @since 1.10
391
         */
392
        public String getCommentToFulfiller() {
393
                return commentToFulfiller;
1✔
394
        }
395
        
396
        /**
397
         * @param commentToFulfiller The commentToFulfiller to set
398
         * @since 1.10
399
         */
400
        public void setCommentToFulfiller(String commentToFulfiller) {
401
                this.commentToFulfiller = commentToFulfiller;
1✔
402
        }
1✔
403
        
404
        /**
405
         * Convenience method to determine if the order is activated as of the current date
406
         * 
407
         * @return boolean indicating whether the order was activated before or on the current date
408
         * @since 2.0
409
         * @see #isActivated(java.util.Date)
410
         */
411
        public boolean isActivated() {
412
                return isActivated(new Date());
×
413
        }
414
        
415
        /**
416
         * Convenience method to determine if the order is activated as of the specified date
417
         * 
418
         * @param checkDate - the date on which to check order. if null, will use current date
419
         * @return boolean indicating whether the order was activated before or on the check date
420
         * @since 2.0
421
         * <strong>Should</strong> return true if an order was activated on the check date
422
         * <strong>Should</strong> return true if an order was activated before the check date
423
         * <strong>Should</strong> return false if dateActivated is null
424
         * <strong>Should</strong> return false for an order activated after the check date
425
         */
426
        public boolean isActivated(Date checkDate) {
427
                if (dateActivated == null) {
1✔
428
                        return false;
1✔
429
                }
430
                if (checkDate == null) {
1✔
431
                        checkDate = new Date();
×
432
                }
433
                return OpenmrsUtil.compare(dateActivated, checkDate) <= 0;
1✔
434
        }
435
        
436
        /**
437
         * Convenience method to determine if the order was active as of the current date
438
         * 
439
         * @since 1.10.1
440
         * @return boolean indicating whether the order was active on the check date
441
         */
442
        public boolean isActive() {
443
                return isActive(new Date());
1✔
444
        }
445
        
446
        /**
447
         * Convenience method to determine if the order is active as of the specified date
448
         * 
449
         * @param aCheckDate - the date on which to check order. if null, will use current date
450
         * @return boolean indicating whether the order was active on the check date
451
         * @since 1.10.1
452
         * <strong>Should</strong> return true if an order expired on the check date
453
         * <strong>Should</strong> return true if an order was discontinued on the check date
454
         * <strong>Should</strong> return true if an order was activated on the check date
455
         * <strong>Should</strong> return true if an order was activated on the check date but scheduled for the future
456
         * <strong>Should</strong> return false for a voided order
457
         * <strong>Should</strong> return false for a discontinued order
458
         * <strong>Should</strong> return false for an expired order
459
         * <strong>Should</strong> return false for an order activated after the check date
460
         * <strong>Should</strong> return false for a discontinuation order
461
         */
462
        public boolean isActive(Date aCheckDate) {
463
                if (getVoided() || action == Action.DISCONTINUE) {
1✔
464
                        return false;
1✔
465
                }
466
                Date checkDate = aCheckDate == null ? new Date() : aCheckDate;
1✔
467
                return isActivated(checkDate) && !isDiscontinued(checkDate) && !isExpired(checkDate);
1✔
468
        }
469
        
470
        /**
471
         * Convenience method to determine if order is started as of the current date
472
         * 
473
         * @return boolean indicating whether the order is started as of the current date
474
         * @since 1.10.1
475
         * @see #isStarted(java.util.Date)
476
         */
477
        public boolean isStarted() {
478
                return isStarted(new Date());
1✔
479
        }
480
        
481
        /**
482
         * Convenience method to determine if the order is started as of the specified date, returns
483
         * true only if the order has been activated. In case of scheduled orders, the scheduledDate
484
         * becomes the effective start date that gets used to determined if it is started.
485
         * 
486
         * @param aCheckDate - the date on which to check order. if null, will use current date
487
         * @return boolean indicating whether the order is started as of the check date
488
         * @since 1.10.1
489
         * <strong>Should</strong> return false for a voided order
490
         * <strong>Should</strong> return false if dateActivated is null
491
         * <strong>Should</strong> return false if the order is not yet activated as of the check date
492
         * <strong>Should</strong> return false if the order was scheduled to start after the check date
493
         * <strong>Should</strong> return true if the order was scheduled to start on the check date
494
         * <strong>Should</strong> return true if the order was scheduled to start before the check date
495
         * <strong>Should</strong> return true if the order is started and not scheduled
496
         */
497
        public boolean isStarted(Date aCheckDate) {
498
                if (getVoided()) {
1✔
499
                        return false;
1✔
500
                }
501
                if (getEffectiveStartDate() == null) {
1✔
502
                        return false;
1✔
503
                }
504
                Date checkDate = aCheckDate == null ? new Date() : aCheckDate;
1✔
505
                return !checkDate.before(getEffectiveStartDate());
1✔
506
        }
507
        
508
        /**
509
         * Convenience method to determine if the order is discontinued as of the specified date
510
         * 
511
         * @param aCheckDate - the date on which to check order. if null, will use current date
512
         * @return boolean indicating whether the order was discontinued on the input date
513
         * <strong>Should</strong> return false for a voided order
514
         * <strong>Should</strong> return false if date stopped and auto expire date are both null
515
         * <strong>Should</strong> return false if auto expire date is null and date stopped is equal to check date
516
         * <strong>Should</strong> return false if auto expire date is null and date stopped is after check date
517
         * <strong>Should</strong> return false if dateActivated is after check date
518
         * <strong>Should</strong> return true if auto expire date is null and date stopped is before check date
519
         * <strong>Should</strong> fail if date stopped is after auto expire date
520
         * <strong>Should</strong> return true if check date is after date stopped but before auto expire date
521
         * <strong>Should</strong> return true if check date is after both date stopped auto expire date
522
         * <strong>Should</strong> return true if the order is scheduled for the future and activated on check date but
523
         *         the check date is after date stopped
524
         */
525
        public boolean isDiscontinued(Date aCheckDate) {
526
                if (dateStopped != null && autoExpireDate != null && dateStopped.after(autoExpireDate)) {
1✔
527
                        throw new APIException("Order.error.invalidDateStoppedAndAutoExpireDate", (Object[]) null);
1✔
528
                }
529
                if (getVoided()) {
1✔
530
                        return false;
1✔
531
                }
532
                Date checkDate = aCheckDate == null ? new Date() : aCheckDate;
1✔
533
                if (!isActivated(checkDate) || dateStopped == null) {
1✔
534
                        return false;
1✔
535
                }
536
                return checkDate.after(dateStopped);
1✔
537
        }
538
        
539
        /**
540
         * Convenience method to determine if the order is expired as of the specified date
541
         * 
542
         * @return boolean indicating whether the order is expired at the current time
543
         * @since 1.10.1
544
         */
545
        public boolean isExpired() {
546
                return isExpired(new Date());
×
547
        }
548
        
549
        /**
550
         * Convenience method to determine if order was expired at a given time
551
         * 
552
         * @param aCheckDate - the date on which to check order. if null, will use current date
553
         * @return boolean indicating whether the order was expired on the input date
554
         * <strong>Should</strong> return false for a voided order
555
         * <strong>Should</strong> return false if date stopped and auto expire date are both null
556
         * <strong>Should</strong> return false if date stopped is null and auto expire date is equal to check date
557
         * <strong>Should</strong> return false if date stopped is null and auto expire date is after check date
558
         * <strong>Should</strong> return false if check date is after both date stopped auto expire date
559
         * <strong>Should</strong> return false if dateActivated is after check date
560
         * <strong>Should</strong> return false if check date is after date stopped but before auto expire date
561
         * <strong>Should</strong> fail if date stopped is after auto expire date
562
         * <strong>Should</strong> return true if date stopped is null and auto expire date is before check date
563
         * @since 1.10.1
564
         */
565
        public boolean isExpired(Date aCheckDate) {
566
                if (dateStopped != null && autoExpireDate != null && dateStopped.after(autoExpireDate)) {
1✔
567
                        throw new APIException("Order.error.invalidDateStoppedAndAutoExpireDate", (Object[]) null);
1✔
568
                }
569
                if (getVoided()) {
1✔
570
                        return false;
1✔
571
                }
572
                Date checkDate = aCheckDate == null ? new Date() : aCheckDate;
1✔
573
                if (!isActivated(checkDate)) {
1✔
574
                        return false;
1✔
575
                }
576
                if (isDiscontinued(checkDate) || autoExpireDate == null) {
1✔
577
                        return false;
1✔
578
                }
579

580
                return checkDate.after(autoExpireDate);
1✔
581
        }
582
        
583
        /*
584
         * orderForm:jsp: <spring:bind path="order.discontinued" /> results in a call to
585
         * isDiscontinued() which doesn't give access to the discontinued property so renamed it to
586
         * isDiscontinuedRightNow which results in a call to getDiscontinued.
587
         * @since 1.5
588
         */
589
        public boolean isDiscontinuedRightNow() {
590
                return isDiscontinued(new Date());
1✔
591
        }
592
        
593
        public Patient getPatient() {
594
                return patient;
1✔
595
        }
596
        
597
        public void setPatient(Patient patient) {
598
                this.patient = patient;
1✔
599
        }
1✔
600
        
601
        @Override
602
        public Integer getId() {
603
                return getOrderId();
1✔
604
        }
605
        
606
        /**
607
         * @see java.lang.Object#toString()
608
         */
609
        @Override
610
        public String toString() {
611
                String prefix = Action.DISCONTINUE == getAction() ? "DC " : "";
1✔
612
                return prefix + "Order. orderId: " + orderId + " patient: " + patient + " concept: " + concept + " care setting: "
1✔
613
                        + careSetting;
614
        }
615
        
616
        /**
617
         * @since 1.5
618
         * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
619
         */
620
        @Override
621
        public void setId(Integer id) {
622
                setOrderId(id);
×
623
        }
×
624
        
625
        /**
626
         * @return the urgency
627
         * @since 1.9.2
628
         */
629
        public Urgency getUrgency() {
630
                return urgency;
1✔
631
        }
632
        
633
        /**
634
         * @param urgency the urgency to set
635
         * @since 1.9.2
636
         */
637
        public void setUrgency(Urgency urgency) {
638
                this.urgency = urgency;
1✔
639
        }
1✔
640
        
641
        /**
642
         * @return the orderNumber
643
         * @since 1.10
644
         */
645
        public String getOrderNumber() {
646
                return orderNumber;
1✔
647
        }
648

649
        /**
650
         * Sets the orderNumber
651
         * 
652
         * @since 2.7.8, 2.8.2
653
         * @param orderNumber
654
         */
655
        public void setOrderNumber(String orderNumber) {
656
                if (this.orderNumber != null && !orderNumber.equals(this.orderNumber)) {
1✔
657
                        throw new APIException("Unable to modify order number");
1✔
658
                }
659
                if (!ConfigUtil.getProperty(OpenmrsConstants.GP_ALLOW_SETTING_ORDER_NUMBER, false) 
1✔
660
                        && this.orderNumber == null && orderNumber != null) {
661
                        throw new APIException("Unable to set order number because GP_ALLOW_SETTING_ORDER_NUMBER is set to false");
1✔
662
                } 
663
                this.orderNumber = orderNumber;
1✔
664
        }
1✔
665
        
666
        /**
667
         * Gets the previous related order.
668
         * 
669
         * @since 1.10
670
         * @return the previous order.
671
         */
672
        public Order getPreviousOrder() {
673
                return HibernateUtil.getRealObjectFromProxy(previousOrder);
1✔
674
        }
675
        
676
        /**
677
         * Sets the previous order.
678
         * 
679
         * @since 1.10
680
         * @param previousOrder the previous order to set.
681
         */
682
        public void setPreviousOrder(Order previousOrder) {
683
                this.previousOrder = previousOrder;
1✔
684
        }
1✔
685
        
686
        /**
687
         * Gets the action
688
         * 
689
         * @return the action
690
         * @since 1.10
691
         */
692
        public Action getAction() {
693
                return action;
1✔
694
        }
695
        
696
        /**
697
         * Sets the ation
698
         * 
699
         * @param action the action to set
700
         * @since 1.10
701
         */
702
        public void setAction(Action action) {
703
                this.action = action;
1✔
704
        }
1✔
705
        
706
        /**
707
         * Gets the careSetting
708
         * 
709
         * @return the action
710
         * @since 1.10
711
         */
712
        public CareSetting getCareSetting() {
713
                return careSetting;
1✔
714
        }
715
        
716
        /**
717
         * Sets the careSetting
718
         * 
719
         * @param careSetting the action to set
720
         * @since 1.10
721
         */
722
        public void setCareSetting(CareSetting careSetting) {
723
                this.careSetting = careSetting;
1✔
724
        }
1✔
725
        
726
        /**
727
         * Get the {@link org.openmrs.OrderType}
728
         * 
729
         * @return the {@link org.openmrs.OrderType}
730
         */
731
        public OrderType getOrderType() {
732
                return orderType;
1✔
733
        }
734
        
735
        /**
736
         * Set the {@link org.openmrs.OrderType}
737
         * 
738
         * @param orderType the {@link org.openmrs.OrderType}
739
         */
740
        public void setOrderType(OrderType orderType) {
741
                this.orderType = orderType;
1✔
742
        }
1✔
743
        
744
        /**
745
         * Creates a discontinuation order for this order, sets the previousOrder and action fields,
746
         * note that the discontinuation order needs to be saved for the discontinuation to take effect
747
         * 
748
         * @return the newly created order
749
         * @since 1.10
750
         * <strong>Should</strong> set all the relevant fields
751
         */
752
        public Order cloneForDiscontinuing() {
753
                Order newOrder = new Order();
1✔
754
                newOrder.setCareSetting(getCareSetting());
1✔
755
                newOrder.setConcept(getConcept());
1✔
756
                newOrder.setAction(Action.DISCONTINUE);
1✔
757
                newOrder.setPreviousOrder(this);
1✔
758
                newOrder.setPatient(getPatient());
1✔
759
                newOrder.setOrderType(getOrderType());
1✔
760
                
761
                return newOrder;
1✔
762
        }
763
        
764
        /**
765
         * Creates an order for revision from this order, sets the previousOrder and action field.
766
         * 
767
         * @return the newly created order
768
         * @since 1.10
769
         * <strong>Should</strong> set all the relevant fields
770
         * <strong>Should</strong> set the relevant fields for a DC order
771
         */
772
        public Order cloneForRevision() {
773
                return cloneForRevisionHelper(new Order());
1✔
774
        }
775
        
776
        /**
777
         * The purpose of this method is to allow subclasses of Order to delegate a portion of their
778
         * cloneForRevision() method back to the superclass, in case the base class implementation
779
         * changes.
780
         * 
781
         * @param target an Order that will have the state of <code>this</code> copied into it
782
         * @return Returns the Order that was passed in, with state copied into it
783
         */
784
        protected Order cloneForRevisionHelper(Order target) {
785
                if (getAction() == Action.DISCONTINUE) {
1✔
786
                        target.setAction(Action.DISCONTINUE);
1✔
787
                        target.setPreviousOrder(getPreviousOrder());
1✔
788
                        target.setDateActivated(getDateActivated());
1✔
789
                } else {
790
                        target.setAction(Action.REVISE);
1✔
791
                        target.setPreviousOrder(this);
1✔
792
                        target.setAutoExpireDate(getAutoExpireDate());
1✔
793
                }
794
                target.setCareSetting(getCareSetting());
1✔
795
                target.setConcept(getConcept());
1✔
796
                target.setPatient(getPatient());
1✔
797
                target.setOrderType(getOrderType());
1✔
798
                target.setScheduledDate(getScheduledDate());
1✔
799
                target.setInstructions(getInstructions());
1✔
800
                target.setUrgency(getUrgency());
1✔
801
                target.setCommentToFulfiller(getCommentToFulfiller());
1✔
802
                target.setOrderReason(getOrderReason());
1✔
803
                target.setOrderReasonNonCoded(getOrderReasonNonCoded());
1✔
804
                target.setOrderGroup(getOrderGroup());
1✔
805
                target.setSortWeight(getSortWeight());
1✔
806
                target.setFulfillerStatus(getFulfillerStatus());
1✔
807
                target.setFulfillerComment(getFulfillerComment());
1✔
808
                target.setFormNamespaceAndPath(getFormNamespaceAndPath());
1✔
809
                
810
                return target;
1✔
811
        }
812
        
813
        /**
814
         * Checks whether this order's orderType matches or is a sub type of the specified one
815
         * 
816
         * @since 1.10
817
         * @param orderType the orderType to match on
818
         * @return true if the type of the order matches or is a sub type of the other order
819
         * <strong>Should</strong> true if it is the same or is a subtype
820
         * <strong>Should</strong> false if it neither the same nor a subtype
821
         */
822
        public boolean isType(OrderType orderType) {
823
                return OrderUtil.isType(orderType, this.orderType);
1✔
824
        }
825
        
826
        /**
827
         * Checks whether orderable of this order is same as other order
828
         * 
829
         * @see org.openmrs.DrugOrder for overridden behaviour
830
         * @since 1.10
831
         * @param otherOrder the other order to match on
832
         * @return true if the concept of the orders match
833
         * <strong>Should</strong> return false if the concept of the orders do not match
834
         * <strong>Should</strong> return false if other order is null
835
         * <strong>Should</strong> return true if the orders have the same concept
836
         */
837
        public boolean hasSameOrderableAs(Order otherOrder) {
838
                if (otherOrder == null) {
1✔
839
                        return false;
1✔
840
                }
841
                return OpenmrsUtil.nullSafeEquals(this.getConcept(), otherOrder.getConcept());
1✔
842
        }
843
        
844
        /**
845
         * A convenience method to return start of the schedule for order.
846
         * 
847
         * @since 1.10
848
         * <strong>Should</strong> return scheduledDate if Urgency is Scheduled
849
         * <strong>Should</strong> return dateActivated if Urgency is not Scheduled
850
         */
851
        public Date getEffectiveStartDate() {
852
                return this.urgency == Urgency.ON_SCHEDULED_DATE ? this.getScheduledDate() : this.getDateActivated();
1✔
853
        }
854
        
855
        /**
856
         * A convenience method to return end of the schedule for order.
857
         * 
858
         * @since 1.10
859
         * <strong>Should</strong> return dateStopped if dateStopped is not null
860
         * <strong>Should</strong> return autoExpireDate if dateStopped is null
861
         */
862
        public Date getEffectiveStopDate() {
863
                return this.getDateStopped() != null ? this.getDateStopped() : this.getAutoExpireDate();
1✔
864
        }
865
        
866
        /**
867
         * @since 1.12 {@link org.openmrs.OrderGroup}
868
         * @returns the OrderGroup
869
         */
870
        public OrderGroup getOrderGroup() {
871
                return orderGroup;
1✔
872
        }
873
        
874
        /**
875
         * Sets the OrderGroup for that order. If the order is ordered independently, it does not set an
876
         * orderGroup for it. If the order is ordered as an orderGroup, then sets a link to the
877
         * OrderGroup for that particular order.
878
         * 
879
         * @since 1.12
880
         * @param orderGroup
881
         */
882
        public void setOrderGroup(OrderGroup orderGroup) {
883
                this.orderGroup = orderGroup;
1✔
884
        }
1✔
885
        
886
        /**
887
         * Gets the sortWeight for an order if it is ordered as an OrderGroup.
888
         * 
889
         * @since 1.12
890
         * @return the sortWeight
891
         */
892
        public Double getSortWeight() {
893
                return sortWeight;
1✔
894
        }
895
        
896
        /**
897
         * Sets the sortWeight for an order if it is ordered as an OrderGroup. <tt>sortWeight</tt> is
898
         * used internally by the API to manage the sequencing of orders when grouped. This value may be
899
         * changed by the API as needed for that purpose. Instead of setting this internal value
900
         * directly please use {@link OrderGroup#addOrder(Order, Integer)}.
901
         * 
902
         * @see OrderGroup#addOrder(Order, Integer)
903
         * @since 1.12
904
         * @param sortWeight
905
         */
906
        public void setSortWeight(Double sortWeight) {
907
                this.sortWeight = sortWeight;
1✔
908
        }
1✔
909
        
910
        /**
911
         * Returns the current status that was received from a fulfiller for this order. It can either be RECEIVED, IN_PROGRESS,
912
         * EXCEPTION or COMPLETED.  
913
         * 
914
         * @since 2.2.0
915
         * @return the status that was received from a fulfiller
916
         */
917
        public FulfillerStatus getFulfillerStatus() {
918
                return fulfillerStatus;
1✔
919
        }
920

921
        /**
922
         * Sets the status of this order according to the value that was received from a fulfiller. 
923
         * 
924
         * @param fulfillerStatus the status that was received from a fulfiller. 
925
         * @since 2.2.0
926
        */
927
        public void setFulfillerStatus(FulfillerStatus fulfillerStatus) {
928
                this.fulfillerStatus = fulfillerStatus;
1✔
929
        }
1✔
930
        
931
        /**
932
         * Returns the comment received from the fulfiller regarding this order.
933
         * 
934
         * @since 2.2.0
935
         * @return the comment of the fulfiller  
936
         */
937
        public String getFulfillerComment() {
938
                return fulfillerComment;
1✔
939
        }
940
        
941
        /**
942
         * Sets the comment received from the fulfiller for this order.
943
         * 
944
         * @param fulfillerComment the comment received from the fulfiller
945
         * @since 2.2.0
946
         */
947
        public void setFulfillerComment(String fulfillerComment) {
948
                this.fulfillerComment = fulfillerComment;                
1✔
949
        }
1✔
950
        
951
        /**
952
         * @return Returns the formNamespaceAndPath.
953
         * @since 2.5.0
954
         */
955
        public String getFormNamespaceAndPath() {
956
                return formNamespaceAndPath;
1✔
957
        }
958

959
        /**
960
         * Sets the form namespace and path
961
         * 
962
         * @param formNamespaceAndPath the form namespace and path to set
963
         * @since 2.5.0
964
         */
965
        public void setFormNamespaceAndPath(String formNamespaceAndPath) {
966
                this.formNamespaceAndPath = formNamespaceAndPath;
1✔
967
        }
1✔
968

969
        @Override
970
        public String getFormFieldNamespace() {
971
                return BaseFormRecordableOpenmrsData.getFormFieldNamespace(formNamespaceAndPath);
×
972
        }
973

974
        @Override
975
        public String getFormFieldPath() {
976
                return BaseFormRecordableOpenmrsData.getFormFieldPath(formNamespaceAndPath);
×
977
        }
978

979
        @Override
980
        public void setFormField(String namespace, String formFieldPath) {
981
                formNamespaceAndPath = BaseFormRecordableOpenmrsData.getFormNamespaceAndPath(namespace, formFieldPath);
1✔
982
        }
1✔
983
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc