Skip to content

Commit

Permalink
Sorting orders for: Add API methods for retrieving active orders -
Browse files Browse the repository at this point in the history
TRUNK-4147
  • Loading branch information
dkayiwa committed Dec 23, 2013
1 parent 683e3bf commit b7ec490
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions api/src/main/java/org/openmrs/api/OrderService.java
Expand Up @@ -48,7 +48,7 @@ public interface OrderService extends OpenmrsService {
* @should not save order if order doesnt validate
* @should save discontinued reason non coded
*/
@Authorized( { PrivilegeConstants.EDIT_ORDERS, PrivilegeConstants.ADD_ORDERS })
@Authorized({ PrivilegeConstants.EDIT_ORDERS, PrivilegeConstants.ADD_ORDERS })
public Order saveOrder(Order order) throws APIException;

/**
Expand Down Expand Up @@ -115,7 +115,7 @@ public interface OrderService extends OpenmrsService {

/**
* Gets the order with the associated order id
*
*
* @param <Ord> An Order type. Currently only org.openmrs.Order or org.openmrs.DrugOrder
* @param orderId the primary key of the Order
* @param orderClassType The class of Order to fetch (Currently only org.openmrs.Order or
Expand All @@ -140,7 +140,7 @@ public interface OrderService extends OpenmrsService {
*/
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<Patient> patients,
List<Concept> concepts, List<User> orderers, List<Encounter> encounters);
List<Concept> concepts, List<User> orderers, List<Encounter> encounters);

/**
* Unvoid order record. Reverse a previous call to {@link #voidOrder(Order, String)}
Expand All @@ -163,7 +163,8 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
public Order getOrderByOrderNumber(String orderNumber);

/**
* Gets all Order objects that use this Concept for a given patient.
* Gets all Order objects that use this Concept for a given patient. Orders will be returned in
* the order in which they occurred, i.e. sorted by dateCreated starting with the latest
*
* @param patient the patient.
* @param concept the concept.
Expand Down
Expand Up @@ -119,6 +119,8 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
if (encounters.size() > 0)
crit.add(Restrictions.in("encounter", encounters));

crit.addOrder(org.hibernate.criterion.Order.desc("dateCreated"));

This comment has been minimized.

Copy link
@wluyima

wluyima Dec 24, 2013

Member

Sometimes what i do here is to statistically import the method, you don't have to do it.


return crit.list();
}

Expand Down
12 changes: 8 additions & 4 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Expand Up @@ -188,16 +188,20 @@ public void getOrderHistoryByConcept_shouldReturnOrdersWithTheGivenConcept() thr
Concept concept = Context.getConceptService().getConcept(88);
Patient patient = Context.getPatientService().getPatient(2);
List<Order> orders = Context.getOrderService().getOrderHistoryByConcept(patient, concept);

//They must be two orders and sorted by dateCreated starting with the latest
Assert.assertEquals(2, orders.size());
for (Order order : orders)
Assert.assertTrue(order.getOrderId() == 4 || order.getOrderId() == 5);
Assert.assertTrue(orders.get(0).getOrderId() == 5);
Assert.assertTrue(orders.get(1).getOrderId() == 4);

//We should have two different orders with this concept
concept = Context.getConceptService().getConcept(792);
orders = Context.getOrderService().getOrderHistoryByConcept(patient, concept);

//They must be two orders and sorted by dateCreated starting with the latest
Assert.assertEquals(2, orders.size());
for (Order order : orders)
Assert.assertTrue(order.getOrderId() == 2 || order.getOrderId() == 3);
Assert.assertTrue(orders.get(0).getOrderId() == 3);
Assert.assertTrue(orders.get(1).getOrderId() == 2);
}

/**
Expand Down

0 comments on commit b7ec490

Please sign in to comment.