use of org.openmrs.CareSetting 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.CareSetting in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting() {
final Patient patient = patientService.getPatient(2);
final Concept cd4Count = conceptService.getConcept(5497);
TestOrder duplicateOrder = (TestOrder) orderService.getOrder(7);
final CareSetting inpatient = orderService.getCareSetting(2);
assertNotEquals(inpatient, duplicateOrder.getCareSetting());
assertTrue(duplicateOrder.isActive());
assertEquals(cd4Count, duplicateOrder.getConcept());
int initialActiveOrderCount = orderService.getActiveOrders(patient, null, null, null).size();
TestOrder order = new TestOrder();
order.setPatient(patient);
order.setCareSetting(orderService.getCareSetting(2));
order.setConcept(cd4Count);
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(inpatient);
orderService.saveOrder(order, null);
List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
assertEquals(++initialActiveOrderCount, activeOrders.size());
}
use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailIfTheCareSettingOfThePreviousOrderDoesNotMatch.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldFailIfTheCareSettingOfThePreviousOrderDoesNotMatch() {
Order order = orderService.getOrder(7);
assertTrue(OrderUtilTest.isActiveOrder(order, null));
Order discontinuationOrder = order.cloneForDiscontinuing();
CareSetting careSetting = orderService.getCareSetting(2);
assertNotEquals(discontinuationOrder.getCareSetting(), careSetting);
discontinuationOrder.setCareSetting(careSetting);
discontinuationOrder.setOrderer(Context.getProviderService().getProvider(1));
discontinuationOrder.setEncounter(Context.getEncounterService().getEncounter(6));
expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
expectedException.expectMessage(mss.getMessage("Order.care.setting.doesnot.match"));
orderService.saveOrder(discontinuationOrder, null);
}
use of org.openmrs.CareSetting 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());
}
use of org.openmrs.CareSetting 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());
}
Aggregations