Search in sources :

Example 31 with ConceptName

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

the class ConceptServiceTest method purgeConcept_shouldFailIfAnyOfTheConceptNamesOfTheConceptIsBeingUsedByAnObs.

/**
 * @see ConceptService#purgeConcept(Concept)
 */
@Test(expected = ConceptNameInUseException.class)
public void purgeConcept_shouldFailIfAnyOfTheConceptNamesOfTheConceptIsBeingUsedByAnObs() {
    Obs o = new Obs();
    o.setConcept(Context.getConceptService().getConcept(3));
    o.setPerson(new Patient(2));
    o.setEncounter(new Encounter(3));
    o.setObsDatetime(new Date());
    o.setLocation(new Location(1));
    ConceptName conceptName = new ConceptName(1847);
    o.setValueCodedName(conceptName);
    Context.getObsService().saveObs(o, null);
    // ensure that the association between the conceptName and the obs has been established
    Assert.assertEquals(true, conceptService.hasAnyObservation(conceptName));
    Concept concept = conceptService.getConceptByName("cd4 count");
    // make sure the name concept name exists
    Assert.assertNotNull(concept);
    conceptService.purgeConcept(concept);
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) ConceptName(org.openmrs.ConceptName) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 32 with ConceptName

use of org.openmrs.ConceptName 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 33 with ConceptName

use of org.openmrs.ConceptName 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 34 with ConceptName

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

Example 35 with ConceptName

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

the class ConceptServiceTest method saveConcept_shouldCreateNewConceptInDatabase.

@Test
public void saveConcept_shouldCreateNewConceptInDatabase() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    Concept conceptToAdd = new Concept();
    ConceptName cn = new ConceptName("new name", Context.getLocale());
    conceptToAdd.addName(cn);
    conceptToAdd.addDescription(new ConceptDescription("some description", null));
    conceptToAdd.setDatatype(new ConceptDatatype(1));
    conceptToAdd.setConceptClass(new ConceptClass(1));
    assertFalse(conceptService.getAllConcepts().contains(conceptToAdd));
    conceptService.saveConcept(conceptToAdd);
    assertTrue(conceptService.getAllConcepts().contains(conceptToAdd));
}
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) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

ConceptName (org.openmrs.ConceptName)100 Test (org.junit.Test)78 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)71 Concept (org.openmrs.Concept)62 ConceptDescription (org.openmrs.ConceptDescription)42 ConceptDatatype (org.openmrs.ConceptDatatype)34 ConceptClass (org.openmrs.ConceptClass)33 Locale (java.util.Locale)32 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)22 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 Obs (org.openmrs.Obs)9 BindException (org.springframework.validation.BindException)8 ConceptMap (org.openmrs.ConceptMap)7 Errors (org.springframework.validation.Errors)7 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Patient (org.openmrs.Patient)6 Encounter (org.openmrs.Encounter)5 OrderFrequency (org.openmrs.OrderFrequency)5