private void ensureCareSettingIsSet(Order order, OrderContext orderContext) { if (order.getCareSetting() != null) { return; } CareSetting careSetting = null; if (orderContext != null) { careSetting = orderContext.getCareSetting(); } Order previousOrder = order.getPreviousOrder(); if (careSetting == null || (previousOrder != null && !careSetting.equals(previousOrder.getCareSetting()))) { throw new OrderEntryException("Order.care.cannot.determine"); } order.setCareSetting(careSetting); }
/** * 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 (!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))) { 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) {
asOfDate = order.getDateActivated(); List<? extends Order> orders = getActiveOrders(order.getPatient(), order.getOrderType(), order.getCareSetting(), asOfDate); boolean isDrugOrderAndHasADrug = isDrugOrder(order)
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldDefaultToCareSettingAndOrderTypeDefinedInTheOrderContextIfNull() { Order order = new TestOrder(); order.setPatient(patientService.getPatient(7)); Concept trimune30 = conceptService.getConcept(792); order.setConcept(trimune30); order.setOrderer(providerService.getProvider(1)); order.setEncounter(encounterService.getEncounter(3)); order.setDateActivated(new Date()); OrderType expectedOrderType = orderService.getOrderType(2); CareSetting expectedCareSetting = orderService.getCareSetting(1); OrderContext orderContext = new OrderContext(); orderContext.setOrderType(expectedOrderType); orderContext.setCareSetting(expectedCareSetting); order = orderService.saveOrder(order, orderContext); assertFalse(expectedOrderType.getConceptClasses().contains(trimune30.getConceptClass())); assertEquals(expectedOrderType, order.getOrderType()); assertEquals(expectedCareSetting, order.getCareSetting()); }
Order.Action.DISCONTINUE); assertEquals(anOrder.getCareSetting(), orderThatCanDiscontinueTheOrder.getCareSetting());
/** * @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 OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldFailIfTheCareSettingOfThePreviousOrderDoesNotMatch() { Order order = orderService.getOrder(7); assertTrue(OrderUtilTest.isActiveOrder(order, null)); Order discontinuationOrder = order.cloneForDiscontinuing(); CareSetting careSetting = orderService.getCareSetting(2); assertNotEquals(discontinuationOrder.getCareSetting(), careSetting); discontinuationOrder.setCareSetting(careSetting); discontinuationOrder.setOrderer(Context.getProviderService().getProvider(1)); discontinuationOrder.setEncounter(Context.getEncounterService().getEncounter(6)); expectedException.expect(EditedOrderDoesNotMatchPreviousException.class); expectedException.expectMessage(mss.getMessage("Order.care.setting.doesnot.match")); orderService.saveOrder(discontinuationOrder, null); }
target.setAutoExpireDate(getAutoExpireDate()); target.setCareSetting(getCareSetting()); target.setConcept(getConcept()); target.setPatient(getPatient());
/** * @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.action = getAction(); target.orderNumber = getOrderNumber(); target.setCareSetting(getCareSetting()); target.setChangedBy(getChangedBy()); target.setDateChanged(getDateChanged());
setOrderer(o, session); if (o.getCareSetting() == null) { CareSetting careSetting = getCareSetting(session, submission); o.setCareSetting(careSetting);
setOrderer(o, session); if (o.getCareSetting() == null) { CareSetting careSetting = getCareSetting(session, submission); o.setCareSetting(careSetting);
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()); 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"));
revisedOrder.add("previousOrder", orderToRevise.getUuid()); revisedOrder.add("patient", patient.getUuid()); revisedOrder.add("careSetting", orderToRevise.getCareSetting().getUuid()); revisedOrder.add("concept", orderToRevise.getConcept().getUuid()); revisedOrder.add("encounter", encounter.getUuid()); assertEquals(revisedOrder.get("action"), Util.getByPath(savedOrder, "action")); assertEquals(patient.getUuid(), Util.getByPath(savedOrder, "patient/uuid")); assertEquals(orderToRevise.getCareSetting().getUuid(), Util.getByPath(savedOrder, "careSetting/uuid")); assertEquals(revisedOrder.get("previousOrder"), Util.getByPath(savedOrder, "previousOrder/uuid")); assertEquals(revisedOrder.get("concept"), Util.getByPath(savedOrder, "concept/uuid"));