Search in sources :

Example 16 with ConceptDescription

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

the class ConceptServiceTest method saveConcept_shouldPassWhenSavingAConceptAfterRemovingAName.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldPassWhenSavingAConceptAfterRemovingAName() {
    executeDataSet("org/openmrs/api/include/ConceptServiceTest-names.xml");
    Concept concept = conceptService.getConcept(3000);
    concept.addDescription(new ConceptDescription("some description", null));
    Assert.assertFalse(concept.getSynonyms().isEmpty());
    concept.removeName(concept.getSynonyms().iterator().next());
    conceptService.saveConcept(concept);
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptDescription(org.openmrs.ConceptDescription) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 17 with ConceptDescription

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

the class ConceptServiceTest method mapConceptProposalToConcept_shouldFailWhenAddingADuplicateSyonymn.

/**
 * @see ConceptService#mapConceptProposalToConcept(ConceptProposal,Concept,Locale)
 */
@Test(expected = DuplicateConceptNameException.class)
public void mapConceptProposalToConcept_shouldFailWhenAddingADuplicateSyonymn() {
    executeDataSet("org/openmrs/api/include/ConceptServiceTest-proposals.xml");
    ConceptService cs = Context.getConceptService();
    ConceptProposal cp = cs.getConceptProposal(10);
    cp.setFinalText(cp.getOriginalText());
    cp.setState(OpenmrsConstants.CONCEPT_PROPOSAL_SYNONYM);
    Concept mappedConcept = cs.getConcept(5);
    Locale locale = new Locale("en", "GB");
    mappedConcept.addDescription(new ConceptDescription("some description", locale));
    Assert.assertTrue(mappedConcept.hasName(cp.getFinalText(), locale));
    cs.mapConceptProposalToConcept(cp, mappedConcept, locale);
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) Locale(java.util.Locale) ConceptProposal(org.openmrs.ConceptProposal) ConceptDescription(org.openmrs.ConceptDescription) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 18 with ConceptDescription

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

the class ConceptServiceTest method saveConcept_shouldReuseConceptNameTagsThatAlreadyExistInTheDatabase.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldReuseConceptNameTagsThatAlreadyExistInTheDatabase() {
    executeDataSet("org/openmrs/api/include/ConceptServiceTest-tags.xml");
    ConceptService cs = Context.getConceptService();
    // make sure the name tag exists already
    ConceptNameTag cnt = cs.getConceptNameTagByName("preferred_en");
    Assert.assertNotNull(cnt);
    ConceptName cn = new ConceptName("Some name", Locale.ENGLISH);
    cn.addTag(new ConceptNameTag("preferred_en", "preferred name in a language"));
    Concept concept = new Concept();
    concept.addName(cn);
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setDatatype(new ConceptDatatype(1));
    concept.setConceptClass(new ConceptClass(1));
    cs.saveConcept(concept);
    Collection<ConceptNameTag> savedConceptNameTags = concept.getName(Locale.ENGLISH, false).getTags();
    ConceptNameTag savedConceptNameTag = (ConceptNameTag) savedConceptNameTags.toArray()[0];
    Assert.assertEquals(cnt.getConceptNameTagId(), savedConceptNameTag.getConceptNameTagId());
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptNameTag(org.openmrs.ConceptNameTag) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 19 with ConceptDescription

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

the class ConceptServiceTest method saveConcept_shouldGenerateIdForNewConceptIfNoneIsSpecified.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldGenerateIdForNewConceptIfNoneIsSpecified() {
    Concept concept = new Concept();
    ConceptName cn = new ConceptName("Weight", Context.getLocale());
    concept.addName(cn);
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setConceptId(null);
    concept.setDatatype(Context.getConceptService().getConceptDatatypeByName("Numeric"));
    concept.setConceptClass(Context.getConceptService().getConceptClassByName("Finding"));
    concept = Context.getConceptService().saveConcept(concept);
    assertFalse(concept.getConceptId().equals(5089));
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 20 with ConceptDescription

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

the class ConceptServiceTest method getOrderableConcepts_shouldGetOrderableConcepts.

/**
 * @see ConceptService#getOrderableConcepts(String, java.util.List, boolean, Integer, Integer)
 */
@Test
public void getOrderableConcepts_shouldGetOrderableConcepts() {
    // In current data set order_type_map table contains conceptClass 1 and 3.
    // Using that adding two concepts to test the functionality
    ConceptService cs = Context.getConceptService();
    ConceptClass cc1 = cs.getConceptClass(1);
    ConceptClass cc3 = cs.getConceptClass(3);
    Locale locale = Locale.ENGLISH;
    ConceptDatatype dt = cs.getConceptDatatype(4);
    Concept c1 = new Concept();
    ConceptName cn1a = new ConceptName("ONE TERM", locale);
    c1.addName(cn1a);
    c1.addDescription(new ConceptDescription("some description", null));
    c1.setConceptClass(cc1);
    c1.setDatatype(dt);
    cs.saveConcept(c1);
    Concept c2 = new Concept();
    ConceptName cn2a = new ConceptName("ONE TO MANY", locale);
    c2.addName(cn2a);
    c2.addDescription(new ConceptDescription("some description", null));
    c2.setConceptClass(cc3);
    c2.setDatatype(dt);
    cs.saveConcept(c2);
    updateSearchIndex();
    List<ConceptSearchResult> conceptSearchResultList = Context.getConceptService().getOrderableConcepts("one", Collections.singletonList(locale), true, null, null);
    assertEquals(2, conceptSearchResultList.size());
}
Also used : Locale(java.util.Locale) OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptSearchResult(org.openmrs.ConceptSearchResult) 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