Skip to content

Commit

Permalink
TRUNK-5687, filter out DISCONTINUE orders (openmrs#3060)
Browse files Browse the repository at this point in the history
  • Loading branch information
cioan authored and mogoodrich committed Nov 21, 2019
1 parent 3a66cab commit 6d1212a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
package org.openmrs.api.db.hibernate;

import static org.openmrs.Order.Action.DISCONTINUE;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -197,6 +199,11 @@ public List<Order> getOrders(OrderSearchCriteria searchCriteria) {
if (searchCriteria.getAction() != null) {
crit.add(Restrictions.eq("action", searchCriteria.getAction()));
}
if (searchCriteria.getExcludeDiscontinueOrders() == true) {
crit.add(Restrictions.or(
Restrictions.ne("action", Order.Action.DISCONTINUE),
Restrictions.isNull("action")));
}
SimpleExpression fulfillerStatusExpr = null;
if (searchCriteria.getFulfillerStatus() != null) {
fulfillerStatusExpr = Restrictions.eq("fulfillerStatus", searchCriteria.getFulfillerStatus());
Expand Down
12 changes: 11 additions & 1 deletion api/src/main/java/org/openmrs/parameter/OrderSearchCriteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class OrderSearchCriteria {

private final boolean excludeCanceledAndExpired;

private final boolean excludeDiscontinueOrders;

/**
* Instead of calling this constructor directly, it is recommended to use {@link OrderSearchCriteriaBuilder}.
* @param patient the patient the order is for
Expand All @@ -95,7 +97,9 @@ public OrderSearchCriteria(Patient patient, CareSetting careSetting, Collection<
Order.Action action,
Order.FulfillerStatus fulfillerStatus,
Boolean includeNullFulfillerStatus,
boolean excludeCanceledAndExpired, boolean includeVoided) {
boolean excludeCanceledAndExpired,
boolean excludeDiscontinueOrders,
boolean includeVoided) {
this.patient = patient;
this.careSetting = careSetting;
this.concepts = concepts;
Expand All @@ -109,6 +113,7 @@ public OrderSearchCriteria(Patient patient, CareSetting careSetting, Collection<
this.fulfillerStatus = fulfillerStatus;
this.includeNullFulfillerStatus = includeNullFulfillerStatus;
this.excludeCanceledAndExpired = excludeCanceledAndExpired;
this.excludeDiscontinueOrders = excludeDiscontinueOrders;
this.includeVoided = includeVoided;
}

Expand Down Expand Up @@ -194,6 +199,11 @@ public boolean getExcludeCanceledAndExpired() {
return excludeCanceledAndExpired;
}


public boolean getExcludeDiscontinueOrders() {
return excludeDiscontinueOrders;
}

/**
* @return whether to include the voided orders or not
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class OrderSearchCriteriaBuilder {

private boolean excludeCanceledAndExpired;

private boolean excludeDiscontinueOrders;

private boolean includeVoided;

/**
Expand Down Expand Up @@ -168,6 +170,11 @@ public OrderSearchCriteriaBuilder setExcludeCanceledAndExpired(boolean excludeCa
return (this);
}

public OrderSearchCriteriaBuilder setExcludeDiscontinueOrders(boolean excludeDiscontinueOrders) {
this.excludeDiscontinueOrders = excludeDiscontinueOrders;
return (this);
}

/**
* @param includeVoided whether to include the voided orders or not
* @return this builder instance
Expand All @@ -184,7 +191,7 @@ public OrderSearchCriteriaBuilder setIncludeVoided(boolean includeVoided) {
public OrderSearchCriteria build() {
return new OrderSearchCriteria(patient, careSetting, concepts, orderTypes, activatedOnOrBeforeDate,
activatedOnOrAfterDate, isStopped, autoExpireOnOrBeforeDate, canceledOrExpiredOnOrBeforeDate,
action, fulfillerStatus, includeNullFulfillerStatus, excludeCanceledAndExpired, includeVoided);
action, fulfillerStatus, includeNullFulfillerStatus, excludeCanceledAndExpired, excludeDiscontinueOrders, includeVoided);
}
}

14 changes: 14 additions & 0 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,20 @@ public void getOrders_shouldreturnDiscontinuedOrders() {
}
}

/**
* @see OrderService#(OrderSearchCriteria)
*/
@Test
public void getOrders_shouldNotReturnDiscontinuedOrders() {
OrderSearchCriteria orderSearchCriteria = new OrderSearchCriteriaBuilder().setExcludeDiscontinueOrders(true).build();
List<Order> orders = orderService.getOrders(orderSearchCriteria);
assertEquals(11, orders.size());
for (Order order : orders) {
assertNotEquals(order.getAction(), org.openmrs.Order.Action.DISCONTINUE);
}
}


/**
* @see OrderService#(OrderSearchCriteria)
*/
Expand Down

0 comments on commit 6d1212a

Please sign in to comment.