Skip to content

Commit

Permalink
Responding to review comments for: The API should be able to assign
Browse files Browse the repository at this point in the history
OrderTypes - TRUNK-4302
  • Loading branch information
dkayiwa committed Mar 26, 2014
1 parent 3d7e18f commit 2345580
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 68 deletions.
23 changes: 23 additions & 0 deletions api/src/main/java/org/openmrs/api/OrderService.java
Expand Up @@ -19,6 +19,7 @@

import org.openmrs.CareSetting;
import org.openmrs.Concept;
import org.openmrs.ConceptClass;
import org.openmrs.Encounter;
import org.openmrs.Order;
import org.openmrs.OrderFrequency;
Expand Down Expand Up @@ -575,4 +576,26 @@ public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, D
*/
@Authorized(PrivilegeConstants.MANAGE_ORDER_TYPES)
public List<OrderType> getSubtypes(OrderType orderType, boolean includeRetired);

/**
* Gets the order type mapped to a given concept class
*
* @param conceptClass the concept class
* @return the matching order type
* @since 1.10
* @should get order type mapped to the given concept class
*/
@Authorized(PrivilegeConstants.VIEW_ORDER_TYPES)
public OrderType getOrderTypeByConceptClass(ConceptClass conceptClass);

/**
* Gets the order type mapped to a given concept
*
* @param concept the concept
* @return the matching order type
* @since 1.10
* @should get order type mapped to the given concept
*/
@Authorized(PrivilegeConstants.VIEW_ORDER_TYPES)
public OrderType getOrderTypeByConcept(Concept concept);
}
5 changes: 1 addition & 4 deletions api/src/main/java/org/openmrs/api/db/OrderDAO.java
Expand Up @@ -197,10 +197,7 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
public List<OrderType> getOrderTypes(boolean includeRetired);

/**
* Gets the order type mapped to a given concept class
*
* @param conceptClass the concept class
* @return the matching order type
* @see org.openmrs.api.OrderService#getOrderTypeByConceptClass(org.openmrs.ConceptClass)
*/
public OrderType getOrderTypeByConceptClass(ConceptClass conceptClass);

Expand Down
20 changes: 16 additions & 4 deletions api/src/main/java/org/openmrs/api/handler/OrderSaveHandler.java
Expand Up @@ -13,12 +13,15 @@
*/
package org.openmrs.api.handler;

import java.util.Date;

import org.openmrs.Order;
import org.openmrs.OrderType;
import org.openmrs.User;
import org.openmrs.annotation.Handler;
import org.openmrs.aop.RequiredDataAdvice;

import java.util.Date;
import org.openmrs.api.APIException;
import org.openmrs.api.context.Context;

/**
* This class deals with {@link Order} objects when they are saved via a save* method in an Openmrs
Expand All @@ -37,7 +40,16 @@ public class OrderSaveHandler implements SaveHandler<Order> {
* java.util.Date, java.lang.String)
*/
public void handle(Order order, User creator, Date dateCreated, String other) {
if (order.getPatient() == null && order.getEncounter() != null)
if (order.getPatient() == null && order.getEncounter() != null) {
order.setPatient(order.getEncounter().getPatient());
}

if (order.getOrderType() == null) {

This comment has been minimized.

Copy link
@wluyima

wluyima Mar 26, 2014

Member

There is code in the OrderServiceImpl.saveOrder that was doing something similar to this, you might have broken some units tests. I made this suggestion before we added the other code, so probably this is no longer needed here in the handler, Sorry about that i should have hinted you.

This comment has been minimized.

Copy link
@wluyima

wluyima Mar 27, 2014

Member

Removed this at f5d4bec

OrderType orderType = Context.getOrderService().getOrderTypeByConcept(order.getConcept());
if (orderType == null) {
throw new APIException("No order type matches the concept class");
}
order.setOrderType(orderType);
}
}
}
}
40 changes: 19 additions & 21 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Expand Up @@ -633,26 +633,6 @@ public List<OrderType> getOrderTypes(boolean includeRetired) {
return dao.getOrderTypes(includeRetired);
}

/**
* Gets the order type mapped to a given concept
*
* @param concept the concept
* @return the matching order type
*/
private OrderType getOrderTypeByConcept(Concept concept) {
return getOrderTypeByConceptClass(concept.getConceptClass());
}

/**
* Gets the order type mapped to a given concept class
*
* @param conceptClass the concept class
* @return the matching order type
*/
private OrderType getOrderTypeByConceptClass(ConceptClass conceptClass) {
return dao.getOrderTypeByConceptClass(conceptClass);
}

/**
* @see org.openmrs.api.OrderService#saveOrderType(org.openmrs.OrderType)
*/
Expand Down Expand Up @@ -706,4 +686,22 @@ public List<OrderType> getSubtypes(OrderType orderType, boolean includeRetired)
}
return allSubtypes;
}
}

/**
* @see org.openmrs.api.OrderService#getOrderTypeByConceptClass(org.openmrs.ConceptClass)
*/
@Override
@Transactional(readOnly = true)
public OrderType getOrderTypeByConceptClass(ConceptClass conceptClass) {
return dao.getOrderTypeByConceptClass(conceptClass);
}

/**
* @see org.openmrs.api.OrderService#getOrderTypeByConcept(org.openmrs.Concept)
*/
@Override
@Transactional(readOnly = true)
public OrderType getOrderTypeByConcept(Concept concept) {
return Context.getOrderService().getOrderTypeByConceptClass(concept.getConceptClass());
}
}
13 changes: 13 additions & 0 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Expand Up @@ -40,6 +40,7 @@
import org.junit.rules.ExpectedException;
import org.openmrs.CareSetting;
import org.openmrs.Concept;
import org.openmrs.ConceptClass;
import org.openmrs.ConceptName;
import org.openmrs.Drug;
import org.openmrs.DrugOrder;
Expand Down Expand Up @@ -1681,4 +1682,16 @@ public void getDiscontinuationOrder_shouldReturnNullIfOrderHasNotBeenDiscontinue

assertThat(discontinuationOrder, is(nullValue()));
}

/**
* @see OrderService#getOrderTypeByConceptClass(ConceptClass)
* @verifies return order type mapped to given concept class
*/
@Test
public void getOrderTypeByConceptClass_shouldReturnOrderTypeMappedToGivenConceptClass() throws Exception {
OrderType orderType = orderService.getOrderTypeByConceptClass(Context.getConceptService().getConceptClass(1));

Assert.assertNotNull(orderType);
Assert.assertEquals(2, orderType.getOrderTypeId().intValue());
}

This comment has been minimized.

Copy link
@wluyima

wluyima Mar 26, 2014

Member

Where is the test for getOrderTypeByConcept?

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa via email Mar 26, 2014

Author Member
}

This file was deleted.

0 comments on commit 2345580

Please sign in to comment.