Search in sources :

Example 1 with CannotStopDiscontinuationOrderException

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);
}
Also used : CannotStopDiscontinuationOrderException(org.openmrs.api.CannotStopDiscontinuationOrderException) CannotStopInactiveOrderException(org.openmrs.api.CannotStopInactiveOrderException) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 CannotStopDiscontinuationOrderException (org.openmrs.api.CannotStopDiscontinuationOrderException)1 CannotStopInactiveOrderException (org.openmrs.api.CannotStopInactiveOrderException)1