use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptServiceTest method saveConcept_shouldSaveNonConceptNumericObjectAsConceptNumeric.
/**
* @see ConceptService#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldSaveNonConceptNumericObjectAsConceptNumeric() {
executeDataSet(INITIAL_CONCEPTS_XML);
// this tests saving a current concept as a newly changed conceptnumeric
// assumes there is already a concept in the database
// with a concept id of #1
ConceptNumeric cn = new ConceptNumeric(1);
cn.setDatatype(new ConceptDatatype(1));
cn.setConceptClass(new ConceptClass(1));
cn.addName(new ConceptName("a new conceptnumeric", Locale.US));
cn.addDescription(new ConceptDescription("some description", null));
cn.setHiAbsolute(20.0);
conceptService.saveConcept(cn);
Concept firstConcept = conceptService.getConceptNumeric(1);
firstConcept.addDescription(new ConceptDescription("some description", null));
assertEquals("a new conceptnumeric", firstConcept.getName(Locale.US).getName());
assertTrue(firstConcept instanceof ConceptNumeric);
ConceptNumeric firstConceptNumeric = (ConceptNumeric) firstConcept;
assertEquals(20.0, firstConceptNumeric.getHiAbsolute(), 0);
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldSetDefaultPreferredNameToASynonymSecond.
/**
* @see ConceptServiceImpl#saveConcept(Concept)
* returns null, saveConcept chooses one. The default first choice is the fully
* specified name in the locale. The default second choice is a synonym in the locale.
*/
@Test
public void saveConcept_shouldSetDefaultPreferredNameToASynonymSecond() {
Locale loc = new Locale("fr", "CA");
Locale otherLocale = new Locale("en", "US");
// Create a fully specified name, but for another locale
// so the Concept passes validation
ConceptName fullySpecifiedName = new ConceptName("fully specified", otherLocale);
// be explicit for test case
fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
ConceptName shortName = new ConceptName("short name", loc);
// be explicit for test case
shortName.setConceptNameType(ConceptNameType.SHORT);
ConceptName synonym = new ConceptName("synonym", loc);
// synonyms are id'd by a null type
synonym.setConceptNameType(null);
ConceptName indexTerm = new ConceptName("indexTerm", loc);
// synonyms are id'd by a null type
indexTerm.setConceptNameType(ConceptNameType.INDEX_TERM);
Concept c = new Concept();
HashSet<ConceptName> allNames = new HashSet<>(4);
allNames.add(indexTerm);
allNames.add(fullySpecifiedName);
allNames.add(synonym);
c.setNames(allNames);
c.addDescription(new ConceptDescription("some description", null));
c.setDatatype(new ConceptDatatype(1));
c.setConceptClass(new ConceptClass(1));
assertNull("check test assumption - the API hasn't promoted a name to a fully specified name", c.getFullySpecifiedName(loc));
Context.getConceptService().saveConcept(c);
assertNotNull("there's a preferred name", c.getPreferredName(loc));
assertTrue("name was explicitly marked preferred", c.getPreferredName(loc).isPreferred());
assertEquals("name matches", c.getPreferredName(loc).getName(), synonym.getName());
assertEquals("fully specified name unchanged", c.getPreferredName(otherLocale).getName(), fullySpecifiedName.getName());
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldReturnTheConceptWithSameConceptIDIfUpdatingExistingConcept.
/**
* @see ConceptServiceImpl#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldReturnTheConceptWithSameConceptIDIfUpdatingExistingConcept() {
Concept c = new Concept();
ConceptName fullySpecifiedName = new ConceptName("requires one name min", new Locale("fr", "CA"));
c.addName(fullySpecifiedName);
c.addDescription(new ConceptDescription("some description", null));
c.setDatatype(new ConceptDatatype(1));
c.setConceptClass(new ConceptClass(1));
Concept savedC = Context.getConceptService().saveConcept(c);
assertNotNull(savedC);
Concept updatedC = Context.getConceptService().saveConcept(c);
assertNotNull(updatedC);
assertEquals(updatedC.getConceptId(), savedC.getConceptId());
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldForceSetFlagIfSetMembersExist.
/**
* @see ConceptServiceImpl#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldForceSetFlagIfSetMembersExist() {
// Given
Concept concept = new Concept();
concept.addName(new ConceptName("Concept", new Locale("en", "US")));
concept.addDescription(new ConceptDescription("some description", null));
concept.setDatatype(new ConceptDatatype(1));
concept.setConceptClass(new ConceptClass(1));
Concept conceptSetMember = new Concept();
conceptSetMember.addName(new ConceptName("Set Member", new Locale("en", "US")));
conceptSetMember.addDescription(new ConceptDescription("some description", null));
conceptSetMember.setConceptClass(new ConceptClass(1));
conceptSetMember.setDatatype(new ConceptDatatype(1));
Context.getConceptService().saveConcept(conceptSetMember);
concept.addSetMember(conceptSetMember);
concept.setSet(false);
// When
Context.getConceptService().saveConcept(concept);
// Then
assertTrue(concept.getSet());
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class JavaSerializationTest method shouldSerializeOpenMrsMetadata.
@Test
public void shouldSerializeOpenMrsMetadata() {
Date date = new Date();
User user = new User(1);
Concept originalConcept = new Concept();
originalConcept.setConceptClass(new ConceptClass(1));
originalConcept.setDatatype(new ConceptDatatype(1));
originalConcept.setUuid("abc123");
originalConcept.setDateCreated(date);
originalConcept.setCreator(user);
originalConcept.setDateChanged(date);
originalConcept.setChangedBy(user);
originalConcept.setRetired(true);
originalConcept.setRetiredBy(user);
originalConcept.setDateRetired(date);
originalConcept.setRetireReason("test");
byte[] serialized = SerializationUtils.serialize(originalConcept);
Concept copyConcept = (Concept) SerializationUtils.deserialize(serialized);
assertThat(copyConcept.getConceptClass(), is(originalConcept.getConceptClass()));
assertThat(copyConcept.getDatatype(), is(originalConcept.getDatatype()));
assertThat(copyConcept.getDateCreated(), is(originalConcept.getDateCreated()));
assertThat(copyConcept.getCreator(), is(originalConcept.getCreator()));
assertThat(copyConcept.getDateChanged(), is(originalConcept.getDateChanged()));
assertThat(copyConcept.getChangedBy(), is(originalConcept.getChangedBy()));
assertThat(copyConcept.getRetired(), is(originalConcept.getRetired()));
assertThat(copyConcept.getRetiredBy(), is(originalConcept.getRetiredBy()));
assertThat(copyConcept.getDateRetired(), is(originalConcept.getDateRetired()));
assertThat(copyConcept.getRetireReason(), is(originalConcept.getRetireReason()));
assertThat(copyConcept.getUuid(), is(originalConcept.getUuid()));
}
Aggregations