public OrderBuilder withCareSetting(Integer careSettingID) { order.setCareSetting(orderService.getCareSetting(careSettingID)); return this; }
/** * @see OrderService#getCareSettings(boolean) */ @Test public void getCareSettings_shouldReturnRetiredCareSettingsIfIncludeRetiredIsSetToTrue() { CareSetting retiredCareSetting = orderService.getCareSetting(3); assertTrue(retiredCareSetting.getRetired()); List<CareSetting> careSettings = orderService.getCareSettings(true); assertEquals(3, careSettings.size()); assertTrue(containsId(careSettings, retiredCareSetting.getCareSettingId())); }
public DrugOrderBuilder withCareSetting(Integer careSettingID) { drugOrder.setCareSetting(orderService.getCareSetting(careSettingID)); return this; }
/** * @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#(OrderSearchCriteria) */ @Test public void getOrders_shouldGetTheOrdersByCareSettingAndOrderType() { CareSetting outPatient = orderService.getCareSetting(1); List<OrderType> orderTypes = new ArrayList<>(); orderTypes.add(orderService.getOrderType(2)); // test order type OrderSearchCriteria orderSearchCriteria = new OrderSearchCriteriaBuilder().setCareSetting(outPatient).setOrderTypes(orderTypes).build(); List<Order> orders = orderService.getOrders(orderSearchCriteria); assertEquals(3, orders.size()); }
/** * @see OrderService#getOrders(org.openmrs.Patient, org.openmrs.CareSetting, * org.openmrs.OrderType, boolean) */ @Test public void getOrders_shouldGetAllUnvoidedMatchesIfIncludeVoidedIsSetToFalse() { Patient patient = patientService.getPatient(2); CareSetting outPatient = orderService.getCareSetting(1); OrderType testOrderType = orderService.getOrderType(2); assertEquals(3, orderService.getOrders(patient, outPatient, testOrderType, false).size()); }
/** * @see OrderService#getOrders(org.openmrs.Patient, org.openmrs.CareSetting, * org.openmrs.OrderType, boolean) */ @Test public void getOrders_shouldIncludeVoidedMatchesIfIncludeVoidedIsSetToTrue() { Patient patient = patientService.getPatient(2); CareSetting outPatient = orderService.getCareSetting(1); OrderType testOrderType = orderService.getOrderType(2); assertEquals(4, orderService.getOrders(patient, outPatient, testOrderType, true).size()); }
/** * @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#(OrderSearchCriteria) */ @Test public void getOrders_shouldGetOrdersByCareSetting() { CareSetting outPatient = orderService.getCareSetting(1); OrderSearchCriteria orderSearchCriteria = new OrderSearchCriteriaBuilder().setCareSetting(outPatient).build(); List<Order> orders = orderService.getOrders(orderSearchCriteria); assertEquals(12, orders.size()); }
/** * @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); }
/** * @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#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldSetOrderTypeIfNullButMappedToTheConceptClass() { TestOrder order = new TestOrder(); order.setPatient(patientService.getPatient(7)); order.setConcept(conceptService.getConcept(5497)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(orderService.getCareSetting(1)); order.setEncounter(encounterService.getEncounter(3)); order.setDateActivated(new Date()); orderService.saveOrder(order, null); assertEquals(2, order.getOrderType().getOrderTypeId().intValue()); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfQuantityIsNullForOutpatientCareSetting() { DrugOrder OutpatientOrder = new DrugOrder(); OutpatientOrder.setCareSetting(Context.getOrderService().getCareSetting(1)); OutpatientOrder.setQuantity(null); Errors OutpatientOrderErrors = new BindException(OutpatientOrder, "order"); new DrugOrderValidator().validate(OutpatientOrder, OutpatientOrderErrors); Assert.assertTrue(OutpatientOrderErrors.hasFieldErrors("quantity")); DrugOrder inPatientOrder = new DrugOrder(); inPatientOrder.setCareSetting(Context.getOrderService().getCareSetting(2)); inPatientOrder.setQuantity(null); Errors InpatientOrderErrors = new BindException(inPatientOrder, "order"); new DrugOrderValidator().validate(inPatientOrder, InpatientOrderErrors); Assert.assertFalse(InpatientOrderErrors.hasFieldErrors("quantity")); }
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldFailIfOrderTypeIsNullAndNotMappedToTheConceptClass() { Order order = new Order(); order.setPatient(patientService.getPatient(7)); order.setConcept(conceptService.getConcept(9)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(orderService.getCareSetting(1)); order.setEncounter(encounterService.getEncounter(3)); order.setDateActivated(new Date()); expectedException.expect(OrderEntryException.class); expectedException.expectMessage("Order.type.cannot.determine"); orderService.saveOrder(order, null); }
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldSetTheOrderNumberReturnedByTheConfiguredGenerator() { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_ORDER_NUMBER_GENERATOR_BEAN_ID, "orderEntry.OrderNumberGenerator"); Context.getAdministrationService().saveGlobalProperty(gp); Order order = new TestOrder(); order.setPatient(patientService.getPatient(7)); order.setConcept(conceptService.getConcept(5497)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(orderService.getCareSetting(1)); order.setOrderType(orderService.getOrderType(2)); order.setEncounter(encounterService.getEncounter(3)); order.setDateActivated(new Date()); order = orderService.saveOrder(order, null); assertTrue(order.getOrderNumber().startsWith(TimestampOrderNumberGenerator.ORDER_NUMBER_PREFIX)); }
/** * @see OrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldNotAllowAFutureDateActivated() { Patient patient = Context.getPatientService().getPatient(7); TestOrder order = new TestOrder(); order.setPatient(patient); order.setOrderType(orderService.getOrderTypeByName("Test order")); order.setEncounter(Context.getEncounterService().getEncounter(3)); order.setConcept(Context.getConceptService().getConcept(5497)); order.setOrderer(Context.getProviderService().getProvider(1)); order.setCareSetting(orderService.getCareSetting(1)); Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR_OF_DAY, 1); order.setDateActivated(cal.getTime()); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("dateActivated")); Assert.assertEquals("Order.error.dateActivatedInFuture", errors.getFieldError("dateActivated").getCode()); }
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldPassForADiscontinuationOrderWithNoPreviousOrder() { TestOrder dcOrder = new TestOrder(); dcOrder.setAction(Action.DISCONTINUE); dcOrder.setPatient(patientService.getPatient(2)); dcOrder.setCareSetting(orderService.getCareSetting(2)); dcOrder.setConcept(conceptService.getConcept(5089)); dcOrder.setEncounter(encounterService.getEncounter(6)); dcOrder.setOrderer(providerService.getProvider(1)); orderService.saveOrder(dcOrder, null); }
/** * @see OrderServiceImpl#discontinueExistingOrdersIfNecessary() */ @Test(expected = AmbiguousOrderException.class) public void saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveOrdersForTheGivenConcepts() { executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinueAmbiguousOrderByConcept.xml"); DrugOrder order = new DrugOrder(); order.setAction(Order.Action.DISCONTINUE); order.setOrderReasonNonCoded("Discontinue this"); order.setConcept(conceptService.getConcept(88)); order.setEncounter(encounterService.getEncounter(7)); order.setPatient(patientService.getPatient(9)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(orderService.getCareSetting(1)); order = (DrugOrder) orderService.saveOrder(order, null); }
/** * @see OrderServiceImpl#discontinueExistingOrdersIfNecessary() */ @Test(expected = AmbiguousOrderException.class) public void saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveDrugOrdersWithTheSameDrug() { executeDataSet("org/openmrs/api/include/OrderServiceTest-ambiguousDrugOrders.xml"); DrugOrder order = new DrugOrder(); order.setAction(Order.Action.DISCONTINUE); order.setOrderReasonNonCoded("Discontinue this"); order.setDrug(conceptService.getDrug(3)); order.setEncounter(encounterService.getEncounter(7)); order.setPatient(patientService.getPatient(9)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(orderService.getCareSetting(1)); order = (DrugOrder) orderService.saveOrder(order, null); }
/** * @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); }