Search in sources :

Example 1 with MissingRequiredPropertyException

use of org.openmrs.api.MissingRequiredPropertyException in project openmrs-core by openmrs.

the class OrderServiceImpl method ensureConceptIsSet.

private void ensureConceptIsSet(Order order) {
    Concept concept = order.getConcept();
    if (concept == null && isDrugOrder(order)) {
        DrugOrder drugOrder = (DrugOrder) order;
        if (drugOrder.getDrug() != null) {
            concept = drugOrder.getDrug().getConcept();
            drugOrder.setConcept(concept);
        }
    }
    if (concept == null) {
        throw new MissingRequiredPropertyException("Order.concept.required");
    }
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) MissingRequiredPropertyException(org.openmrs.api.MissingRequiredPropertyException)

Example 2 with MissingRequiredPropertyException

use of org.openmrs.api.MissingRequiredPropertyException in project openmrs-core by openmrs.

the class OrderServiceImpl method saveOrder.

private Order saveOrder(Order order, OrderContext orderContext, boolean isRetrospective) {
    failOnExistingOrder(order);
    ensureDateActivatedIsSet(order);
    ensureConceptIsSet(order);
    ensureDrugOrderAutoExpirationDateIsSet(order);
    ensureOrderTypeIsSet(order, orderContext);
    ensureCareSettingIsSet(order, orderContext);
    failOnOrderTypeMismatch(order);
    Order previousOrder = order.getPreviousOrder();
    if (REVISE == order.getAction()) {
        if (previousOrder == null) {
            throw new MissingRequiredPropertyException("Order.previous.required", (Object[]) null);
        }
        stopOrder(previousOrder, aMomentBefore(order.getDateActivated()), isRetrospective);
    } else if (DISCONTINUE == order.getAction()) {
        discontinueExistingOrdersIfNecessary(order, isRetrospective);
    }
    if (previousOrder != null) {
        // concept should be the same as on previous order, same applies to drug for drug orders
        if (!order.hasSameOrderableAs(previousOrder)) {
            throw new EditedOrderDoesNotMatchPreviousException("Order.orderable.doesnot.match");
        } else if (!order.getOrderType().equals(previousOrder.getOrderType())) {
            throw new EditedOrderDoesNotMatchPreviousException("Order.type.doesnot.match");
        } else if (!order.getCareSetting().equals(previousOrder.getCareSetting())) {
            throw new EditedOrderDoesNotMatchPreviousException("Order.care.setting.doesnot.match");
        } else if (!getActualType(order).equals(getActualType(previousOrder))) {
            throw new EditedOrderDoesNotMatchPreviousException("Order.class.doesnot.match");
        }
    }
    if (DISCONTINUE != order.getAction()) {
        Date asOfDate = new Date();
        if (isRetrospective) {
            asOfDate = order.getDateActivated();
        }
        List<Order> activeOrders = getActiveOrders(order.getPatient(), null, order.getCareSetting(), asOfDate);
        List<String> parallelOrders = Collections.emptyList();
        if (orderContext != null && orderContext.getAttribute(PARALLEL_ORDERS) != null) {
            parallelOrders = Arrays.asList((String[]) orderContext.getAttribute(PARALLEL_ORDERS));
        }
        for (Order activeOrder : activeOrders) {
            // Reject if there is an active drug order for the same orderable with overlapping schedule
            if (!parallelOrders.contains(activeOrder.getUuid()) && areDrugOrdersOfSameOrderableAndOverlappingSchedule(order, activeOrder)) {
                throw new AmbiguousOrderException("Order.cannot.have.more.than.one");
            }
        }
    }
    return saveOrderInternal(order, orderContext);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) EditedOrderDoesNotMatchPreviousException(org.openmrs.api.EditedOrderDoesNotMatchPreviousException) MissingRequiredPropertyException(org.openmrs.api.MissingRequiredPropertyException) Date(java.util.Date) AmbiguousOrderException(org.openmrs.api.AmbiguousOrderException)

Aggregations

DrugOrder (org.openmrs.DrugOrder)2 MissingRequiredPropertyException (org.openmrs.api.MissingRequiredPropertyException)2 Date (java.util.Date)1 Concept (org.openmrs.Concept)1 Order (org.openmrs.Order)1 TestOrder (org.openmrs.TestOrder)1 AmbiguousOrderException (org.openmrs.api.AmbiguousOrderException)1 EditedOrderDoesNotMatchPreviousException (org.openmrs.api.EditedOrderDoesNotMatchPreviousException)1