Search in sources :

Example 31 with ConceptReferenceTerm

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"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 32 with ConceptReferenceTerm

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());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 33 with ConceptReferenceTerm

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"));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Errors(org.springframework.validation.Errors) ConceptMapType(org.openmrs.ConceptMapType) ConceptReferenceTermMap(org.openmrs.ConceptReferenceTermMap) BindException(org.springframework.validation.BindException) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 34 with ConceptReferenceTerm

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);
}
Also used : APIException(org.openmrs.api.APIException) List(java.util.List) ArrayList(java.util.ArrayList) OpenmrsObject(org.openmrs.OpenmrsObject) Criteria(org.hibernate.Criteria) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm)

Example 35 with ConceptReferenceTerm

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());
}
Also used : ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)37 Test (org.junit.Test)33 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)31 BindException (org.springframework.validation.BindException)19 Errors (org.springframework.validation.Errors)19 ConceptSource (org.openmrs.ConceptSource)7 ConceptReferenceTermMap (org.openmrs.ConceptReferenceTermMap)5 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)3 Drug (org.openmrs.Drug)3 APIException (org.openmrs.api.APIException)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Criteria (org.hibernate.Criteria)2 ConceptMap (org.openmrs.ConceptMap)2 ConceptMapType (org.openmrs.ConceptMapType)2 ConceptName (org.openmrs.ConceptName)2 DrugReferenceMap (org.openmrs.DrugReferenceMap)2 OpenmrsObject (org.openmrs.OpenmrsObject)2 ConceptService (org.openmrs.api.ConceptService)2