Search in sources :

Example 16 with OrderFrequency

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

the class OrderServiceTest method purgeOrderFrequency_shouldNotAllowDeletingAnOrderFrequencyThatIsInUse.

/**
 * @see OrderService#purgeOrderFrequency(OrderFrequency)
 */
@Test
public void purgeOrderFrequency_shouldNotAllowDeletingAnOrderFrequencyThatIsInUse() {
    OrderFrequency orderFrequency = orderService.getOrderFrequency(1);
    assertNotNull(orderFrequency);
    expectedException.expect(CannotDeleteObjectInUseException.class);
    expectedException.expectMessage(mss.getMessage("Order.frequency.cannot.delete"));
    orderService.purgeOrderFrequency(orderFrequency);
}
Also used : OrderFrequency(org.openmrs.OrderFrequency) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 17 with OrderFrequency

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

the class OrderServiceTest method purgeOrderFrequency_shouldDeleteGivenOrderFrequency.

@Test
public void purgeOrderFrequency_shouldDeleteGivenOrderFrequency() {
    OrderFrequency orderFrequency = orderService.getOrderFrequency(3);
    assertNotNull(orderFrequency);
    orderService.purgeOrderFrequency(orderFrequency);
    orderFrequency = orderService.getOrderFrequency(3);
    Assert.assertNull(orderFrequency);
    // Should reduce the existing number of order frequencies.
    assertEquals(2, orderService.getOrderFrequencies(true).size());
}
Also used : OrderFrequency(org.openmrs.OrderFrequency) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 18 with OrderFrequency

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

the class OrderServiceTest method unretireOrderFrequency_shouldUnretireGivenOrderFrequency.

@Test
public void unretireOrderFrequency_shouldUnretireGivenOrderFrequency() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-otherOrderFrequencies.xml");
    OrderFrequency orderFrequency = orderService.getOrderFrequency(103);
    assertNotNull(orderFrequency);
    assertTrue(orderFrequency.getRetired());
    assertNotNull(orderFrequency.getRetireReason());
    assertNotNull(orderFrequency.getDateRetired());
    orderService.unretireOrderFrequency(orderFrequency);
    orderFrequency = orderService.getOrderFrequency(103);
    assertNotNull(orderFrequency);
    assertFalse(orderFrequency.getRetired());
    assertNull(orderFrequency.getRetireReason());
    assertNull(orderFrequency.getDateRetired());
    // Should not change the number of order frequencies.
    assertEquals(7, orderService.getOrderFrequencies(true).size());
}
Also used : OrderFrequency(org.openmrs.OrderFrequency) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 19 with OrderFrequency

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

the class OrderServiceTest method getOrderFrequencies_shouldReturnUniqueFrequencies.

/**
 * @see OrderService#getOrderFrequencies(String, java.util.Locale, boolean, boolean)
 */
@Test
public void getOrderFrequencies_shouldReturnUniqueFrequencies() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-otherOrderFrequencies.xml");
    final String searchPhrase = "once";
    final Locale locale = Locale.ENGLISH;
    List<OrderFrequency> orderFrequencies = orderService.getOrderFrequencies(searchPhrase, locale, true, false);
    assertEquals(1, orderFrequencies.size());
    final OrderFrequency expectedOrderFrequency = orderService.getOrderFrequency(100);
    assertEquals(expectedOrderFrequency, orderFrequencies.get(0));
    // Add a new name to the frequency concept so that our search phrase matches on 2
    // concept names for the same frequency concept
    Concept frequencyConcept = expectedOrderFrequency.getConcept();
    final String newConceptName = searchPhrase + " A Day";
    frequencyConcept.addName(new ConceptName(newConceptName, locale));
    frequencyConcept.addDescription(new ConceptDescription("some description", null));
    conceptService.saveConcept(frequencyConcept);
    orderFrequencies = orderService.getOrderFrequencies(searchPhrase, locale, true, false);
    assertEquals(1, orderFrequencies.size());
    assertEquals(expectedOrderFrequency, orderFrequencies.get(0));
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) OrderFrequency(org.openmrs.OrderFrequency) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Aggregations

OrderFrequency (org.openmrs.OrderFrequency)19 Test (org.junit.Test)17 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)17 OrderUtilTest (org.openmrs.order.OrderUtilTest)8 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Concept (org.openmrs.Concept)6 ConceptDescription (org.openmrs.ConceptDescription)5 ConceptName (org.openmrs.ConceptName)5 ConceptService (org.openmrs.api.ConceptService)3 Locale (java.util.Locale)1 Criteria (org.hibernate.Criteria)1 ConceptDatatype (org.openmrs.ConceptDatatype)1