Search in sources :

Example 31 with Order

use of org.openmrs.Order 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 32 with Order

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

the class OrderServiceTest method discontinueOrder_shouldFailForADiscontinuationOrder.

/**
 * @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date,
 *      org.openmrs.Provider, org.openmrs.Encounter)
 */
@Test
public void discontinueOrder_shouldFailForADiscontinuationOrder() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinuedOrder.xml");
    Order discontinuationOrder = orderService.getOrder(26);
    assertEquals(Action.DISCONTINUE, discontinuationOrder.getAction());
    Encounter encounter = encounterService.getEncounter(3);
    expectedException.expect(CannotStopDiscontinuationOrderException.class);
    expectedException.expectMessage(mss.getMessage("Order.action.cannot.discontinue"));
    orderService.discontinueOrder(discontinuationOrder, "Test if I can discontinue this", null, null, encounter);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 33 with Order

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

the class OrderServiceTest method saveOrder_shouldPassIfAnActiveDrugOrderForTheSameDrugFormulationExistsBeyondSchedule.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldPassIfAnActiveDrugOrderForTheSameDrugFormulationExistsBeyondSchedule() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-DrugOrders.xml");
    final Patient patient = patientService.getPatient(2);
    DrugOrder existingOrder = (DrugOrder) orderService.getOrder(2000);
    int initialActiveOrderCount = orderService.getActiveOrders(patient, null, null, null).size();
    // New Drug order
    DrugOrder order = new DrugOrder();
    order.setPatient(patient);
    order.setDrug(existingOrder.getDrug());
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(existingOrder.getCareSetting());
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setDosingInstructions("2 for 10 days");
    order.setQuantity(10.0);
    order.setQuantityUnits(conceptService.getConcept(51));
    order.setNumRefills(2);
    order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    order.setScheduledDate(DateUtils.addDays(existingOrder.getDateStopped(), 1));
    orderService.saveOrder(order, null);
    List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
    assertEquals(++initialActiveOrderCount, activeOrders.size());
}
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)

Example 34 with Order

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

the class OrderServiceTest method unvoidOrder_shouldFailForAReviseOrderIfThePreviousOrderIsInactive.

/**
 * @throws InterruptedException
 * @see OrderService#unvoidOrder(org.openmrs.Order)
 */
@Test
public void unvoidOrder_shouldFailForAReviseOrderIfThePreviousOrderIsInactive() throws InterruptedException {
    Order order = orderService.getOrder(111);
    assertEquals(Action.REVISE, order.getAction());
    Order previousOrder = order.getPreviousOrder();
    assertNotNull(previousOrder.getDateStopped());
    assertFalse(order.getVoided());
    // void the DC order for testing purposes so we can unvoid it later
    orderService.voidOrder(order, "None");
    assertTrue(order.getVoided());
    assertNull(previousOrder.getDateStopped());
    // stop the order with a different REVISE order
    Order revise = previousOrder.cloneForRevision();
    revise.setOrderer(order.getOrderer());
    revise.setEncounter(order.getEncounter());
    orderService.saveOrder(revise, null);
    Thread.sleep(10);
    expectedException.expect(CannotUnvoidOrderException.class);
    expectedException.expectMessage(mss.getMessage("Order.action.cannot.unvoid", new Object[] { "revision" }, null));
    orderService.unvoidOrder(order);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 35 with Order

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

the class OrderServiceTest method discontinueOrder_shouldPassForAnActiveOrderWhichIsScheduledAndNotStartedAsOfDiscontinueDate.

/**
 * @see OrderService#discontinueOrder(Order,String,Date,Provider,Encounter)
 */
@Test
public void discontinueOrder_shouldPassForAnActiveOrderWhichIsScheduledAndNotStartedAsOfDiscontinueDate() {
    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.setEncounter(encounterService.getEncounter(3));
    order.setOrderType(orderService.getOrderType(17));
    order.setDateActivated(new Date());
    order.setScheduledDate(DateUtils.addMonths(new Date(), 2));
    order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    order = orderService.saveOrder(order, null);
    assertTrue(OrderUtilTest.isActiveOrder(order, null));
    assertFalse(order.isStarted());
    Encounter encounter = encounterService.getEncounter(3);
    Provider orderer = providerService.getProvider(1);
    Date discontinueDate = new Date();
    String discontinueReasonNonCoded = "Test if I can discontinue this";
    Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate, orderer, encounter);
    Assert.assertEquals(order.getDateStopped(), discontinueDate);
    Assert.assertNotNull(discontinueOrder);
    Assert.assertNotNull(discontinueOrder.getId());
    Assert.assertEquals(discontinueOrder.getDateActivated(), discontinueOrder.getAutoExpireDate());
    Assert.assertEquals(discontinueOrder.getAction(), Action.DISCONTINUE);
    Assert.assertEquals(discontinueOrder.getOrderReasonNonCoded(), discontinueReasonNonCoded);
    Assert.assertEquals(discontinueOrder.getPreviousOrder(), order);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Encounter(org.openmrs.Encounter) Date(java.util.Date) Provider(org.openmrs.Provider) 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