Search in sources :

Example 26 with ConceptName

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

the class ConceptServiceImplTest method saveConcept_shouldReturnTheConceptWithNewConceptIDIfCreatingNewConcept.

/**
 * @see ConceptServiceImpl#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldReturnTheConceptWithNewConceptIDIfCreatingNewConcept() {
    Concept c = new Concept();
    ConceptName fullySpecifiedName = new ConceptName("requires one name min", new Locale("fr", "CA"));
    c.addName(fullySpecifiedName);
    c.addDescription(new ConceptDescription("some description", null));
    c.setDatatype(new ConceptDatatype(1));
    c.setConceptClass(new ConceptClass(1));
    Concept savedC = Context.getConceptService().saveConcept(c);
    assertNotNull(savedC);
    assertTrue(savedC.getConceptId() > 0);
}
Also used : Concept(org.openmrs.Concept) Locale(java.util.Locale) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 27 with ConceptName

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

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

the class ConceptServiceTest method getConceptNameByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see ConceptService#getConceptNameByUuid(String)
 */
@Test
public void getConceptNameByUuid_shouldFindObjectGivenValidUuid() {
    String uuid = "9bc5693a-f558-40c9-8177-145a4b119ca7";
    ConceptName conceptName = Context.getConceptService().getConceptNameByUuid(uuid);
    Assert.assertEquals(1439, (int) conceptName.getConceptNameId());
}
Also used : ConceptName(org.openmrs.ConceptName) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 29 with ConceptName

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

the class ConceptServiceTest method saveConcept_shouldEnsureThatEveryConcepNameLocaleHasExactlyOnePreferredName.

/**
 * This test is run against the xml test dataset for all concepts to ensure that in every locale
 * with one or more names, there isn't more than one name explicitly marked as locale preferred.
 * NOTE that it doesn't test a particular API method directly
 */
@Test
public void saveConcept_shouldEnsureThatEveryConcepNameLocaleHasExactlyOnePreferredName() {
    List<Concept> concepts = Context.getConceptService().getAllConcepts();
    Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder();
    for (Concept concept : concepts) {
        for (Locale locale : allowedLocales) {
            Collection<ConceptName> namesInLocale = concept.getNames(locale);
            if (!CollectionUtils.isEmpty(namesInLocale)) {
                int preferredNamesFound = 0;
                for (ConceptName conceptName : namesInLocale) {
                    if (conceptName.getLocalePreferred()) {
                        preferredNamesFound++;
                        Assert.assertTrue("Found multiple preferred names for conceptId: " + concept.getConceptId() + " in the locale '" + locale + "'", preferredNamesFound < 2);
                    }
                }
            }
        }
    }
}
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 30 with ConceptName

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

the class ConceptServiceTest method saveConcept_shouldVoidTheConceptNameIfTheTextOfTheNameHasChanged.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldVoidTheConceptNameIfTheTextOfTheNameHasChanged() {
    Concept concept = conceptService.getConceptByName("cd4 count");
    Assert.assertEquals(false, conceptService.getConceptName(1847).getVoided());
    for (ConceptName cn : concept.getNames()) {
        if (cn.getConceptNameId().equals(1847)) {
            cn.setName("new name");
        }
    }
    // ensure that the conceptName has actually been found and replaced
    Assert.assertEquals(true, concept.hasName("new name", new Locale("en", "GB")));
    conceptService.saveConcept(concept);
    Assert.assertEquals(true, conceptService.getConceptName(1847).getVoided());
}
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)

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