use of org.openmrs.api.CannotStopDiscontinuationOrderException in project openmrs-core by openmrs.
the class OrderServiceImpl method stopOrder.
/**
* Make necessary checks, set necessary fields for discontinuing <code>orderToDiscontinue</code>
* and save.
*
* @param orderToStop
* @param discontinueDate
*/
private void stopOrder(Order orderToStop, Date discontinueDate, boolean isRetrospective) {
if (discontinueDate == null) {
discontinueDate = new Date();
}
if (discontinueDate.after(new Date())) {
throw new IllegalArgumentException("Discontinue date cannot be in the future");
}
if (DISCONTINUE == orderToStop.getAction()) {
throw new CannotStopDiscontinuationOrderException();
}
if (isRetrospective && orderToStop.getDateStopped() != null) {
throw new CannotStopInactiveOrderException();
}
if (!isRetrospective && !orderToStop.isActive()) {
throw new CannotStopInactiveOrderException();
} else if (isRetrospective && !orderToStop.isActive(discontinueDate)) {
throw new CannotStopInactiveOrderException();
}
setProperty(orderToStop, "dateStopped", discontinueDate);
saveOrderInternal(orderToStop, null);
}
Aggregations