/** * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType, * org.openmrs.CareSetting, java.util.Date) */ @Test public void getActiveOrders_shouldReturnAllActiveTestOrdersForTheSpecifiedPatient() { Patient patient = patientService.getPatient(2); List<Order> orders = orderService .getActiveOrders(patient, orderService.getOrderTypeByName("Test order"), null, null); assertEquals(1, orders.size()); assertEquals(orders.get(0), orderService.getOrder(7)); }
/** * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType, * org.openmrs.CareSetting, java.util.Date) */ @Test public void getActiveOrders_shouldFailIfPatientIsNull() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Patient is required when fetching active orders"); orderService.getActiveOrders(null, null, orderService.getCareSetting(1), null); }
/** * @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, * org.openmrs.Provider, org.openmrs.Encounter) */ @Test public void discontinueOrder_shouldFailIfDiscontinueDateIsInTheFuture() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR_OF_DAY, 1); Order orderToDiscontinue = orderService.getActiveOrders(Context.getPatientService().getPatient(2), null, orderService.getCareSetting(1), null).get(0); Encounter encounter = encounterService.getEncounter(3); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Discontinue date cannot be in the future"); orderService.discontinueOrder(orderToDiscontinue, "Testing", cal.getTime(), null, encounter); }
/** * @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, * org.openmrs.Provider, org.openmrs.Encounter) */ @Test public void discontinueOrder_shouldRejectAFutureDiscontinueDate() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR_OF_DAY, 1); Patient patient = Context.getPatientService().getPatient(2); CareSetting careSetting = orderService.getCareSetting(1); Order orderToDiscontinue = orderService.getActiveOrders(patient, null, careSetting, null).get(0); Encounter encounter = encounterService.getEncounter(3); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Discontinue date cannot be in the future"); orderService.discontinueOrder(orderToDiscontinue, new Concept(), cal.getTime(), null, encounter); }
@Test public void shouldReviseAnOrderAndFlushSuccessfully() { Order originalOrder = orderService.getOrder(111); assertTrue(OrderUtilTest.isActiveOrder(originalOrder, null)); final Patient patient = originalOrder.getPatient(); List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null); final int originalOrderCount = originalActiveOrders.size(); assertTrue(originalActiveOrders.contains(originalOrder)); Order revisedOrder = originalOrder.cloneForRevision(); revisedOrder.setInstructions("Take after a meal"); revisedOrder.setDateActivated(new Date()); revisedOrder.setOrderer(providerService.getProvider(1)); revisedOrder.setEncounter(encounterService.getEncounter(3)); orderService.saveOrder(revisedOrder, null); Context.flushSession(); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(originalOrderCount, activeOrders.size()); assertFalse(OrderUtilTest.isActiveOrder(originalOrder, null)); }
@Test public void shouldGetTheActiveOrdersForAPatient() { Patient patient = patientService.getPatient(2); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(5, activeOrders.size()); Order[] expectedOrders = { orderService.getOrder(3), orderService.getOrder(5), orderService.getOrder(7), orderService.getOrder(222), orderService.getOrder(444) }; assertThat(activeOrders, hasItems(expectedOrders)); }
@Test public void shouldGetTheActiveDrugOrdersForAPatient() { Patient patient = patientService.getPatient(2); List<Order> activeDrugOrders = orderService.getActiveOrders(patient, orderService.getOrderTypeByName("Drug order"), null, null); assertEquals(4, activeDrugOrders.size()); Order[] expectedDrugOrders = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5) }; assertThat(activeDrugOrders, hasItems(expectedDrugOrders)); }
/** * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType, * org.openmrs.CareSetting, java.util.Date) */ @Test public void getActiveOrders_shouldReturnAllActiveOrdersForTheSpecifiedPatient() { Patient patient = Context.getPatientService().getPatient(2); List<Order> orders = orderService.getActiveOrders(patient, null, null, null); assertEquals(5, orders.size()); Order[] expectedOrders = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5), orderService.getOrder(7) }; assertThat(orders, hasItems(expectedOrders)); assertTrue(OrderUtilTest.isActiveOrder(orders.get(0), null)); assertTrue(OrderUtilTest.isActiveOrder(orders.get(1), null)); assertTrue(OrderUtilTest.isActiveOrder(orders.get(2), null)); assertTrue(OrderUtilTest.isActiveOrder(orders.get(3), null)); assertTrue(OrderUtilTest.isActiveOrder(orders.get(4), null)); }
@Test public void shouldReviseAnOrder() { Order originalOrder = orderService.getOrder(111); assertTrue(OrderUtilTest.isActiveOrder(originalOrder, null)); final Patient patient = originalOrder.getPatient(); List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null); final int originalOrderCount = originalActiveOrders.size(); assertTrue(originalActiveOrders.contains(originalOrder)); Order revisedOrder = originalOrder.cloneForRevision(); revisedOrder.setInstructions("Take after a meal"); revisedOrder.setDateActivated(new Date()); revisedOrder.setOrderer(providerService.getProvider(1)); revisedOrder.setEncounter(encounterService.getEncounter(3)); orderService.saveOrder(revisedOrder, null); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(originalOrderCount, activeOrders.size()); assertEquals(revisedOrder.getDateActivated(), DateUtils.addSeconds(originalOrder.getDateStopped(), 1)); assertFalse(OrderUtilTest.isActiveOrder(originalOrder, null)); }
/** * @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)); }
/** * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType, * org.openmrs.CareSetting, java.util.Date) */ @Test public void getActiveOrders_shouldReturnAllActiveOrdersForTheSpecifiedPatientAndCareSetting() { Patient patient = patientService.getPatient(2); CareSetting careSetting = orderService.getCareSetting(1); List<Order> orders = orderService.getActiveOrders(patient, null, careSetting, null); assertEquals(4, orders.size()); Order[] expectedOrders = { orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5), orderService.getOrder(7) }; assertThat(orders, hasItems(expectedOrders)); }
/** * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType, * org.openmrs.CareSetting, java.util.Date) */ @Test public void getActiveOrders_shouldReturnAllOrdersIfNoOrderTypeIsSpecified() { Patient patient = Context.getPatientService().getPatient(2); List<Order> orders = orderService.getActiveOrders(patient, null, null, null); assertEquals(5, orders.size()); Order[] expectedOrders = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5), orderService.getOrder(7) }; assertThat(orders, hasItems(expectedOrders)); }
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldSaveARevisedOrder() { Order originalOrder = orderService.getOrder(111); assertTrue(originalOrder.isActive()); final Patient patient = originalOrder.getPatient(); List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null); final int originalOrderCount = originalActiveOrders.size(); assertTrue(originalActiveOrders.contains(originalOrder)); Order revisedOrder = originalOrder.cloneForRevision(); revisedOrder.setEncounter(encounterService.getEncounter(5)); revisedOrder.setInstructions("Take after a meal"); revisedOrder.setDateActivated(new Date()); revisedOrder.setOrderer(providerService.getProvider(1)); revisedOrder.setEncounter(encounterService.getEncounter(3)); orderService.saveOrder(revisedOrder, null); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(originalOrderCount, activeOrders.size()); assertEquals(revisedOrder.getDateActivated(), DateUtils.addSeconds(originalOrder.getDateStopped(), 1)); assertFalse(originalOrder.isActive()); }
/** * @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)); }
/** * @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()); }
Patient patient = patientService.getPatient(7); CareSetting careSetting = orderService.getCareSetting(1); int activeTestOrderCount = orderService.getActiveOrders(patient, orderService.getOrderTypeByName("Test order"), careSetting, null).size(); List<Order> activeOrders = orderService.getActiveOrders(patient, orderService.getOrderTypeByName("Test order"), careSetting, null); assertEquals(++activeTestOrderCount, activeOrders.size());
int initialActiveOrderCount = orderService.getActiveOrders(patient, null, null, null).size(); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(++initialActiveOrderCount, activeOrders.size());
assertTrue(OrderUtilTest.isActiveOrder(firstOrderToDiscontinue, null)); Patient patient = firstOrderToDiscontinue.getPatient(); int ordersCount = orderService.getActiveOrders(patient, null, null, null).size(); orderService.saveOrder(discontinuationOrder, null); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(ordersCount - 3, activeOrders.size()); assertFalse(activeOrders.contains(firstOrderToDiscontinue));
List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null); final int originalOrderCount = originalActiveOrders.size(); assertTrue(originalActiveOrders.contains(originalOrder)); orderService.saveOrder(revisedOrder, null); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(originalOrderCount, activeOrders.size()); assertEquals(revisedOrder.getDateActivated(), DateUtils.addSeconds(originalOrder.getDateStopped(), 1));
Patient patient = patientService.getPatient(7); CareSetting careSetting = orderService.getCareSetting(1); int activeDrugOrderCount = orderService.getActiveOrders(patient, orderService.getOrderTypeByName("Drug order"), careSetting, null).size(); List<Order> activeOrders = orderService.getActiveOrders(patient, orderService.getOrderTypeByName("Drug order"), careSetting, null); assertEquals(++activeDrugOrderCount, activeOrders.size());