Search in sources :

Example 51 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrderType_shouldAddANewOrderTypeToTheDatabase.

/**
 * @see OrderService#saveOrderType(org.openmrs.OrderType)
 */
@Test
public void saveOrderType_shouldAddANewOrderTypeToTheDatabase() {
    int orderTypeCount = orderService.getOrderTypes(true).size();
    OrderType orderType = new OrderType();
    orderType.setName("New Order");
    orderType.setJavaClassName("org.openmrs.NewTestOrder");
    orderType.setDescription("New order type for testing");
    orderType.setRetired(false);
    orderType = orderService.saveOrderType(orderType);
    assertNotNull(orderType);
    assertEquals("New Order", orderType.getName());
    assertNotNull(orderType.getId());
    assertEquals((orderTypeCount + 1), orderService.getOrderTypes(true).size());
}
Also used : OrderType(org.openmrs.OrderType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 52 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrder_shouldDefaultToCareSettingAndOrderTypeDefinedInTheOrderContextIfNull.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldDefaultToCareSettingAndOrderTypeDefinedInTheOrderContextIfNull() {
    Order order = new TestOrder();
    order.setPatient(patientService.getPatient(7));
    Concept trimune30 = conceptService.getConcept(792);
    order.setConcept(trimune30);
    order.setOrderer(providerService.getProvider(1));
    order.setEncounter(encounterService.getEncounter(3));
    order.setDateActivated(new Date());
    OrderType expectedOrderType = orderService.getOrderType(2);
    CareSetting expectedCareSetting = orderService.getCareSetting(1);
    OrderContext orderContext = new OrderContext();
    orderContext.setOrderType(expectedOrderType);
    orderContext.setCareSetting(expectedCareSetting);
    order = orderService.saveOrder(order, orderContext);
    assertFalse(expectedOrderType.getConceptClasses().contains(trimune30.getConceptClass()));
    assertEquals(expectedOrderType, order.getOrderType());
    assertEquals(expectedCareSetting, order.getCareSetting());
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Concept(org.openmrs.Concept) OrderType(org.openmrs.OrderType) TestOrder(org.openmrs.TestOrder) CareSetting(org.openmrs.CareSetting) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 53 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrder_shouldFailIfTheOrderTypeOfThePreviousOrderDoesNotMatch.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldFailIfTheOrderTypeOfThePreviousOrderDoesNotMatch() {
    Order order = orderService.getOrder(7);
    assertTrue(OrderUtilTest.isActiveOrder(order, null));
    Order discontinuationOrder = order.cloneForDiscontinuing();
    OrderType orderType = orderService.getOrderType(7);
    assertNotEquals(discontinuationOrder.getOrderType(), orderType);
    assertTrue(OrderUtil.isType(discontinuationOrder.getOrderType(), orderType));
    discontinuationOrder.setOrderType(orderType);
    discontinuationOrder.setOrderer(Context.getProviderService().getProvider(1));
    discontinuationOrder.setEncounter(Context.getEncounterService().getEncounter(6));
    expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
    expectedException.expectMessage(mss.getMessage("Order.type.doesnot.match"));
    orderService.saveOrder(discontinuationOrder, null);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) OrderType(org.openmrs.OrderType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 54 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderServiceTest method getOrders_shouldGetTheOrdersThatMatchAllTheArguments.

/**
 * @see OrderService#getOrders(org.openmrs.Patient, org.openmrs.CareSetting,
 *      org.openmrs.OrderType, boolean)
 */
@Test
public void getOrders_shouldGetTheOrdersThatMatchAllTheArguments() {
    Patient patient = patientService.getPatient(2);
    CareSetting outPatient = orderService.getCareSetting(1);
    OrderType testOrderType = orderService.getOrderType(2);
    List<Order> testOrders = orderService.getOrders(patient, outPatient, testOrderType, false);
    assertEquals(3, testOrders.size());
    TestUtil.containsId(testOrders, 6);
    TestUtil.containsId(testOrders, 7);
    TestUtil.containsId(testOrders, 9);
    OrderType drugOrderType = orderService.getOrderType(1);
    List<Order> drugOrders = orderService.getOrders(patient, outPatient, drugOrderType, false);
    assertEquals(5, drugOrders.size());
    TestUtil.containsId(drugOrders, 2);
    TestUtil.containsId(drugOrders, 3);
    TestUtil.containsId(drugOrders, 44);
    TestUtil.containsId(drugOrders, 444);
    TestUtil.containsId(drugOrders, 5);
    CareSetting inPatient = orderService.getCareSetting(2);
    List<Order> inPatientDrugOrders = orderService.getOrders(patient, inPatient, drugOrderType, false);
    assertEquals(222, inPatientDrugOrders.get(0).getOrderId().intValue());
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Aggregations

OrderType (org.openmrs.OrderType)54 Test (org.junit.Test)46 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)45 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 BindException (org.springframework.validation.BindException)22 Errors (org.springframework.validation.Errors)22 Patient (org.openmrs.Patient)17 DrugOrder (org.openmrs.DrugOrder)16 CareSetting (org.openmrs.CareSetting)15 Encounter (org.openmrs.Encounter)11 GlobalProperty (org.openmrs.GlobalProperty)8 Order (org.openmrs.Order)8 TestOrder (org.openmrs.TestOrder)6 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)5 ConceptClass (org.openmrs.ConceptClass)5 HashSet (java.util.HashSet)4 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 Criteria (org.hibernate.Criteria)2 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)2