Search in sources :

Example 51 with ConceptClass

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

the class ConceptServiceTest method saveConcept_shouldSaveNonConceptComplexObjectAsConceptComplex.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSaveNonConceptComplexObjectAsConceptComplex() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    // this tests saving a current concept as a newly changed conceptComplex
    // assumes there is already a concept in the database
    // with a concept id of #1
    ConceptComplex cn = new ConceptComplex(1);
    cn.setDatatype(new ConceptDatatype(13));
    cn.setConceptClass(new ConceptClass(1));
    cn.addName(new ConceptName("a new conceptComplex", Locale.US));
    cn.addDescription(new ConceptDescription("some description", null));
    cn.setHandler("SomeHandler");
    conceptService.saveConcept(cn);
    Concept firstConcept = conceptService.getConceptComplex(1);
    assertEquals("a new conceptComplex", firstConcept.getName(Locale.US).getName());
    assertTrue(firstConcept instanceof ConceptComplex);
    ConceptComplex firstConceptComplex = (ConceptComplex) firstConcept;
    assertEquals("SomeHandler", firstConceptComplex.getHandler());
}
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) ConceptComplex(org.openmrs.ConceptComplex) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 52 with ConceptClass

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

the class ConceptServiceTest method saveConcept_shouldSetAPreferredNameForEachLocaleIfNoneIsMarked.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSetAPreferredNameForEachLocaleIfNoneIsMarked() {
    // add some other locales to locale.allowed.list for testing purposes
    GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST);
    gp.setPropertyValue(gp.getPropertyValue().concat(",fr,ja,en_GB"));
    Context.getAdministrationService().saveGlobalProperty(gp);
    Concept concept = new Concept();
    concept.addName(new ConceptName("name1", Locale.ENGLISH));
    concept.addName(new ConceptName("name2", Locale.ENGLISH));
    concept.addName(new ConceptName("name3", Locale.FRENCH));
    concept.addName(new ConceptName("name4", Locale.FRENCH));
    concept.addName(new ConceptName("name5", Locale.JAPANESE));
    concept.addName(new ConceptName("name6", Locale.JAPANESE));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setDatatype(new ConceptDatatype(1));
    concept.setConceptClass(new ConceptClass(1));
    concept = Context.getConceptService().saveConcept(concept);
    Assert.assertNotNull(concept.getPreferredName(Locale.ENGLISH));
    Assert.assertNotNull(concept.getPreferredName(Locale.FRENCH));
    Assert.assertNotNull(concept.getPreferredName(Locale.JAPANESE));
}
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) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 53 with ConceptClass

use of org.openmrs.ConceptClass 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 54 with ConceptClass

use of org.openmrs.ConceptClass 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 55 with ConceptClass

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

the class ConceptDAOTest method getConcepts_shouldReturnCorrectResultsIfAConceptNameContainsSameWordMoreThanOnce.

/**
 * @see {@link
 *      ConceptDAO#getConcepts(String,List<Locale>,null,List<ConceptClass>,List<ConceptClass>,
 *      List<ConceptDatatype>,List<ConceptDatatype>,Concept,Integer,Integer)}
 */
@SuppressWarnings("unchecked")
@Test
@Ignore
public void getConcepts_shouldReturnCorrectResultsIfAConceptNameContainsSameWordMoreThanOnce() {
    ConceptService cs = Context.getConceptService();
    ConceptClass cc = cs.getConceptClass(1);
    Locale locale = Locale.ENGLISH;
    ConceptDatatype dt = cs.getConceptDatatype(4);
    Concept c1 = new Concept();
    ConceptName cn1a = new ConceptName("ONE TERM", locale);
    c1.addName(cn1a);
    c1.setConceptClass(cc);
    c1.setDatatype(dt);
    cs.saveConcept(c1);
    ConceptName cn1b = new ConceptName("ONE TO ONE", locale);
    cn1b.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    cn1b.setLocalePreferred(true);
    c1.addName(cn1b);
    cs.saveConcept(c1);
    Assert.assertTrue(cn1a.isSynonym());
    Assert.assertTrue(cn1b.getConceptNameId() > cn1a.getConceptNameId());
    Concept c2 = new Concept();
    ConceptName cn2a = new ConceptName("ONE TO MANY", locale);
    c2.addName(cn2a);
    c2.setConceptClass(cc);
    c2.setDatatype(dt);
    cs.saveConcept(c2);
    updateSearchIndex();
    List<ConceptSearchResult> searchResults1 = dao.getConcepts("one", Collections.singletonList(locale), false, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, null, null, null);
    Assert.assertEquals(2, searchResults1.size());
    Assert.assertEquals(c1, searchResults1.get(0).getConcept());
    Assert.assertEquals(cn1b, searchResults1.get(0).getConceptName());
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptSearchResult(org.openmrs.ConceptSearchResult) ConceptService(org.openmrs.api.ConceptService) ConceptDatatype(org.openmrs.ConceptDatatype) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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