use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptServiceImpl method saveConcept.
/**
* @see org.openmrs.api.ConceptService#saveConcept(org.openmrs.Concept)
* @should return the concept with new conceptID if creating new concept
* @should return the concept with same conceptID if updating existing concept
* @should leave preferred name preferred if set
* @should set default preferred name to fully specified first
* @should not set default preferred name to short or index terms
* @should force set flag if set members exist
*/
@Override
public Concept saveConcept(Concept concept) throws APIException {
ensureConceptMapTypeIsSet(concept);
CustomDatatypeUtil.saveAttributesIfNecessary(concept);
// make sure the administrator hasn't turned off concept editing
checkIfLocked();
checkIfDatatypeCanBeChanged(concept);
List<ConceptName> changedConceptNames = null;
Map<String, ConceptName> uuidClonedConceptNameMap = null;
if (concept.getConceptId() != null) {
uuidClonedConceptNameMap = new HashMap<>();
for (ConceptName conceptName : concept.getNames()) {
// ignore newly added names
if (conceptName.getConceptNameId() != null) {
ConceptName clone = cloneConceptName(conceptName);
clone.setConceptNameId(null);
uuidClonedConceptNameMap.put(conceptName.getUuid(), clone);
if (hasNameChanged(conceptName)) {
if (changedConceptNames == null) {
changedConceptNames = new ArrayList<>();
}
changedConceptNames.add(conceptName);
} else {
// put back the concept name id
clone.setConceptNameId(conceptName.getConceptNameId());
// Use the cloned version
try {
BeanUtils.copyProperties(conceptName, clone);
} catch (IllegalAccessException | InvocationTargetException e) {
log.error(errorMessage, e);
}
}
}
}
}
if (CollectionUtils.isNotEmpty(changedConceptNames)) {
for (ConceptName changedName : changedConceptNames) {
// void old concept name
changedName.setVoided(true);
changedName.setDateVoided(new Date());
changedName.setVoidedBy(Context.getAuthenticatedUser());
changedName.setVoidReason(Context.getMessageSourceService().getMessage("Concept.name.voidReason.nameChanged"));
makeVoidedNameSynonym(changedName);
makeLocaleNotPreferred(changedName);
// create a new concept name from the matching cloned
// conceptName
ConceptName clone = uuidClonedConceptNameMap.get(changedName.getUuid());
clone.setUuid(UUID.randomUUID().toString());
clone.setDateCreated(null);
clone.setCreator(null);
concept.addName(clone);
}
}
ensurePreferredNameForLocale(concept);
logConceptChangedData(concept);
// force isSet when concept has members
if (!concept.getSet() && (!concept.getSetMembers().isEmpty())) {
concept.setSet(true);
}
return dao.saveConcept(concept);
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptValidatorTest method validate_shouldNotFailIfAnyDescriptionIsNotEnteredWhileCreatingANewConcept.
@Test
public void validate_shouldNotFailIfAnyDescriptionIsNotEnteredWhileCreatingANewConcept() {
concept.addName(new ConceptName("some name", Context.getLocale()));
validator.validate(concept, errors);
assertThat(errors, not(hasFieldErrors("description")));
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptValidatorTest method validate_shouldPassIfTheConceptHasASynonymThatIsAlsoAShortName.
@Test
public void validate_shouldPassIfTheConceptHasASynonymThatIsAlsoAShortName() {
concept.addName(new ConceptName("CD4", Context.getLocale()));
concept.addDescription(new ConceptDescription("some description", null));
concept.setConceptClass(new ConceptClass());
concept.setDatatype(new ConceptDatatype());
// Add the short name. Because the short name is not counted as a Synonym.
// ConceptValidator will not record any errors.
ConceptName name = new ConceptName("CD4", Context.getLocale());
name.setConceptNameType(ConceptNameType.SHORT);
concept.addName(name);
validator.validate(concept, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptValidatorTest method validate_shouldNotFailIfATermHasTwoNewMappingsOnIt.
@Test
public void validate_shouldNotFailIfATermHasTwoNewMappingsOnIt() {
concept.addName(new ConceptName("my name", Context.getLocale()));
ConceptReferenceTerm newTerm = new ConceptReferenceTerm(conceptService.getConceptSource(1), "1234", "term one two three four");
ConceptMap map1 = new ConceptMap(newTerm, conceptService.getConceptMapType(1));
concept.addConceptMapping(map1);
ConceptReferenceTerm newTermTwo = new ConceptReferenceTerm(conceptService.getConceptSource(1), "12345", "term one two three four five");
ConceptMap map2 = new ConceptMap(newTermTwo, conceptService.getConceptMapType(1));
concept.addConceptMapping(map2);
validator.validate(concept, errors);
assertThat(errors, not(hasFieldErrors("conceptMappings[1]")));
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptValidatorTest method validate_shouldNotFailIfBlankConceptDescriptionIsPassed.
@Test
public void validate_shouldNotFailIfBlankConceptDescriptionIsPassed() {
concept.addName(new ConceptName("some name", Context.getLocale()));
concept.addDescription(new ConceptDescription(" ", null));
validator.validate(concept, errors);
assertThat(errors, not(hasFieldErrors("description")));
}
Aggregations