Search in sources :

Example 31 with DrugOrder

use of org.openmrs.DrugOrder in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method validate_shouldFailValidationIfDoseUnitsIsNotADoseUnitConcept.

/**
 * @see DrugOrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfDoseUnitsIsNotADoseUnitConcept() {
    Concept concept = Context.getConceptService().getConcept(3);
    assertThat(concept, not(isIn(Context.getOrderService().getDrugDosingUnits())));
    DrugOrder order = new DrugOrder();
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setDuration(5);
    order.setDurationUnits(concept);
    order.setDose(1.0);
    order.setDoseUnits(concept);
    order.setQuantity(30.0);
    order.setQuantityUnits(concept);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("doseUnits"));
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 32 with DrugOrder

use of org.openmrs.DrugOrder in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method validate_shouldFailValidationIfDurationUnitsIsNotADurationUnitConcept.

/**
 * @see DrugOrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfDurationUnitsIsNotADurationUnitConcept() {
    Concept concept = Context.getConceptService().getConcept(3);
    assertThat(concept, not(isIn(Context.getOrderService().getDurationUnits())));
    DrugOrder order = new DrugOrder();
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setDuration(5);
    order.setDurationUnits(concept);
    order.setDose(1.0);
    order.setDoseUnits(concept);
    order.setQuantity(30.0);
    order.setQuantityUnits(concept);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("durationUnits"));
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 33 with DrugOrder

use of org.openmrs.DrugOrder in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType.

/**
 * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType() {
    DrugOrder order = new DrugOrder();
    order.setDosingType(SimpleDosingInstructions.class);
    order.setDose(null);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dose"));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 34 with DrugOrder

use of org.openmrs.DrugOrder 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 35 with DrugOrder

use of org.openmrs.DrugOrder in project openmrs-core by openmrs.

the class OrderServiceImpl method discontinueExistingOrdersIfNecessary.

/**
 * If this is a discontinue order, ensure that the previous order is discontinued. If a
 * previousOrder is present, then ensure this is discontinued. If no previousOrder is present,
 * then try to find a previousOrder and discontinue it. If cannot find a previousOrder, throw
 * exception
 *
 * @param order
 * @param isRetrospective
 */
// Ignore and return if this is not an order to discontinue
private void discontinueExistingOrdersIfNecessary(Order order, Boolean isRetrospective) {
    if (DISCONTINUE != order.getAction()) {
        return;
    }
    // Mark previousOrder as discontinued if it is not already
    Order previousOrder = order.getPreviousOrder();
    if (previousOrder != null) {
        stopOrder(previousOrder, aMomentBefore(order.getDateActivated()), isRetrospective);
        return;
    }
    // Mark first order found corresponding to this DC order as discontinued.
    Date asOfDate = null;
    if (isRetrospective) {
        asOfDate = order.getDateActivated();
    }
    List<? extends Order> orders = getActiveOrders(order.getPatient(), order.getOrderType(), order.getCareSetting(), asOfDate);
    boolean isDrugOrderAndHasADrug = isDrugOrder(order) && (((DrugOrder) order).getDrug() != null || ((DrugOrder) order).isNonCodedDrug());
    Order orderToBeDiscontinued = null;
    for (Order activeOrder : orders) {
        if (!getActualType(order).equals(getActualType(activeOrder))) {
            continue;
        }
        // For drug orders, the drug must match if the order has a drug
        if (isDrugOrderAndHasADrug) {
            Order existing = order.hasSameOrderableAs(activeOrder) ? activeOrder : null;
            if (existing != null) {
                if (orderToBeDiscontinued == null) {
                    orderToBeDiscontinued = existing;
                } else {
                    throw new AmbiguousOrderException("Order.discontinuing.ambiguous.orders");
                }
            }
        } else if (activeOrder.getConcept().equals(order.getConcept())) {
            if (orderToBeDiscontinued == null) {
                orderToBeDiscontinued = activeOrder;
            } else {
                throw new AmbiguousOrderException("Order.discontinuing.ambiguous.orders");
            }
        }
    }
    if (orderToBeDiscontinued != null) {
        order.setPreviousOrder(orderToBeDiscontinued);
        stopOrder(orderToBeDiscontinued, aMomentBefore(order.getDateActivated()), isRetrospective);
    }
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) Date(java.util.Date) AmbiguousOrderException(org.openmrs.api.AmbiguousOrderException)

Aggregations

DrugOrder (org.openmrs.DrugOrder)68 Test (org.junit.Test)64 OrderUtilTest (org.openmrs.order.OrderUtilTest)64 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)64 BindException (org.springframework.validation.BindException)38 Errors (org.springframework.validation.Errors)38 Patient (org.openmrs.Patient)22 Date (java.util.Date)18 Encounter (org.openmrs.Encounter)17 Concept (org.openmrs.Concept)12 CareSetting (org.openmrs.CareSetting)11 Order (org.openmrs.Order)11 OrderType (org.openmrs.OrderType)11 TestOrder (org.openmrs.TestOrder)11 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)7 Drug (org.openmrs.Drug)7 GlobalProperty (org.openmrs.GlobalProperty)7 Calendar (java.util.Calendar)5 SimpleDateFormat (java.text.SimpleDateFormat)1 Ignore (org.junit.Ignore)1