use of org.openmrs.ConceptDescription in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrderFrequency_shouldAddANewOrderFrequencyToTheDatabase.
/**
* @see OrderService#saveOrderFrequency(OrderFrequency)
*/
@Test
public void saveOrderFrequency_shouldAddANewOrderFrequencyToTheDatabase() {
Concept concept = new Concept();
concept.addName(new ConceptName("new name", Context.getLocale()));
concept.addDescription(new ConceptDescription("some description", null));
concept.setDatatype(new ConceptDatatype(1));
concept.setConceptClass(conceptService.getConceptClassByName("Frequency"));
concept = conceptService.saveConcept(concept);
Integer originalSize = orderService.getOrderFrequencies(true).size();
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
orderFrequency.setFrequencyPerDay(2d);
orderFrequency = orderService.saveOrderFrequency(orderFrequency);
assertNotNull(orderFrequency.getId());
assertNotNull(orderFrequency.getUuid());
assertNotNull(orderFrequency.getCreator());
assertNotNull(orderFrequency.getDateCreated());
assertEquals(originalSize + 1, orderService.getOrderFrequencies(true).size());
}
use of org.openmrs.ConceptDescription in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setDatatype(cs.getConceptDatatype(1));
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
cs.saveConcept(concept);
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
orderFrequency.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.openmrs.ConceptDescription in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldPassForAValidNewOrderFrequency.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassForAValidNewOrderFrequency() {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setDatatype(cs.getConceptDatatype(1));
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
cs.saveConcept(concept);
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.ConceptDescription 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.ConceptDescription 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