Skip to content

Commit

Permalink
Added more end to end tests and fixed some code in Order.cloneForDisc…
Browse files Browse the repository at this point in the history
…ontinuing
  • Loading branch information
wluyima committed Feb 6, 2014
1 parent d9eb970 commit 21026f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions api/src/main/java/org/openmrs/Order.java
Expand Up @@ -548,6 +548,7 @@ public Order cloneForDiscontinuing() throws IllegalAccessException, Instantiatio
newOrder.setConcept(this.getConcept());
newOrder.setAction(Action.DISCONTINUE);
newOrder.setPreviousOrder(this);
newOrder.setPatient(this.getPatient());

return newOrder;
}
Expand Down
21 changes: 19 additions & 2 deletions api/src/test/java/org/openmrs/OrderEntryIntegrationTest.java
Expand Up @@ -46,13 +46,23 @@ public class OrderEntryIntegrationTest extends BaseContextSensitiveTest {

@Autowired
private ConceptService conceptService;

@Test
public void shouldGetTheActiveOrdersForAPatient() {
Patient patient = patientService.getPatient(2);
List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
assertEquals(5, activeOrders.size());
Order[] expectedOrders = { orderService.getOrder(3), orderService.getOrder(5), orderService.getOrder(7),
orderService.getOrder(222), orderService.getOrder(444) };
assertThat(activeOrders, hasItems(expectedOrders));
}

@Test
public void shouldGetTheActiveDrugOrdersForAPatient() {
Patient patient = patientService.getPatient(2);
List<DrugOrder> activeDrugOrders = orderService.getActiveOrders(patient, DrugOrder.class, null, null);
assertEquals(2, activeDrugOrders.size());
DrugOrder[] expectedDrugOrders = { (DrugOrder) orderService.getOrder(3), (DrugOrder) orderService.getOrder(3) };
DrugOrder[] expectedDrugOrders = { (DrugOrder) orderService.getOrder(3), (DrugOrder) orderService.getOrder(5) };
assertThat(activeDrugOrders, hasItems(expectedDrugOrders));
}

Expand Down Expand Up @@ -129,12 +139,19 @@ public void shouldDiscontinueAnActiveOrder() throws Exception {
assertEquals(patient, secondOrderToDiscontinue.getPatient());
assertTrue(OrderUtil.isOrderActive(secondOrderToDiscontinue, null));

//Lets discontinue another order by saving a DC order
Order thirdOrderToDiscontinue = orderService.getOrder(7);
assertTrue(OrderUtil.isOrderActive(thirdOrderToDiscontinue, null));
Order discontinuationOrder = thirdOrderToDiscontinue.cloneForDiscontinuing();
orderService.saveOrder(discontinuationOrder);

Order discontinuationOrder2 = orderService.discontinueOrder(secondOrderToDiscontinue, "Testing", null);
assertEquals(secondOrderToDiscontinue, discontinuationOrder2.getPreviousOrder());

List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
assertEquals(ordersCount - 2, activeOrders.size());
assertEquals(ordersCount - 3, activeOrders.size());
assertFalse(activeOrders.contains(firstOrderToDiscontinue));
assertFalse(activeOrders.contains(secondOrderToDiscontinue));
assertFalse(activeOrders.contains(thirdOrderToDiscontinue));
}
}
11 changes: 8 additions & 3 deletions api/src/test/java/org/openmrs/OrderTest.java
Expand Up @@ -13,9 +13,7 @@
*/
package org.openmrs;

import org.junit.Assert;
import org.junit.Test;
import org.openmrs.test.Verifies;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -103,11 +101,18 @@ public void shouldIsCurrent() throws Exception {
public void cloneForDiscontinuing_shouldSetAllTheRelevantFields() throws Exception {

TestOrder anOrder = new TestOrder();
anOrder.setPatient(new Patient());
anOrder.setCareSetting(new CareSetting());
anOrder.setConcept(new Concept());
anOrder.setUuid(UUID.randomUUID().toString());

Order orderThatCanDiscontinueTheOrder = anOrder.cloneForDiscontinuing();

assertEquals(anOrder.getClass(), anOrder.cloneForDiscontinuing().getClass());
assertEquals(anOrder.getClass(), orderThatCanDiscontinueTheOrder.getClass());

assertEquals(anOrder.getPatient(), orderThatCanDiscontinueTheOrder.getPatient());

assertEquals(anOrder.getConcept(), orderThatCanDiscontinueTheOrder.getConcept());

assertEquals("should set previous order to anOrder", orderThatCanDiscontinueTheOrder.getPreviousOrder(), anOrder);

Expand Down

0 comments on commit 21026f4

Please sign in to comment.