use of org.openmrs.OrderFrequency in project openmrs-core by openmrs.
the class HibernateOrderDAO method getOrderFrequencyByConcept.
/**
* @see org.openmrs.api.db.OrderDAO#getOrderFrequencyByConcept(org.openmrs.Concept)
*/
@Override
public OrderFrequency getOrderFrequencyByConcept(Concept concept) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(OrderFrequency.class);
criteria.add(Restrictions.eq("concept", concept));
return (OrderFrequency) criteria.uniqueResult();
}
use of org.openmrs.OrderFrequency in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrderFrequency_shouldNotAllowEditingAnExistingOrderFrequencyThatIsInUse.
/**
* @see OrderService#saveOrderFrequency(OrderFrequency)
*/
@Test
public void saveOrderFrequency_shouldNotAllowEditingAnExistingOrderFrequencyThatIsInUse() {
OrderFrequency orderFrequency = orderService.getOrderFrequency(1);
assertNotNull(orderFrequency);
orderFrequency.setFrequencyPerDay(4d);
expectedException.expect(CannotUpdateObjectInUseException.class);
expectedException.expectMessage("Order.frequency.cannot.edit");
orderService.saveOrderFrequency(orderFrequency);
}
use of org.openmrs.OrderFrequency in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrderFrequency_shouldEditAnExistingOrderFrequencyThatIsNotInUse.
/**
* @see OrderService#saveOrderFrequency(OrderFrequency)
*/
@Test
public void saveOrderFrequency_shouldEditAnExistingOrderFrequencyThatIsNotInUse() {
executeDataSet(OTHER_ORDER_FREQUENCIES_XML);
OrderFrequency orderFrequency = orderService.getOrderFrequency(100);
assertNotNull(orderFrequency);
orderFrequency.setFrequencyPerDay(4d);
orderService.saveOrderFrequency(orderFrequency);
}
use of org.openmrs.OrderFrequency 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.OrderFrequency in project openmrs-core by openmrs.
the class OrderFrequencyValidator method validate.
/**
* Checks the order frequency object for any inconsistencies/errors
*
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
* @should fail if orderFrequency is null
* @should fail if concept is null
* @should fail if the concept is not of class frequency
* @should fail if concept is used by another frequency
* @should pass for a valid new order frequency
* @should pass for a valid existing order frequency
* @should be invoked when an order frequency is saved
* @should pass validation if field lengths are correct
* @should fail validation if field lengths are not correct
*/
@Override
public void validate(Object obj, Errors errors) {
OrderFrequency orderFrequency = (OrderFrequency) obj;
if (orderFrequency == null) {
errors.reject("error.general");
} else {
ValidationUtils.rejectIfEmpty(errors, "concept", "Concept.noConceptSelected");
Concept concept = orderFrequency.getConcept();
if (concept != null) {
if (!ConceptClass.FREQUENCY_UUID.equals(concept.getConceptClass().getUuid())) {
errors.rejectValue("concept", "OrderFrequency.concept.shouldBeClassFrequency");
}
OrderFrequency of = Context.getOrderService().getOrderFrequencyByConcept(concept);
if (of != null && !of.equals(orderFrequency)) {
errors.rejectValue("concept", "OrderFrequency.concept.shouldNotBeShared");
}
}
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "retireReason");
}
}
Aggregations