Skip to content

Commit a2e7eb8

Browse files
akshika47wluyima
authored andcommittedFeb 28, 2014
Add an optional orderer argument to OrderService.discontinueOrder methods - TRUNK-4277
1 parent 27d6c00 commit a2e7eb8

File tree

4 files changed

+42
-44
lines changed

4 files changed

+42
-44
lines changed
 

‎api/src/main/java/org/openmrs/api/OrderService.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.openmrs.annotation.Authorized;
2828
import org.openmrs.api.db.OrderDAO;
2929
import org.openmrs.util.PrivilegeConstants;
30+
import org.openmrs.Provider;
3031

3132
/**
3233
* Contains methods pertaining to creating/deleting/voiding Orders
@@ -357,10 +358,12 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
357358
/**
358359
* Discontinues an order. Creates a new order that discontinues the orderToDiscontinue
359360
*
360-
* @param orderToDiscontinue
361-
* @param reasonCoded
362-
* @param discontinueDate
363-
* @return the new order that discontinued orderToDiscontinue
361+
*
362+
* @param orderToDiscontinue
363+
* @param reasonCoded
364+
* @param discontinueDate
365+
* @param orderer
366+
* @return the new order that discontinued orderToDiscontinue
364367
* @throws APIException if the <code>action</code> of orderToDiscontinue is
365368
* <code>Order.Action.DISCONTINUE</code>
366369
* @since 1.10
@@ -372,15 +375,17 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
372375
* @should fail for a discontinuation order
373376
*/
374377
@Authorized(PrivilegeConstants.ADD_ORDERS)
375-
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate) throws Exception;
378+
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate, Provider orderer) throws Exception;
376379

377380
/**
378381
* Discontinues an order. Creates a new order that discontinues the orderToDiscontinue.
379382
*
380-
* @param orderToDiscontinue
381-
* @param reasonNonCoded
382-
* @param discontinueDate
383-
* @return the new order that discontinued orderToDiscontinue
383+
*
384+
* @param orderToDiscontinue
385+
* @param reasonNonCoded
386+
* @param discontinueDate
387+
* @param orderer
388+
* @return the new order that discontinued orderToDiscontinue
384389
* @throws APIException if the <code>action</code> of orderToDiscontinue is
385390
* <code>Order.Action.DISCONTINUE</code>
386391
* @since 1.10
@@ -390,7 +395,7 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
390395
* @should fail for a voided order
391396
*/
392397
@Authorized(PrivilegeConstants.ADD_ORDERS)
393-
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate) throws Exception;
398+
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer) throws Exception;
394399

395400
/**
396401
* Creates or updates the given order frequency in the database

‎api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java

+7-14
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@
2222

2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
25-
import org.openmrs.CareSetting;
26-
import org.openmrs.Concept;
27-
import org.openmrs.DrugOrder;
28-
import org.openmrs.Encounter;
29-
import org.openmrs.Order;
30-
import org.openmrs.OrderFrequency;
31-
import org.openmrs.Patient;
32-
import org.openmrs.User;
25+
import org.openmrs.*;
3326
import org.openmrs.api.APIException;
3427
import org.openmrs.api.OrderNumberGenerator;
3528
import org.openmrs.api.OrderService;
@@ -408,27 +401,27 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
408401
}
409402

410403
/**
411-
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept,
412-
* java.util.Date)
404+
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)
413405
*/
414406
@Override
415-
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate) throws Exception {
407+
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate, Provider orderer) throws Exception {
416408
stopOrder(orderToDiscontinue, discontinueDate);
417409
Order newOrder = orderToDiscontinue.cloneForDiscontinuing();
418410
newOrder.setOrderReason(reasonCoded);
411+
newOrder.setOrderer(orderer);
419412

420413
return saveOrderInternal(newOrder);
421414
}
422415

423416
/**
424-
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date)
417+
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, org.openmrs.Provider)
425418
*/
426419
@Override
427-
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate) throws Exception {
420+
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer) throws Exception {
428421
stopOrder(orderToDiscontinue, discontinueDate);
429422
Order newOrder = orderToDiscontinue.cloneForDiscontinuing();
430423
newOrder.setOrderReasonNonCoded(reasonNonCoded);
431-
424+
newOrder.setOrderer(orderer);
432425
return saveOrderInternal(newOrder);
433426
}
434427

