Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1555f99243c2
Choose a base ref
...
head repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d846c3fa80d8
Choose a head ref
  • 2 commits
  • 20 files changed
  • 2 contributors

Commits on Mar 13, 2014

  1. Add order_type column to orders table - TRUNK-4287

    TRUNK-4287: order_type field added to Order.hbm.xml
    
    TRUNK-4287: Updated OrderService.getOrders(...) and OrderService.getActiveOrders(...) that should use OrderType as a parameter, not a java class
    
    TRUNK-4287: Boundaries removed from OrderService.getOrders(...), OrderService.getActiveOrders(...) and OrderService.getOrder(...)
    
    TRUNK-4287: Changed the methods in the OrderDAO.java and in the HibernateOrderDAO.java implementation
    
    TRUNK-4287: Set order_type column
    
    TRUNK-4287: Test if there's any order which has no type, then set all orders with a matching row in the test_order or drug_order table of their type
    
    TRUNK-4287: Changes applied as advised
    Andrew Szell authored and wluyima committed Mar 13, 2014
    Copy the full SHA
    3303068 View commit details
  2. Follow up to Add order_type column to orders table - TRUNK-4287

    Follow  - TRUNK-4287
    wluyima committed Mar 13, 2014
    Copy the full SHA
    d846c3f View commit details
