use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptServiceTest method saveConcept_shouldAddNewConceptName.
/**
* @see ConceptService#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldAddNewConceptName() {
Concept concept = conceptService.getConcept(3);
ConceptName name = new ConceptName("new name", Locale.US);
concept.addName(name);
conceptService.saveConcept(concept);
assertNotNull(name.getConceptNameId());
}
use of org.openmrs.ConceptName 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.ConceptName 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.ConceptName in project openmrs-core by openmrs.
the class ConceptServiceTest method saveConcept_shouldNotAcceptALocaleThatIsNeitherAmongTheLocaleAllowedListNorADefaultLocale.
/**
* This test fetches all concepts in the xml test dataset and ensures that every locale for a
* concept name is among those listed in the global property 'locale.allowed.list' and default
* locale. NOTE that it doesn't test a particular API method directly.
*/
@Test
public void saveConcept_shouldNotAcceptALocaleThatIsNeitherAmongTheLocaleAllowedListNorADefaultLocale() {
List<Concept> concepts = Context.getConceptService().getAllConcepts();
Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder();
for (Concept concept : concepts) {
if (!CollectionUtils.isEmpty(concept.getNames())) {
for (ConceptName cn : concept.getNames()) {
Assert.assertTrue("The locale '" + cn.getLocale() + "' of conceptName with id: " + cn.getConceptNameId() + " is not among those listed in the global property 'locale.allowed.list'", allowedLocales.contains(cn.getLocale()));
}
}
}
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class OrderServiceTest method getOrderFrequencies_shouldReturnUniqueFrequencies.
/**
* @see OrderService#getOrderFrequencies(String, java.util.Locale, boolean, boolean)
*/
@Test
public void getOrderFrequencies_shouldReturnUniqueFrequencies() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-otherOrderFrequencies.xml");
final String searchPhrase = "once";
final Locale locale = Locale.ENGLISH;
List<OrderFrequency> orderFrequencies = orderService.getOrderFrequencies(searchPhrase, locale, true, false);
assertEquals(1, orderFrequencies.size());
final OrderFrequency expectedOrderFrequency = orderService.getOrderFrequency(100);
assertEquals(expectedOrderFrequency, orderFrequencies.get(0));
// Add a new name to the frequency concept so that our search phrase matches on 2
// concept names for the same frequency concept
Concept frequencyConcept = expectedOrderFrequency.getConcept();
final String newConceptName = searchPhrase + " A Day";
frequencyConcept.addName(new ConceptName(newConceptName, locale));
frequencyConcept.addDescription(new ConceptDescription("some description", null));
conceptService.saveConcept(frequencyConcept);
orderFrequencies = orderService.getOrderFrequencies(searchPhrase, locale, true, false);
assertEquals(1, orderFrequencies.size());
assertEquals(expectedOrderFrequency, orderFrequencies.get(0));
}
Aggregations