/** * A convenience method to return end of the schedule for order. * * @since 1.10 * @should return dateStopped if dateStopped is not null * @should return autoExpireDate if dateStopped is null */ public Date getEffectiveStopDate() { return this.getDateStopped() != null ? this.getDateStopped() : this.getAutoExpireDate(); }
/** * @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, * org.openmrs.Provider, org.openmrs.Encounter) */ @Test public void discontinueOrder_shouldFailForAnExpiredOrder() { Order orderToDiscontinue = orderService.getOrder(6); Encounter encounter = encounterService.getEncounter(3); assertNotNull(orderToDiscontinue.getAutoExpireDate()); assertTrue(orderToDiscontinue.getAutoExpireDate().before(new Date())); expectedException.expect(CannotStopInactiveOrderException.class); expectedException.expectMessage(mss.getMessage("Order.cannot.discontinue.inactive")); orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null, null, encounter); }
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldNotAllowRevisingAnExpiredOrder() { Order originalOrder = orderService.getOrder(6); assertNotNull(originalOrder.getAutoExpireDate()); assertTrue(originalOrder.getAutoExpireDate().before(new Date())); Order revisedOrder = originalOrder.cloneForRevision(); revisedOrder.setEncounter(encounterService.getEncounter(6)); revisedOrder.setInstructions("Take after a meal"); revisedOrder.setOrderer(providerService.getProvider(1)); revisedOrder.setDateActivated(new Date()); revisedOrder.setAutoExpireDate(new Date()); expectedException.expect(CannotStopInactiveOrderException.class); expectedException.expectMessage(mss.getMessage("Order.cannot.discontinue.inactive")); orderService.saveOrder(revisedOrder, null); }
/** * @throws ParseException * @see OrderUtil#checkScheduleOverlap(org.openmrs.Order, org.openmrs.Order) */ @Test public void checkScheduleOverlap_shouldReturnTrueIfBothOrdersStartAndEndOnSameDates() throws ParseException { DateFormat df = new SimpleDateFormat("dd/MM/yyy"); Order order1 = new Order(); order1.setDateActivated(df.parse("05/08/2014")); order1.setAutoExpireDate(df.parse("13/08/2014")); Order order2 = new Order(); order2.setDateActivated(order1.getDateActivated()); order2.setDateActivated(order1.getAutoExpireDate()); assertTrue(OrderUtil.checkScheduleOverlap(order1, order2)); assertTrue(OrderUtil.checkScheduleOverlap(order2, order1)); } }
/** * @throws ParseException * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldNotChangeTheAutoExpireDateIfItHasATimeComponent() throws ParseException { Order order = new TestOrder(); order.setPatient(patientService.getPatient(2)); order.setCareSetting(orderService.getCareSetting(2)); order.setConcept(conceptService.getConcept(5089)); order.setEncounter(encounterService.getEncounter(6)); order.setOrderer(providerService.getProvider(1)); order.setDateActivated(new Date()); DateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); order.setDateActivated(dateformat.parse("14/08/2014 10:00:00")); Date autoExpireDate = dateformat.parse("18/08/2014 10:00:00"); order.setAutoExpireDate(autoExpireDate); orderService.saveOrder(order, null); assertEquals(autoExpireDate, order.getAutoExpireDate()); }
/** * @see Order#isActivated(Date) */ @Test public void isActivated_shouldReturnFalseIfDateActivatedIsNull() throws Exception { Order order = new Order(); assertNull(order.getDateActivated()); assertNull(order.getAutoExpireDate()); assertFalse(order.isActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnFalseIfAutoExpireDateIsNullAndDateStoppedIsEqualToCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); Date checkDate = DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT); OrderUtilTest.setDateStopped(order, checkDate); assertNull(order.getAutoExpireDate()); assertFalse(order.isDiscontinued(checkDate)); }
/** * @see Order#isActivated(Date) */ @Test public void isActivated_shouldReturnTrueIfAnOrderWasActivatedOnTheCheckDate() throws Exception { Order order = new Order(); Date activationDate = DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT); order.setDateActivated(activationDate); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertTrue(order.isActivated(activationDate)); }
/** * @see Order#isActive(java.util.Date) */ @Test public void isActive_shouldReturnTrueIfAnOrderWasActivatedOnTheCheckDate() throws Exception { Order order = new Order(); Date activationDate = DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT); order.setDateActivated(activationDate); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertTrue(order.isActive(activationDate)); }
/** * @see Order#isActive(Date) */ @Test public void isActive_shouldReturnTrueIfAnOrderWasActivatedOnTheCheckDateButScheduledForTheFuture() throws Exception { Order order = new Order(); order.setUrgency(Urgency.ON_SCHEDULED_DATE); Date scheduledDateInFuture = DateUtils.addMonths(new Date(), 2); order.setScheduledDate(scheduledDateInFuture); Date activationDate = DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT); order.setDateActivated(activationDate); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertTrue(order.isActive(activationDate)); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnFalseIfDateStoppedAndAutoExpireDateAreBothNull() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertFalse(order.isExpired(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnFalseIfDateStoppedAndAutoExpireDateAreBothNull() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertFalse(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }
/** * @see Order#isActivated(Date) */ @Test public void isActivated_shouldReturnTrueIfAnOrderWasActivatedBeforeTheCheckDate() throws Exception { Order order = new Order(); Date activationDate = DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT); order.setDateActivated(activationDate); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertTrue(order.isActivated(DateUtils.addMonths(activationDate, 2))); }
/** * @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 Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnFalseIfAutoExpireDateIsNullAndDateStoppedIsAfterCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT)); assertNull(order.getAutoExpireDate()); assertFalse(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnTrueIfAutoExpireDateIsNullAndDateStoppedIsBeforeCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); assertNull(order.getAutoExpireDate()); assertTrue(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }
/** * @see Order#isActive(java.util.Date) */ @Test public void isActive_shouldReturnFalseForAnOrderActivatedAfterTheCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertFalse(order.isActive(DateUtils.parseDate("2014-11-01 11:11:09", DATE_FORMAT))); }
/** * @see Order#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnFalseForAVoidedOrder() throws Exception { Order order = new Order(); order.setVoided(true); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); assertNull(order.getAutoExpireDate()); assertFalse(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }
/** * @see Order#isActivated(Date) */ @Test public void isActivated_shouldReturnFalseForAnOrderActivatedAfterTheCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertFalse(order.isActivated(DateUtils.addMonths(order.getDateActivated(), -2))); }
/** * @see Order#isActive(java.util.Date) */ @Test public void isActive_shouldReturnFalseForAVoidedOrder() throws Exception { Order order = new Order(); order.setVoided(true); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertFalse(order.isActive(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }