use of org.openmrs.Concept in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldCascadeSaveToContainedObs.
/**
* You should be able to add an obs to an encounter, save the encounter, and have the obs
* automatically persisted. Added to test bug reported in ticket #827
*
* @see EncounterService#saveEncounter(Encounter)
*/
@Test
public void saveEncounter_shouldCascadeSaveToContainedObs() {
EncounterService es = Context.getEncounterService();
// First, create a new Encounter
Encounter enc = buildEncounter();
// add an obs to the encounter
Obs groupObs = new Obs();
Concept c = Context.getConceptService().getConcept(1);
groupObs.setConcept(c);
// add an obs to the group
Obs childObs = new Obs();
childObs.setConcept(c);
childObs.setValueNumeric(50d);
groupObs.addGroupMember(childObs);
enc.addObs(groupObs);
// confirm that save and new enc id are cascaded to obs groupMembers
// even though childObs aren't directly associated to enc
assertNotNull("save succeeds without error", es.saveEncounter(enc));
assertTrue("enc save succeeds", enc.getId() > 0);
assertNotNull("obs save succeeds", groupObs.getObsId());
assertEquals("encounter id propogated", groupObs.getEncounter().getId(), enc.getId());
assertEquals("encounter time propogated", groupObs.getObsDatetime(), enc.getEncounterDatetime());
assertNotNull("obs save succeeds", childObs.getObsId());
assertEquals("encounter id propogated", childObs.getEncounter().getId(), enc.getId());
assertEquals("encounter time propogated", childObs.getObsDatetime(), enc.getEncounterDatetime());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldSetDefaultPreferredNameToFullySpecifiedFirst.
/**
* @see ConceptServiceImpl#saveConcept(Concept)
* Concept.getPreferredName(locale) 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_shouldSetDefaultPreferredNameToFullySpecifiedFirst() {
Locale loc = new Locale("fr", "CA");
ConceptName fullySpecifiedName = new ConceptName("fully specified", loc);
// 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();
c.addName(fullySpecifiedName);
c.addName(synonym);
c.addName(indexTerm);
c.addName(shortName);
c.addDescription(new ConceptDescription("some description", null));
c.setDatatype(new ConceptDatatype(1));
c.setConceptClass(new ConceptClass(1));
assertFalse("check test assumption - the API didn't automatically set preferred vlag", c.getFullySpecifiedName(loc).isPreferred());
assertNotNull("Concept is legit, save succeeds", Context.getConceptService().saveConcept(c));
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(), fullySpecifiedName.getName());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldTrimWhitespacesInConceptName.
@Test
public void saveConcept_shouldTrimWhitespacesInConceptName() {
// Given
Concept concept = new Concept();
String nameWithSpaces = " jwm ";
concept.addName(new ConceptName(nameWithSpaces, new Locale("en", "US")));
concept.addDescription(new ConceptDescription("some description", null));
concept.setDatatype(new ConceptDatatype(1));
concept.setConceptClass(new ConceptClass(1));
// When
Context.getConceptService().saveConcept(concept);
// Then
assertNotEquals(concept.getName().getName(), nameWithSpaces);
assertEquals(concept.getName().getName(), "jwm");
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class ConceptServiceImplTest method getConceptsByAnswer_shouldReturnAnEmptyListIfConceptIdIsNull.
/**
* @see ConceptService#getConceptsByAnswer(Concept)
*/
@Test
public void getConceptsByAnswer_shouldReturnAnEmptyListIfConceptIdIsNull() {
List<Concept> concepts = conceptService.getConceptsByAnswer(new Concept());
assertEquals(concepts, Collections.emptyList());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class ConceptServiceImplTest method retireConcept_shouldFailIfNoReasonIsGiven.
/**
* @see ConceptServiceImpl#retireConcept(Concept,String)
*/
@Test
public void retireConcept_shouldFailIfNoReasonIsGiven() {
Concept concept = conceptService.getConcept(3);
expectedException.expect(IllegalArgumentException.class);
conceptService.retireConcept(concept, "");
}
Aggregations