‎api/src/test/java/org/openmrs/OrderEntryIntegrationTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ public void shouldDiscontinueAnActiveOrder() throws Exception {
135135
int ordersCount = orderService.getActiveOrders(patient, null, null, null).size();
136136

137137
Concept discontinueReason = Context.getConceptService().getConcept(1);
138-
Order discontinuationOrder1 = orderService.discontinueOrder(firstOrderToDiscontinue, discontinueReason, null);
138+
Order discontinuationOrder1 = orderService.discontinueOrder(firstOrderToDiscontinue, discontinueReason, null, null);
139139
assertEquals(firstOrderToDiscontinue, discontinuationOrder1.getPreviousOrder());
140140

141141
//Lets discontinue another order with reason being a string instead of concept
142142
Order secondOrderToDiscontinue = orderService.getOrder(5);
143143
assertEquals(patient, secondOrderToDiscontinue.getPatient());
144144
assertTrue(OrderUtil.isOrderActive(secondOrderToDiscontinue, null));
145-
Order discontinuationOrder2 = orderService.discontinueOrder(secondOrderToDiscontinue, "Testing", null);
145+
Order discontinuationOrder2 = orderService.discontinueOrder(secondOrderToDiscontinue, "Testing", null, null);
146146
assertEquals(secondOrderToDiscontinue, discontinuationOrder2.getPreviousOrder());
147147

148148
//Lets discontinue another order by saving a DC order

‎api/src/test/java/org/openmrs/api/OrderServiceTest.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ public void getActiveOrders_shouldDefaultToOrderClassIfNoOrderClassIsSpecified()
476476
}
477477

478478
/**
479-
* @see {@link OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date)}
479+
* @see {@link OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, org.openmrs.Provider)}
480480
*/
481481
@Test
482482
@Verifies(value = "populate correct attributes on the discontinue and discontinued orders", method = "discontinueOrder(Order, String, Date)")
@@ -486,7 +486,7 @@ public void discontinueOrderWithNonCodedReason_shouldPopulateCorrectAttributesOn
486486
Date discontinueDate = new Date();
487487
String discontinueReasonNonCoded = "Test if I can discontinue this";
488488

489-
Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate);
489+
Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate, null);
490490

491491
Assert.assertEquals(order.getDateStopped(), discontinueDate);
492492
Assert.assertNotNull(discontinueOrder);
@@ -497,7 +497,7 @@ public void discontinueOrderWithNonCodedReason_shouldPopulateCorrectAttributesOn
497497
}
498498

499499
/**
500-
* @see {@link OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date)}
500+
* @see {@link OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)}
501501
*/
502502
@Test
503503
@Verifies(value = "populate correct attributes on the discontinue and discontinued orders", method = "discontinueOrder(Order, Concept, Date)")
@@ -508,7 +508,7 @@ public void discontinueOrderWithConcept_shouldPopulateCorrectAttributesOnBothOrd
508508
Date discontinueDate = new Date();
509509
Concept concept = Context.getConceptService().getConcept(1);
510510

511-
Order discontinueOrder = orderService.discontinueOrder(order, concept, discontinueDate);
511+
Order discontinueOrder = orderService.discontinueOrder(order, concept, discontinueDate, null);
512512

513513
Assert.assertEquals(order.getDateStopped(), discontinueDate);
514514
Assert.assertNotNull(discontinueOrder);
@@ -519,7 +519,7 @@ public void discontinueOrderWithConcept_shouldPopulateCorrectAttributesOnBothOrd
519519
}
520520

521521
/**
522-
* @see {@link OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date)}
522+
* @see {@link OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, org.openmrs.Provider)}
523523
*/
524524
@Test(expected = APIException.class)
525525
@Verifies(value = "fail for a discontinue order", method = "discontinueOrder(Order, String, Date)")
@@ -528,11 +528,11 @@ public void discontinueOrderWithNonCodedReason_shouldFailForADiscontinueOrder()
528528
OrderService orderService = Context.getOrderService();
529529
Order discontinueOrder = orderService.getOrder(26);
530530

531-
orderService.discontinueOrder(discontinueOrder, "Test if I can discontinue this", null);
531+
orderService.discontinueOrder(discontinueOrder, "Test if I can discontinue this", null, null);
532532
}
533533

