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"));
}
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"));
}
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"));
}
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");
}
}
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);
}
}
Aggregations