public OrderBuilder withConcept(Integer conceptID) { order.setConcept(conceptService.getConcept(conceptID)); return this; }
/** * @see Order#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnTrueIfTheOrdersHaveTheSameConcept() throws Exception { Order order = new Order(); Concept concept = new Concept(); order.setConcept(concept); Order otherOrder = new Order(); otherOrder.setConcept(concept); assertTrue(order.hasSameOrderableAs(otherOrder)); }
/** * @see Order#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfTheConceptOfTheOrdersDoNotMatch() throws Exception { Order order = new Order(); order.setConcept(new Concept()); Order otherOrder = new Order(); otherOrder.setConcept(new Concept()); assertFalse(order.hasSameOrderableAs(otherOrder)); }
/** * @see Order#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfOtherOrderIsNull() throws Exception { Order order = new Order(); order.setConcept(new Concept()); assertFalse(order.hasSameOrderableAs(null)); }
/** * Creates a discontinuation order for this order, sets the previousOrder and action fields, * note that the discontinuation order needs to be saved for the discontinuation to take effect * * @return the newly created order * @since 1.10 * @should set all the relevant fields */ public Order cloneForDiscontinuing() { Order newOrder = new Order(); newOrder.setCareSetting(getCareSetting()); newOrder.setConcept(getConcept()); newOrder.setAction(Action.DISCONTINUE); newOrder.setPreviousOrder(this); newOrder.setPatient(getPatient()); newOrder.setOrderType(getOrderType()); return newOrder; }
/** * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfDateActivatedAfterAutoExpireDate() { Order order = new Order(); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); order.setOrderer(Context.getProviderService().getProvider(1)); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1); order.setDateActivated(new Date()); order.setAutoExpireDate(cal.getTime()); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("dateActivated")); Assert.assertTrue(errors.hasFieldErrors("autoExpireDate")); }
/** * @throws Exception * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfDateActivatedAfterDateStopped() throws Exception { Order order = new Order(); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); order.setOrderer(Context.getProviderService().getProvider(1)); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1); order.setDateActivated(new Date()); OrderUtilTest.setDateStopped(order, cal.getTime()); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("dateActivated")); Assert.assertTrue(errors.hasFieldErrors("dateStopped")); }
/** * @see DrugOrder#hasSameOrderableAs(Order) */ @Test public void hasSameOrderableAs_shouldReturnFalseIfTheOtherOrderIsNotADrugOrder() { DrugOrder order = new DrugOrder(); Drug drug1 = new Drug(); Concept concept = new Concept(); drug1.setConcept(concept); order.setDrug(drug1); Order otherOrder = new Order(); otherOrder.setConcept(concept); assertFalse(order.hasSameOrderableAs(otherOrder)); }
/** * @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 OrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfOrderTypejavaClassDoesNotMatchOrderclass() { Order order = new DrugOrder(); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); order.setOrderer(Context.getProviderService().getProvider(1)); order.setOrderType(Context.getOrderService().getOrderTypeByName("Test order")); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("orderType")); Assert.assertTrue(Arrays.asList(errors.getFieldError("orderType").getCodes()).contains( "Order.error.orderTypeClassMismatchesOrderClass")); }
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThatOfTheRevisedOrder() { Order previousOrder = orderService.getOrder(7); Order order = previousOrder.cloneForRevision(); order.setDateActivated(new Date()); order.setOrderer(providerService.getProvider(1)); order.setEncounter(encounterService.getEncounter(6)); Concept newConcept = conceptService.getConcept(5089); assertFalse(previousOrder.getConcept().equals(newConcept)); order.setConcept(newConcept); expectedException.expect(EditedOrderDoesNotMatchPreviousException.class); expectedException.expectMessage("The orderable of the previous order and the new one order don't match"); orderService.saveOrder(order, null); }
/** * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfActionIsNull() { Order order = new Order(); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); order.setAction(null); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("action")); }
/** * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfEncounterIsNull() { Order order = new Order(); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); order.setEncounter(null); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("encounter")); }
/** * @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,Errors) */ @Test public void validate_shouldFailValidationIfUrgencyIsNull() { Order order = new Order(); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); order.setUrgency(null); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("urgency")); }
/** * @see OrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfDateActivatedIsBeforeEncountersEncounterDatetime() { Date encounterDate = new Date(); Date orderDate = DateUtils.addDays(encounterDate, -1); Encounter encounter = Context.getEncounterService().getEncounter(3); encounter.setEncounterDatetime(encounterDate); Order order = new Order(); order.setDateActivated(orderDate); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); order.setEncounter(encounter); order.setOrderer(Context.getProviderService().getProvider(1)); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("dateActivated")); }
/** * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfOrderAndEncounterHaveDifferentPatients() { Order order = new Order(); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); order.setEncounter(Context.getEncounterService().getEncounter(3)); order.setOrderer(Context.getProviderService().getProvider(1)); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("encounter")); }
/** * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfOrdererIsNull() { Order order = new Order(); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertFalse(errors.hasFieldErrors("discontinued")); Assert.assertFalse(errors.hasFieldErrors("concept")); Assert.assertTrue(errors.hasFieldErrors("orderer")); Assert.assertFalse(errors.hasFieldErrors("patient")); }
/** * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfPatientIsNull() { Order order = new Order(); order.setConcept(Context.getConceptService().getConcept(88)); order.setOrderer(Context.getProviderService().getProvider(1)); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertFalse(errors.hasFieldErrors("discontinued")); Assert.assertFalse(errors.hasFieldErrors("concept")); Assert.assertTrue(errors.hasFieldErrors("patient")); Assert.assertFalse(errors.hasFieldErrors("orderer")); }
/** * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfVoidedIsNull() { Order order = new Order(); order.setVoided(null); order.setConcept(Context.getConceptService().getConcept(88)); order.setPatient(Context.getPatientService().getPatient(2)); order.setOrderer(Context.getProviderService().getProvider(1)); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertFalse(errors.hasFieldErrors("discontinued")); Assert.assertTrue(errors.hasFieldErrors("voided")); Assert.assertFalse(errors.hasFieldErrors("concept")); Assert.assertFalse(errors.hasFieldErrors("patient")); Assert.assertFalse(errors.hasFieldErrors("orderer")); }