public DrugOrderBuilder withOrderType(Integer orderTypeID) { drugOrder.setOrderType(orderService.getOrderType(orderTypeID)); return this; }
public OrderBuilder withOrderType(Integer orderTypeID) { order.setOrderType(orderService.getOrderType(orderTypeID)); return this; }
/** * @see OrderService#purgeOrderType(org.openmrs.OrderType) */ @Test public void purgeOrderType_shouldDeleteOrderTypeIfNotInUse() { final Integer id = 13; OrderType orderType = orderService.getOrderType(id); assertNotNull(orderType); orderService.purgeOrderType(orderType); assertNull(orderService.getOrderType(id)); }
/** * @see OrderService#getOrderType(Integer) */ @Test public void getOrderType_shouldReturnNullIfNoOrderTypeObjectFoundWithGivenId() { OrderType orderType = orderService.getOrderType(1000); assertNull(orderType); }
/** * @see OrderService#getSubtypes(org.openmrs.OrderType, boolean) */ @Test public void getOrderSubTypes_shouldGetAllSubOrderTypesWithRetiredOrderTypes() { List<OrderType> orderTypeList = orderService.getSubtypes(orderService.getOrderType(2), true); assertEquals(7, orderTypeList.size()); }
/** * @see OrderService#getSubtypes(org.openmrs.OrderType, boolean) */ @Test public void getOrderSubTypes_shouldGetAllSubOrderTypesWithoutRetiredOrderTypes() { List<OrderType> orderTypeList = orderService.getSubtypes(orderService.getOrderType(2), false); assertEquals(6, orderTypeList.size()); }
/** * @see OrderService#(OrderSearchCriteria) */ @Test public void getOrders_shouldGetOrdersByOrderTypes() { List<OrderType> orderTypes = new ArrayList<>(); orderTypes.add(orderService.getOrderType(1)); // drug order OrderSearchCriteria orderSearchCriteria = new OrderSearchCriteriaBuilder().setOrderTypes(orderTypes).build(); List<Order> orders = orderService.getOrders(orderSearchCriteria); assertEquals(10, orders.size()); }
/** * @see OrderService#getOrderType(Integer) */ @Test public void getOrderType_shouldFindOrderTypeObjectGivenValidId() { assertEquals("Drug order", orderService.getOrderType(1).getName()); }
/** * @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 OrderTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfParentIsAlsoADirectChild() { OrderType orderType = orderService.getOrderType(8); OrderType descendant = orderService.getOrderType(12); Assert.assertTrue(descendant.getParent().equals(orderType)); orderType.setParent(descendant); Errors errors = new BindException(orderType, "orderType"); new OrderTypeValidator().validate(orderType, errors); Assert.assertEquals(true, errors.hasFieldErrors("parent")); }
/** * @see OrderTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfParentIsAmongItsDescendants() { OrderType orderType = orderService.getOrderType(2); OrderType descendant = orderService.getOrderType(9); Assert.assertTrue(descendant.getParent().getParent().equals(orderType)); orderType.setParent(descendant); Errors errors = new BindException(orderType, "orderType"); new OrderTypeValidator().validate(orderType, errors); Assert.assertEquals(true, errors.hasFieldErrors("parent")); }
/** * @see OrderTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfConceptClassIsADuplicate() { OrderType orderType = new OrderType(); orderType.setName("concept class test"); OrderType existing = orderService.getOrderType(2); assertEquals(1, existing.getConceptClasses().size()); orderType.addConceptClass(existing.getConceptClasses().iterator().next()); Errors errors = new BindException(orderType, "orderType"); new OrderTypeValidator().validate(orderType, errors); Assert.assertEquals(true, errors.hasFieldErrors("conceptClasses[0]")); }
/** * @see OrderService#purgeOrderType(org.openmrs.OrderType) */ @Test public void purgeOrderType_shouldNotAllowDeletingAnOrderTypeThatIsInUse() { OrderType orderType = orderService.getOrderType(1); assertNotNull(orderType); expectedException.expect(CannotDeleteObjectInUseException.class); expectedException.expectMessage(mss.getMessage("Order.type.cannot.delete")); orderService.purgeOrderType(orderType); }
/** * @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldBeInvokedWhenAnOrderTypeIsSaved() { OrderType orderType = orderService.getOrderType(1); orderType.setName(null); expectedException.expect(APIException.class); String expectedMsg = "'" + orderType + "' failed to validate with reason: name: " + Context.getMessageSourceService().getMessage("error.name"); expectedException.expectMessage(expectedMsg); orderService.saveOrderType(orderType); }
/** * @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassIfAllFieldsAreCorrectForAnExistingOrderType() { OrderType orderType = orderService.getOrderType(1); assertNotNull(orderType); Errors errors = new BindException(orderType, "orderType"); new OrderTypeValidator().validate(orderType, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @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#retireOrderType(org.openmrs.OrderType, String) */ @Test public void retireOrderType_shouldNotRetireIndependentField() { OrderType orderType = orderService.getOrderType(2); ConceptClass conceptClass = conceptService.getConceptClass(1); Assert.assertFalse(conceptClass.getRetired()); orderType.addConceptClass(conceptClass); orderService.retireOrderType(orderType, "test retire reason"); Assert.assertFalse(conceptClass.getRetired()); }
/** * @see OrderTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfNameIsADuplicate() { OrderType orderType = new OrderType(); orderType.setName(orderService.getOrderType(1).getName()); Errors errors = new BindException(orderType, "orderType"); new OrderTypeValidator().validate(orderType, errors); Assert.assertEquals(true, errors.hasFieldErrors("name")); }