use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldSetConceptForDrugOrdersIfNull.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldSetConceptForDrugOrdersIfNull() {
Patient patient = patientService.getPatient(7);
CareSetting careSetting = orderService.getCareSetting(2);
OrderType orderType = orderService.getOrderTypeByName("Drug order");
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = encounterService.getEncounter(3);
order.setEncounter(encounter);
order.setPatient(patient);
order.setDrug(conceptService.getDrug(2));
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");
orderService.saveOrder(order, null);
assertNotNull(order.getOrderId());
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrderType_shouldEditAnExistingOrderType.
/**
* @see OrderService#saveOrderType(org.openmrs.OrderType)
*/
@Test
public void saveOrderType_shouldEditAnExistingOrderType() {
OrderType orderType = orderService.getOrderType(1);
assertNull(orderType.getDateChanged());
assertNull(orderType.getChangedBy());
final String newDescription = "new";
orderType.setDescription(newDescription);
orderService.saveOrderType(orderType);
Context.flushSession();
assertNotNull(orderType.getDateChanged());
assertNotNull(orderType.getChangedBy());
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderServiceTest method unretireOrderType_shouldUnretireOrderType.
/**
* @see OrderService#unretireOrderType(org.openmrs.OrderType)
*/
@Test
public void unretireOrderType_shouldUnretireOrderType() {
OrderType orderType = orderService.getOrderType(16);
assertTrue(orderType.getRetired());
assertNotNull(orderType.getRetiredBy());
assertNotNull(orderType.getRetireReason());
assertNotNull(orderType.getDateRetired());
orderService.unretireOrderType(orderType);
orderType = orderService.getOrderType(16);
assertFalse(orderType.getRetired());
assertNull(orderType.getRetiredBy());
assertNull(orderType.getRetireReason());
assertNull(orderType.getDateRetired());
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderTypeValidator method validate.
/**
* Validates an Order object
*
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
* @should fail if the orderType object is null
* @should fail if name is null
* @should fail if name is empty
* @should fail if name is whitespace
* @should fail if name is a duplicate
* @should fail if conceptClass is a duplicate
* @should fail if parent is among its descendants
* @should fail if parent is also a direct child
* @should pass if all fields are correct for a new order type
* @should pass if all fields are correct for an existing order type
* @should be invoked when an order type is saved
* @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) {
if (obj == null || !(obj instanceof OrderType)) {
throw new IllegalArgumentException("The parameter obj should not be null and must be of type" + OrderType.class);
} else {
OrderType orderType = (OrderType) obj;
String name = orderType.getName();
if (!StringUtils.hasText(name)) {
errors.rejectValue("name", "error.name");
return;
}
if (orderType.getParent() != null && OrderUtil.isType(orderType, orderType.getParent())) {
errors.rejectValue("parent", "OrderType.parent.amongDescendants", new Object[] { orderType.getName() }, "Parent of " + orderType.getName() + " is among its descendants");
}
OrderType duplicate = Context.getOrderService().getOrderTypeByName(name);
if (duplicate != null && !orderType.equals(duplicate)) {
errors.rejectValue("name", "OrderType.duplicate.name", "Duplicate order type name: " + name);
}
for (OrderType ot : Context.getOrderService().getOrderTypes(true)) {
if (ot != null) {
// If this was an edit, skip past the order we are actually validating
if (orderType.equals(ot)) {
continue;
}
int index = 0;
for (ConceptClass cc : ot.getConceptClasses()) {
if (cc != null && orderType.getConceptClasses().contains(cc)) {
errors.rejectValue("conceptClasses[" + index + "]", "OrderType.duplicate", new Object[] { cc.getName(), orderType.getName() }, cc.getName() + " is already associated to another order type:" + orderType.getName());
}
index++;
}
}
}
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason", "javaClassName");
}
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet.
@Test
public void saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet() {
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.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.drugIsRequired", errors.getFieldError("drug").getCode());
}
Aggregations