Search in sources :

Example 1 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldPassForADiscontinuationOrderWithNoPreviousOrder.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldPassForADiscontinuationOrderWithNoPreviousOrder() {
    TestOrder dcOrder = new TestOrder();
    dcOrder.setAction(Action.DISCONTINUE);
    dcOrder.setPatient(patientService.getPatient(2));
    dcOrder.setCareSetting(orderService.getCareSetting(2));
    dcOrder.setConcept(conceptService.getConcept(5089));
    dcOrder.setEncounter(encounterService.getEncounter(6));
    dcOrder.setOrderer(providerService.getProvider(1));
    orderService.saveOrder(dcOrder, null);
}
Also used : TestOrder(org.openmrs.TestOrder) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 2 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldSetTheOrderNumberReturnedByTheConfiguredGenerator.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetTheOrderNumberReturnedByTheConfiguredGenerator() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_ORDER_NUMBER_GENERATOR_BEAN_ID, "orderEntry.OrderNumberGenerator");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Order order = new TestOrder();
    order.setPatient(patientService.getPatient(7));
    order.setConcept(conceptService.getConcept(5497));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    order.setOrderType(orderService.getOrderType(2));
    order.setEncounter(encounterService.getEncounter(3));
    order.setDateActivated(new Date());
    order = orderService.saveOrder(order, null);
    assertTrue(order.getOrderNumber().startsWith(TimestampOrderNumberGenerator.ORDER_NUMBER_PREFIX));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Date(java.util.Date) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 3 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldSaveRevisionOrderScheduledOnDateNotOverlappingWithAnActiveOrderForTheSameConceptAndCareSetting.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
@Ignore("Ignored because it fails after removal of deprecated methods TRUNK-4772")
public void saveOrder_shouldSaveRevisionOrderScheduledOnDateNotOverlappingWithAnActiveOrderForTheSameConceptAndCareSetting() {
    // sanity check that we have an active order
    final Patient patient = patientService.getPatient(2);
    final Concept cd4Count = conceptService.getConcept(5497);
    TestOrder activeOrder = new TestOrder();
    activeOrder.setPatient(patient);
    activeOrder.setConcept(cd4Count);
    activeOrder.setEncounter(encounterService.getEncounter(6));
    activeOrder.setOrderer(providerService.getProvider(1));
    activeOrder.setCareSetting(orderService.getCareSetting(2));
    activeOrder.setDateActivated(new Date());
    activeOrder.setAutoExpireDate(DateUtils.addDays(new Date(), 10));
    orderService.saveOrder(activeOrder, null);
    // New Drug order in future for same concept
    TestOrder secondOrder = new TestOrder();
    secondOrder.setPatient(activeOrder.getPatient());
    secondOrder.setConcept(activeOrder.getConcept());
    secondOrder.setEncounter(encounterService.getEncounter(6));
    secondOrder.setOrderer(providerService.getProvider(1));
    secondOrder.setCareSetting(activeOrder.getCareSetting());
    secondOrder.setDateActivated(new Date());
    secondOrder.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStopDate(), 1));
    secondOrder.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    orderService.saveOrder(secondOrder, null);
    // Revise Second Order to have scheduled date not overlapping with active order
    TestOrder revision = secondOrder.cloneForRevision();
    revision.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStopDate(), 2));
    revision.setEncounter(encounterService.getEncounter(6));
    revision.setOrderer(providerService.getProvider(1));
    Order savedRevisionOrder = orderService.saveOrder(revision, null);
    assertNotNull(orderService.getOrder(savedRevisionOrder.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) Date(java.util.Date) Ignore(org.junit.Ignore) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 4 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldSetOrderTypeIfNullButMappedToTheConceptClass.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetOrderTypeIfNullButMappedToTheConceptClass() {
    TestOrder order = new TestOrder();
    order.setPatient(patientService.getPatient(7));
    order.setConcept(conceptService.getConcept(5497));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    order.setEncounter(encounterService.getEncounter(3));
    order.setDateActivated(new Date());
    orderService.saveOrder(order, null);
    assertEquals(2, order.getOrderType().getOrderTypeId().intValue());
}
Also used : TestOrder(org.openmrs.TestOrder) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 5 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldPassForRevisionOrderIfAnActiveTestOrderForTheSameConceptAndCareSettingsExists.

/**
 *           settings exists
 * @see OrderService#saveOrder(Order, OrderContext)
 */
@Test
@Ignore("Ignored because it fails after removal of deprecated methods TRUNK-4772")
public void saveOrder_shouldPassForRevisionOrderIfAnActiveTestOrderForTheSameConceptAndCareSettingsExists() {
    final Patient patient = patientService.getPatient(2);
    final Concept cd4Count = conceptService.getConcept(5497);
    TestOrder activeOrder = new TestOrder();
    activeOrder.setPatient(patient);
    activeOrder.setConcept(cd4Count);
    activeOrder.setEncounter(encounterService.getEncounter(6));
    activeOrder.setOrderer(providerService.getProvider(1));
    activeOrder.setCareSetting(orderService.getCareSetting(2));
    activeOrder.setDateActivated(new Date());
    activeOrder.setAutoExpireDate(DateUtils.addDays(new Date(), 10));
    orderService.saveOrder(activeOrder, null);
    // New order in future for same concept
    TestOrder secondOrder = new TestOrder();
    secondOrder.setPatient(activeOrder.getPatient());
    secondOrder.setConcept(activeOrder.getConcept());
    secondOrder.setEncounter(encounterService.getEncounter(6));
    secondOrder.setOrderer(providerService.getProvider(1));
    secondOrder.setCareSetting(activeOrder.getCareSetting());
    secondOrder.setDateActivated(new Date());
    secondOrder.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStopDate(), 1));
    secondOrder.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    orderService.saveOrder(secondOrder, null);
    // Revise second order to have scheduled date overlapping with active order
    TestOrder revision = secondOrder.cloneForRevision();
    revision.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStartDate(), 2));
    revision.setEncounter(encounterService.getEncounter(6));
    revision.setOrderer(providerService.getProvider(1));
    Order savedSecondOrder = orderService.saveOrder(revision, null);
    assertNotNull(orderService.getOrder(savedSecondOrder.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) Date(java.util.Date) Ignore(org.junit.Ignore) 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