use of org.openmrs.ConceptDatatype 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());
}
use of org.openmrs.ConceptDatatype 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());
}
use of org.openmrs.ConceptDatatype 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));
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class HibernateConceptDAOTest method isConceptNameDuplicate_shouldNotFailIfConceptDoesNotHaveADefaultNameForLocale.
// TRUNK-4967
@Test
public void isConceptNameDuplicate_shouldNotFailIfConceptDoesNotHaveADefaultNameForLocale() {
// given
ConceptClass diagnosis = dao.getConceptClasses("Diagnosis").get(0);
ConceptDatatype na = dao.getConceptDatatypeByName("N/A");
Concept tuberculosis = new Concept();
tuberculosis.addName(new ConceptName("Tuberculosis", Locale.US));
tuberculosis.setDatatype(na);
tuberculosis.setConceptClass(diagnosis);
dao.saveConcept(tuberculosis);
ConceptName shortName = new ConceptName("TB", Locale.FRANCE);
shortName.setConceptNameType(ConceptNameType.SHORT);
tuberculosis.addName(shortName);
// when
boolean duplicate = dao.isConceptNameDuplicate(shortName);
// then
// no NPE exception thrown
assertThat(duplicate, is(false));
}
use of org.openmrs.ConceptDatatype in project openmrs-module-coreapps by openmrs.
the class ParserEncounterIntoSimpleObjectsTest method testParsingSimpleObs.
@Test
public void testParsingSimpleObs() throws Exception {
ConceptDatatype textDatatype = conceptService.getConceptDatatypeByName("Text");
ConceptClass misc = conceptService.getConceptClassByName("Misc");
// intentionally the same as what will result from capitalizeFirstLetter(consultNote)
String consultNote = "Consult note";
String valueText = "Patient is here for blah blah blah.";
Concept consultComments = new ConceptBuilder(conceptService, textDatatype, misc).addName(consultNote).get();
encounter.addObs(new ObsBuilder().setConcept(consultComments).setValue(valueText).get());
ParsedObs parsed = parser.parseObservations(Locale.ENGLISH);
assertThat(parsed.getDiagnoses().size(), is(0));
assertThat(parsed.getDispositions().size(), is(0));
assertThat(parsed.getObs().size(), is(1));
assertThat(path(parsed.getObs(), 0, "question"), is((Object) consultNote));
assertThat(path(parsed.getObs(), 0, "answer"), is((Object) valueText));
}
Aggregations