Search in sources :

Example 36 with ConceptNumeric

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

the class ConceptServiceTest method shouldFetchDescriptionsForConceptsThatWereFirstFetchedAsNumerics.

/**
 * This test verifies that {@link ConceptDescription}s are fetched correctly from the hibernate
 * cache. (Or really, not fetched from the cache but instead are mapped with lazy=false. For
 * some reason Hibernate isn't able to find objects in the cache if a parent object was the one
 * that loaded them)
 *
 * @throws Exception
 */
@Test
public void shouldFetchDescriptionsForConceptsThatWereFirstFetchedAsNumerics() {
    Concept concept = Context.getConceptService().getConcept(5089);
    ConceptNumeric conceptNumeric = Context.getConceptService().getConceptNumeric(5089);
    conceptNumeric.getDescriptions().size();
    concept.getDescriptions().size();
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptNumeric(org.openmrs.ConceptNumeric) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 37 with ConceptNumeric

use of org.openmrs.ConceptNumeric 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 38 with ConceptNumeric

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

the class ConceptServiceTest method shouldFetchNamesForConceptsThatWereFirstFetchedAsNumerics.

/**
 * This test verifies that {@link ConceptName}s are fetched correctly from the hibernate cache.
 * (Or really, not fetched from the cache but instead are mapped with lazy=false. For some
 * reason Hibernate isn't able to find objects in the cache if a parent object was the one that
 * loaded them)
 *
 * @throws Exception
 */
@Test
public void shouldFetchNamesForConceptsThatWereFirstFetchedAsNumerics() {
    Concept concept = Context.getConceptService().getConcept(5089);
    ConceptNumeric conceptNumeric = Context.getConceptService().getConceptNumeric(5089);
    conceptNumeric.getNames().size();
    concept.getNames().size();
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptNumeric(org.openmrs.ConceptNumeric) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 39 with ConceptNumeric

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

the class ConceptServiceTest method saveConcept_shouldSaveANewConceptNumeric.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSaveANewConceptNumeric() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    Context.setLocale(Locale.US);
    // this tests saving a never before in the database conceptnumeric
    ConceptNumeric cn3 = new ConceptNumeric();
    cn3.setDatatype(new ConceptDatatype(1));
    cn3.setConceptClass(new ConceptClass(1));
    ConceptName cn = new ConceptName("a brand new conceptnumeric", Locale.US);
    cn3.addName(cn);
    cn3.addDescription(new ConceptDescription("some description", null));
    cn3.setHiAbsolute(50.0);
    conceptService.saveConcept(cn3);
    Concept thirdConcept = conceptService.getConcept(cn3.getConceptId());
    assertTrue(thirdConcept instanceof ConceptNumeric);
    ConceptNumeric thirdConceptNumeric = (ConceptNumeric) thirdConcept;
    assertEquals("a brand new conceptnumeric", thirdConceptNumeric.getName(Locale.US).getName());
    assertEquals(50.0, thirdConceptNumeric.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)

Aggregations

ConceptNumeric (org.openmrs.ConceptNumeric)39 Test (org.junit.Test)36 Concept (org.openmrs.Concept)7 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)7 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)5 ConceptDatatype (org.openmrs.ConceptDatatype)4 ConceptDescription (org.openmrs.ConceptDescription)4 ConceptName (org.openmrs.ConceptName)4 ConceptClass (org.openmrs.ConceptClass)3 ConceptComplex (org.openmrs.ConceptComplex)3 Query (org.hibernate.Query)2 SQLQuery (org.hibernate.SQLQuery)2 LuceneQuery (org.openmrs.api.db.hibernate.search.LuceneQuery)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1