/** * Checks whether orderable of this drug order is same as other order * * @since 1.10 * @param otherOrder the other order to match on * @return true if the drugs match * @should return false if the other order is null * @should return false if the other order is not a drug order * @should return false if both drugs are null and the concepts are different * @should return false if the concepts match and only this has a drug * @should return false if the concepts match and only the other has a drug * @should return false if the concepts match and drugs are different and not null * @should return true if both drugs are null and the concepts match * @should return true if the drugs match */ @Override public boolean hasSameOrderableAs(Order otherOrder) { if (!super.hasSameOrderableAs(otherOrder)) { return false; } if (!(otherOrder instanceof DrugOrder)) { return false; } DrugOrder otherDrugOrder = (DrugOrder) otherOrder; if (isNonCodedDrug() || otherDrugOrder.isNonCodedDrug()) { return OpenmrsUtil.nullSafeEqualsIgnoreCase(this.getDrugNonCoded(), otherDrugOrder.getDrugNonCoded()); } return OpenmrsUtil.nullSafeEquals(this.getDrug(), otherDrugOrder.getDrug()); }
@Override public String toString() { String prefix = DISCONTINUE == getAction() ? "DC " : ""; return prefix + "DrugOrder(" + getDose() + getDoseUnits() + " of " + (isNonCodedDrug() ? getDrugNonCoded() : (getDrug() != null ? getDrug().getName() : "[no drug]")) + " from " + getDateActivated() + " to " + (isDiscontinuedRightNow() ? getDateStopped() : getAutoExpireDate()) + ")"; }
/** * @see org.openmrs.Order#cloneForDiscontinuing() * @should set all the relevant fields * @since 1.10 */ @Override public DrugOrder cloneForDiscontinuing() { DrugOrder newOrder = new DrugOrder(); newOrder.setCareSetting(getCareSetting()); newOrder.setConcept(getConcept()); newOrder.setAction(DISCONTINUE); newOrder.setPreviousOrder(this); newOrder.setPatient(getPatient()); newOrder.setDrug(getDrug()); newOrder.setOrderType(getOrderType()); newOrder.setDrugNonCoded(getDrugNonCoded()); return newOrder; }
@Test public void saveOrder_shouldFailIfDrugNonCodedInPreviousDrugOrderDoesNotMatchThatOfTheRevisedDrugOrder() { executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml"); DrugOrder previousOrder = (DrugOrder) orderService.getOrder(584); DrugOrder order = previousOrder.cloneForRevision(); String drugNonCodedParacetemol = "non coded aspirin"; order.setDateActivated(new Date()); order.setOrderer(providerService.getProvider(1)); order.setEncounter(encounterService.getEncounter(6)); assertFalse(previousOrder.getDrugNonCoded().equals(drugNonCodedParacetemol)); order.setDrugNonCoded(drugNonCodedParacetemol); order.setPreviousOrder(previousOrder); expectedException.expect(EditedOrderDoesNotMatchPreviousException.class); expectedException.expectMessage("The orderable of the previous order and the new one order don't match"); orderService.saveOrder(order, null); }
/** * @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 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; }