Search in sources :

Example 16 with ConceptClass

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

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

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

the class ConceptServiceImplTest method purgeConceptClass_shouldDeleteTheGivenConceptClass.

/**
 * @see ConceptServiceImpl#purgeConceptClass(ConceptClass)
 */
@Test
public void purgeConceptClass_shouldDeleteTheGivenConceptClass() {
    int conceptClassId = 1;
    ConceptClass cc = conceptService.getConceptClass(conceptClassId);
    assertNotNull(cc);
    conceptService.purgeConceptClass(cc);
    assertNull(conceptService.getConceptClass(conceptClassId));
}
Also used : ConceptClass(org.openmrs.ConceptClass) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 19 with ConceptClass

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

the class ConceptServiceImplTest method saveConceptClass_shouldSaveTheGivenConceptClass.

/**
 * @see ConceptServiceImpl#saveConceptClass(ConceptClass)
 */
@Test
public void saveConceptClass_shouldSaveTheGivenConceptClass() {
    int unusedConceptClassId = 123;
    ConceptClass conceptClass = new ConceptClass(unusedConceptClassId);
    conceptClass.setName("name");
    conceptClass.setDescription("description");
    conceptService.saveConceptClass(conceptClass);
    assertEquals(conceptClass, conceptService.getConceptClass(unusedConceptClassId));
}
Also used : ConceptClass(org.openmrs.ConceptClass) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 20 with ConceptClass

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

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