Search in sources :

Example 16 with OrderType

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

the class DrugOrderValidatorTest method saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse.

/**
 * @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
 */
@Test
public void saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "false");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Patient patient = Context.getPatientService().getPatient(7);
    CareSetting careSetting = Context.getOrderService().getCareSetting(2);
    OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    order.setEncounter(encounter);
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setPatient(patient);
    order.setCareSetting(careSetting);
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setDateActivated(encounter.getEncounterDatetime());
    order.setOrderType(orderType);
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setInstructions("None");
    order.setDosingInstructions("Test Instruction");
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors());
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 17 with OrderType

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

the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsTrue.

/**
 * @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
 */
@Test
public void saveOrder_shouldFailDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsTrue() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Patient patient = Context.getPatientService().getPatient(7);
    CareSetting careSetting = Context.getOrderService().getCareSetting(2);
    OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    order.setEncounter(encounter);
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setPatient(patient);
    order.setCareSetting(careSetting);
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setDateActivated(encounter.getEncounterDatetime());
    order.setOrderType(orderType);
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setInstructions("None");
    order.setDosingInstructions("Test Instruction");
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("drug"));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 18 with OrderType

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

the class OrderServiceImpl method ensureOrderTypeIsSet.

private void ensureOrderTypeIsSet(Order order, OrderContext orderContext) {
    if (order.getOrderType() != null) {
        return;
    }
    OrderType orderType = null;
    if (orderContext != null) {
        orderType = orderContext.getOrderType();
    }
    if (orderType == null) {
        orderType = getOrderTypeByConcept(order.getConcept());
    }
    if (orderType == null && order instanceof DrugOrder) {
        orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID);
    }
    if (orderType == null && order instanceof TestOrder) {
        orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.TEST_ORDER_TYPE_UUID);
    }
    if (orderType == null) {
        throw new OrderEntryException("Order.type.cannot.determine");
    }
    Order previousOrder = order.getPreviousOrder();
    if (previousOrder != null && !orderType.equals(previousOrder.getOrderType())) {
        throw new OrderEntryException("Order.type.does.not.match");
    }
    order.setOrderType(orderType);
}
Also used : DrugOrder(org.openmrs.DrugOrder) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) OrderEntryException(org.openmrs.api.OrderEntryException) OrderType(org.openmrs.OrderType) TestOrder(org.openmrs.TestOrder)

Example 19 with OrderType

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

the class OrderTypeValidatorTest method validate_shouldPassIfAllFieldsAreCorrectForANewOrderType.

/**
 * @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassIfAllFieldsAreCorrectForANewOrderType() {
    OrderType orderType = new OrderType();
    orderType.setName("unique name");
    orderType.setJavaClassName("org.openmrs.TestDrugOrder");
    Collection<ConceptClass> col = new HashSet<>();
    col.add(Context.getConceptService().getConceptClass(2));
    orderType.setConceptClasses(col);
    Errors errors = new BindException(orderType, "orderType");
    new OrderTypeValidator().validate(orderType, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) HashSet(java.util.HashSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 20 with OrderType

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

the class OrderTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    OrderType orderType = new OrderType();
    orderType.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    orderType.setJavaClassName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Collection<ConceptClass> col = new HashSet<>();
    col.add(Context.getConceptService().getConceptClass(2));
    orderType.setConceptClasses(col);
    orderType.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    orderType.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(orderType, "orderType");
    new OrderTypeValidator().validate(orderType, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("name"));
    Assert.assertEquals(true, errors.hasFieldErrors("javaClassName"));
    Assert.assertEquals(true, errors.hasFieldErrors("description"));
    Assert.assertEquals(true, errors.hasFieldErrors("retireReason"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) HashSet(java.util.HashSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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