Search in sources :

Example 21 with ConceptName

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

the class ConceptValidatorTest method validate_shouldFailIfAnyNamesInTheSameLocaleForThisConceptAreSimilar.

@Test
public void validate_shouldFailIfAnyNamesInTheSameLocaleForThisConceptAreSimilar() {
    concept.addName(new ConceptName("same name", Context.getLocale()));
    concept.addName(new ConceptName("same name", Context.getLocale()));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setConceptClass(new ConceptClass());
    concept.setDatatype(new ConceptDatatype());
    expectedException.expect(DuplicateConceptNameException.class);
    expectedException.expectMessage("'same name' is a duplicate name in locale '" + Context.getLocale() + "'");
    validator.validate(concept, errors);
}
Also used : 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 22 with ConceptName

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

the class ConceptValidatorTest method validate_shouldPassForANewConceptWithAMapCreatedWithDeprecatedConceptMapMethods.

@Test
public void validate_shouldPassForANewConceptWithAMapCreatedWithDeprecatedConceptMapMethods() {
    concept.addName(new ConceptName("test name", Context.getLocale()));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setConceptClass(new ConceptClass());
    concept.setDatatype(new ConceptDatatype());
    ConceptMap map = new ConceptMap();
    map.getConceptReferenceTerm().setCode("unique code");
    map.getConceptReferenceTerm().setConceptSource(conceptService.getConceptSource(1));
    concept.addConceptMapping(map);
    ValidateUtil.validate(concept);
}
Also used : ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptMap(org.openmrs.ConceptMap) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with ConceptName

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

the class ConceptServiceImplTest method saveConcept_shouldSetDefaultPreferredNameToFullySpecifiedFirst.

/**
 * @see ConceptServiceImpl#saveConcept(Concept)
 *           Concept.getPreferredName(locale) returns null, saveConcept chooses one. The default
 *           first choice is the fully specified name in the locale. The default second choice
 *           is a synonym in the locale.
 */
@Test
public void saveConcept_shouldSetDefaultPreferredNameToFullySpecifiedFirst() {
    Locale loc = new Locale("fr", "CA");
    ConceptName fullySpecifiedName = new ConceptName("fully specified", loc);
    // be explicit for test case
    fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    ConceptName shortName = new ConceptName("short name", loc);
    // be explicit for test case
    shortName.setConceptNameType(ConceptNameType.SHORT);
    ConceptName synonym = new ConceptName("synonym", loc);
    // synonyms are id'd by a null type
    synonym.setConceptNameType(null);
    ConceptName indexTerm = new ConceptName("indexTerm", loc);
    // synonyms are id'd by a null type
    indexTerm.setConceptNameType(ConceptNameType.INDEX_TERM);
    Concept c = new Concept();
    c.addName(fullySpecifiedName);
    c.addName(synonym);
    c.addName(indexTerm);
    c.addName(shortName);
    c.addDescription(new ConceptDescription("some description", null));
    c.setDatatype(new ConceptDatatype(1));
    c.setConceptClass(new ConceptClass(1));
    assertFalse("check test assumption - the API didn't automatically set preferred vlag", c.getFullySpecifiedName(loc).isPreferred());
    assertNotNull("Concept is legit, save succeeds", Context.getConceptService().saveConcept(c));
    Context.getConceptService().saveConcept(c);
    assertNotNull("there's a preferred name", c.getPreferredName(loc));
    assertTrue("name was explicitly marked preferred", c.getPreferredName(loc).isPreferred());
    assertEquals("name matches", c.getPreferredName(loc).getName(), fullySpecifiedName.getName());
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) 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 24 with ConceptName

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

the class ConceptServiceImplTest method saveConcept_shouldTrimWhitespacesInConceptName.

@Test
public void saveConcept_shouldTrimWhitespacesInConceptName() {
    // Given
    Concept concept = new Concept();
    String nameWithSpaces = "  jwm  ";
    concept.addName(new ConceptName(nameWithSpaces, new Locale("en", "US")));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setDatatype(new ConceptDatatype(1));
    concept.setConceptClass(new ConceptClass(1));
    // When
    Context.getConceptService().saveConcept(concept);
    // Then
    assertNotEquals(concept.getName().getName(), nameWithSpaces);
    assertEquals(concept.getName().getName(), "jwm");
}
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 25 with ConceptName

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

the class ConceptServiceImplTest method saveConcept_shouldLeavePreferredNamePreferredIfSet.

/**
 * @see ConceptServiceImpl#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldLeavePreferredNamePreferredIfSet() {
    Locale loc = new Locale("fr", "CA");
    ConceptName fullySpecifiedName = new ConceptName("fully specified", loc);
    // be explicit for test case
    fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    ConceptName shortName = new ConceptName("short name", loc);
    // be explicit for test case
    shortName.setConceptNameType(ConceptNameType.SHORT);
    ConceptName synonym = new ConceptName("synonym", loc);
    // synonyms are id'd by a null type
    synonym.setConceptNameType(null);
    ConceptName indexTerm = new ConceptName("indexTerm", loc);
    // synonyms are id'd by a null type
    indexTerm.setConceptNameType(ConceptNameType.INDEX_TERM);
    // saveConcept never picks an index term for default, so we'll use it for the test
    indexTerm.setLocalePreferred(true);
    Concept c = new Concept();
    c.addName(fullySpecifiedName);
    c.addName(synonym);
    c.addName(indexTerm);
    c.addName(shortName);
    // ignore it so we can test the set default preferred name  functionality
    try {
        Context.getConceptService().saveConcept(c);
    } catch (org.openmrs.api.APIException e) {
    // ignore it
    }
    assertNotNull("there's a preferred name", c.getPreferredName(loc));
    assertTrue("name was explicitly marked preferred", c.getPreferredName(loc).isPreferred());
    assertEquals("name matches", c.getPreferredName(loc).getName(), indexTerm.getName());
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) APIException(org.openmrs.api.APIException) ConceptName(org.openmrs.ConceptName) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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