Search in sources :

Example 11 with TestOrder

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

the class OrderValidatorTest method validate_shouldNotAllowAFutureDateActivated.

/**
 * @see OrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldNotAllowAFutureDateActivated() {
    Patient patient = Context.getPatientService().getPatient(7);
    TestOrder order = new TestOrder();
    order.setPatient(patient);
    order.setOrderType(orderService.getOrderTypeByName("Test order"));
    order.setEncounter(Context.getEncounterService().getEncounter(3));
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, 1);
    order.setDateActivated(cal.getTime());
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
    Assert.assertEquals("Order.error.dateActivatedInFuture", errors.getFieldError("dateActivated").getCode());
}
Also used : Errors(org.springframework.validation.Errors) TestOrder(org.openmrs.TestOrder) Calendar(java.util.Calendar) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 12 with TestOrder

use of org.openmrs.TestOrder 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 13 with TestOrder

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

the class EncounterServiceTest method saveEncounter_shouldNotCascadeToExistingOrder.

/**
 * @see EncounterService#unvoidEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldNotCascadeToExistingOrder() {
    EncounterService es = Context.getEncounterService();
    TestOrder order = (TestOrder) Context.getOrderService().getOrder(7);
    order.setVoided(true);
    Encounter encounter = es.getEncounter(6);
    es.saveEncounter(encounter);
    String sql = "SELECT voided FROM orders WHERE order_id=7";
    Boolean voided = (Boolean) Context.getAdministrationService().executeSQL(sql, true).get(0).get(0);
    Assert.assertFalse(voided);
}
Also used : TestOrder(org.openmrs.TestOrder) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 14 with TestOrder

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

the class EncounterServiceTest method saveEncounter_shouldSetDateStoppedOnTheOriginalAfterAddingReviseOrder.

/**
 * @see EncounterService#unvoidEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldSetDateStoppedOnTheOriginalAfterAddingReviseOrder() {
    EncounterService es = Context.getEncounterService();
    TestOrder order = (TestOrder) Context.getOrderService().getOrder(7);
    Assert.assertNull(order.getDateStopped());
    Encounter encounter = es.getEncounter(6);
    TestOrder reviseOrder = order.cloneForRevision();
    reviseOrder.setOrderer(Context.getProviderService().getProvider(1));
    encounter.addOrder(reviseOrder);
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    Date dateStopped = Context.getOrderService().getOrder(7).getDateStopped();
    Assert.assertNotNull(dateStopped);
}
Also used : TestOrder(org.openmrs.TestOrder) Encounter(org.openmrs.Encounter) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 15 with TestOrder

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

Aggregations

TestOrder (org.openmrs.TestOrder)21 Test (org.junit.Test)19 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)18 OrderUtilTest (org.openmrs.order.OrderUtilTest)13 Date (java.util.Date)12 Order (org.openmrs.Order)12 DrugOrder (org.openmrs.DrugOrder)10 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)9 Concept (org.openmrs.Concept)9 Patient (org.openmrs.Patient)8 Encounter (org.openmrs.Encounter)6 CareSetting (org.openmrs.CareSetting)4 BindException (org.springframework.validation.BindException)3 Errors (org.springframework.validation.Errors)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Ignore (org.junit.Ignore)2 GlobalProperty (org.openmrs.GlobalProperty)2 OrderType (org.openmrs.OrderType)2 ConceptService (org.openmrs.api.ConceptService)2