Search in sources :

Example 61 with Order

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

the class OrderValidatorTest method validate_shouldFailValidationIfUrgencyIsNull.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfUrgencyIsNull() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setUrgency(null);
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(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) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 62 with Order

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

the class OrderValidatorTest method validate_shouldFailValidationIfActionIsNull.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfActionIsNull() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setAction(null);
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("action"));
}
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)

Example 63 with Order

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

the class OrderValidatorTest method validate_shouldFailValidationIfDateActivatedIsBeforeEncountersEncounterDatetime.

/**
 * @see OrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfDateActivatedIsBeforeEncountersEncounterDatetime() {
    Date encounterDate = new Date();
    Date orderDate = DateUtils.addDays(encounterDate, -1);
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    encounter.setEncounterDatetime(encounterDate);
    Order order = new Order();
    order.setDateActivated(orderDate);
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setEncounter(encounter);
    order.setOrderer(Context.getProviderService().getProvider(1));
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 64 with Order

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

the class OrderValidatorTest method validate_shouldFailValidationIfOrdererIsNull.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfOrdererIsNull() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors("discontinued"));
    Assert.assertFalse(errors.hasFieldErrors("concept"));
    Assert.assertTrue(errors.hasFieldErrors("orderer"));
    Assert.assertFalse(errors.hasFieldErrors("patient"));
}
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)

Example 65 with Order

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

the class OrderServiceImpl method ensureCareSettingIsSet.

private void ensureCareSettingIsSet(Order order, OrderContext orderContext) {
    if (order.getCareSetting() != null) {
        return;
    }
    CareSetting careSetting = null;
    if (orderContext != null) {
        careSetting = orderContext.getCareSetting();
    }
    Order previousOrder = order.getPreviousOrder();
    if (careSetting == null || (previousOrder != null && !careSetting.equals(previousOrder.getCareSetting()))) {
        throw new OrderEntryException("Order.care.cannot.determine");
    }
    order.setCareSetting(careSetting);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) OrderEntryException(org.openmrs.api.OrderEntryException) CareSetting(org.openmrs.CareSetting)

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