Search in sources :

Example 36 with DrugOrder

use of org.openmrs.DrugOrder 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 37 with DrugOrder

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

the class OrderValidatorTest method validate_shouldPassValidationIfAllFieldsAreCorrect.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllFieldsAreCorrect() {
    Order order = new DrugOrder();
    Encounter encounter = new Encounter();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setOrderer(Context.getProviderService().getProvider(1));
    Patient patient = Context.getPatientService().getPatient(2);
    encounter.setPatient(patient);
    order.setPatient(patient);
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1);
    order.setDateActivated(cal.getTime());
    order.setAutoExpireDate(new Date());
    order.setCareSetting(new CareSetting());
    order.setEncounter(encounter);
    order.setUrgency(Order.Urgency.ROUTINE);
    order.setAction(Order.Action.NEW);
    order.setOrderType(Context.getOrderService().getOrderTypeByName("Drug order"));
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) Calendar(java.util.Calendar) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 38 with DrugOrder

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

the class OrderValidatorTest method validate_shouldFailValidationIfOrderTypejavaClassDoesNotMatchOrderclass.

/**
 * @see OrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfOrderTypejavaClassDoesNotMatchOrderclass() {
    Order order = new DrugOrder();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setOrderType(Context.getOrderService().getOrderTypeByName("Test order"));
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("orderType"));
    Assert.assertTrue(Arrays.asList(errors.getFieldError("orderType").getCodes()).contains("Order.error.orderTypeClassMismatchesOrderClass"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) 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 39 with DrugOrder

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

the class DrugOrderValidatorTest method validate_shouldFailValidationIfDoseUnitsIsNullForSimpleDosingInstructionsDosingType.

/**
 * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfDoseUnitsIsNullForSimpleDosingInstructionsDosingType() {
    DrugOrder order = new DrugOrder();
    order.setDosingType(SimpleDosingInstructions.class);
    order.setDoseUnits(null);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("doseUnits"));
}
Also used : 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 40 with DrugOrder

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

the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithBothDrugNonCodedAndDrugAreSetForDrugOrder.

@Test
public void saveOrder_shouldFailDrugOrderWithBothDrugNonCodedAndDrugAreSetForDrugOrder() {
    Patient patient = Context.getPatientService().getPatient(7);
    CareSetting careSetting = Context.getOrderService().getCareSetting(2);
    OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    order.setEncounter(encounter);
    order.setDrug(Context.getConceptService().getDrug(3));
    order.setDrugNonCoded("paracetemol drug non coded");
    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());
    assertEquals("DrugOrder.error.onlyOneOfDrugOrNonCodedShouldBeSet", errors.getFieldError("concept").getCode());
}
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)

Aggregations

DrugOrder (org.openmrs.DrugOrder)68 Test (org.junit.Test)64 OrderUtilTest (org.openmrs.order.OrderUtilTest)64 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)64 BindException (org.springframework.validation.BindException)38 Errors (org.springframework.validation.Errors)38 Patient (org.openmrs.Patient)22 Date (java.util.Date)18 Encounter (org.openmrs.Encounter)17 Concept (org.openmrs.Concept)12 CareSetting (org.openmrs.CareSetting)11 Order (org.openmrs.Order)11 OrderType (org.openmrs.OrderType)11 TestOrder (org.openmrs.TestOrder)11 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)7 Drug (org.openmrs.Drug)7 GlobalProperty (org.openmrs.GlobalProperty)7 Calendar (java.util.Calendar)5 SimpleDateFormat (java.text.SimpleDateFormat)1 Ignore (org.junit.Ignore)1