Search in sources :

Example 36 with ConceptDescription

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

the class ConceptValidatorTest method validate_shouldFailIfATermIsMappedMultipleTimesToTheSameConcept.

@Test
public void validate_shouldFailIfATermIsMappedMultipleTimesToTheSameConcept() {
    concept.setConceptClass(new ConceptClass());
    concept.setDatatype(new ConceptDatatype());
    concept.addName(new ConceptName("my name", Context.getLocale()));
    concept.addDescription(new ConceptDescription("some description", null));
    ConceptMap map1 = new ConceptMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1));
    concept.addConceptMapping(map1);
    ConceptMap map2 = new ConceptMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1));
    concept.addConceptMapping(map2);
    validator.validate(concept, errors);
    assertThat(errors, hasFieldErrors("conceptMappings[1]"));
}
Also used : ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptMap(org.openmrs.ConceptMap) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 37 with ConceptDescription

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

the class ConceptValidatorTest method validate_shouldPassIfDifferentConceptsHaveTheSameShortNames.

@Test
public void validate_shouldPassIfDifferentConceptsHaveTheSameShortNames() {
    Context.setLocale(new Locale("en", "GB"));
    List<Concept> concepts = conceptService.getConceptsByName("HSM");
    Assert.assertEquals(1, concepts.size());
    Assert.assertEquals(true, concepts.get(0).getShortNameInLocale(Context.getLocale()).getName().equalsIgnoreCase("HSM"));
    concept.setConceptClass(new ConceptClass());
    concept.setDatatype(new ConceptDatatype());
    ConceptName conceptFullySpecifiedName = new ConceptName("holosystolic murmur", Context.getLocale());
    conceptFullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    ConceptName conceptShortName = new ConceptName("HSM", Context.getLocale());
    conceptShortName.setConceptNameType(ConceptNameType.SHORT);
    concept.addName(conceptFullySpecifiedName);
    concept.addName(conceptShortName);
    concept.addDescription(new ConceptDescription("some description", null));
    validator.validate(concept, errors);
    Assert.assertFalse(errors.hasErrors());
}
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) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 38 with ConceptDescription

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

the class ConceptValidatorTest method validate_shouldPassIfNoneofTheConceptDescriptionsIsNull.

@Test
public void validate_shouldPassIfNoneofTheConceptDescriptionsIsNull() {
    concept.addName(new ConceptName("some name", Context.getLocale()));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setConceptClass(new ConceptClass());
    concept.setDatatype(new ConceptDatatype());
    validator.validate(concept, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : 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 39 with ConceptDescription

use of org.openmrs.ConceptDescription 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 40 with ConceptDescription

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

Aggregations

Test (org.junit.Test)48 ConceptDescription (org.openmrs.ConceptDescription)48 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)47 ConceptName (org.openmrs.ConceptName)42 Concept (org.openmrs.Concept)33 ConceptDatatype (org.openmrs.ConceptDatatype)32 ConceptClass (org.openmrs.ConceptClass)31 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)20 Locale (java.util.Locale)14 OrderFrequency (org.openmrs.OrderFrequency)5 ConceptMap (org.openmrs.ConceptMap)4 ConceptNumeric (org.openmrs.ConceptNumeric)4 ConceptComplex (org.openmrs.ConceptComplex)3 ConceptService (org.openmrs.api.ConceptService)3 BindException (org.springframework.validation.BindException)3 Errors (org.springframework.validation.Errors)3 ConceptProposal (org.openmrs.ConceptProposal)2 OrderUtilTest (org.openmrs.order.OrderUtilTest)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1