/** * Sets autoExpireDate based on duration. * * @should delegate calculation to dosingInstructions * @should not calculate for discontinue action * @should not calculate if autoExpireDate already set */ public void setAutoExpireDateBasedOnDuration() { if (DISCONTINUE != getAction() && getAutoExpireDate() == null) { setAutoExpireDate(getDosingInstructionsInstance().getAutoExpireDate(this)); } }
/** * @see DrugOrder#setAutoExpireDateBasedOnDuration() */ @Test public void setAutoExpireDateBasedOnDuration_shouldDelegateCalculationToDosingInstructions() { DrugOrder drugOrder = spy(new DrugOrder()); drugOrder.setAutoExpireDate(null); DosingInstructions dosingInstructions = mock(DosingInstructions.class); when(drugOrder.getDosingInstructionsInstance()).thenReturn(dosingInstructions); Date expectedAutoExpireDate = new Date(); when(dosingInstructions.getAutoExpireDate(drugOrder)).thenReturn(expectedAutoExpireDate); drugOrder.setAutoExpireDateBasedOnDuration(); assertEquals(expectedAutoExpireDate, drugOrder.getAutoExpireDate()); }
@Test public void shouldAllowToSetCustomDosingTypes() { DrugOrder drugOrder = new DrugOrder(); assertEquals(SimpleDosingInstructions.class, drugOrder.getDosingType()); CustomDosingInstructions customDosingInstructions = new CustomDosingInstructions(); drugOrder.setDosingType(customDosingInstructions.getClass()); DosingInstructions dosingInstructionsObject = drugOrder.getDosingInstructionsInstance(); assertEquals(customDosingInstructions.getClass(), dosingInstructionsObject.getClass()); assertEquals(customDosingInstructions.getClass(), drugOrder.getDosingType()); }
DosingInstructions dosingInstructions = order.getDosingInstructionsInstance(); dosingInstructions.validate(order, errors);
/** * @see OrderResource1_10#getDisplayString(org.openmrs.Order) */ @PropertyGetter("display") public static String getDisplay(DrugOrder delegate) { StringBuilder ret = new StringBuilder(); ret.append("(" + delegate.getAction() + ") "); if (delegate.getDrug() != null) { ret.append(delegate.getDrug().getName()); } else { ret.append(delegate.getConcept().getDisplayString()); } if (Order.Action.DISCONTINUE != delegate.getAction() && delegate.getDosingType() != null && delegate.getDosingInstructionsInstance() != null) { String dosingInstructionsAsString = delegate.getDosingInstructionsInstance().getDosingInstructionsAsString( Context.getLocale()); ret.append(": "); ret.append(dosingInstructionsAsString); } return ret.toString(); } }