-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
half way though: Add API methods for retrieving active orders -
TRUNK-4147
- Loading branch information
Showing
5 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,4 +207,29 @@ public synchronized String getNewOrderNumber() { | |
|
||
return orderNumber; | ||
} | ||
|
||
/** | ||
* @see org.openmrs.api.OrderService#getOrderByOrderNumber(java.lang.String) | ||
*/ | ||
@Override | ||
public Order getOrderByOrderNumber(String orderNumber) { | ||
return dao.getOrderByOrderNumber(orderNumber); | ||
} | ||
|
||
/** | ||
* @see org.openmrs.api.OrderService#getOrderHistoryByConcept(org.openmrs.Patient, org.openmrs.Concept) | ||
*/ | ||
@Override | ||
public List<Order> getOrderHistoryByConcept(Patient patient, Concept concept) { | ||
if (patient == null) | ||
throw new IllegalArgumentException("patient is required"); | ||
|
||
This comment has been minimized.
Sorry, something went wrong. |
||
List<Concept> concepts = new Vector<Concept>(); | ||
concepts.add(concept); | ||
|
||
List<Patient> patients = new Vector<Patient>(); | ||
patients.add(patient); | ||
|
||
return getOrders(Order.class, patients, concepts, null, null); | ||
This comment has been minimized.
Sorry, something went wrong.
wluyima
Member
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,10 @@ | |
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openmrs.Concept; | ||
import org.openmrs.Obs; | ||
import org.openmrs.Order; | ||
import org.openmrs.Patient; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.test.BaseContextSensitiveTest; | ||
import org.openmrs.test.Verifies; | ||
|
@@ -149,4 +151,58 @@ public void run() { | |
//since we used a set we should have the size as N indicating that there were no duplicates | ||
Assert.assertEquals(N, uniqueOrderNumbers.size()); | ||
} | ||
|
||
/** | ||
* @see {@link OrderService#getOrderByOrderNumber(String)} | ||
*/ | ||
@Test | ||
@Verifies(value = "should find object given valid order number", method = "getOrderByOrderNumber(String)") | ||
public void getOrderByOrderNumber_shouldFindObjectGivenValidOrderNumber() throws Exception { | ||
Order order = Context.getOrderService().getOrderByOrderNumber("1"); | ||
Assert.assertNotNull(order); | ||
Assert.assertEquals(1, (int) order.getOrderId()); | ||
} | ||
|
||
/** | ||
* @see {@link OrderService#getOrderByOrderNumber(String)} | ||
*/ | ||
@Test | ||
@Verifies(value = "should return null if no object found with given order number", method = "getOrderByOrderNumber(String)") | ||
public void getOrderByOrderNumber_shouldReturnNullIfNoObjectFoundWithGivenOrderNumber() throws Exception { | ||
Assert.assertNull(Context.getOrderService().getOrderByOrderNumber("some invalid order number")); | ||
} | ||
|
||
/** | ||
* @see {@link OrderService#getOrderHistoryByConcept(Patient,Concept)} | ||
*/ | ||
@Test | ||
@Verifies(value = "should return orders with the given concept", method = "getOrderHistoryByConcept(Patient,Concept)") | ||
public void getOrderHistoryByConcept_shouldReturnOrdersWithTheGivenConcept() throws Exception { | ||
//We should have two orders with this concept. | ||
Concept concept = Context.getConceptService().getConcept(88); | ||
Patient patient = Context.getPatientService().getPatient(2); | ||
List<Order> orders = Context.getOrderService().getOrderHistoryByConcept(patient, concept); | ||
Assert.assertEquals(2, orders.size()); | ||
for (Order order : orders) | ||
Assert.assertTrue(order.getOrderId() == 4 || order.getOrderId() == 5); | ||
This comment has been minimized.
Sorry, something went wrong.
wluyima
Member
|
||
|
||
//We should have two different orders with this concept | ||
concept = Context.getConceptService().getConcept(792); | ||
orders = Context.getOrderService().getOrderHistoryByConcept(patient, concept); | ||
Assert.assertEquals(2, orders.size()); | ||
for (Order order : orders) | ||
Assert.assertTrue(order.getOrderId() == 2 || order.getOrderId() == 3); | ||
} | ||
|
||
/** | ||
* @see {@link OrderService#getOrderHistoryByConcept(PatientConcept)} | ||
*/ | ||
@Test | ||
@Verifies(value = "should return empty list for concept without orders", method = "getOrderHistoryByConcept(Patient,Concept)") | ||
public void getOrderHistoryByConcept_shouldReturnEmptyListForConceptWithoutOrders() throws Exception { | ||
Concept concept = Context.getConceptService().getConcept(21); | ||
Patient patient = Context.getPatientService().getPatient(2); | ||
List<Order> orders = Context.getOrderService().getOrderHistoryByConcept(patient, concept); | ||
Assert.assertEquals(0, orders.size()); | ||
} | ||
} |
I think this needs to say clearly that the orders will be returned in the order in which they occurred i.e sorted by dateCreated starting with the latest