Search in sources :

Example 21 with ConceptClass

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

the class ConceptServiceTest method getConceptsByName_shouldReturnConceptsForAllCountriesAndGlobalLanguageGivenLanguageOnlyLocale.

/**
 * @see ConceptService#getConceptsByName(String,Locale)
 */
@Test
public void getConceptsByName_shouldReturnConceptsForAllCountriesAndGlobalLanguageGivenLanguageOnlyLocale() {
    // 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"), false);
    // then
    Assert.assertEquals(3, concepts.size());
    Assert.assertTrue(concepts.containsAll(Arrays.asList(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 22 with ConceptClass

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

the class ConceptServiceTest method getConceptClassByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see ConceptService#getConceptClassByUuid(String)
 */
@Test
public void getConceptClassByUuid_shouldFindObjectGivenValidUuid() {
    String uuid = "97097dd9-b092-4b68-a2dc-e5e5be961d42";
    ConceptClass conceptClass = Context.getConceptService().getConceptClassByUuid(uuid);
    Assert.assertEquals(1, (int) conceptClass.getConceptClassId());
}
Also used : ConceptClass(org.openmrs.ConceptClass) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 23 with ConceptClass

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

the class ConceptServiceTest method saveConcept_shouldReuseConceptNameTagsThatAlreadyExistInTheDatabase.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldReuseConceptNameTagsThatAlreadyExistInTheDatabase() {
    executeDataSet("org/openmrs/api/include/ConceptServiceTest-tags.xml");
    ConceptService cs = Context.getConceptService();
    // make sure the name tag exists already
    ConceptNameTag cnt = cs.getConceptNameTagByName("preferred_en");
    Assert.assertNotNull(cnt);
    ConceptName cn = new ConceptName("Some name", Locale.ENGLISH);
    cn.addTag(new ConceptNameTag("preferred_en", "preferred name in a language"));
    Concept concept = new Concept();
    concept.addName(cn);
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setDatatype(new ConceptDatatype(1));
    concept.setConceptClass(new ConceptClass(1));
    cs.saveConcept(concept);
    Collection<ConceptNameTag> savedConceptNameTags = concept.getName(Locale.ENGLISH, false).getTags();
    ConceptNameTag savedConceptNameTag = (ConceptNameTag) savedConceptNameTags.toArray()[0];
    Assert.assertEquals(cnt.getConceptNameTagId(), savedConceptNameTag.getConceptNameTagId());
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptNameTag(org.openmrs.ConceptNameTag) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 24 with ConceptClass

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

the class ConceptServiceTest method getOrderableConcepts_shouldGetOrderableConcepts.

/**
 * @see ConceptService#getOrderableConcepts(String, java.util.List, boolean, Integer, Integer)
 */
@Test
public void getOrderableConcepts_shouldGetOrderableConcepts() {
    // In current data set order_type_map table contains conceptClass 1 and 3.
    // Using that adding two concepts to test the functionality
    ConceptService cs = Context.getConceptService();
    ConceptClass cc1 = cs.getConceptClass(1);
    ConceptClass cc3 = cs.getConceptClass(3);
    Locale locale = Locale.ENGLISH;
    ConceptDatatype dt = cs.getConceptDatatype(4);
    Concept c1 = new Concept();
    ConceptName cn1a = new ConceptName("ONE TERM", locale);
    c1.addName(cn1a);
    c1.addDescription(new ConceptDescription("some description", null));
    c1.setConceptClass(cc1);
    c1.setDatatype(dt);
    cs.saveConcept(c1);
    Concept c2 = new Concept();
    ConceptName cn2a = new ConceptName("ONE TO MANY", locale);
    c2.addName(cn2a);
    c2.addDescription(new ConceptDescription("some description", null));
    c2.setConceptClass(cc3);
    c2.setDatatype(dt);
    cs.saveConcept(c2);
    updateSearchIndex();
    List<ConceptSearchResult> conceptSearchResultList = Context.getConceptService().getOrderableConcepts("one", Collections.singletonList(locale), true, null, null);
    assertEquals(2, conceptSearchResultList.size());
}
Also used : Locale(java.util.Locale) OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptSearchResult(org.openmrs.ConceptSearchResult) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 25 with ConceptClass

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

the class ConceptServiceTest method saveConcept_shouldCreateNewConceptInDatabase.

@Test
public void saveConcept_shouldCreateNewConceptInDatabase() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    Concept conceptToAdd = new Concept();
    ConceptName cn = new ConceptName("new name", Context.getLocale());
    conceptToAdd.addName(cn);
    conceptToAdd.addDescription(new ConceptDescription("some description", null));
    conceptToAdd.setDatatype(new ConceptDatatype(1));
    conceptToAdd.setConceptClass(new ConceptClass(1));
    assertFalse(conceptService.getAllConcepts().contains(conceptToAdd));
    conceptService.saveConcept(conceptToAdd);
    assertTrue(conceptService.getAllConcepts().contains(conceptToAdd));
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) 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)

Aggregations

ConceptClass (org.openmrs.ConceptClass)55 Test (org.junit.Test)50 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)46 ConceptDatatype (org.openmrs.ConceptDatatype)38 ConceptName (org.openmrs.ConceptName)33 ConceptDescription (org.openmrs.ConceptDescription)31 Concept (org.openmrs.Concept)27 Locale (java.util.Locale)12 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)12 BindException (org.springframework.validation.BindException)9 Errors (org.springframework.validation.Errors)9 OrderType (org.openmrs.OrderType)5 HashSet (java.util.HashSet)4 ConceptMap (org.openmrs.ConceptMap)3 ConceptNumeric (org.openmrs.ConceptNumeric)3 ConceptBuilder (org.openmrs.module.emrapi.test.builder.ConceptBuilder)3 ConceptComplex (org.openmrs.ConceptComplex)2 ConceptMapType (org.openmrs.ConceptMapType)2 ConceptSearchResult (org.openmrs.ConceptSearchResult)2 ConceptSource (org.openmrs.ConceptSource)2