Search in sources :

Example 91 with Concept

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

the class ConceptServiceImplTest method retireConcept_shouldRetireTheGivenConcept.

/**
 * @see ConceptServiceImpl#retireConcept(Concept,String)
 */
@Test
public void retireConcept_shouldRetireTheGivenConcept() {
    String retireReason = "dummy reason";
    Concept concept = conceptService.getConcept(3);
    assertFalse(concept.getRetired());
    conceptService.retireConcept(concept, retireReason);
    assertTrue(concept.getRetired());
    assertEquals(retireReason, concept.getRetireReason());
}
Also used : Concept(org.openmrs.Concept) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 92 with Concept

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

the class ConceptServiceImplTest method getNextConcept_shouldReturnTheConceptNextToTheGivenConcept.

/**
 * @see ConceptServiceImpl#getNextConcept(Concept)
 */
@Test
public void getNextConcept_shouldReturnTheConceptNextToTheGivenConcept() {
    Integer conceptId = 3;
    Integer nextConceptId = 4;
    Concept returnedConcept = conceptService.getNextConcept(conceptService.getConcept(conceptId));
    assertEquals(returnedConcept, conceptService.getConcept(nextConceptId));
}
Also used : Concept(org.openmrs.Concept) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 93 with Concept

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

Example 94 with Concept

use of org.openmrs.Concept 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 95 with Concept

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

Aggregations

Concept (org.openmrs.Concept)294 Test (org.junit.Test)210 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)176 ConceptName (org.openmrs.ConceptName)62 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)62 Obs (org.openmrs.Obs)49 Date (java.util.Date)48 Patient (org.openmrs.Patient)42 ConceptDescription (org.openmrs.ConceptDescription)33 Locale (java.util.Locale)32 ConceptDatatype (org.openmrs.ConceptDatatype)32 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 ConceptClass (org.openmrs.ConceptClass)27 ArrayList (java.util.ArrayList)26 BindException (org.springframework.validation.BindException)26 DrugOrder (org.openmrs.DrugOrder)25 Encounter (org.openmrs.Encounter)25 Errors (org.springframework.validation.Errors)25 ConceptMapBuilder (org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)21 Location (org.openmrs.Location)19