Search in sources :

Example 91 with ConceptName

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

the class ConceptServiceTest method saveConcept_shouldAddNewConceptName.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldAddNewConceptName() {
    Concept concept = conceptService.getConcept(3);
    ConceptName name = new ConceptName("new name", Locale.US);
    concept.addName(name);
    conceptService.saveConcept(concept);
    assertNotNull(name.getConceptNameId());
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 92 with ConceptName

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

the class ConceptServiceTest method getConceptsByName_shouldReturnConceptsForSpecificCountryAndGlobalLanguageGivenLanguageAndCountryLocale.

/**
 * @see ConceptService#getConceptsByName(String,Locale)
 */
@Test
public void getConceptsByName_shouldReturnConceptsForSpecificCountryAndGlobalLanguageGivenLanguageAndCountryLocale() {
    // given
    String name = "Concept";
    Concept concept1 = new Concept();
    concept1.addName(new ConceptName(name, new Locale("en", "US")));
    concept1.addDescription(new ConceptDescription("some description", null));
    concept1.setDatatype(new ConceptDatatype(1));
    concept1.setConceptClass(new ConceptClass(1));
    Context.getConceptService().saveConcept(concept1);
    Concept concept2 = new Concept();
    concept2.addName(new ConceptName(name, new Locale("en", "GB")));
    concept2.addDescription(new ConceptDescription("some description", null));
    concept2.setDatatype(new ConceptDatatype(1));
    concept2.setConceptClass(new ConceptClass(1));
    Context.getConceptService().saveConcept(concept2);
    Concept concept3 = new Concept();
    concept3.addName(new ConceptName(name, new Locale("en")));
    concept3.addDescription(new ConceptDescription("some description", null));
    concept3.setDatatype(new ConceptDatatype(1));
    concept3.setConceptClass(new ConceptClass(1));
    Context.getConceptService().saveConcept(concept3);
    updateSearchIndex();
    // when
    List<Concept> concepts = Context.getConceptService().getConceptsByName(name, new Locale("en", "US"), false);
    // then
    assertThat(concepts.get(0), is(concept1));
    assertThat(concepts, containsInAnyOrder(concept1, concept2, concept3));
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) Locale(java.util.Locale) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 93 with ConceptName

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

the class ConceptServiceTest method saveConcept_shouldSaveANewConceptNumeric.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSaveANewConceptNumeric() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    Context.setLocale(Locale.US);
    // this tests saving a never before in the database conceptnumeric
    ConceptNumeric cn3 = new ConceptNumeric();
    cn3.setDatatype(new ConceptDatatype(1));
    cn3.setConceptClass(new ConceptClass(1));
    ConceptName cn = new ConceptName("a brand new conceptnumeric", Locale.US);
    cn3.addName(cn);
    cn3.addDescription(new ConceptDescription("some description", null));
    cn3.setHiAbsolute(50.0);
    conceptService.saveConcept(cn3);
    Concept thirdConcept = conceptService.getConcept(cn3.getConceptId());
    assertTrue(thirdConcept instanceof ConceptNumeric);
    ConceptNumeric thirdConceptNumeric = (ConceptNumeric) thirdConcept;
    assertEquals("a brand new conceptnumeric", thirdConceptNumeric.getName(Locale.US).getName());
    assertEquals(50.0, thirdConceptNumeric.getHiAbsolute(), 0);
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptNumeric(org.openmrs.ConceptNumeric) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 94 with ConceptName

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

the class ConceptServiceTest method saveConcept_shouldNotAcceptALocaleThatIsNeitherAmongTheLocaleAllowedListNorADefaultLocale.

/**
 * This test fetches all concepts in the xml test dataset and ensures that every locale for a
 * concept name is among those listed in the global property 'locale.allowed.list' and default
 * locale. NOTE that it doesn't test a particular API method directly.
 */
@Test
public void saveConcept_shouldNotAcceptALocaleThatIsNeitherAmongTheLocaleAllowedListNorADefaultLocale() {
    List<Concept> concepts = Context.getConceptService().getAllConcepts();
    Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder();
    for (Concept concept : concepts) {
        if (!CollectionUtils.isEmpty(concept.getNames())) {
            for (ConceptName cn : concept.getNames()) {
                Assert.assertTrue("The locale '" + cn.getLocale() + "' of conceptName with id: " + cn.getConceptNameId() + " is not among those listed in the global property 'locale.allowed.list'", allowedLocales.contains(cn.getLocale()));
            }
        }
    }
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) Locale(java.util.Locale) ConceptName(org.openmrs.ConceptName) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 95 with ConceptName

use of org.openmrs.ConceptName 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

ConceptName (org.openmrs.ConceptName)100 Test (org.junit.Test)78 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)71 Concept (org.openmrs.Concept)62 ConceptDescription (org.openmrs.ConceptDescription)42 ConceptDatatype (org.openmrs.ConceptDatatype)34 ConceptClass (org.openmrs.ConceptClass)33 Locale (java.util.Locale)32 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)22 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 Obs (org.openmrs.Obs)9 BindException (org.springframework.validation.BindException)8 ConceptMap (org.openmrs.ConceptMap)7 Errors (org.springframework.validation.Errors)7 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Patient (org.openmrs.Patient)6 Encounter (org.openmrs.Encounter)5 OrderFrequency (org.openmrs.OrderFrequency)5