use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method getActiveOrders_shouldIncludeOrdersForSubTypesIfOrderTypeIsSpecified.
/**
* @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
* org.openmrs.CareSetting, java.util.Date)
*/
@Test
public void getActiveOrders_shouldIncludeOrdersForSubTypesIfOrderTypeIsSpecified() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-otherOrders.xml");
Patient patient = Context.getPatientService().getPatient(2);
OrderType testOrderType = orderService.getOrderType(2);
List<Order> orders = orderService.getActiveOrders(patient, testOrderType, null, null);
assertEquals(5, orders.size());
Order[] expectedOrder1 = { orderService.getOrder(7), orderService.getOrder(101), orderService.getOrder(102), orderService.getOrder(103), orderService.getOrder(104) };
assertThat(orders, hasItems(expectedOrder1));
OrderType labTestOrderType = orderService.getOrderType(7);
orders = orderService.getActiveOrders(patient, labTestOrderType, null, null);
assertEquals(3, orders.size());
Order[] expectedOrder2 = { orderService.getOrder(101), orderService.getOrder(103), orderService.getOrder(104) };
assertThat(orders, hasItems(expectedOrder2));
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrderWithScheduledDate_shouldAddANewOrderWithScheduledDateToTheDatabase.
@Test
public void saveOrderWithScheduledDate_shouldAddANewOrderWithScheduledDateToTheDatabase() {
Date scheduledDate = new Date();
Order order = new Order();
order.setAction(Action.NEW);
order.setPatient(Context.getPatientService().getPatient(7));
order.setConcept(Context.getConceptService().getConcept(5497));
order.setCareSetting(orderService.getCareSetting(1));
order.setOrderer(orderService.getOrder(1).getOrderer());
order.setEncounter(encounterService.getEncounter(3));
order.setDateActivated(new Date());
order.setScheduledDate(scheduledDate);
order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
order.setEncounter(encounterService.getEncounter(3));
order.setOrderType(orderService.getOrderType(17));
order = orderService.saveOrder(order, null);
Order newOrder = orderService.getOrder(order.getOrderId());
assertNotNull(order);
assertEquals(DateUtil.truncateToSeconds(scheduledDate), order.getScheduledDate());
assertNotNull(newOrder);
assertEquals(DateUtil.truncateToSeconds(scheduledDate), newOrder.getScheduledDate());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldDiscontinuePreviousOrderIfItIsNotAlreadyDiscontinued.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldDiscontinuePreviousOrderIfItIsNotAlreadyDiscontinued() {
// We are trying to discontinue order id 111 in standardTestDataset.xml
DrugOrder order = new DrugOrder();
order.setAction(Order.Action.DISCONTINUE);
order.setOrderReasonNonCoded("Discontinue this");
order.setDrug(conceptService.getDrug(3));
order.setEncounter(encounterService.getEncounter(5));
order.setPatient(Context.getPatientService().getPatient(7));
order.setOrderer(Context.getProviderService().getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
order.setEncounter(encounterService.getEncounter(3));
order.setOrderType(orderService.getOrderType(1));
order.setDateActivated(new Date());
order.setDosingType(SimpleDosingInstructions.class);
order.setDose(500.0);
order.setDoseUnits(conceptService.getConcept(50));
order.setFrequency(orderService.getOrderFrequency(1));
order.setRoute(conceptService.getConcept(22));
order.setNumRefills(10);
order.setQuantity(20.0);
order.setQuantityUnits(conceptService.getConcept(51));
Order previousOrder = orderService.getOrder(111);
assertTrue(OrderUtilTest.isActiveOrder(previousOrder, null));
order.setPreviousOrder(previousOrder);
orderService.saveOrder(order, null);
Assert.assertEquals(order.getDateActivated(), order.getAutoExpireDate());
Assert.assertNotNull("previous order should be discontinued", previousOrder.getDateStopped());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method getActiveOrders_shouldReturnAllActiveDrugOrdersForTheSpecifiedPatient.
/**
* @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
* org.openmrs.CareSetting, java.util.Date)
*/
@Test
public void getActiveOrders_shouldReturnAllActiveDrugOrdersForTheSpecifiedPatient() {
Patient patient = patientService.getPatient(2);
List<Order> orders = orderService.getActiveOrders(patient, orderService.getOrderType(1), null, null);
assertEquals(4, orders.size());
Order[] expectedOrders = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5) };
assertThat(orders, hasItems(expectedOrders));
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnActiveDrugOrderForTheSameConceptAndCareSettingButDifferentFormulationExists.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfAnActiveDrugOrderForTheSameConceptAndCareSettingButDifferentFormulationExists() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrdersWithSameConceptAndDifferentFormAndStrength.xml");
final Patient patient = patientService.getPatient(2);
// sanity check that we have an active order
DrugOrder existingOrder = (DrugOrder) orderService.getOrder(1000);
assertTrue(existingOrder.isActive());
// New Drug order
DrugOrder order = new DrugOrder();
order.setPatient(patient);
order.setConcept(existingOrder.getConcept());
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(existingOrder.getCareSetting());
order.setDrug(conceptService.getDrug(3001));
order.setDosingType(FreeTextDosingInstructions.class);
order.setDosingInstructions("2 for 5 days");
order.setQuantity(10.0);
order.setQuantityUnits(conceptService.getConcept(51));
order.setNumRefills(2);
Order savedDrugOrder = orderService.saveOrder(order, null);
assertNotNull(orderService.getOrder(savedDrugOrder.getOrderId()));
}
Aggregations