Search in sources :

Example 21 with Order

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

the class OrderServiceTest method getActiveOrders_shouldIncludeOrdersForSubTypesIfOrderTypeIsSpecified.

/**
 * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
 *      org.openmrs.CareSetting, java.util.Date)
 */
@Test
public void getActiveOrders_shouldIncludeOrdersForSubTypesIfOrderTypeIsSpecified() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-otherOrders.xml");
    Patient patient = Context.getPatientService().getPatient(2);
    OrderType testOrderType = orderService.getOrderType(2);
    List<Order> orders = orderService.getActiveOrders(patient, testOrderType, null, null);
    assertEquals(5, orders.size());
    Order[] expectedOrder1 = { orderService.getOrder(7), orderService.getOrder(101), orderService.getOrder(102), orderService.getOrder(103), orderService.getOrder(104) };
    assertThat(orders, hasItems(expectedOrder1));
    OrderType labTestOrderType = orderService.getOrderType(7);
    orders = orderService.getActiveOrders(patient, labTestOrderType, null, null);
    assertEquals(3, orders.size());
    Order[] expectedOrder2 = { orderService.getOrder(101), orderService.getOrder(103), orderService.getOrder(104) };
    assertThat(orders, hasItems(expectedOrder2));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 22 with Order

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

the class OrderServiceTest method saveOrderWithScheduledDate_shouldAddANewOrderWithScheduledDateToTheDatabase.

@Test
public void saveOrderWithScheduledDate_shouldAddANewOrderWithScheduledDateToTheDatabase() {
    Date scheduledDate = new Date();
    Order order = new Order();
    order.setAction(Action.NEW);
    order.setPatient(Context.getPatientService().getPatient(7));
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setCareSetting(orderService.getCareSetting(1));
    order.setOrderer(orderService.getOrder(1).getOrderer());
    order.setEncounter(encounterService.getEncounter(3));
    order.setDateActivated(new Date());
    order.setScheduledDate(scheduledDate);
    order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    order.setEncounter(encounterService.getEncounter(3));
    order.setOrderType(orderService.getOrderType(17));
    order = orderService.saveOrder(order, null);
    Order newOrder = orderService.getOrder(order.getOrderId());
    assertNotNull(order);
    assertEquals(DateUtil.truncateToSeconds(scheduledDate), order.getScheduledDate());
    assertNotNull(newOrder);
    assertEquals(DateUtil.truncateToSeconds(scheduledDate), newOrder.getScheduledDate());
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 23 with Order

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

the class OrderServiceTest method saveOrder_shouldDiscontinuePreviousOrderIfItIsNotAlreadyDiscontinued.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldDiscontinuePreviousOrderIfItIsNotAlreadyDiscontinued() {
    // We are trying to discontinue order id 111 in standardTestDataset.xml
    DrugOrder order = new DrugOrder();
    order.setAction(Order.Action.DISCONTINUE);
    order.setOrderReasonNonCoded("Discontinue this");
    order.setDrug(conceptService.getDrug(3));
    order.setEncounter(encounterService.getEncounter(5));
    order.setPatient(Context.getPatientService().getPatient(7));
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    order.setEncounter(encounterService.getEncounter(3));
    order.setOrderType(orderService.getOrderType(1));
    order.setDateActivated(new Date());
    order.setDosingType(SimpleDosingInstructions.class);
    order.setDose(500.0);
    order.setDoseUnits(conceptService.getConcept(50));
    order.setFrequency(orderService.getOrderFrequency(1));
    order.setRoute(conceptService.getConcept(22));
    order.setNumRefills(10);
    order.setQuantity(20.0);
    order.setQuantityUnits(conceptService.getConcept(51));
    Order previousOrder = orderService.getOrder(111);
    assertTrue(OrderUtilTest.isActiveOrder(previousOrder, null));
    order.setPreviousOrder(previousOrder);
    orderService.saveOrder(order, null);
    Assert.assertEquals(order.getDateActivated(), order.getAutoExpireDate());
    Assert.assertNotNull("previous order should be discontinued", previousOrder.getDateStopped());
}
Also used : DrugOrder(org.openmrs.DrugOrder) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 24 with Order

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

the class OrderServiceTest method getActiveOrders_shouldReturnAllActiveDrugOrdersForTheSpecifiedPatient.

/**
 * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
 *      org.openmrs.CareSetting, java.util.Date)
 */
@Test
public void getActiveOrders_shouldReturnAllActiveDrugOrdersForTheSpecifiedPatient() {
    Patient patient = patientService.getPatient(2);
    List<Order> orders = orderService.getActiveOrders(patient, orderService.getOrderType(1), null, null);
    assertEquals(4, orders.size());
    Order[] expectedOrders = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5) };
    assertThat(orders, hasItems(expectedOrders));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 25 with Order

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

the class OrderServiceTest method saveOrder_shouldPassIfAnActiveDrugOrderForTheSameConceptAndCareSettingButDifferentFormulationExists.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldPassIfAnActiveDrugOrderForTheSameConceptAndCareSettingButDifferentFormulationExists() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrdersWithSameConceptAndDifferentFormAndStrength.xml");
    final Patient patient = patientService.getPatient(2);
    // sanity check that we have an active order
    DrugOrder existingOrder = (DrugOrder) orderService.getOrder(1000);
    assertTrue(existingOrder.isActive());
    // New Drug order
    DrugOrder order = new DrugOrder();
    order.setPatient(patient);
    order.setConcept(existingOrder.getConcept());
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(existingOrder.getCareSetting());
    order.setDrug(conceptService.getDrug(3001));
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setDosingInstructions("2 for 5 days");
    order.setQuantity(10.0);
    order.setQuantityUnits(conceptService.getConcept(51));
    order.setNumRefills(2);
    Order savedDrugOrder = orderService.saveOrder(order, null);
    assertNotNull(orderService.getOrder(savedDrugOrder.getOrderId()));
}
Also used : DrugOrder(org.openmrs.DrugOrder) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Aggregations

Order (org.openmrs.Order)155 Test (org.junit.Test)133 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)115 TestOrder (org.openmrs.TestOrder)114 DrugOrder (org.openmrs.DrugOrder)106 OrderUtilTest (org.openmrs.order.OrderUtilTest)97 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)77 Date (java.util.Date)67 Encounter (org.openmrs.Encounter)41 Patient (org.openmrs.Patient)36 BindException (org.springframework.validation.BindException)20 Errors (org.springframework.validation.Errors)20 Concept (org.openmrs.Concept)15 CareSetting (org.openmrs.CareSetting)11 Obs (org.openmrs.Obs)11 SimpleDateFormat (java.text.SimpleDateFormat)10 OrderGroup (org.openmrs.OrderGroup)10 ArrayList (java.util.ArrayList)9 Calendar (java.util.Calendar)9 OrderBuilder (org.openmrs.api.builder.OrderBuilder)9