Skip to content

Commit

Permalink
Add an optional orderer argument to OrderService.discontinueOrder met…
Browse files Browse the repository at this point in the history
…hods - TRUNK-4277
  • Loading branch information
akshika47 authored and wluyima committed Feb 28, 2014
1 parent 27d6c00 commit a2e7eb8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 44 deletions.
25 changes: 15 additions & 10 deletions api/src/main/java/org/openmrs/api/OrderService.java
Expand Up @@ -27,6 +27,7 @@
import org.openmrs.annotation.Authorized;
import org.openmrs.api.db.OrderDAO;
import org.openmrs.util.PrivilegeConstants;
import org.openmrs.Provider;

/**
* Contains methods pertaining to creating/deleting/voiding Orders
Expand Down Expand Up @@ -357,10 +358,12 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
/**
* Discontinues an order. Creates a new order that discontinues the orderToDiscontinue
*
* @param orderToDiscontinue
* @param reasonCoded
* @param discontinueDate
* @return the new order that discontinued orderToDiscontinue
*
* @param orderToDiscontinue
* @param reasonCoded
* @param discontinueDate
* @param orderer
* @return the new order that discontinued orderToDiscontinue
* @throws APIException if the <code>action</code> of orderToDiscontinue is
* <code>Order.Action.DISCONTINUE</code>
* @since 1.10
Expand All @@ -372,15 +375,17 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
* @should fail for a discontinuation order
*/
@Authorized(PrivilegeConstants.ADD_ORDERS)
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate) throws Exception;
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate, Provider orderer) throws Exception;

/**
* Discontinues an order. Creates a new order that discontinues the orderToDiscontinue.
*
* @param orderToDiscontinue
* @param reasonNonCoded
* @param discontinueDate
* @return the new order that discontinued orderToDiscontinue
*
* @param orderToDiscontinue
* @param reasonNonCoded
* @param discontinueDate
* @param orderer
* @return the new order that discontinued orderToDiscontinue
* @throws APIException if the <code>action</code> of orderToDiscontinue is
* <code>Order.Action.DISCONTINUE</code>
* @since 1.10
Expand All @@ -390,7 +395,7 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
* @should fail for a voided order
*/
@Authorized(PrivilegeConstants.ADD_ORDERS)
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate) throws Exception;
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer) throws Exception;

/**
* Creates or updates the given order frequency in the database
Expand Down
21 changes: 7 additions & 14 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Expand Up @@ -22,14 +22,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.CareSetting;
import org.openmrs.Concept;
import org.openmrs.DrugOrder;
import org.openmrs.Encounter;
import org.openmrs.Order;
import org.openmrs.OrderFrequency;
import org.openmrs.Patient;
import org.openmrs.User;
import org.openmrs.*;
import org.openmrs.api.APIException;
import org.openmrs.api.OrderNumberGenerator;
import org.openmrs.api.OrderService;
Expand Down Expand Up @@ -408,27 +401,27 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
}

/**
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept,
* java.util.Date)
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)
*/
@Override
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate) throws Exception {
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate, Provider orderer) throws Exception {
stopOrder(orderToDiscontinue, discontinueDate);
Order newOrder = orderToDiscontinue.cloneForDiscontinuing();
newOrder.setOrderReason(reasonCoded);
newOrder.setOrderer(orderer);

return saveOrderInternal(newOrder);
}

/**
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date)
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, org.openmrs.Provider)
*/
@Override
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate) throws Exception {
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer) throws Exception {
stopOrder(orderToDiscontinue, discontinueDate);
Order newOrder = orderToDiscontinue.cloneForDiscontinuing();
newOrder.setOrderReasonNonCoded(reasonNonCoded);

newOrder.setOrderer(orderer);
return saveOrderInternal(newOrder);
}

Expand Down
4 changes: 2 additions & 2 deletions api/src/test/java/org/openmrs/OrderEntryIntegrationTest.java
Expand Up @@ -135,14 +135,14 @@ public void shouldDiscontinueAnActiveOrder() throws Exception {
int ordersCount = orderService.getActiveOrders(patient, null, null, null).size();

Concept discontinueReason = Context.getConceptService().getConcept(1);
Order discontinuationOrder1 = orderService.discontinueOrder(firstOrderToDiscontinue, discontinueReason, null);
Order discontinuationOrder1 = orderService.discontinueOrder(firstOrderToDiscontinue, discontinueReason, null, null);
assertEquals(firstOrderToDiscontinue, discontinuationOrder1.getPreviousOrder());

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

//Lets discontinue another order by saving a DC order
Expand Down
36 changes: 18 additions & 18 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Expand Up @@ -476,7 +476,7 @@ public void getActiveOrders_shouldDefaultToOrderClassIfNoOrderClassIsSpecified()
}

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

Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate);
Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate, null);

Assert.assertEquals(order.getDateStopped(), discontinueDate);
Assert.assertNotNull(discontinueOrder);
Expand All @@ -497,7 +497,7 @@ public void discontinueOrderWithNonCodedReason_shouldPopulateCorrectAttributesOn
}

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

Order discontinueOrder = orderService.discontinueOrder(order, concept, discontinueDate);
Order discontinueOrder = orderService.discontinueOrder(order, concept, discontinueDate, null);

Assert.assertEquals(order.getDateStopped(), discontinueDate);
Assert.assertNotNull(discontinueOrder);
Expand All @@ -519,7 +519,7 @@ public void discontinueOrderWithConcept_shouldPopulateCorrectAttributesOnBothOrd
}

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

orderService.discontinueOrder(discontinueOrder, "Test if I can discontinue this", null);
orderService.discontinueOrder(discontinueOrder, "Test if I can discontinue this", null, null);
}

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

orderService.discontinueOrder(discontinueOrder, (Concept) null, null);
orderService.discontinueOrder(discontinueOrder, (Concept) null, null, null);
}

/**
Expand Down Expand Up @@ -617,7 +617,7 @@ public void saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThisConcept(

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

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

/**
Expand Down Expand Up @@ -697,36 +697,36 @@ public void saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDru

/**
* @verifies fail for a stopped order
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date)
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)
*/
@Test(expected = APIException.class)
public void discontinueOrder_shouldFailForAStoppedOrder() throws Exception {
Order orderToDiscontinue = orderService.getOrder(1);
assertNotNull(orderToDiscontinue.getDateStopped());
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null);
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null, null);
}

/**
* @verifies fail for a voided order
* @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date)
* @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, org.openmrs.Provider)
*/
@Test(expected = APIException.class)
public void discontinueOrder_shouldFailForAVoidedOrder() throws Exception {
Order orderToDiscontinue = orderService.getOrder(8);
assertTrue(orderToDiscontinue.isVoided());
orderService.discontinueOrder(orderToDiscontinue, "testing", null);
orderService.discontinueOrder(orderToDiscontinue, "testing", null, null);
}

/**
* @verifies fail for an expired order
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date)
* @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)
*/
@Test(expected = APIException.class)
public void discontinueOrder_shouldFailForAnExpiredOrder() throws Exception {
Order orderToDiscontinue = orderService.getOrder(6);
assertNotNull(orderToDiscontinue.getAutoExpireDate());
assertTrue(orderToDiscontinue.getAutoExpireDate().before(new Date()));
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null);
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null, null);
}

/**
Expand Down

0 comments on commit a2e7eb8

Please sign in to comment.