Skip to content

Commit

Permalink
Add isType() method to Order class - TRUNK-4290
Browse files Browse the repository at this point in the history
Follow up - TRUNK-4290
  • Loading branch information
wluyima committed Mar 21, 2014
1 parent 3723e8c commit f00b9f0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
25 changes: 25 additions & 0 deletions api/src/main/java/org/openmrs/Order.java
Expand Up @@ -555,6 +555,7 @@ public void setCareSetting(CareSetting careSetting) {

/**
* Get the {@link org.openmrs.OrderType}
*
* @return the {@link org.openmrs.OrderType}
*/
public OrderType getOrderType() {
Expand All @@ -563,6 +564,7 @@ public OrderType getOrderType() {

/**
* Set the {@link org.openmrs.OrderType}
*
* @param orderType the {@link org.openmrs.OrderType}
*/
public void setOrderType(OrderType orderType) {
Expand Down Expand Up @@ -615,4 +617,27 @@ public Order cloneForRevision() {
newOrder.setOrderReasonNonCoded(this.getOrderReasonNonCoded());
return newOrder;
}

/**
* Checks whether this order's orderType matches or is a sub type of the specified one
*
* @since 1.10
* @param orderType the orderType to match on
* @return true if the type of the order matches or is a sub type of the other order
* @should true if it is the same or is a subtype
* @should false if it neither the same nor a subtype
*/
public boolean isType(OrderType orderType) {
if (this.orderType.equals(orderType)) {
return true;
}
OrderType parentType = this.orderType.getParent();
while (parentType != null) {
if (parentType.equals(orderType)) {
return true;
}
parentType = parentType.getParent();
}
return false;
}
}
31 changes: 31 additions & 0 deletions api/src/test/java/org/openmrs/OrderTest.java
Expand Up @@ -192,4 +192,35 @@ public void cloneForRevision_shouldSetAllTheRelevantFields() throws Exception {
"dateChanged", "voided", "dateVoided", "voidedBy", "voidReason", "encounter", "orderNumber", "orderer",
"previousOrder", "startDate", "dateStopped");
}

/**
* @verifies true if it is the same or is a subtype
* @see Order#isType(OrderType)
*/
@Test
public void isType_shouldTrueIfItIsTheSameOrIsASubtype() throws Exception {
Order order = new Order();
OrderType orderType = new OrderType();
OrderType subType1 = new OrderType();
OrderType subType2 = new OrderType();
subType2.setParent(subType1);
subType1.setParent(orderType);
order.setOrderType(subType2);

assertTrue(order.isType(subType2));
assertTrue(order.isType(subType1));
assertTrue(order.isType(orderType));
}

/**
* @verifies false if it neither the same nor a subtype
* @see Order#isType(OrderType)
*/
@Test
public void isType_shouldFalseIfItNeitherTheSameNorASubtype() throws Exception {
Order order = new Order();
order.setOrderType(new OrderType());

assertFalse(order.isType(new OrderType()));
}
}

0 comments on commit f00b9f0

Please sign in to comment.