Skip to content

Commit b7ec490

Browse files
committedDec 23, 2013
Sorting orders for: Add API methods for retrieving active orders -
TRUNK-4147
1 parent 683e3bf commit b7ec490

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed
 

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface OrderService extends OpenmrsService {
4848
* @should not save order if order doesnt validate
4949
* @should save discontinued reason non coded
5050
*/
51-
@Authorized( { PrivilegeConstants.EDIT_ORDERS, PrivilegeConstants.ADD_ORDERS })
51+
@Authorized({ PrivilegeConstants.EDIT_ORDERS, PrivilegeConstants.ADD_ORDERS })
5252
public Order saveOrder(Order order) throws APIException;
5353

5454
/**
@@ -115,7 +115,7 @@ public interface OrderService extends OpenmrsService {
115115

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

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

165165
/**
166-
* Gets all Order objects that use this Concept for a given patient.
166+
* Gets all Order objects that use this Concept for a given patient. Orders will be returned in
167+
* the order in which they occurred, i.e. sorted by dateCreated starting with the latest
167168
*
168169
* @param patient the patient.
169170
* @param concept the concept.

‎api/src/main/java/org/openmrs/api/db/hibernate/HibernateOrderDAO.java

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
119119
if (encounters.size() > 0)
120120
crit.add(Restrictions.in("encounter", encounters));
121121

122+
crit.addOrder(org.hibernate.criterion.Order.desc("dateCreated"));
Has a conversation. Original line has a conversation.
123+
122124
return crit.list();
123125
}
124126

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,20 @@ public void getOrderHistoryByConcept_shouldReturnOrdersWithTheGivenConcept() thr
188188
Concept concept = Context.getConceptService().getConcept(88);
189189
Patient patient = Context.getPatientService().getPatient(2);
190190
List<Order> orders = Context.getOrderService().getOrderHistoryByConcept(patient, concept);
191+
192+
//They must be two orders and sorted by dateCreated starting with the latest
191193
Assert.assertEquals(2, orders.size());
192-
for (Order order : orders)
193-
Assert.assertTrue(order.getOrderId() == 4 || order.getOrderId() == 5);
194+
Assert.assertTrue(orders.get(0).getOrderId() == 5);
195+
Assert.assertTrue(orders.get(1).getOrderId() == 4);
194196

195197
//We should have two different orders with this concept
196198
concept = Context.getConceptService().getConcept(792);
197199
orders = Context.getOrderService().getOrderHistoryByConcept(patient, concept);
200+
201+
//They must be two orders and sorted by dateCreated starting with the latest
198202
Assert.assertEquals(2, orders.size());
199-
for (Order order : orders)
200-
Assert.assertTrue(order.getOrderId() == 2 || order.getOrderId() == 3);
203+
Assert.assertTrue(orders.get(0).getOrderId() == 3);
204+
Assert.assertTrue(orders.get(1).getOrderId() == 2);
201205
}
202206

203207
/**

0 commit comments

Comments
 (0)
Please sign in to comment.