/** * Checks whether orderable of this order is same as other order * * @see org.openmrs.DrugOrder for overridden behaviour * @since 1.10 * @param otherOrder the other order to match on * @return true if the concept of the orders match * @should return false if the concept of the orders do not match * @should return false if other order is null * @should return true if the orders have the same concept */ public boolean hasSameOrderableAs(Order otherOrder) { if (otherOrder == null) { return false; } return OpenmrsUtil.nullSafeEquals(this.getConcept(), otherOrder.getConcept()); }
private void ensureConceptIsSet(Order order) { Concept concept = order.getConcept(); if (concept == null && isDrugOrder(order)) { DrugOrder drugOrder = (DrugOrder) order; if (drugOrder.getDrug() != null) { concept = drugOrder.getDrug().getConcept(); drugOrder.setConcept(concept); } } if (concept == null) { throw new MissingRequiredPropertyException("Order.concept.required"); } }
/** * 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; }
} else if (activeOrder.getConcept().equals(order.getConcept())) { if (orderToBeDiscontinued == null) { orderToBeDiscontinued = activeOrder;
private void ensureOrderTypeIsSet(Order order, OrderContext orderContext) { if (order.getOrderType() != null) { return; } OrderType orderType = null; if (orderContext != null) { orderType = orderContext.getOrderType(); } if (orderType == null) { orderType = getOrderTypeByConcept(order.getConcept()); } if (orderType == null && order instanceof DrugOrder) { orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID); } if (orderType == null && order instanceof TestOrder) { orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.TEST_ORDER_TYPE_UUID); } if (orderType == null) { throw new OrderEntryException("Order.type.cannot.determine"); } Order previousOrder = order.getPreviousOrder(); if (previousOrder != null && !orderType.equals(previousOrder.getOrderType())) { throw new OrderEntryException("Order.type.does.not.match"); } order.setOrderType(orderType); }
/** * @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); }
/** * Display string for {@link Order} * * @param order * @return ConceptName */ @PropertyGetter("display") public String getDisplayString(Order order) { if (order.getConcept() == null) return "[No Concept]"; return order.getConcept().getName().getName(); }
/** * Removes an Order of the relevant Concept from existingOrders, and returns it. * * @param concept - question the concept associated with the Obs to remove * @return */ public Order removeExistingOrder(Concept concept) { List<Order> list = existingOrders.get(concept); if (list != null) { for (Iterator<Order> iter = list.iterator(); iter.hasNext();) { Order test = iter.next(); if (equalConcepts(concept, test.getConcept())) { iter.remove(); if (list.size() == 0) existingOrders.remove(concept); return test; } } } return null; }
/** * @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); }
assertEquals(anOrder.getConcept(), orderThatCanDiscontinueTheOrder.getConcept());
/** * @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); }
List<Order> list = existingOrders.get(order.getConcept()); if (list == null) { list = new LinkedList<Order>(); existingOrders.put(order.getConcept(), list);
target.setConcept(getConcept()); target.setPatient(getPatient()); target.setOrderType(getOrderType());
/** * @see TestOrder#cloneForDiscontinuing() */ @Test public void cloneForDiscontinuing_shouldSetAllTheRelevantFields() { TestOrder anOrder = new TestOrder(); 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()); }
target.setPatient(getPatient()); target.setOrderType(getOrderType()); target.setConcept(getConcept()); target.setInstructions(getInstructions()); target.setDateActivated(getDateActivated());
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()); 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"));
revisedOrder.add("patient", patient.getUuid()); revisedOrder.add("careSetting", orderToRevise.getCareSetting().getUuid()); revisedOrder.add("concept", orderToRevise.getConcept().getUuid()); revisedOrder.add("encounter", encounter.getUuid()); revisedOrder.add("orderer", "c2299800-cca9-11e0-9572-0800200c9a66");