private void validateSamePatientInOrderAndEncounter(Order order, Errors errors) { if (order.getEncounter() != null && order.getPatient() != null && !order.getEncounter().getPatient().equals(order.getPatient())) { errors.rejectValue("encounter", "Order.error.encounterPatientMismatch"); } }
/** * @see org.openmrs.api.handler.SaveHandler#handle(org.openmrs.OpenmrsObject, org.openmrs.User, * java.util.Date, java.lang.String) */ @Override public void handle(Order order, User creator, Date dateCreated, String other) { if (order.getPatient() == null && order.getEncounter() != null) { order.setPatient(order.getEncounter().getPatient()); } } }
private void validateOrderGroupPatient(Order order, Errors errors) { if (order.getOrderGroup() != null && !(order.getPatient().equals(order.getOrderGroup().getPatient()))) { errors.rejectValue("patient", "Order.error.orderPatientAndOrderGroupPatientMismatch"); } } }
/** * @see EncounterService#saveEncounter(Encounter) */ @Test public void saveEncounter_shouldCascadePatientToOrdersInTheEncounter() { Encounter enc = Context.getEncounterService().getEncounter(15); Order existing = enc.getOrders().iterator().next(); // for some reason the xml for the existing encounter has already given // this order a different patient than the encounter that it's contained // in, but let's verify that: Assert.assertNotSame(enc.getPatient().getId(), existing.getPatient().getId()); Context.getEncounterService().saveEncounter(enc); Assert.assertEquals(enc.getPatient().getId(), existing.getPatient().getId()); }
/** * 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; }
@Test public void shouldReviseAnOrderAndFlushSuccessfully() { Order originalOrder = orderService.getOrder(111); assertTrue(OrderUtilTest.isActiveOrder(originalOrder, null)); final Patient patient = originalOrder.getPatient(); List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null); final int originalOrderCount = originalActiveOrders.size(); assertTrue(originalActiveOrders.contains(originalOrder)); Order revisedOrder = originalOrder.cloneForRevision(); revisedOrder.setInstructions("Take after a meal"); revisedOrder.setDateActivated(new Date()); revisedOrder.setOrderer(providerService.getProvider(1)); revisedOrder.setEncounter(encounterService.getEncounter(3)); orderService.saveOrder(revisedOrder, null); Context.flushSession(); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(originalOrderCount, activeOrders.size()); assertFalse(OrderUtilTest.isActiveOrder(originalOrder, null)); }
@Test public void shouldAllowEditingADiscontinuationOrder() { Order originalDCOrder = orderService.getOrder(22); assertEquals(Order.Action.DISCONTINUE, originalDCOrder.getAction()); List<Order> originalPatientOrders = orderService.getAllOrdersByPatient(originalDCOrder.getPatient()); final Order previousOrder = originalDCOrder.getPreviousOrder(); assertNotNull(previousOrder); final Date newStartDate = originalDCOrder.getEncounter().getEncounterDatetime(); Order newDcOrder = originalDCOrder.cloneForRevision(); newDcOrder.setEncounter(originalDCOrder.getEncounter()); newDcOrder.setOrderer(originalDCOrder.getOrderer()); newDcOrder.setDateActivated(newStartDate); orderService.voidOrder(originalDCOrder, "To be replace with a new one"); assertNull(originalDCOrder.getDateStopped()); orderService.saveOrder(newDcOrder, null); //We need to flush so that we ensure the interceptor is okay with all this Context.flushSession(); assertTrue(originalDCOrder.getVoided()); List<Order> newPatientOrders = orderService.getAllOrdersByPatient(originalDCOrder.getPatient()); assertEquals(originalPatientOrders.size() + 1, newPatientOrders.size()); Collection<Order> newOrders = CollectionUtils.disjunction(originalPatientOrders, newPatientOrders); assertEquals(1, newOrders.size()); assertEquals(newOrders.iterator().next().getPreviousOrder(), 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) {
@Test public void shouldReviseAnOrder() { Order originalOrder = orderService.getOrder(111); assertTrue(OrderUtilTest.isActiveOrder(originalOrder, null)); final Patient patient = originalOrder.getPatient(); List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null); final int originalOrderCount = originalActiveOrders.size(); assertTrue(originalActiveOrders.contains(originalOrder)); Order revisedOrder = originalOrder.cloneForRevision(); revisedOrder.setInstructions("Take after a meal"); revisedOrder.setDateActivated(new Date()); revisedOrder.setOrderer(providerService.getProvider(1)); revisedOrder.setEncounter(encounterService.getEncounter(3)); orderService.saveOrder(revisedOrder, null); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(originalOrderCount, activeOrders.size()); assertEquals(revisedOrder.getDateActivated(), DateUtils.addSeconds(originalOrder.getDateStopped(), 1)); assertFalse(OrderUtilTest.isActiveOrder(originalOrder, null)); }
if (!p.equals(o.getPatient())) { o.setPatient(p);
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldSaveARevisedOrder() { Order originalOrder = orderService.getOrder(111); assertTrue(originalOrder.isActive()); final Patient patient = originalOrder.getPatient(); List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null); final int originalOrderCount = originalActiveOrders.size(); assertTrue(originalActiveOrders.contains(originalOrder)); Order revisedOrder = originalOrder.cloneForRevision(); revisedOrder.setEncounter(encounterService.getEncounter(5)); revisedOrder.setInstructions("Take after a meal"); revisedOrder.setDateActivated(new Date()); revisedOrder.setOrderer(providerService.getProvider(1)); revisedOrder.setEncounter(encounterService.getEncounter(3)); orderService.saveOrder(revisedOrder, null); List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null); assertEquals(originalOrderCount, activeOrders.size()); assertEquals(revisedOrder.getDateActivated(), DateUtils.addSeconds(originalOrder.getDateStopped(), 1)); assertFalse(originalOrder.isActive()); }
Encounter encounter = encounterService.getEncounter(3); assertTrue(OrderUtilTest.isActiveOrder(firstOrderToDiscontinue, null)); Patient patient = firstOrderToDiscontinue.getPatient(); int ordersCount = orderService.getActiveOrders(patient, null, null, null).size(); assertEquals(patient, secondOrderToDiscontinue.getPatient()); assertTrue(OrderUtilTest.isActiveOrder(secondOrderToDiscontinue, null)); Order discontinuationOrder2 = orderService.discontinueOrder(secondOrderToDiscontinue, "Testing", null, orderer,
asOfDate = order.getDateActivated(); List<? extends Order> orders = getActiveOrders(order.getPatient(), order.getOrderType(), order.getCareSetting(), asOfDate); boolean isDrugOrderAndHasADrug = isDrugOrder(order)
assertEquals(anOrder.getPatient(), orderThatCanDiscontinueTheOrder.getPatient());
final Patient patient = originalOrder.getPatient(); List<Order> originalActiveOrders = orderService.getActiveOrders(patient, null, null, null); final int originalOrderCount = originalActiveOrders.size();
/** * @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); }
target.setPatient(getPatient()); target.setOrderType(getOrderType()); target.setScheduledDate(getScheduledDate());
/** * @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());
@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)); 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"));