Search in sources :

Example 6 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldNotChangeTheAutoExpireDateIfItHasATimeComponent.

/**
 * @throws ParseException
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldNotChangeTheAutoExpireDateIfItHasATimeComponent() throws ParseException {
    Order order = new TestOrder();
    order.setPatient(patientService.getPatient(2));
    order.setCareSetting(orderService.getCareSetting(2));
    order.setConcept(conceptService.getConcept(5089));
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    order.setDateActivated(new Date());
    DateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    order.setDateActivated(dateformat.parse("14/08/2014 10:00:00"));
    Date autoExpireDate = dateformat.parse("18/08/2014 10:00:00");
    order.setAutoExpireDate(autoExpireDate);
    orderService.saveOrder(order, null);
    assertEquals(autoExpireDate, order.getAutoExpireDate());
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 7 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldSetOrderTypeOfTestOrderToTestOrderIfNotSetAndConceptNotMapped.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetOrderTypeOfTestOrderToTestOrderIfNotSetAndConceptNotMapped() {
    TestOrder testOrder = new TestOrder();
    testOrder.setPatient(patientService.getPatient(7));
    Concept unmappedConcept = conceptService.getConcept(113);
    Assert.assertNull(orderService.getOrderTypeByConcept(unmappedConcept));
    testOrder.setConcept(unmappedConcept);
    testOrder.setOrderer(providerService.getProvider(1));
    testOrder.setCareSetting(orderService.getCareSetting(1));
    Encounter encounter = encounterService.getEncounter(3);
    testOrder.setEncounter(encounter);
    testOrder.setDateActivated(encounter.getEncounterDatetime());
    testOrder.setClinicalHistory("Patient had a negative reaction to the test in the past");
    testOrder.setFrequency(orderService.getOrderFrequency(3));
    testOrder.setSpecimenSource(conceptService.getConcept(22));
    testOrder.setNumberOfRepeats(3);
    orderService.saveOrder(testOrder, null);
    Assert.assertNotNull(testOrder.getOrderType());
    Assert.assertEquals(orderService.getOrderTypeByUuid(OrderType.TEST_ORDER_TYPE_UUID), testOrder.getOrderType());
}
Also used : Concept(org.openmrs.Concept) TestOrder(org.openmrs.TestOrder) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 8 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldPassIfAnActiveTestOrderForTheSameConceptAndCareSettingExists.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldPassIfAnActiveTestOrderForTheSameConceptAndCareSettingExists() {
    final Patient patient = patientService.getPatient(2);
    final Concept cd4Count = conceptService.getConcept(5497);
    // sanity check that we have an active order for the same concept
    TestOrder duplicateOrder = (TestOrder) orderService.getOrder(7);
    assertTrue(duplicateOrder.isActive());
    assertEquals(cd4Count, duplicateOrder.getConcept());
    Order order = new TestOrder();
    order.setPatient(patient);
    order.setCareSetting(orderService.getCareSetting(2));
    order.setConcept(cd4Count);
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(duplicateOrder.getCareSetting());
    Order savedOrder = orderService.saveOrder(order, null);
    assertNotNull(orderService.getOrder(savedOrder.getOrderId()));
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 9 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting() {
    final Patient patient = patientService.getPatient(2);
    final Concept cd4Count = conceptService.getConcept(5497);
    TestOrder duplicateOrder = (TestOrder) orderService.getOrder(7);
    final CareSetting inpatient = orderService.getCareSetting(2);
    assertNotEquals(inpatient, duplicateOrder.getCareSetting());
    assertTrue(duplicateOrder.isActive());
    assertEquals(cd4Count, duplicateOrder.getConcept());
    int initialActiveOrderCount = orderService.getActiveOrders(patient, null, null, null).size();
    TestOrder order = new TestOrder();
    order.setPatient(patient);
    order.setCareSetting(orderService.getCareSetting(2));
    order.setConcept(cd4Count);
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(inpatient);
    orderService.saveOrder(order, null);
    List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
    assertEquals(++initialActiveOrderCount, activeOrders.size());
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 10 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldRollTheAutoExpireDateToTheEndOfTheDayIfItHasNoTimeComponent.

/**
 * @throws ParseException
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldRollTheAutoExpireDateToTheEndOfTheDayIfItHasNoTimeComponent() throws ParseException {
    Order order = new TestOrder();
    order.setPatient(patientService.getPatient(2));
    order.setCareSetting(orderService.getCareSetting(2));
    order.setConcept(conceptService.getConcept(5089));
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    DateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
    order.setDateActivated(dateformat.parse("14/08/2014"));
    order.setAutoExpireDate(dateformat.parse("18/08/2014"));
    orderService.saveOrder(order, null);
    dateformat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.S");
    assertEquals(dateformat.parse("18/08/2014 23:59:59.000"), order.getAutoExpireDate());
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

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