2 changes: 2 additions & 0 deletions api/src/main/java/org/openmrs/DrugOrder.java
Original file line number Diff line number Diff line change
@@ -434,6 +434,7 @@ public Order cloneForDiscontinuing() {
newOrder.setPreviousOrder(this);
newOrder.setPatient(this.getPatient());
newOrder.setDrug(this.getDrug());
newOrder.setOrderType(this.getOrderType());
newOrder.setStartDate(this.getStartDate());
return newOrder;
}
@@ -454,6 +455,7 @@ public Order cloneForRevision() {
newOrder.setAction(Action.REVISE);
newOrder.setPreviousOrder(this);
newOrder.setPatient(this.getPatient());
newOrder.setOrderType(this.getOrderType());
newOrder.setInstructions(this.getInstructions());
newOrder.setUrgency(this.getUrgency());
newOrder.setCommentToFulfiller(this.getCommentToFulfiller());
21 changes: 21 additions & 0 deletions api/src/main/java/org/openmrs/Order.java
Original file line number Diff line number Diff line change
@@ -85,6 +85,8 @@ public enum Action {

private CareSetting careSetting;

private OrderType orderType;

private Date scheduledDate;

/**
@@ -131,6 +133,7 @@ public Order copy() {
protected Order copyHelper(Order target) {
target.setPatient(getPatient());
target.setConcept(getConcept());
target.setOrderType(getOrderType());
target.setInstructions(getInstructions());
target.setStartDate(getStartDate());
target.setAutoExpireDate(getAutoExpireDate());
@@ -550,6 +553,22 @@ public void setCareSetting(CareSetting careSetting) {
this.careSetting = careSetting;
}

/**
* Get the {@link org.openmrs.OrderType}
* @return the {@link org.openmrs.OrderType}
*/
public OrderType getOrderType() {
return orderType;
}

/**
* Set the {@link org.openmrs.OrderType}
* @param orderType the {@link org.openmrs.OrderType}
*/
public void setOrderType(OrderType orderType) {
this.orderType = orderType;
}

/**
* Creates a discontinuation order for this order, sets the previousOrder and action fields,
* note that the discontinuation order needs to be saved for the discontinuation to take effect
@@ -565,6 +584,7 @@ public Order cloneForDiscontinuing() {
newOrder.setAction(Action.DISCONTINUE);
newOrder.setPreviousOrder(this);
newOrder.setPatient(this.getPatient());
newOrder.setOrderType(getOrderType());
newOrder.setStartDate(this.getStartDate());

return newOrder;
@@ -584,6 +604,7 @@ public Order cloneForRevision() {
newOrder.setAction(Action.REVISE);
newOrder.setPreviousOrder(this);
newOrder.setPatient(this.getPatient());
newOrder.setOrderType(this.getOrderType());
newOrder.setScheduledDate(getScheduledDate());
newOrder.setInstructions(this.getInstructions());
newOrder.setUrgency(this.getUrgency());
1 change: 1 addition & 0 deletions api/src/main/java/org/openmrs/TestOrder.java
Original file line number Diff line number Diff line change
@@ -166,6 +166,7 @@ public Order cloneForRevision() {
newOrder.setAction(Action.REVISE);
newOrder.setPreviousOrder(this);
newOrder.setPatient(this.getPatient());
newOrder.setOrderType(this.getOrderType());
newOrder.setInstructions(this.getInstructions());
newOrder.setUrgency(this.getUrgency());
newOrder.setCommentToFulfiller(this.getCommentToFulfiller());
33 changes: 9 additions & 24 deletions api/src/main/java/org/openmrs/api/OrderService.java
Original file line number Diff line number Diff line change
@@ -129,35 +129,21 @@ public interface OrderService extends OpenmrsService {
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public Order getOrderByUuid(String uuid) throws APIException;

/**
* Gets the order with the associated order id
*
* @param <Ord> An Order type. Currently only org.openmrs.Order or org.openmrs.DrugOrder
* @param orderId the primary key of the Order
* @param orderClassType The class of Order to fetch (Currently only org.openmrs.Order or
* org.openmrs.DrugOrder)
* @return The Order in the system corresponding to given primary key id
* @throws APIException
*/
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public <Ord extends Order> Ord getOrder(Integer orderId, Class<Ord> orderClassType) throws APIException;

/**
* This searches for orders given the parameters. Most arguments are optional (nullable). If
* multiple arguments are given, the returned orders will match on all arguments. The orders are
* sorted by startDate with the latest coming first
*
* @param orderClassType The type of Order to get (currently only options are Order and
* DrugOrder)
* @param orderType The type of Order to get
* @param patients The patients to get orders for
* @param concepts The concepts in order.getConcept to get orders for
* @param orderers The users/orderers of the
* @param encounters The encounters that the orders are assigned to
* @return list of Orders matching the parameters
*/
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<Patient> patients,
List<Concept> concepts, List<User> orderers, List<Encounter> encounters);
public List<Order> getOrders(OrderType orderType, List<Patient> patients, List<Concept> concepts, List<User> orderers,
List<Encounter> encounters);

/**
* Unvoid order record. Reverse a previous call to {@link #voidOrder(Order, String)}
@@ -209,14 +195,14 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
*
* @param orderNumber the order number whose history to get
* @return a list of orders for given order number
* @should return return all order history for given order number
* @should return all order history for given order number
*/
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public List<Order> getOrderHistoryByOrderNumber(String orderNumber);

/**
* Gets all active orders for the specified patient matching the specified CareSetting, Order
* class as of the specified date. Below is the criteria for determining an active order:
* Gets all active orders for the specified patient matching the specified CareSetting,
* OrderType as of the specified date. Below is the criteria for determining an active order:
*
* <pre>
* <p>
@@ -231,7 +217,7 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
* <pre/>
*
* @param patient the patient
* @param orderClass the order class to match against, this is required
* @param orderType The OrderType to match
* @param careSetting the care setting, returns all ignoring care setting if value is null
* @param asOfDate defaults to current time
* @return all active orders for given patient parameters
@@ -242,11 +228,10 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
* @should return all active test orders for the specified patient
* @should fail if patient is null
* @should return active orders as of the specified date
* @should default to Order class if no orderClass is specified
* @should return all orders if no orderType is specified
*/
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public <Ord extends Order> List<Ord> getActiveOrders(Patient patient, Class<Ord> orderClass, CareSetting careSetting,
Date asOfDate);
public List<Order> getActiveOrders(Patient patient, OrderType orderType, CareSetting careSetting, Date asOfDate);

/**
* Retrieve care setting
24 changes: 7 additions & 17 deletions api/src/main/java/org/openmrs/api/db/OrderDAO.java
Original file line number Diff line number Diff line change
@@ -17,14 +17,7 @@
import java.util.List;
import java.util.Locale;

import org.openmrs.CareSetting;
import org.openmrs.Concept;
import org.openmrs.Encounter;
import org.openmrs.Order;
import org.openmrs.OrderFrequency;
import org.openmrs.Patient;
import org.openmrs.User;
import org.openmrs.OrderType;
import org.openmrs.*;

/**
* Order-related database functions
@@ -53,14 +46,13 @@ public interface OrderDAO {
/**
* @see org.openmrs.api.OrderService#getOrder(Integer)
*/
public <Ord extends Order> Ord getOrder(Integer orderId, Class<Ord> classType) throws DAOException;
public Order getOrder(Integer orderId) throws DAOException;

/**
* @see org.openmrs.api.OrderService#getOrders(java.lang.Class, java.util.List, java.util.List,
* java.util.List, java.util.List)
* @see org.openmrs.api.OrderService#getOrders(org.openmrs.OrderType, java.util.List, java.util.List, java.util.List, java.util.List)
*/
public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<Patient> patients,
List<Concept> concepts, List<User> orderers, List<Encounter> encounters);
public List<Order> getOrders(OrderType orderType, List<Patient> patients, List<Concept> concepts, List<User> orderers,
List<Encounter> encounters);

