Search in sources :

Example 56 with Order

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

the class OrderServiceTest method getDiscontinuationOrder_shouldReturnNullIfOrderHasNotBeenDiscontinued.

/**
 * @see OrderService#getDiscontinuationOrder(Order)
 */
@Test
public void getDiscontinuationOrder_shouldReturnNullIfOrderHasNotBeenDiscontinued() {
    Order order = orderService.getOrder(111);
    Order discontinuationOrder = orderService.getDiscontinuationOrder(order);
    assertThat(discontinuationOrder, is(nullValue()));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 57 with Order

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

the class OrderServiceTest method getActiveOrders_shouldReturnAllOrdersIfNoOrderTypeIsSpecified.

/**
 * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
 *      org.openmrs.CareSetting, java.util.Date)
 */
@Test
public void getActiveOrders_shouldReturnAllOrdersIfNoOrderTypeIsSpecified() {
    Patient patient = Context.getPatientService().getPatient(2);
    List<Order> orders = orderService.getActiveOrders(patient, null, null, null);
    assertEquals(5, orders.size());
    Order[] expectedOrders = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5), orderService.getOrder(7) };
    assertThat(orders, hasItems(expectedOrders));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 58 with Order

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

the class OrderValidatorTest method validate_shouldFailValidationIfDateActivatedAfterAutoExpireDate.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfDateActivatedAfterAutoExpireDate() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setOrderer(Context.getProviderService().getProvider(1));
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1);
    order.setDateActivated(new Date());
    order.setAutoExpireDate(cal.getTime());
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
    Assert.assertTrue(errors.hasFieldErrors("autoExpireDate"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) Calendar(java.util.Calendar) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 59 with Order

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

the class OrderValidatorTest method validate_shouldFailValidationIfScheduledDateIsSetAndUrgencyIsNotSetAsON_SCHEDULED_DATE.

/**
 * @see OrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfScheduledDateIsSetAndUrgencyIsNotSetAsON_SCHEDULED_DATE() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setScheduledDate(new Date());
    order.setUrgency(Order.Urgency.ROUTINE);
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("urgency"));
    order.setScheduledDate(new Date());
    order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors("urgency"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 60 with Order

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

the class OrderValidatorTest method validate_shouldFailValidationIfEncounterIsNull.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfEncounterIsNull() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setEncounter(null);
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("encounter"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Aggregations

Order (org.openmrs.Order)155 Test (org.junit.Test)133 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)115 TestOrder (org.openmrs.TestOrder)114 DrugOrder (org.openmrs.DrugOrder)106 OrderUtilTest (org.openmrs.order.OrderUtilTest)97 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)77 Date (java.util.Date)67 Encounter (org.openmrs.Encounter)41 Patient (org.openmrs.Patient)36 BindException (org.springframework.validation.BindException)20 Errors (org.springframework.validation.Errors)20 Concept (org.openmrs.Concept)15 CareSetting (org.openmrs.CareSetting)11 Obs (org.openmrs.Obs)11 SimpleDateFormat (java.text.SimpleDateFormat)10 OrderGroup (org.openmrs.OrderGroup)10 ArrayList (java.util.ArrayList)9 Calendar (java.util.Calendar)9 OrderBuilder (org.openmrs.api.builder.OrderBuilder)9