private void failOnOrderTypeMismatch(Order order) { if (!order.getOrderType().getJavaClass().isAssignableFrom(order.getClass())) { throw new OrderEntryException("Order.type.class.does.not.match", new Object[] { order.getOrderType().getJavaClass(), order.getClass().getName() }); } }
private void validateOrderTypeClass(Order order, Errors errors) { OrderType orderType = order.getOrderType(); if (orderType != null && !orderType.getJavaClass().isAssignableFrom(order.getClass())) { errors.rejectValue("orderType", "Order.error.orderTypeClassMismatchesOrderClass"); } }
private void requireNoActiveOrderOfSameType(Patient patient1, Patient patient2) { String messageKey = "Patient.merge.cannotHaveSameTypeActiveOrders"; List<Order> ordersByPatient1 = Context.getOrderService().getAllOrdersByPatient(patient1); List<Order> ordersByPatient2 = Context.getOrderService().getAllOrdersByPatient(patient2); ordersByPatient1.forEach((Order order1) -> ordersByPatient2.forEach((Order order2) -> { if (order1.isActive() && order2.isActive() && order1.getOrderType().equals(order2.getOrderType())) { Object[] parameters = { patient1.getPatientId(), patient2.getPatientId(), order1.getOrderType() }; String message = Context.getMessageSourceService().getMessage(messageKey, parameters, Context.getLocale()); log.debug(message); throw new APIException(message); } })); }
private boolean hasActiveOrderOfType(Patient patient, String orderTypeName) { OrderType drugOrder = Context.getOrderService().getOrderTypeByName(orderTypeName); List<Order> preferredPatientOrders = Context.getOrderService().getAllOrdersByPatient(patient).stream() .filter(Order::isActive) .filter(order -> Objects.equals(drugOrder, order.getOrderType())) .collect(Collectors.toList()); return !preferredPatientOrders.isEmpty(); }
private void voidOrdersForType(Collection<Patient> patients, OrderType ot) { patients.forEach(patient -> Context.getOrderService().getAllOrdersByPatient(patient).forEach(order -> { if(order.getOrderType().equals(ot)){ order.setVoided(true); } })); }
private boolean areDrugOrdersOfSameOrderableAndOverlappingSchedule(Order firstOrder, Order secondOrder) { return firstOrder.hasSameOrderableAs(secondOrder) && !OpenmrsUtil.nullSafeEquals(firstOrder.getPreviousOrder(), secondOrder) && OrderUtil.checkScheduleOverlap(firstOrder, secondOrder) && firstOrder.getOrderType().equals( Context.getOrderService().getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID)); }
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); }
/** * 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())) {
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldFailIfTheOrderTypeOfThePreviousOrderDoesNotMatch() { Order order = orderService.getOrder(7); assertTrue(OrderUtilTest.isActiveOrder(order, null)); Order discontinuationOrder = order.cloneForDiscontinuing(); OrderType orderType = orderService.getOrderType(7); assertNotEquals(discontinuationOrder.getOrderType(), orderType); assertTrue(OrderUtil.isType(discontinuationOrder.getOrderType(), orderType)); discontinuationOrder.setOrderType(orderType); discontinuationOrder.setOrderer(Context.getProviderService().getProvider(1)); discontinuationOrder.setEncounter(Context.getEncounterService().getEncounter(6)); expectedException.expect(EditedOrderDoesNotMatchPreviousException.class); expectedException.expectMessage(mss.getMessage("Order.type.doesnot.match")); orderService.saveOrder(discontinuationOrder, null); }
/** * @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); }
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()); }
assertEquals(anOrder.getOrderType(), orderThatCanDiscontinueTheOrder.getOrderType());
target.setConcept(getConcept()); target.setPatient(getPatient()); target.setOrderType(getOrderType()); target.setScheduledDate(getScheduledDate()); target.setInstructions(getInstructions());
/** * @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.setOrderType(getOrderType()); target.setConcept(getConcept()); target.setInstructions(getInstructions());