534534
/**
535-
* @see {@link OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date)}
535+
* @see {@link OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)}
536536
*/
537537
@Test(expected = APIException.class)
538538
@Verifies(value = "fail for a discontinue order", method = "discontinueOrder(Order, Concept, Date)")
@@ -542,7 +542,7 @@ public void discontinueOrderWithConcept_shouldFailForADiscontinueOrder() throws
542542
OrderService orderService = Context.getOrderService();
543543
Order discontinueOrder = orderService.getOrder(26);
544544

545-
orderService.discontinueOrder(discontinueOrder, (Concept) null, null);
545+
orderService.discontinueOrder(discontinueOrder, (Concept) null, null, null);
546546
}
547547

548548
/**
@@ -617,7 +617,7 @@ public void saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThisConcept(
617617

618618
/**
619619
* @verifies reject a future discontinueDate
620-
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date)
620+
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)
621621
*/
622622
@Test(expected = IllegalArgumentException.class)
623623
public void discontinueOrder_shouldRejectAFutureDiscontinueDate() throws Exception {
@@ -626,20 +626,20 @@ public void discontinueOrder_shouldRejectAFutureDiscontinueDate() throws Excepti
626626
Patient patient = Context.getPatientService().getPatient(2);
627627
CareSetting careSetting = orderService.getCareSetting(1);
628628
Order orderToDiscontinue = orderService.getActiveOrders(patient, Order.class, careSetting, null).get(0);
629-
orderService.discontinueOrder(orderToDiscontinue, new Concept(), cal.getTime());
629+
orderService.discontinueOrder(orderToDiscontinue, new Concept(), cal.getTime(), null);
630630
}
631631

632632
/**
633633
* @verifies fail if discontinueDate is in the future
634-
* @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date)
634+
* @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, org.openmrs.Provider)
635635
*/
636636
@Test(expected = IllegalArgumentException.class)
637637
public void discontinueOrder_shouldFailIfDiscontinueDateIsInTheFuture() throws Exception {
638638
Calendar cal = Calendar.getInstance();
639639
cal.add(Calendar.HOUR_OF_DAY, 1);
640640
Order orderToDiscontinue = orderService.getActiveOrders(Context.getPatientService().getPatient(2), Order.class,
641641
orderService.getCareSetting(1), null).get(0);
642-
orderService.discontinueOrder(orderToDiscontinue, "Testing", cal.getTime());
642+
orderService.discontinueOrder(orderToDiscontinue, "Testing", cal.getTime(), null);
643643
}
644644

645645
/**
@@ -697,36 +697,36 @@ public void saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDru
697697

698698
/**
699699
* @verifies fail for a stopped order
700-
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date)
700+
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)
701701
*/
702702
@Test(expected = APIException.class)
703703
public void discontinueOrder_shouldFailForAStoppedOrder() throws Exception {
704704
Order orderToDiscontinue = orderService.getOrder(1);
705705
assertNotNull(orderToDiscontinue.getDateStopped());
706-
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null);
706+
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null, null);
707707
}
708708

709709
/**
710710
* @verifies fail for a voided order
711-
* @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date)
711+
* @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, org.openmrs.Provider)
712712
*/
713713
@Test(expected = APIException.class)
714714
public void discontinueOrder_shouldFailForAVoidedOrder() throws Exception {
715715
Order orderToDiscontinue = orderService.getOrder(8);
716716
assertTrue(orderToDiscontinue.isVoided());
717-
orderService.discontinueOrder(orderToDiscontinue, "testing", null);
717+
orderService.discontinueOrder(orderToDiscontinue, "testing", null, null);
718718
}
719719

720720
/**
721721
* @verifies fail for an expired order
722-
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date)
722+
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)
723723
*/
724724
@Test(expected = APIException.class)
725725
public void discontinueOrder_shouldFailForAnExpiredOrder() throws Exception {
726726
Order orderToDiscontinue = orderService.getOrder(6);
727727
assertNotNull(orderToDiscontinue.getAutoExpireDate());
728728
assertTrue(orderToDiscontinue.getAutoExpireDate().before(new Date()));
729-
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null);
729+
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null, null);
730730
}
731731

732732
/**

0 commit comments

Comments
 (0)
Please sign in to comment.