Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,15 @@ protected PageableResult doSearch(RequestContext context) throws ResponseExcepti
if (context.getType() != null) {
filterByType(orders, context.getType());
}


// if the user indicated a specific sort parameter, apply sort here
if (StringUtils.isNotBlank(sortParam)) {
List<Order> sortedOrder = sortOrdersBasedOnDateActivatedOrDateStopped(orders, sortParam, status);
return new NeedsPaging<Order>(sortedOrder, context);
}
else {
return new NeedsPaging<Order>(orders, context);
List<Order> descSortedOrder = sortOrdersBasedOnDateActivatedOrDateStopped(orders, "DESC", status);
return new NeedsPaging<Order>(descSortedOrder, context);
}
} else {
throw new InvalidSearchException("Please provide patientUuid in the patient parameter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public void shouldGetTheActiveOrdersForAPatientInTheSpecifiedCareSetting() throw
@Test
public void shouldGetTheActiveOrdersForAPatientAsOfTheSpecifiedDate() throws Exception {
SimpleObject results = deserialize(handle(newGetRequest(getURI(), new Parameter("patient", patientService
.getPatient(2).getUuid()), new Parameter("asOfDate", "2007-12-10"))));
.getPatient(2).getUuid()), new Parameter("status", "active"), new Parameter("asOfDate", "2007-12-10"))));

assertEquals(2, Util.getResultsSize(results));

Expand Down Expand Up @@ -566,7 +566,8 @@ public void shouldGetOrdersByOrderType() throws Exception {

// order service should return all orders when no order type filter specified
req = newGetRequest(getURI(),
new Parameter("patient", PATIENT_UUID)
new Parameter("patient", PATIENT_UUID),
new Parameter("status", "active")
);
SimpleObject orders = deserialize(handle(req));
ArrayList<Object> resp = (ArrayList<Object>) PropertyUtils.getProperty(orders, "results");
Expand Down Expand Up @@ -598,4 +599,24 @@ public void doSearch_shouldReturnExceptionIfNoPatientUuidIsSpecified() throws Ex
);
handle(req);
}

@Test
public void doSearch_shouldReturnOrdersSortedInDescendingOrderByDate() throws Exception {
SimpleObject orders = deserialize(handle(newGetRequest(getURI(),
new Parameter("patient", "da7f524f-27ce-4bb2-86d6-6d1d05312bd5"),
new Parameter("status", "active")
)));

List<Object> resultList = Util.getResultsList(orders);
assertTrue(resultList.size() >= 2);

String uuid1 = PropertyUtils.getProperty(resultList.get(0), "uuid").toString();
String uuid2 = PropertyUtils.getProperty(resultList.get(1), "uuid").toString();

Order order1 = orderService.getOrderByUuid(uuid1);
Order order2 = orderService.getOrderByUuid(uuid2);

// orders sorted by date in descending order (newest first)
assertTrue(order1.getDateActivated().after(order2.getDateActivated()));
}
}
Loading