/**
* Auto generated method comment
@@ -88,11 +80,9 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
public Long getNextOrderNumberSeedSequenceValue();

/**
* @see org.openmrs.api.OrderService#getActiveOrders(org.openmrs.Patient, Class,
* org.openmrs.CareSetting, java.util.Date)
* @see org.openmrs.api.OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType, org.openmrs.CareSetting, java.util.Date)
*/
public <Ord extends Order> List<Ord> getActiveOrders(Patient patient, Class<Ord> orderClass, CareSetting careSetting,
Date asOfDate);
public List<Order> getActiveOrders(Patient patient, OrderType orderType, CareSetting careSetting, Date asOfDate);

/**
* Get care setting by type
Original file line number Diff line number Diff line change
@@ -33,16 +33,8 @@
import org.hibernate.criterion.Restrictions;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.transform.DistinctRootEntityResultTransformer;
import org.openmrs.CareSetting;
import org.openmrs.Concept;
import org.openmrs.Encounter;
import org.openmrs.GlobalProperty;
import org.openmrs.Order;
import org.openmrs.*;
import org.openmrs.Order.Action;
import org.openmrs.OrderFrequency;
import org.openmrs.Patient;
import org.openmrs.User;
import org.openmrs.OrderType;
import org.openmrs.api.APIException;
import org.openmrs.api.db.DAOException;
import org.openmrs.api.db.OrderDAO;
@@ -102,22 +94,24 @@ public void deleteOrder(Order order) throws DAOException {
* @see org.openmrs.api.OrderService#getOrder(java.lang.Integer)
*/
@SuppressWarnings("unchecked")
public <Ord extends Order> Ord getOrder(Integer orderId, Class<Ord> orderClassType) throws DAOException {
public Order getOrder(Integer orderId) throws DAOException {
if (log.isDebugEnabled())
log.debug("getting order #" + orderId + " with class: " + orderClassType);
log.debug("getting order #" + orderId);

return (Ord) sessionFactory.getCurrentSession().get(orderClassType, orderId);
return (Order) sessionFactory.getCurrentSession().get(Order.class, orderId);
}

/**
* @see org.openmrs.api.db.OrderDAO#getOrders(java.lang.Class, java.util.List, java.util.List,
* java.util.List, java.util.List)
* @see org.openmrs.api.db.OrderDAO#getOrders(org.openmrs.OrderType, java.util.List, java.util.List, java.util.List, java.util.List)
*/
@SuppressWarnings("unchecked")
public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<Patient> patients,
List<Concept> concepts, List<User> orderers, List<Encounter> encounters) {
public List<Order> getOrders(OrderType orderType, List<Patient> patients, List<Concept> concepts, List<User> orderers,
List<Encounter> encounters) {

Criteria crit = sessionFactory.getCurrentSession().createCriteria(orderClassType);
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Order.class);

if (orderType != null)
crit.add(Restrictions.eq("orderType", orderType));

if (patients.size() > 0)
crit.add(Restrictions.in("patient", patients));
@@ -201,14 +195,16 @@ public Long getNextOrderNumberSeedSequenceValue() {
}

/**
* @see org.openmrs.api.db.OrderDAO#getActiveOrders(org.openmrs.Patient, Class,
* org.openmrs.CareSetting, java.util.Date)
* @see org.openmrs.api.db.OrderDAO#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType, org.openmrs.CareSetting, java.util.Date)
*/
@SuppressWarnings("unchecked")
public <Ord extends Order> List<Ord> getActiveOrders(Patient patient, Class<Ord> orderClass, CareSetting careSetting,
Date asOfDate) {
public List<Order> getActiveOrders(Patient patient, OrderType orderType, CareSetting careSetting, Date asOfDate) {

Criteria crit = sessionFactory.getCurrentSession().createCriteria(Order.class);

Criteria crit = sessionFactory.getCurrentSession().createCriteria(orderClass);
if (orderType != null) {
crit.add(Restrictions.eq("orderType", orderType));
}

crit.add(Restrictions.eq("patient", patient));
if (careSetting != null) {
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public void handle(Patient patient, User originalVoidingUser, Date origParentVoi
OrderService os = Context.getOrderService();
List<Patient> patients = new ArrayList<Patient>();
patients.add(patient);
List<Order> orders = os.getOrders(Order.class, patients, null, null, null);
List<Order> orders = os.getOrders(null, patients, null, null, null);
if (CollectionUtils.isNotEmpty(orders)) {
for (Order order : orders) {
if (order.isVoided() && order.getDateVoided().equals(origParentVoidedDate)
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ public void handle(Patient patient, User voidingUser, Date voidedDate, String vo
OrderService os = Context.getOrderService();
List<Patient> patients = new ArrayList<Patient>();
patients.add(patient);
List<Order> orders = os.getOrders(Order.class, patients, null, null, null);
List<Order> orders = os.getOrders(null, patients, null, null, null);
if (CollectionUtils.isNotEmpty(orders)) {
for (Order order : orders) {
if (!order.isVoided()) {
40 changes: 13 additions & 27 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
@@ -160,14 +160,16 @@ private void discontinueExistingOrdersIfNecessary(Order order) {
}

//Mark first order found corresponding to this DC order as discontinued.
List<? extends Order> orders = getActiveOrders(order.getPatient(), order.getClass(), order.getCareSetting(), null);
List<? extends Order> orders = getActiveOrders(order.getPatient(), order.getOrderType(), order.getCareSetting(),
null);
boolean isDrugOrderAndHasADrug = DrugOrder.class.isAssignableFrom(order.getClass())
&& ((DrugOrder) order).getDrug() != null;
for (Order activeOrder : orders) {
boolean shouldMarkAsDiscontinued = false;
//For drug orders, the drug must match if the order has a drug
if (isDrugOrderAndHasADrug) {
DrugOrder drugOrder1 = (DrugOrder) order;
System.out.println("ID:" + activeOrder.getId());
DrugOrder drugOrder2 = (DrugOrder) activeOrder;
if (OpenmrsUtil.nullSafeEquals(drugOrder1.getDrug(), drugOrder2.getDrug())) {
shouldMarkAsDiscontinued = true;
@@ -244,28 +246,16 @@ public Order unvoidOrder(Order order) throws APIException {
*/
@Transactional(readOnly = true)
public Order getOrder(Integer orderId) throws APIException {
return getOrder(orderId, Order.class);
return dao.getOrder(orderId);
}

/**
* @see org.openmrs.api.OrderService#getOrder(java.lang.Integer, java.lang.Class)
* @see org.openmrs.api.OrderService#getOrders(org.openmrs.OrderType, java.util.List,
* java.util.List, java.util.List, java.util.List)
*/
@Transactional(readOnly = true)
public <o extends Order> o getOrder(Integer orderId, Class<o> orderClassType) throws APIException {
return dao.getOrder(orderId, orderClassType);
}

/**
* @see org.openmrs.api.OrderService#getOrders(java.lang.Class, java.util.List, java.util.List,
* java.util.List, java.util.List)
*/
@Transactional(readOnly = true)
public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<Patient> patients,
List<Concept> concepts, List<User> orderers, List<Encounter> encounters) {
if (orderClassType == null)
throw new APIException(
"orderClassType cannot be null. An order type of Order.class or DrugOrder.class is required");

public List<Order> getOrders(OrderType orderType, List<Patient> patients, List<Concept> concepts, List<User> orderers,
List<Encounter> encounters) {
if (patients == null)
patients = new Vector<Patient>();

@@ -278,7 +268,7 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
if (encounters == null)
encounters = new Vector<Encounter>();

return dao.getOrders(orderClassType, patients, concepts, orderers, encounters);
return dao.getOrders(orderType, patients, concepts, orderers, encounters);
}

/**
@@ -323,7 +313,7 @@ public List<Order> getOrderHistoryByConcept(Patient patient, Concept concept) {
List<Patient> patients = new Vector<Patient>();
patients.add(patient);

return getOrders(Order.class, patients, concepts, null, null);
return getOrders(null, patients, concepts, null, null);
}

/**
@@ -351,23 +341,19 @@ public List<Order> getOrderHistoryByOrderNumber(String orderNumber) {
}

/**
* @see org.openmrs.api.OrderService#getActiveOrders(org.openmrs.Patient, Class,
* @see org.openmrs.api.OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
* org.openmrs.CareSetting, java.util.Date)
*/
@Override
@Transactional(readOnly = true)
public <Ord extends Order> List<Ord> getActiveOrders(Patient patient, Class<Ord> orderClass, CareSetting careSetting,
Date asOfDate) {
public List<Order> getActiveOrders(Patient patient, OrderType orderType, CareSetting careSetting, Date asOfDate) {
if (patient == null) {
throw new IllegalArgumentException("Patient is required when fetching active orders");
}
if (asOfDate == null) {
asOfDate = new Date();
}
if (orderClass == null) {
orderClass = (Class<Ord>) Order.class;
}
return dao.getActiveOrders(patient, orderClass, careSetting, asOfDate);
return dao.getActiveOrders(patient, orderType, careSetting, asOfDate);
}

/**
Loading