use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldPassDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredISNotSet.
@Test
public void saveOrder_shouldPassDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredISNotSet() {
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, "false");
Context.getAdministrationService().saveGlobalProperty(gp);
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = Context.getEncounterService().getEncounter(3);
order.setEncounter(encounter);
order.setPatient(patient);
order.setCareSetting(careSetting);
order.setConcept(Context.getOrderService().getNonCodedDrugConcept());
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_shouldApplyValidationForACustomDosingType.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldApplyValidationForACustomDosingType() {
DrugOrder order = new DrugOrder();
Encounter encounter = new Encounter();
Patient patient = Context.getPatientService().getPatient(2);
order.setConcept(Context.getConceptService().getConcept(88));
order.setOrderer(Context.getProviderService().getProvider(1));
order.setDosingType(CustomDosingInstructions.class);
order.setInstructions("Instructions");
order.setPatient(patient);
encounter.setPatient(patient);
order.setEncounter(encounter);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1);
order.setDateActivated(cal.getTime());
order.setAutoExpireDate(new Date());
order.setOrderType(Context.getOrderService().getOrderTypeByName("Drug order"));
order.setDrug(Context.getConceptService().getDrug(3));
order.setCareSetting(Context.getOrderService().getCareSetting(1));
order.setQuantity(2.00);
order.setQuantityUnits(Context.getConceptService().getConcept(51));
order.setNumRefills(10);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("brandName"));
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidator method validate.
/**
* Checks the form object for any inconsistencies/errors
*
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
* @should fail validation if asNeeded is null
* @should fail validation if dosingType is null
* @should fail validation if drug concept is different from order concept
* @should fail validation if dose is null for SimpleDosingInstructions dosingType
* @should fail validation if doseUnits is null for SimpleDosingInstructions dosingType
* @should fail validation if route is null for SimpleDosingInstructions dosingType
* @should fail validation if frequency is null for SimpleDosingInstructions dosingType
* @should fail validation if dosingInstructions is null for FreeTextDosingInstructions
* dosingType
* @should fail validation if numberOfRefills is null for outpatient careSetting
* @should fail validation if quantity is null for outpatient careSetting
* @should fail validation if doseUnits is null when dose is present
* @should fail validation if doseUnits is not a dose unit concept
* @should fail validation if quantityUnits is null when quantity is present
* @should fail validation if quantityUnits it not a quantity unit concept
* @should fail validation if durationUnits is null when duration is present
* @should fail validation if durationUnits is not a duration unit concept
* @should pass validation if all fields are correct
* @should not require all fields for a discontinuation order
* @should fail if route is not a valid concept
* @should fail if concept is null and drug is not specified
* @should fail if concept is null and cannot infer it from drug
* @should pass if concept is null and drug is set
* @should not validate a custom dosing type against any other dosing type validation
* @should apply validation for a custom dosing type
* @should pass validation if field lengths are correct
* @should fail validation if field lengths are not correct
*/
@Override
public void validate(Object obj, Errors errors) {
super.validate(obj, errors);
DrugOrder order = (DrugOrder) obj;
if (order == null) {
errors.reject("error.general");
} else {
// for the following elements Order.hbm.xml says: not-null="true"
ValidationUtils.rejectIfEmpty(errors, "asNeeded", "error.null");
if (order.getAction() != Order.Action.DISCONTINUE) {
ValidationUtils.rejectIfEmpty(errors, "dosingType", "error.null");
}
if (order.getDrug() == null || order.getDrug().getConcept() == null) {
ValidationUtils.rejectIfEmpty(errors, "concept", "error.null");
}
if (order.getConcept() != null && order.getDrug() != null && order.getDrug().getConcept() != null && !order.getDrug().getConcept().equals(order.getConcept())) {
errors.rejectValue("drug", "error.general");
errors.rejectValue("concept", "error.concept");
}
if (order.getAction() != Order.Action.DISCONTINUE && order.getDosingType() != null) {
DosingInstructions dosingInstructions = order.getDosingInstructionsInstance();
dosingInstructions.validate(order, errors);
}
validateFieldsForOutpatientCareSettingType(order, errors);
validatePairedFields(order, errors);
validateUnitsAreAmongAllowedConcepts(errors, order);
validateForRequireDrug(errors, order);
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "asNeededCondition", "brandName");
}
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldDiscontinuePreviousNonCodedOrderIfItIsNotAlreadyDiscontinued.
@Test
public void saveOrder_shouldDiscontinuePreviousNonCodedOrderIfItIsNotAlreadyDiscontinued() {
// We are trying to discontinue order id 584 in OrderServiceTest-nonCodedDrugs.xml
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
DrugOrder previousOrder = (DrugOrder) orderService.getOrder(584);
DrugOrder drugOrder = previousOrder.cloneForDiscontinuing();
drugOrder.setPreviousOrder(previousOrder);
drugOrder.setDateActivated(new Date());
drugOrder.setOrderer(previousOrder.getOrderer());
drugOrder.setEncounter(previousOrder.getEncounter());
Order saveOrder = orderService.saveOrder(drugOrder, null);
Assert.assertNotNull("previous order should be discontinued", previousOrder.getDateStopped());
assertNotNull(orderService.getOrder(saveOrder.getOrderId()));
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnActiveDrugOrderForTheSameConceptAndDifferentDrugNonCodedExists.
/**
* @see OrderService#saveOrder(Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfAnActiveDrugOrderForTheSameConceptAndDifferentDrugNonCodedExists() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
final Concept nonCodedConcept = orderService.getNonCodedDrugConcept();
// sanity check that we have an active order for the same concept
DrugOrder duplicateOrder = (DrugOrder) orderService.getOrder(584);
assertTrue(duplicateOrder.isActive());
assertEquals(nonCodedConcept, duplicateOrder.getConcept());
DrugOrder drugOrder = duplicateOrder.copy();
drugOrder.setDrugNonCoded("non coded drug paracetemol");
Order savedOrder = orderService.saveOrder(drugOrder, null);
assertNotNull(orderService.getOrder(savedOrder.getOrderId()));
}
Aggregations