public OrderBuilder withAction(Order.Action action) { order.setAction(action); return this; }
/** * 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 Order#isActive(java.util.Date) */ @Test public void isActive_shouldReturnFalseForADiscontinuationOrder() throws Exception { Order order = new Order(); Date activationDate = DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT); order.setDateActivated(activationDate); order.setAction(Order.Action.DISCONTINUE); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertFalse(order.isActive(activationDate)); }
/** * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfAllFieldsAreCorrect() { Order order = new DrugOrder(); Encounter encounter = new Encounter(); order.setConcept(Context.getConceptService().getConcept(88)); order.setOrderer(Context.getProviderService().getProvider(1)); Patient patient = Context.getPatientService().getPatient(2); encounter.setPatient(patient); order.setPatient(patient); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1); order.setDateActivated(cal.getTime()); order.setAutoExpireDate(new Date()); order.setCareSetting(new CareSetting()); order.setEncounter(encounter); order.setUrgency(Order.Urgency.ROUTINE); order.setAction(Order.Action.NEW); order.setOrderType(Context.getOrderService().getOrderTypeByName("Drug order")); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see OrderValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { Order order = new Order(); Encounter encounter = new Encounter(); order.setConcept(Context.getConceptService().getConcept(88)); order.setOrderer(Context.getProviderService().getProvider(1)); Patient patient = Context.getPatientService().getPatient(2); encounter.setPatient(patient); order.setPatient(patient); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1); order.setDateActivated(cal.getTime()); order.setAutoExpireDate(new Date()); order.setCareSetting(new CareSetting()); order.setEncounter(encounter); order.setUrgency(Order.Urgency.ROUTINE); order.setAction(Order.Action.NEW); order.setOrderReasonNonCoded("orderReasonNonCoded"); order.setAccessionNumber("accessionNumber"); order.setCommentToFulfiller("commentToFulfiller"); order.setVoidReason("voidReason"); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @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")); }
order.setEncounter(encounter); order.setUrgency(Order.Urgency.ROUTINE); order.setAction(Order.Action.NEW);
public void saveOrder_shouldSaveARevisedOrderForAScheduledOrderWhichIsNotStarted() { Order originalOrder = new Order(); originalOrder.setAction(Action.NEW); originalOrder.setPatient(Context.getPatientService().getPatient(7)); originalOrder.setConcept(Context.getConceptService().getConcept(5497));
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() { Order order = orderService.getOrder(7); assertTrue(OrderUtilTest.isActiveOrder(order, null)); Order discontinuationOrder = new SomeTestOrder(); discontinuationOrder.setCareSetting(order.getCareSetting()); discontinuationOrder.setConcept(order.getConcept()); discontinuationOrder.setAction(Action.DISCONTINUE); discontinuationOrder.setPreviousOrder(order); discontinuationOrder.setPatient(order.getPatient()); assertTrue(order.getOrderType().getJavaClass().isAssignableFrom(discontinuationOrder.getClass())); discontinuationOrder.setOrderType(order.getOrderType()); discontinuationOrder.setOrderer(Context.getProviderService().getProvider(1)); discontinuationOrder.setEncounter(Context.getEncounterService().getEncounter(6)); expectedException.expect(EditedOrderDoesNotMatchPreviousException.class); expectedException.expectMessage(mss.getMessage("Order.class.doesnot.match")); orderService.saveOrder(discontinuationOrder, null); }
/** * @see Order#cloneForRevision() */ @Test public void cloneForRevision_shouldSetTheRelevantFieldsForADCOrder() throws Exception { Order order = new Order(); order.setAction(Order.Action.DISCONTINUE); Date date = new Date(); order.setDateActivated(date); order.setPreviousOrder(new Order()); order.setAutoExpireDate(date); order.setAccessionNumber("some number"); OrderUtilTest.setDateStopped(order, date); Order clone = order.cloneForRevision(); assertEquals(Order.Action.DISCONTINUE, clone.getAction()); assertEquals(order.getDateActivated(), clone.getDateActivated()); assertEquals(order.getPreviousOrder(), clone.getPreviousOrder()); assertNull(clone.getAutoExpireDate()); assertNull(clone.getDateStopped()); assertNull(clone.getAccessionNumber()); }
/** * @throws Exception * @see DrugOrder#cloneForRevision() */ @Test public void cloneForRevision_shouldSetTheRelevantFieldsForADCOrder() { Order order = new DrugOrder(); order.setAction(Order.Action.DISCONTINUE); Date date = new Date(); order.setDateActivated(date); order.setAutoExpireDate(date); order.setAccessionNumber("some number"); OrderUtilTest.setDateStopped(order, date); order.setPreviousOrder(new Order()); Order clone = order.cloneForRevision(); assertEquals(Order.Action.DISCONTINUE, clone.getAction()); assertEquals(order.getDateActivated(), clone.getDateActivated()); assertEquals(order.getPreviousOrder(), clone.getPreviousOrder()); assertNull(clone.getAutoExpireDate()); assertNull(clone.getDateStopped()); assertNull(clone.getAccessionNumber()); }
/** * @see TestOrder#cloneForRevision() */ @Test public void cloneForRevision_shouldSetTheRelevantFieldsForADCOrder() { Order order = new TestOrder(); order.setAction(Order.Action.DISCONTINUE); Date date = new Date(); order.setDateActivated(date); order.setAutoExpireDate(date); order.setAccessionNumber("some number"); OrderUtilTest.setDateStopped(order, date); order.setPreviousOrder(new Order()); Order clone = order.cloneForRevision(); assertEquals(Order.Action.DISCONTINUE, clone.getAction()); assertEquals(order.getDateActivated(), clone.getDateActivated()); assertEquals(order.getPreviousOrder(), clone.getPreviousOrder()); assertNull(clone.getAutoExpireDate()); assertNull(clone.getDateStopped()); assertNull(clone.getAccessionNumber()); } }
@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()); }
order.setAction(Action.NEW); order.setPatient(Context.getPatientService().getPatient(7)); order.setConcept(Context.getConceptService().getConcept(5497));
order.setAction(Action.NEW); order.setPatient(Context.getPatientService().getPatient(7)); order.setConcept(Context.getConceptService().getConcept(5497));