Search in sources :

Example 11 with CareSetting

use of org.openmrs.CareSetting 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 12 with CareSetting

use of org.openmrs.CareSetting 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)

Example 13 with CareSetting

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

the class TestOrderValidatorTest method validate_shouldFailValidationIfTheSpecimenSourceIsInvalid.

/**
 * @see TestOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfTheSpecimenSourceIsInvalid() {
    ConceptService conceptService = Context.getConceptService();
    Concept specimenSource = conceptService.getConcept(3);
    OrderService orderService = Context.getOrderService();
    assertThat(specimenSource, not(isIn(orderService.getDrugRoutes())));
    TestOrder order = new TestOrder();
    Patient patient = new Patient(8);
    order.setPatient(patient);
    order.setOrderType(orderService.getOrderTypeByName("Test order"));
    order.setConcept(conceptService.getConcept(5497));
    order.setOrderer(new Provider());
    order.setCareSetting(new CareSetting());
    Encounter encounter = new Encounter();
    encounter.setPatient(patient);
    order.setEncounter(encounter);
    order.setDateActivated(new Date());
    order.setSpecimenSource(specimenSource);
    Errors errors = new BindException(order, "order");
    new TestOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("specimenSource"));
    Assert.assertEquals("TestOrder.error.specimenSourceNotAmongAllowedConcepts", errors.getFieldError("specimenSource").getCode());
}
Also used : Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) OrderService(org.openmrs.api.OrderService) ConceptService(org.openmrs.api.ConceptService) Date(java.util.Date) Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with CareSetting

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

the class TestOrderValidatorTest method validate_shouldPassValidationIfTheSpecimenSourceIsValid.

/**
 * @see TestOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassValidationIfTheSpecimenSourceIsValid() {
    ConceptService conceptService = Context.getConceptService();
    Concept specimenSource = conceptService.getConcept(22);
    OrderService orderService = Context.getOrderService();
    assertThat(specimenSource, isIn(orderService.getDrugRoutes()));
    TestOrder order = new TestOrder();
    Patient patient = new Patient(8);
    order.setPatient(patient);
    order.setOrderType(orderService.getOrderTypeByName("Test order"));
    order.setConcept(conceptService.getConcept(5497));
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setCareSetting(new CareSetting());
    Encounter encounter = new Encounter();
    encounter.setPatient(patient);
    order.setEncounter(encounter);
    order.setDateActivated(new Date());
    order.setSpecimenSource(specimenSource);
    Errors errors = new BindException(order, "order");
    new TestOrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors());
}
Also used : Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) OrderService(org.openmrs.api.OrderService) ConceptService(org.openmrs.api.ConceptService) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with CareSetting

use of org.openmrs.CareSetting 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)

Aggregations

CareSetting (org.openmrs.CareSetting)28 Test (org.junit.Test)27 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)27 OrderUtilTest (org.openmrs.order.OrderUtilTest)25 Patient (org.openmrs.Patient)22 DrugOrder (org.openmrs.DrugOrder)21 Encounter (org.openmrs.Encounter)16 OrderType (org.openmrs.OrderType)15 BindException (org.springframework.validation.BindException)14 Errors (org.springframework.validation.Errors)14 TestOrder (org.openmrs.TestOrder)13 Order (org.openmrs.Order)11 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)7 GlobalProperty (org.openmrs.GlobalProperty)7 Date (java.util.Date)6 Concept (org.openmrs.Concept)5 Calendar (java.util.Calendar)4 ConceptService (org.openmrs.api.ConceptService)3 OrderService (org.openmrs.api.OrderService)2 Provider (org.openmrs.Provider)1