use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsNotSet.
/**
* @throws SQLException
* @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
*/
@Test
public void saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsNotSet() throws SQLException {
deleteAllData();
baseSetupWithStandardDataAndAuthentication();
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
assertNull(Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG));
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = Context.getEncounterService().getEncounter(3);
order.setEncounter(encounter);
order.setConcept(Context.getConceptService().getConcept(5497));
order.setPatient(patient);
order.setCareSetting(careSetting);
order.setOrderer(Context.getProviderService().getProvider(1));
order.setDateActivated(encounter.getEncounterDatetime());
order.setOrderType(orderType);
order.setDosingType(FreeTextDosingInstructions.class);
order.setInstructions("None");
order.setDosingInstructions("Test Instruction");
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertFalse(errors.hasFieldErrors());
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailIfRouteIsNotAValidConcept.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfRouteIsNotAValidConcept() {
Concept concept = Context.getConceptService().getConcept(3);
assertThat(concept, not(isIn(Context.getOrderService().getDrugRoutes())));
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);
order.setRoute(concept);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("route"));
Assert.assertEquals("DrugOrder.error.routeNotAmongAllowedConcepts", errors.getFieldError("route").getCode());
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithoutADrugNonCodedWhenDrugOrderIsNonCoded.
@Test
public void saveOrder_shouldFailDrugOrderWithoutADrugNonCodedWhenDrugOrderIsNonCoded() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
Context.getAdministrationService().saveGlobalProperty(gp);
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = Context.getEncounterService().getEncounter(3);
order.setEncounter(encounter);
order.setConcept(Context.getOrderService().getNonCodedDrugConcept());
order.setPatient(patient);
order.setCareSetting(careSetting);
order.setOrderer(Context.getProviderService().getProvider(1));
order.setDateActivated(encounter.getEncounterDatetime());
order.setOrderType(orderType);
order.setDosingType(FreeTextDosingInstructions.class);
order.setInstructions("None");
order.setDosingInstructions("Test Instruction");
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors());
assertEquals("DrugOrder.error.drugNonCodedIsRequired", errors.getFieldError("drugNonCoded").getCode());
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDurationUnitsIsNullWhenDurationIsPresent.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfDurationUnitsIsNullWhenDurationIsPresent() {
DrugOrder order = new DrugOrder();
order.setDosingType(FreeTextDosingInstructions.class);
order.setDuration(20);
order.setDurationUnits(null);
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_shouldNotRequireAllFieldsForADiscontinuationOrder.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldNotRequireAllFieldsForADiscontinuationOrder() {
DrugOrder orderToDiscontinue = (DrugOrder) Context.getOrderService().getOrder(111);
assertTrue(OrderUtilTest.isActiveOrder(orderToDiscontinue, null));
DrugOrder discontinuationOrder = new DrugOrder();
discontinuationOrder.setDosingType(null);
discontinuationOrder.setCareSetting(orderToDiscontinue.getCareSetting());
discontinuationOrder.setConcept(orderToDiscontinue.getConcept());
discontinuationOrder.setAction(Order.Action.DISCONTINUE);
discontinuationOrder.setPreviousOrder(orderToDiscontinue);
discontinuationOrder.setPatient(orderToDiscontinue.getPatient());
discontinuationOrder.setDrug(orderToDiscontinue.getDrug());
discontinuationOrder.setOrderType(orderToDiscontinue.getOrderType());
discontinuationOrder.setOrderer(Context.getProviderService().getProvider(1));
discontinuationOrder.setEncounter(Context.getEncounterService().getEncounter(3));
Errors errors = new BindException(discontinuationOrder, "order");
new DrugOrderValidator().validate(discontinuationOrder, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations