use of org.openmrs.ConceptReferenceTerm in project openmrs-core by openmrs.
the class ConceptReferenceTermValidatorTest method validate_shouldFailIfTheCodeIsAnEmptyString.
/**
* @see ConceptReferenceTermValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfTheCodeIsAnEmptyString() {
ConceptReferenceTerm term = new ConceptReferenceTerm();
term.setName("name");
term.setCode("");
term.setConceptSource(Context.getConceptService().getConceptSource(1));
Errors errors = new BindException(term, "term");
new ConceptReferenceTermValidator().validate(term, errors);
Assert.assertEquals(true, errors.hasFieldErrors("code"));
}
use of org.openmrs.ConceptReferenceTerm in project openmrs-core by openmrs.
the class ConceptReferenceTermValidatorTest method validate_shouldPassIfAllTheRequiredFieldsAreSetAndValid.
/**
* @see ConceptReferenceTermValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassIfAllTheRequiredFieldsAreSetAndValid() {
ConceptReferenceTerm term = new ConceptReferenceTerm();
term.setName("name");
term.setCode("code");
term.setConceptSource(Context.getConceptService().getConceptSource(1));
Errors errors = new BindException(term, "term");
new ConceptReferenceTermValidator().validate(term, errors);
Assert.assertEquals(false, errors.hasErrors());
}
use of org.openmrs.ConceptReferenceTerm in project openmrs-core by openmrs.
the class ConceptReferenceTermValidatorTest method validate_shouldFailIfTermBOfAConceptReferenceTermMapIsNotSet.
/**
* @see ConceptReferenceTermValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfTermBOfAConceptReferenceTermMapIsNotSet() {
ConceptReferenceTerm term = new ConceptReferenceTerm();
term.setName("name");
term.setCode("code");
term.setConceptSource(Context.getConceptService().getConceptSource(1));
Set<ConceptReferenceTermMap> maps = new LinkedHashSet<>();
maps.add(new ConceptReferenceTermMap(null, new ConceptMapType(1)));
term.setConceptReferenceTermMaps(maps);
Errors errors = new BindException(term, "term");
new ConceptReferenceTermValidator().validate(term, errors);
Assert.assertEquals(true, errors.hasFieldErrors("conceptReferenceTermMaps[0].termB"));
}
use of org.openmrs.ConceptReferenceTerm in project openmrs-core by openmrs.
the class HibernateConceptDAO method getConceptReferenceTermByName.
/**
* @see org.openmrs.api.db.ConceptDAO#getConceptReferenceTermByName(java.lang.String,
* org.openmrs.ConceptSource)
*/
@SuppressWarnings("rawtypes")
@Override
public ConceptReferenceTerm getConceptReferenceTermByName(String name, ConceptSource conceptSource) throws DAOException {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptReferenceTerm.class);
criteria.add(Restrictions.ilike("name", name, MatchMode.EXACT));
criteria.add(Restrictions.eq("conceptSource", conceptSource));
List terms = criteria.list();
if (terms.isEmpty()) {
return null;
} else if (terms.size() > 1) {
throw new APIException("ConceptReferenceTerm.foundMultipleTermsWithNameInSource", new Object[] { name, conceptSource.getName() });
}
return (ConceptReferenceTerm) terms.get(0);
}
use of org.openmrs.ConceptReferenceTerm in project openmrs-core by openmrs.
the class ConceptServiceTest method unretireConceptReferenceTerm_shouldUnretireTheSpecifiedConceptReferenceTermAndDropAllRetireRelatedFields.
/**
* @see ConceptService#unretireConceptReferenceTerm(ConceptReferenceTerm)
*/
@Test
public void unretireConceptReferenceTerm_shouldUnretireTheSpecifiedConceptReferenceTermAndDropAllRetireRelatedFields() {
ConceptReferenceTerm term = Context.getConceptService().getConceptReferenceTerm(11);
Assert.assertTrue(term.getRetired());
Assert.assertNotNull(term.getRetireReason());
Assert.assertNotNull(term.getRetiredBy());
Assert.assertNotNull(term.getDateRetired());
ConceptReferenceTerm retiredTerm = Context.getConceptService().unretireConceptReferenceTerm(term);
Assert.assertFalse(retiredTerm.getRetired());
Assert.assertNull(retiredTerm.getRetireReason());
Assert.assertNull(retiredTerm.getRetiredBy());
Assert.assertNull(retiredTerm.getDateRetired());
}
Aggregations