Search in sources :

Example 61 with ConceptName

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

the class ConceptServiceImplTest method saveConcept_shouldNotSetDefaultPreferredNameToShortOrIndexTerms.

/**
 * @see ConceptServiceImpl#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldNotSetDefaultPreferredNameToShortOrIndexTerms() {
    Locale loc = new Locale("fr", "CA");
    ConceptName shortName = new ConceptName("short name", loc);
    // be explicit for test case
    shortName.setConceptNameType(ConceptNameType.SHORT);
    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(shortName);
    c.setNames(allNames);
    // 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
    }
    assertNull("there's a preferred name", c.getPreferredName(loc));
    assertFalse("name was explicitly marked preferred", shortName.isPreferred());
    assertFalse("name was explicitly marked preferred", indexTerm.isPreferred());
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) APIException(org.openmrs.api.APIException) ConceptName(org.openmrs.ConceptName) HashSet(java.util.HashSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 62 with ConceptName

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

the class ConceptServiceImplTest method saveConcept_shouldForceSetFlagIfSetMembersExist.

/**
 * @see ConceptServiceImpl#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldForceSetFlagIfSetMembersExist() {
    // Given
    Concept concept = new Concept();
    concept.addName(new ConceptName("Concept", new Locale("en", "US")));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setDatatype(new ConceptDatatype(1));
    concept.setConceptClass(new ConceptClass(1));
    Concept conceptSetMember = new Concept();
    conceptSetMember.addName(new ConceptName("Set Member", new Locale("en", "US")));
    conceptSetMember.addDescription(new ConceptDescription("some description", null));
    conceptSetMember.setConceptClass(new ConceptClass(1));
    conceptSetMember.setDatatype(new ConceptDatatype(1));
    Context.getConceptService().saveConcept(conceptSetMember);
    concept.addSetMember(conceptSetMember);
    concept.setSet(false);
    // When
    Context.getConceptService().saveConcept(concept);
    // Then
    assertTrue(concept.getSet());
}
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 63 with ConceptName

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

the class ProgramWorkflowServiceTest method getSortedStates_shouldSortNamesContainingNumbersIntelligently.

/**
 * THIS TEST SHOULD BE IN THE CLASS 'PROGRAMWORKFLOWTEST.JAVA' BUT IT REQUIRES ACCESS TO THE DAO
 * LAYER
 *
 * @see ProgramWorkflow#getSortedStates()
 */
@Test
public void getSortedStates_shouldSortNamesContainingNumbersIntelligently() {
    ProgramWorkflow program = new ProgramWorkflow();
    ConceptName state1ConceptName = new ConceptName("Group 10", Context.getLocale());
    Concept state1Concept = new Concept();
    state1Concept.addName(state1ConceptName);
    ProgramWorkflowState state1 = new ProgramWorkflowState();
    state1.setConcept(state1Concept);
    program.addState(state1);
    ConceptName state2ConceptName = new ConceptName("Group 2", Context.getLocale());
    Concept state2Concept = new Concept();
    state2Concept.addName(state2ConceptName);
    ProgramWorkflowState state2 = new ProgramWorkflowState();
    state2.setConcept(state2Concept);
    program.addState(state2);
    Set<ProgramWorkflowState> sortedStates = program.getSortedStates();
    int x = 1;
    for (ProgramWorkflowState state : sortedStates) {
        if (x == 1) {
            Assert.assertEquals("Group 2", state.getConcept().getName(Context.getLocale()).getName());
        } else if (x == 2) {
            Assert.assertEquals("Group 10", state.getConcept().getName(Context.getLocale()).getName());
        } else {
            Assert.fail("Wha?!");
        }
        x++;
    }
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) Concept(org.openmrs.Concept) ProgramWorkflowState(org.openmrs.ProgramWorkflowState) ConceptName(org.openmrs.ConceptName) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 64 with ConceptName

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

the class ConceptNameSaveHandlerTest method handle_shouldNotFailIfTagsIsNull.

/**
 * @see ConceptNameSaveHandler#handle(ConceptName,User,Date,String)
 */
@Test
public void handle_shouldNotFailIfTagsIsNull() {
    ConceptNameSaveHandler handler = new ConceptNameSaveHandler();
    ConceptName name = new ConceptName();
    name.setTags(null);
    handler.handle(name, null, null, null);
}
Also used : ConceptName(org.openmrs.ConceptName) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 65 with ConceptName

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

the class ConceptNameSaveHandlerTest method handle_shouldNotReplaceTagsWithoutIdsThatAreNotInTheDatabase.

/**
 * @see ConceptNameSaveHandler#handle(ConceptName,User,Date,String)
 */
@Test
public void handle_shouldNotReplaceTagsWithoutIdsThatAreNotInTheDatabase() {
    ConceptNameSaveHandler handler = new ConceptNameSaveHandler();
    ConceptName name = new ConceptName();
    // this tag has a null id
    name.addTag(new ConceptNameTag("Some randome tag name", ""));
    handler.handle(name, null, null, null);
    ConceptNameTag newTag = name.getTags().iterator().next();
    Assert.assertNull(newTag.getConceptNameTagId());
}
Also used : ConceptNameTag(org.openmrs.ConceptNameTag) 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