Search in sources :

Example 56 with ConceptName

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

the class ConceptServiceTest method saveConcept_shouldCreateANewConceptNameWhenTheOldNameIsChanged.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldCreateANewConceptNameWhenTheOldNameIsChanged() {
    Concept concept = conceptService.getConceptByName("cd4 count");
    Assert.assertEquals(3, concept.getNames(true).size());
    ConceptName oldName = null;
    for (ConceptName cn : concept.getNames()) {
        if (cn.getConceptNameId().equals(1847)) {
            oldName = cn;
            cn.setName("new name");
        }
    }
    conceptService.saveConcept(concept);
    // force Hibernate interceptor to set dateCreated
    Context.flushSession();
    Assert.assertEquals(4, concept.getNames(true).size());
    for (ConceptName cn : concept.getNames()) {
        if (cn.getName().equals("new name")) {
            Assert.assertTrue(oldName.getDateCreated().before(cn.getDateCreated()));
        }
    }
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 57 with ConceptName

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

the class ConceptServiceTest method saveConcept_shouldSaveNonConceptNumericObjectAsConceptNumeric.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSaveNonConceptNumericObjectAsConceptNumeric() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    // this tests saving a current concept as a newly changed conceptnumeric
    // assumes there is already a concept in the database
    // with a concept id of #1
    ConceptNumeric cn = new ConceptNumeric(1);
    cn.setDatatype(new ConceptDatatype(1));
    cn.setConceptClass(new ConceptClass(1));
    cn.addName(new ConceptName("a new conceptnumeric", Locale.US));
    cn.addDescription(new ConceptDescription("some description", null));
    cn.setHiAbsolute(20.0);
    conceptService.saveConcept(cn);
    Concept firstConcept = conceptService.getConceptNumeric(1);
    firstConcept.addDescription(new ConceptDescription("some description", null));
    assertEquals("a new conceptnumeric", firstConcept.getName(Locale.US).getName());
    assertTrue(firstConcept instanceof ConceptNumeric);
    ConceptNumeric firstConceptNumeric = (ConceptNumeric) firstConcept;
    assertEquals(20.0, firstConceptNumeric.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 58 with ConceptName

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

the class ConceptServiceTest method getConcepts_shouldReturnPreferredNamesHigher.

/**
 * @see ConceptService#getConcepts(String,List,boolean,List,List,List,List,Concept,Integer,Integer)
 */
@Test
public void getConcepts_shouldReturnPreferredNamesHigher() {
    Concept hivProgram = conceptService.getConceptByName("hiv program");
    ConceptName synonym = new ConceptName("synonym", Context.getLocale());
    hivProgram.addName(synonym);
    conceptService.saveConcept(hivProgram);
    Concept mdrTbProgram = conceptService.getConceptByName("mdr-tb program");
    synonym = new ConceptName("synonym", Context.getLocale());
    synonym.setLocalePreferred(true);
    mdrTbProgram.addName(synonym);
    conceptService.saveConcept(mdrTbProgram);
    updateSearchIndex();
    List<ConceptSearchResult> concepts = conceptService.getConcepts("synonym", null, false, null, null, null, null, null, null, null);
    assertThat(concepts, contains(hasConcept(is(mdrTbProgram)), hasConcept(is(hivProgram))));
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName) ConceptSearchResult(org.openmrs.ConceptSearchResult) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 59 with ConceptName

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

the class ConceptServiceImplTest method saveConcept_shouldSetDefaultPreferredNameToASynonymSecond.

/**
 * @see ConceptServiceImpl#saveConcept(Concept)
 *           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_shouldSetDefaultPreferredNameToASynonymSecond() {
    Locale loc = new Locale("fr", "CA");
    Locale otherLocale = new Locale("en", "US");
    // Create a fully specified name, but for another locale
    // so the Concept passes validation
    ConceptName fullySpecifiedName = new ConceptName("fully specified", otherLocale);
    // 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();
    HashSet<ConceptName> allNames = new HashSet<>(4);
    allNames.add(indexTerm);
    allNames.add(fullySpecifiedName);
    allNames.add(synonym);
    c.setNames(allNames);
    c.addDescription(new ConceptDescription("some description", null));
    c.setDatatype(new ConceptDatatype(1));
    c.setConceptClass(new ConceptClass(1));
    assertNull("check test assumption - the API hasn't promoted a name to a fully specified name", c.getFullySpecifiedName(loc));
    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(), synonym.getName());
    assertEquals("fully specified name unchanged", c.getPreferredName(otherLocale).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) HashSet(java.util.HashSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 60 with ConceptName

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

the class ConceptServiceImplTest method saveConcept_shouldReturnTheConceptWithSameConceptIDIfUpdatingExistingConcept.

/**
 * @see ConceptServiceImpl#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldReturnTheConceptWithSameConceptIDIfUpdatingExistingConcept() {
    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);
    Concept updatedC = Context.getConceptService().saveConcept(c);
    assertNotNull(updatedC);
    assertEquals(updatedC.getConceptId(), savedC.getConceptId());
}
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

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