use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse.
/**
* @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
*/
@Test
public void saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse() {
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "false");
Context.getAdministrationService().saveGlobalProperty(gp);
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
// 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.OrderType in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsTrue.
/**
* @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
*/
@Test
public void saveOrder_shouldFailDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsTrue() {
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
Context.getAdministrationService().saveGlobalProperty(gp);
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
// 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.assertTrue(errors.hasFieldErrors("drug"));
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderServiceImpl method ensureOrderTypeIsSet.
private void ensureOrderTypeIsSet(Order order, OrderContext orderContext) {
if (order.getOrderType() != null) {
return;
}
OrderType orderType = null;
if (orderContext != null) {
orderType = orderContext.getOrderType();
}
if (orderType == null) {
orderType = getOrderTypeByConcept(order.getConcept());
}
if (orderType == null && order instanceof DrugOrder) {
orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID);
}
if (orderType == null && order instanceof TestOrder) {
orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.TEST_ORDER_TYPE_UUID);
}
if (orderType == null) {
throw new OrderEntryException("Order.type.cannot.determine");
}
Order previousOrder = order.getPreviousOrder();
if (previousOrder != null && !orderType.equals(previousOrder.getOrderType())) {
throw new OrderEntryException("Order.type.does.not.match");
}
order.setOrderType(orderType);
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderTypeValidatorTest method validate_shouldPassIfAllFieldsAreCorrectForANewOrderType.
/**
* @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassIfAllFieldsAreCorrectForANewOrderType() {
OrderType orderType = new OrderType();
orderType.setName("unique name");
orderType.setJavaClassName("org.openmrs.TestDrugOrder");
Collection<ConceptClass> col = new HashSet<>();
col.add(Context.getConceptService().getConceptClass(2));
orderType.setConceptClasses(col);
Errors errors = new BindException(orderType, "orderType");
new OrderTypeValidator().validate(orderType, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
OrderType orderType = new OrderType();
orderType.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
orderType.setJavaClassName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Collection<ConceptClass> col = new HashSet<>();
col.add(Context.getConceptService().getConceptClass(2));
orderType.setConceptClasses(col);
orderType.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
orderType.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(orderType, "orderType");
new OrderTypeValidator().validate(orderType, errors);
Assert.assertEquals(true, errors.hasFieldErrors("name"));
Assert.assertEquals(true, errors.hasFieldErrors("javaClassName"));
Assert.assertEquals(true, errors.hasFieldErrors("description"));
Assert.assertEquals(true, errors.hasFieldErrors("retireReason"));
}
Aggregations