target.setPatient(getPatient()); target.setOrderType(getOrderType()); target.setConcept(getConcept()); target.setInstructions(getInstructions()); target.setDateActivated(getDateActivated()); target.setAutoExpireDate(getAutoExpireDate()); target.setEncounter(getEncounter()); target.setOrderer(getOrderer()); target.setCreator(getCreator()); target.setDateCreated(getDateCreated()); target.dateStopped = getDateStopped(); target.setOrderReason(getOrderReason()); target.setOrderReasonNonCoded(getOrderReasonNonCoded()); target.setAccessionNumber(getAccessionNumber()); target.setVoided(getVoided()); target.setVoidedBy(getVoidedBy()); target.setDateVoided(getDateVoided()); target.setVoidReason(getVoidReason()); target.setUrgency(getUrgency()); target.setCommentToFulfiller(getCommentToFulfiller()); target.previousOrder = getPreviousOrder(); target.action = getAction(); target.orderNumber = getOrderNumber(); target.setCareSetting(getCareSetting()); target.setChangedBy(getChangedBy()); target.setDateChanged(getDateChanged()); target.setScheduledDate(getScheduledDate()); target.setOrderGroup(getOrderGroup()); target.setSortWeight(getSortWeight());
Order previousOrder = order.getPreviousOrder(); if (REVISE == order.getAction()) { if (previousOrder == null) { throw new MissingRequiredPropertyException("Order.previous.required", (Object[]) null); stopOrder(previousOrder, aMomentBefore(order.getDateActivated()), isRetrospective); } else if (DISCONTINUE == order.getAction()) { discontinueExistingOrdersIfNecessary(order, isRetrospective); if (!order.hasSameOrderableAs(previousOrder)) { throw new EditedOrderDoesNotMatchPreviousException("Order.orderable.doesnot.match"); } else if (!order.getOrderType().equals(previousOrder.getOrderType())) { throw new EditedOrderDoesNotMatchPreviousException("Order.type.doesnot.match"); } else if (!order.getCareSetting().equals(previousOrder.getCareSetting())) { throw new EditedOrderDoesNotMatchPreviousException("Order.care.setting.doesnot.match"); } else if (!getActualType(order).equals(getActualType(previousOrder))) { if (DISCONTINUE != order.getAction()) { Date asOfDate = new Date(); if (isRetrospective) { asOfDate = order.getDateActivated(); List<Order> activeOrders = getActiveOrders(order.getPatient(), null, order.getCareSetting(), asOfDate); List<String> parallelOrders = Collections.emptyList(); if (orderContext != null && orderContext.getAttribute(PARALLEL_ORDERS) != null) { if (!parallelOrders.contains(activeOrder.getUuid()) && areDrugOrdersOfSameOrderableAndOverlappingSchedule(order, activeOrder)) { throw new AmbiguousOrderException("Order.cannot.have.more.than.one");
/** * @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))); }
/** * 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(); }
/** * 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; }
/** * Convenience method to determine if the order is active as of the specified date * * @param checkDate - the date on which to check order. if null, will use current date * @return boolean indicating whether the order was active on the check date * @since 1.10.1 * @should return true if an order expired on the check date * @should return true if an order was discontinued on the check date * @should return true if an order was activated on the check date * @should return true if an order was activated on the check date but scheduled for the future * @should return false for a voided order * @should return false for a discontinued order * @should return false for an expired order * @should return false for an order activated after the check date * @should return false for a discontinuation order */ public boolean isActive(Date aCheckDate) { if (getVoided() || action == Action.DISCONTINUE) { return false; } Date checkDate = aCheckDate == null ? new Date() : aCheckDate; return isActivated(checkDate) && !isDiscontinued(checkDate) && !isExpired(checkDate); }
if (getAction() == Action.DISCONTINUE) { target.setAction(Action.DISCONTINUE); target.setPreviousOrder(getPreviousOrder()); target.setDateActivated(getDateActivated()); } else { target.setAction(Action.REVISE); target.setPreviousOrder(this); target.setAutoExpireDate(getAutoExpireDate()); target.setCareSetting(getCareSetting()); target.setConcept(getConcept()); target.setPatient(getPatient()); target.setOrderType(getOrderType()); target.setScheduledDate(getScheduledDate()); target.setInstructions(getInstructions()); target.setUrgency(getUrgency()); target.setCommentToFulfiller(getCommentToFulfiller()); target.setOrderReason(getOrderReason()); target.setOrderReasonNonCoded(getOrderReasonNonCoded()); target.setOrderGroup(getOrderGroup()); target.setSortWeight(getSortWeight()); target.setFulfillerStatus(getFulfillerStatus()); target.setFulfillerComment(getFulfillerComment());
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnFalseForAVoidedOrder() throws Exception { Order order = new Order(); order.setVoided(true); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); assertNull(order.getDateStopped()); assertFalse(order.isExpired(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }
if (o.getDateCreated() == null) o.setDateCreated(new Date()); if (o.getCreator() == null) o.setCreator(Context.getAuthenticatedUser()); if (o.getUuid() == null) o.setUuid(UUID.randomUUID().toString()); Order discontinuationOrder = null; if (discontinuedDate != null) { discontinuationOrder = newDiscontinuationOrder(discontinuedDate, discontinuedReasonStr, o); if (o.getOrderer() == null) { setOrderer(o, session); if (o.getCareSetting() == null) { CareSetting careSetting = getCareSetting(session, submission); o.setCareSetting(careSetting);
public void cloneForDiscontinuing_shouldSetAllTheRelevantFields() throws Exception { Order anOrder = new Order(); anOrder.setPatient(new Patient()); anOrder.setCareSetting(new CareSetting()); anOrder.setConcept(new Concept()); anOrder.setOrderType(new OrderType()); Order orderThatCanDiscontinueTheOrder = anOrder.cloneForDiscontinuing(); assertEquals(anOrder.getPatient(), orderThatCanDiscontinueTheOrder.getPatient()); assertEquals(anOrder.getConcept(), orderThatCanDiscontinueTheOrder.getConcept()); assertEquals("should set previous order to anOrder", anOrder, orderThatCanDiscontinueTheOrder.getPreviousOrder()); assertEquals("should set new order action to new", orderThatCanDiscontinueTheOrder.getAction(), Order.Action.DISCONTINUE); assertEquals(anOrder.getCareSetting(), orderThatCanDiscontinueTheOrder.getCareSetting()); assertEquals(anOrder.getOrderType(), orderThatCanDiscontinueTheOrder.getOrderType()); assertNull("Discontinued order should not have orderGroup", orderThatCanDiscontinueTheOrder.getOrderGroup());
/** * @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 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#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)); }
protected void enterStandardRegimen(FormEntrySession session, HttpServletRequest submission, String regCode, Date startDate, Date discontinuedDate, String discontinuedReasonStr) { RegimenSuggestion rs = RegimenUtil.getStandardRegimenByCode(possibleRegimens, regCode); //create new drugOrders Set<Order> ords = RegimenUtil.standardRegimenToDrugOrders(rs, startDate, session.getPatient()); for (Order o: ords){ if (o.getDateCreated() == null) o.setDateCreated(new Date()); if (o.getCreator() == null) o.setCreator(Context.getAuthenticatedUser()); if (o.getUuid() == null) o.setUuid(UUID.randomUUID().toString()); if (!StringUtils.isEmpty(discontinuedReasonStr)) o.setDiscontinuedReason(HtmlFormEntryUtil.getConcept(discontinuedReasonStr)); if (discontinuedDate != null){ o.setDiscontinuedDate(discontinuedDate); o.setDiscontinued(true); o.setDiscontinuedBy(Context.getAuthenticatedUser()); } session.getSubmissionActions().getCurrentEncounter().addOrder(o); } }
if (DISCONTINUE != order.getAction()) { return; Order previousOrder = order.getPreviousOrder(); if (previousOrder != null) { stopOrder(previousOrder, aMomentBefore(order.getDateActivated()), isRetrospective); return; asOfDate = order.getDateActivated(); List<? extends Order> orders = getActiveOrders(order.getPatient(), order.getOrderType(), order.getCareSetting(), asOfDate); boolean isDrugOrderAndHasADrug = isDrugOrder(order) Order existing = order.hasSameOrderableAs(activeOrder) ? activeOrder : null; if (existing != null) { if (orderToBeDiscontinued == null) { } else if (activeOrder.getConcept().equals(order.getConcept())) { if (orderToBeDiscontinued == null) { orderToBeDiscontinued = activeOrder; order.setPreviousOrder(orderToBeDiscontinued); stopOrder(orderToBeDiscontinued, aMomentBefore(order.getDateActivated()), isRetrospective);
/** * @see Order#isDiscontinued(Date) */ @Test public void isDiscontinued_shouldReturnTrueIfTheOrderIsScheduledForTheFutureAndActivatedOnCheckDateButTheCheckDateIsAfterDateStopped() throws Exception { // tests the case when a scheduled order is revised: // in that case its original order is stopped. // the stopped date of the original order is set to a moment before the activated date of the revised order. // the order here represents such an original order Order order = new Order(); order.setUrgency(Urgency.ON_SCHEDULED_DATE); Date today = new Date(); Date scheduledDateInFuture = DateUtils.addMonths(today, 2); order.setScheduledDate(scheduledDateInFuture); Date activationDate = DateUtils.addDays(today, -2); order.setDateActivated(activationDate); Date stopDate = new Date(); OrderUtilTest.setDateStopped(order, stopDate); assertNotNull(order.getDateActivated()); assertNotNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertTrue(order.isDiscontinued(DateUtils.addSeconds(stopDate, 1))); }
@Test public void shouldDiscontinueAnActiveOrder() throws Exception { Order orderToDiscontinue = orderService.getOrder(7); Patient patient = orderToDiscontinue.getPatient(); List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null); assertTrue(originalActiveOrders.contains(orderToDiscontinue)); dcOrder.add("action", "DISCONTINUE"); dcOrder.add("patient", patient.getUuid()); dcOrder.add("concept", orderToDiscontinue.getConcept().getUuid()); dcOrder.add("careSetting", orderToDiscontinue.getCareSetting().getUuid()); dcOrder.add("previousOrder", orderToDiscontinue.getUuid()); dcOrder.add("encounter", Context.getEncounterService().getEncounter(6).getUuid()); dcOrder.add("orderer", "c2299800-cca9-11e0-9572-0800200c9a66"); assertNotNull(PropertyUtils.getProperty(savedDCOrder, "orderNumber")); assertEquals(dcOrder.get("action"), Util.getByPath(savedDCOrder, "action")); assertEquals(orderToDiscontinue.getPatient().getUuid(), Util.getByPath(savedDCOrder, "patient/uuid")); assertEquals(orderToDiscontinue.getCareSetting().getUuid(), Util.getByPath(savedDCOrder, "careSetting/uuid")); assertEquals(dcOrder.get("previousOrder"), Util.getByPath(savedDCOrder, "previousOrder/uuid")); assertNotNull(PropertyUtils.getProperty(savedDCOrder, "dateActivated")); assertEquals(orderToDiscontinue.getConcept().getUuid(), Util.getByPath(savedDCOrder, "concept/uuid")); assertEquals(dcOrder.get("encounter"), Util.getByPath(savedDCOrder, "encounter/uuid")); assertEquals(dcOrder.get("orderer"), Util.getByPath(savedDCOrder, "orderer/uuid"));
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThisConcept() { Order previousOrder = orderService.getOrder(7); assertTrue(OrderUtilTest.isActiveOrder(previousOrder, null)); Order order = previousOrder.cloneForDiscontinuing(); order.setDateActivated(new Date()); order.setOrderReasonNonCoded("Discontinue this"); order.setEncounter(encounterService.getEncounter(6)); order.setOrderer(providerService.getProvider(1)); 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 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#isDiscontinued(java.util.Date) */ @Test public void isDiscontinued_shouldReturnTrueIfCheckDateIsAfterDateStoppedButBeforeAutoExpireDate() 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)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:13", DATE_FORMAT)); assertTrue(order.isDiscontinued(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }