Search in sources :

Example 46 with ConceptDatatype

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

the class ConceptServiceTest method saveConcept_shouldSaveChangesBetweenConceptNumericAndComplex.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSaveChangesBetweenConceptNumericAndComplex() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    // save a concept numeric
    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);
    // confirm that we saved a concept numeric
    Concept firstConcept = conceptService.getConceptNumeric(1);
    assertEquals("a new conceptnumeric", firstConcept.getName(Locale.US).getName());
    assertTrue(firstConcept instanceof ConceptNumeric);
    ConceptNumeric firstConceptNumeric = (ConceptNumeric) firstConcept;
    assertEquals(20.0, firstConceptNumeric.getHiAbsolute(), 0);
    // change to concept complex
    ConceptComplex cn2 = new ConceptComplex(1);
    cn2.setDatatype(new ConceptDatatype(13));
    cn2.setConceptClass(new ConceptClass(1));
    cn2.addName(new ConceptName("a new conceptComplex", Locale.US));
    cn2.addDescription(new ConceptDescription("some description", null));
    cn2.setHandler("SomeHandler");
    conceptService.saveConcept(cn2);
    // confirm that we saved a concept complex
    firstConcept = conceptService.getConceptComplex(1);
    assertEquals("a new conceptComplex", firstConcept.getName(Locale.US).getName());
    assertTrue(firstConcept instanceof ConceptComplex);
    ConceptComplex firstConceptComplex = (ConceptComplex) firstConcept;
    assertEquals("SomeHandler", firstConceptComplex.getHandler());
    // change to concept numeric
    cn = new ConceptNumeric(1);
    ConceptDatatype dt = new ConceptDatatype(1);
    dt.setName("Numeric");
    cn.setDatatype(dt);
    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);
    // confirm that we saved a concept numeric
    firstConcept = conceptService.getConceptNumeric(1);
    assertEquals("a new conceptnumeric", firstConcept.getName(Locale.US).getName());
    assertTrue(firstConcept instanceof ConceptNumeric);
    firstConceptNumeric = (ConceptNumeric) firstConcept;
    assertEquals(20.0, firstConceptNumeric.getHiAbsolute(), 0);
    // change to concept complex
    cn2 = new ConceptComplex(1);
    cn2.setDatatype(new ConceptDatatype(13));
    cn2.setConceptClass(new ConceptClass(1));
    cn2.addName(new ConceptName("a new conceptComplex", Locale.US));
    cn2.addDescription(new ConceptDescription("some description", null));
    cn2.setHandler("SomeHandler");
    conceptService.saveConcept(cn2);
    // confirm we saved a concept complex
    firstConcept = conceptService.getConceptComplex(1);
    assertEquals("a new conceptComplex", firstConcept.getName(Locale.US).getName());
    assertTrue(firstConcept instanceof ConceptComplex);
    firstConceptComplex = (ConceptComplex) firstConcept;
    assertEquals("SomeHandler", firstConceptComplex.getHandler());
}
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) ConceptComplex(org.openmrs.ConceptComplex) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 47 with ConceptDatatype

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

the class ConceptServiceTest method getConceptDatatypeByName_shouldNotReturnAFuzzyMatchOnName.

/**
 * @see ConceptService#getConceptDatatypeByName(String)
 */
@Test
public void getConceptDatatypeByName_shouldNotReturnAFuzzyMatchOnName() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    ConceptDatatype result = conceptService.getConceptDatatypeByName("Tex");
    Assert.assertNull(result);
}
Also used : ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 48 with ConceptDatatype

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

the class ConceptServiceTest method getConceptDatatypeByName_shouldReturnAnExactMatchOnName.

/**
 * @see ConceptService#getConceptDatatypeByName(String)
 */
@Test
public void getConceptDatatypeByName_shouldReturnAnExactMatchOnName() {
    // given
    executeDataSet(INITIAL_CONCEPTS_XML);
    // when
    ConceptDatatype result = conceptService.getConceptDatatypeByName("Text");
    // then
    assertEquals("Text", result.getName());
}
Also used : ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 49 with ConceptDatatype

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

the class ConceptServiceTest method saveConcept_shouldCreateAReferenceTermForAConceptMappingOnTheFlyWhenCreatingAConcept.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldCreateAReferenceTermForAConceptMappingOnTheFlyWhenCreatingAConcept() {
    int initialTermCount = conceptService.getAllConceptReferenceTerms().size();
    Concept concept = new Concept();
    concept.addName(new ConceptName("test name", Context.getLocale()));
    concept.setDatatype(new ConceptDatatype(1));
    concept.setConceptClass(new ConceptClass(1));
    ConceptMap map = new ConceptMap();
    map.getConceptReferenceTerm().setCode("unique code");
    map.getConceptReferenceTerm().setConceptSource(conceptService.getConceptSource(1));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.addConceptMapping(map);
    conceptService.saveConcept(concept);
    Assert.assertNotNull(concept.getId());
    Assert.assertEquals(initialTermCount + 1, conceptService.getAllConceptReferenceTerms().size());
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptMap(org.openmrs.ConceptMap) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 50 with ConceptDatatype

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

the class ConceptServiceTest method saveConcept_shouldSaveNonConceptComplexObjectAsConceptComplex.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSaveNonConceptComplexObjectAsConceptComplex() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    // this tests saving a current concept as a newly changed conceptComplex
    // assumes there is already a concept in the database
    // with a concept id of #1
    ConceptComplex cn = new ConceptComplex(1);
    cn.setDatatype(new ConceptDatatype(13));
    cn.setConceptClass(new ConceptClass(1));
    cn.addName(new ConceptName("a new conceptComplex", Locale.US));
    cn.addDescription(new ConceptDescription("some description", null));
    cn.setHandler("SomeHandler");
    conceptService.saveConcept(cn);
    Concept firstConcept = conceptService.getConceptComplex(1);
    assertEquals("a new conceptComplex", firstConcept.getName(Locale.US).getName());
    assertTrue(firstConcept instanceof ConceptComplex);
    ConceptComplex firstConceptComplex = (ConceptComplex) firstConcept;
    assertEquals("SomeHandler", firstConceptComplex.getHandler());
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptComplex(org.openmrs.ConceptComplex) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

ConceptDatatype (org.openmrs.ConceptDatatype)54 Test (org.junit.Test)49 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)45 ConceptClass (org.openmrs.ConceptClass)38 ConceptName (org.openmrs.ConceptName)34 Concept (org.openmrs.Concept)32 ConceptDescription (org.openmrs.ConceptDescription)32 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)13 Locale (java.util.Locale)12 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 Date (java.util.Date)4 ConceptNumeric (org.openmrs.ConceptNumeric)4 Obs (org.openmrs.Obs)4 ConceptMap (org.openmrs.ConceptMap)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