use of org.openmrs.ConceptClass 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());
}
use of org.openmrs.ConceptClass in project openmrs-core by openmrs.
the class ConceptServiceTest method saveConcept_shouldSetAPreferredNameForEachLocaleIfNoneIsMarked.
/**
* @see ConceptService#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldSetAPreferredNameForEachLocaleIfNoneIsMarked() {
// add some other locales to locale.allowed.list for testing purposes
GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST);
gp.setPropertyValue(gp.getPropertyValue().concat(",fr,ja,en_GB"));
Context.getAdministrationService().saveGlobalProperty(gp);
Concept concept = new Concept();
concept.addName(new ConceptName("name1", Locale.ENGLISH));
concept.addName(new ConceptName("name2", Locale.ENGLISH));
concept.addName(new ConceptName("name3", Locale.FRENCH));
concept.addName(new ConceptName("name4", Locale.FRENCH));
concept.addName(new ConceptName("name5", Locale.JAPANESE));
concept.addName(new ConceptName("name6", Locale.JAPANESE));
concept.addDescription(new ConceptDescription("some description", null));
concept.setDatatype(new ConceptDatatype(1));
concept.setConceptClass(new ConceptClass(1));
concept = Context.getConceptService().saveConcept(concept);
Assert.assertNotNull(concept.getPreferredName(Locale.ENGLISH));
Assert.assertNotNull(concept.getPreferredName(Locale.FRENCH));
Assert.assertNotNull(concept.getPreferredName(Locale.JAPANESE));
}
use of org.openmrs.ConceptClass in project openmrs-core by openmrs.
the class ConceptServiceTest method getConceptsByName_shouldReturnConceptsForSpecificCountryAndGlobalLanguageGivenLanguageAndCountryLocale.
/**
* @see ConceptService#getConceptsByName(String,Locale)
*/
@Test
public void getConceptsByName_shouldReturnConceptsForSpecificCountryAndGlobalLanguageGivenLanguageAndCountryLocale() {
// given
String name = "Concept";
Concept concept1 = new Concept();
concept1.addName(new ConceptName(name, new Locale("en", "US")));
concept1.addDescription(new ConceptDescription("some description", null));
concept1.setDatatype(new ConceptDatatype(1));
concept1.setConceptClass(new ConceptClass(1));
Context.getConceptService().saveConcept(concept1);
Concept concept2 = new Concept();
concept2.addName(new ConceptName(name, new Locale("en", "GB")));
concept2.addDescription(new ConceptDescription("some description", null));
concept2.setDatatype(new ConceptDatatype(1));
concept2.setConceptClass(new ConceptClass(1));
Context.getConceptService().saveConcept(concept2);
Concept concept3 = new Concept();
concept3.addName(new ConceptName(name, new Locale("en")));
concept3.addDescription(new ConceptDescription("some description", null));
concept3.setDatatype(new ConceptDatatype(1));
concept3.setConceptClass(new ConceptClass(1));
Context.getConceptService().saveConcept(concept3);
updateSearchIndex();
// when
List<Concept> concepts = Context.getConceptService().getConceptsByName(name, new Locale("en", "US"), false);
// then
assertThat(concepts.get(0), is(concept1));
assertThat(concepts, containsInAnyOrder(concept1, concept2, concept3));
}
use of org.openmrs.ConceptClass 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);
}
use of org.openmrs.ConceptClass in project openmrs-core by openmrs.
the class ConceptDAOTest method getConcepts_shouldReturnCorrectResultsIfAConceptNameContainsSameWordMoreThanOnce.
/**
* @see {@link
* ConceptDAO#getConcepts(String,List<Locale>,null,List<ConceptClass>,List<ConceptClass>,
* List<ConceptDatatype>,List<ConceptDatatype>,Concept,Integer,Integer)}
*/
@SuppressWarnings("unchecked")
@Test
@Ignore
public void getConcepts_shouldReturnCorrectResultsIfAConceptNameContainsSameWordMoreThanOnce() {
ConceptService cs = Context.getConceptService();
ConceptClass cc = cs.getConceptClass(1);
Locale locale = Locale.ENGLISH;
ConceptDatatype dt = cs.getConceptDatatype(4);
Concept c1 = new Concept();
ConceptName cn1a = new ConceptName("ONE TERM", locale);
c1.addName(cn1a);
c1.setConceptClass(cc);
c1.setDatatype(dt);
cs.saveConcept(c1);
ConceptName cn1b = new ConceptName("ONE TO ONE", locale);
cn1b.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
cn1b.setLocalePreferred(true);
c1.addName(cn1b);
cs.saveConcept(c1);
Assert.assertTrue(cn1a.isSynonym());
Assert.assertTrue(cn1b.getConceptNameId() > cn1a.getConceptNameId());
Concept c2 = new Concept();
ConceptName cn2a = new ConceptName("ONE TO MANY", locale);
c2.addName(cn2a);
c2.setConceptClass(cc);
c2.setDatatype(dt);
cs.saveConcept(c2);
updateSearchIndex();
List<ConceptSearchResult> searchResults1 = dao.getConcepts("one", Collections.singletonList(locale), false, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, null, null, null);
Assert.assertEquals(2, searchResults1.size());
Assert.assertEquals(c1, searchResults1.get(0).getConcept());
Assert.assertEquals(cn1b, searchResults1.get(0).getConceptName());
}
Aggregations