/** * Gets the dosingInstructions instance * * @since 1.10 */ public DosingInstructions getDosingInstructionsInstance() { try { DosingInstructions instructions = getDosingType().newInstance(); return instructions.getDosingInstructions(this); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } }
/** * @see DosingInstructions#getDosingInstructions(DrugOrder) */ @Override public DosingInstructions getDosingInstructions(DrugOrder order) { if (!order.getDosingType().equals(this.getClass())) { throw new APIException("DrugOrder.error.dosingTypeIsMismatched", new Object[] { this.getClass(), order.getDosingType() }); } FreeTextDosingInstructions freeTextDosingInstructions = new FreeTextDosingInstructions(); freeTextDosingInstructions.setInstructions(order.getDosingInstructions()); return freeTextDosingInstructions; }
@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()); }
@Test public void shouldSetDefaultDosingTypeToFreeText() { DrugOrder drugOrder = new DrugOrder(); assertEquals(SimpleDosingInstructions.class, drugOrder.getDosingType()); }
/** * @see DosingInstructions#getDosingInstructions(DrugOrder) */ @Override public DosingInstructions getDosingInstructions(DrugOrder order) { if (!order.getDosingType().equals(this.getClass())) { throw new APIException("DrugOrder.error.dosingTypeIsMismatched", new Object[] { this.getClass().getName(), order.getDosingType() }); } SimpleDosingInstructions simpleDosingInstructions = new SimpleDosingInstructions(); simpleDosingInstructions.setDose(order.getDose()); simpleDosingInstructions.setDoseUnits(order.getDoseUnits()); simpleDosingInstructions.setRoute(order.getRoute()); simpleDosingInstructions.setFrequency(order.getFrequency()); simpleDosingInstructions.setDuration(order.getDuration()); simpleDosingInstructions.setDurationUnits(order.getDurationUnits()); simpleDosingInstructions.setAsNeeded(order.getAsNeeded()); simpleDosingInstructions.setAsNeededCondition(order.getAsNeededCondition()); simpleDosingInstructions.setAdministrationInstructions(order.getDosingInstructions()); return simpleDosingInstructions; }
errors.rejectValue("concept", "error.concept"); if (order.getAction() != Order.Action.DISCONTINUE && order.getDosingType() != null) { DosingInstructions dosingInstructions = order.getDosingInstructionsInstance(); dosingInstructions.validate(order, errors);
/** * @see org.openmrs.Order#copyHelper(Order) */ protected DrugOrder copyHelper(DrugOrder target) { super.copyHelper(target); target.setDose(getDose()); target.setDoseUnits(getDoseUnits()); target.setFrequency(getFrequency()); target.setAsNeeded(getAsNeeded()); target.setAsNeededCondition(getAsNeededCondition()); target.setQuantity(getQuantity()); target.setQuantityUnits(getQuantityUnits()); target.setDrug(getDrug()); target.setDosingType(getDosingType()); target.setDosingInstructions(getDosingInstructions()); target.setDuration(getDuration()); target.setDurationUnits(getDurationUnits()); target.setNumRefills(getNumRefills()); target.setRoute(getRoute()); target.setBrandName(getBrandName()); target.setDispenseAsWritten(getDispenseAsWritten()); target.setDrugNonCoded(getDrugNonCoded()); return target; }
/** * @see Order#cloneForRevisionHelper(Order) */ protected DrugOrder cloneForRevisionHelper(DrugOrder target) { super.cloneForRevisionHelper(target); target.setDose(getDose()); target.setDoseUnits(getDoseUnits()); target.setFrequency(getFrequency()); target.setAsNeeded(getAsNeeded()); target.setAsNeededCondition(getAsNeededCondition()); target.setQuantity(getQuantity()); target.setQuantityUnits(getQuantityUnits()); target.setDrug(getDrug()); target.setDosingType(getDosingType()); target.setDosingInstructions(getDosingInstructions()); target.setDuration(getDuration()); target.setDurationUnits(getDurationUnits()); target.setRoute(getRoute()); target.setNumRefills(getNumRefills()); target.setBrandName(getBrandName()); target.setDispenseAsWritten(getDispenseAsWritten()); target.setDrugNonCoded(getDrugNonCoded()); return target; }
/** * @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(); } }
dosingTypeWidget.setInitialValue(lastRevision.getDosingType().toString());