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: 3dcf4c6be5a0
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: 6ad9d86e76d3
Choose a head ref
  • 2 commits
  • 19 files changed
  • 1 contributor

Commits on Mar 17, 2014

  1. Fixed faulty not null constraints in Order.hbm.xml and updated the ex…

    …isting test data and methods
    
    Fixed failing tests
    wluyima committed Mar 17, 2014
    Copy the full SHA
    772e3ce View commit details
  2. 2
    Copy the full SHA
    6ad9d86 View commit details
Showing with 355 additions and 156 deletions.
  1. +24 −11 api/src/main/java/org/openmrs/api/OrderService.java
  2. +27 −3 api/src/main/java/org/openmrs/api/db/OrderDAO.java
  3. +56 −19 api/src/main/java/org/openmrs/api/db/hibernate/HibernateOrderDAO.java
  4. +1 −4 api/src/main/java/org/openmrs/api/handler/PatientDataUnvoidHandler.java
  5. +1 −4 api/src/main/java/org/openmrs/api/handler/PatientDataVoidHandler.java
  6. +23 −20 api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
  7. +7 −21 api/src/main/resources/org/openmrs/api/db/hibernate/Order.hbm.xml
  8. +17 −7 api/src/test/java/org/openmrs/OrderEntryIntegrationTest.java
  9. +8 −5 api/src/test/java/org/openmrs/api/EncounterServiceTest.java
  10. +141 −12 api/src/test/java/org/openmrs/api/OrderServiceTest.java
  11. +2 −6 api/src/test/java/org/openmrs/api/PatientServiceTest.java
  12. +16 −16 api/src/test/java/org/openmrs/api/handler/PatientDataUnvoidHandlerTest.java
  13. +2 −5 api/src/test/java/org/openmrs/api/handler/PatientDataVoidHandlerTest.java
  14. +3 −3 api/src/test/resources/org/openmrs/api/include/EncounterServiceTest-initialData.xml
  15. +2 −1 api/src/test/resources/org/openmrs/api/include/OrderEntryIntegrationTest-other.xml
  16. +3 −3 api/src/test/resources/org/openmrs/api/include/OrderServiceTest-deleteObsThatReference.xml
  17. +2 −2 api/src/test/resources/org/openmrs/api/include/OrderServiceTest-discontinuedOrder.xml
  18. +5 −0 api/src/test/resources/org/openmrs/api/include/OrderServiceTest-otherEncounters.xml
  19. +15 −14 api/src/test/resources/org/openmrs/include/standardTestDataset.xml
35 changes: 24 additions & 11 deletions api/src/main/java/org/openmrs/api/OrderService.java
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.openmrs.OrderType;
import org.openmrs.Patient;
import org.openmrs.Provider;
import org.openmrs.User;
import org.openmrs.annotation.Authorized;
import org.openmrs.api.db.OrderDAO;
import org.openmrs.util.PrivilegeConstants;
@@ -130,20 +129,34 @@ public interface OrderService extends OpenmrsService {
public Order getOrderByUuid(String uuid) 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
* Gets all Orders that match the specified parameters excluding discontinuation orders
*
* @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
* @param patient the patient to match on
* @param careSetting the CareSetting to match on
* @param orderType The OrderType to match on
* @param includeVoided Specifies whether voided orders should be included or not
* @return list of Orders matching the parameters
* @since 1.10
* @should fail if patient is null
* @should fail if careSetting is null
* @should get the orders that match all the arguments
* @should get all unvoided matches if includeVoided is set to false
* @should include voided matches if includeVoided is set to true
*/
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public List<Order> getOrders(Patient patient, CareSetting careSetting, OrderType orderType, boolean includeVoided);

/**
* Gets all orders for the specified patient including discontinuation orders
*
* @param patient the patient to match on
* @return list of matching {@link org.openmrs.Order}
* @since 1.10
* @should fail if patient is null
* @should get all the orders for the specified patient
*/
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public List<Order> getOrders(OrderType orderType, List<Patient> patients, List<Concept> concepts, List<User> orderers,
List<Encounter> encounters);
public List<Order> getAllOrdersByPatient(Patient patient);

/**
* Unvoid order record. Reverse a previous call to {@link #voidOrder(Order, String)}
30 changes: 27 additions & 3 deletions api/src/main/java/org/openmrs/api/db/OrderDAO.java
Original file line number Diff line number Diff line change
@@ -17,7 +17,14 @@
import java.util.List;
import java.util.Locale;

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

/**
* Order-related database functions
@@ -49,11 +56,27 @@ public interface OrderDAO {
public Order getOrder(Integer orderId) throws DAOException;

/**
* @see org.openmrs.api.OrderService#getOrders(org.openmrs.OrderType, java.util.List, java.util.List, java.util.List, java.util.List)
* 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 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
*/
public List<Order> getOrders(OrderType orderType, List<Patient> patients, List<Concept> concepts, List<User> orderers,
List<Encounter> encounters);

/**
* @see org.openmrs.api.OrderService#getOrders(org.openmrs.Patient, org.openmrs.CareSetting,
* org.openmrs.OrderType, boolean)
*/
public List<Order> getOrders(Patient patient, CareSetting careSetting, OrderType orderType, boolean includeVoided,
boolean includeDiscontinuationOrders);

/**
* Auto generated method comment
*
@@ -80,7 +103,8 @@ public List<Order> getOrders(OrderType orderType, List<Patient> patients, List<C
public Long getNextOrderNumberSeedSequenceValue();

/**
* @see org.openmrs.api.OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType, 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 List<Order> getActiveOrders(Patient patient, OrderType orderType, CareSetting careSetting, Date asOfDate);

Original file line number Diff line number Diff line change
@@ -33,8 +33,15 @@
import org.hibernate.criterion.Restrictions;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.transform.DistinctRootEntityResultTransformer;
import org.openmrs.*;
import org.openmrs.Order.Action;
import org.openmrs.CareSetting;
import org.openmrs.Concept;
import org.openmrs.Encounter;
import org.openmrs.GlobalProperty;
import org.openmrs.Order;
import org.openmrs.OrderFrequency;
import org.openmrs.OrderType;
import org.openmrs.Patient;
import org.openmrs.User;
import org.openmrs.api.APIException;
import org.openmrs.api.db.DAOException;
import org.openmrs.api.db.OrderDAO;
@@ -102,7 +109,8 @@ public Order getOrder(Integer orderId) throws DAOException {
}

/**
* @see org.openmrs.api.db.OrderDAO#getOrders(org.openmrs.OrderType, 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 List<Order> getOrders(OrderType orderType, List<Patient> patients, List<Concept> concepts, List<User> orderers,
@@ -133,6 +141,16 @@ public List<Order> getOrders(OrderType orderType, List<Patient> patients, List<C
return crit.list();
}

/**
* @see OrderDAO#getOrders(org.openmrs.Patient, org.openmrs.CareSetting, org.openmrs.OrderType,
* boolean, boolean)
*/
@Override
public List<Order> getOrders(Patient patient, CareSetting careSetting, OrderType orderType, boolean includeVoided,
boolean includeDiscontinuationOrders) {
return createOrderCriteria(patient, careSetting, orderType, includeVoided, includeDiscontinuationOrders).list();
}

/**
* @see org.openmrs.api.db.OrderDAO#getOrderByUuid(java.lang.String)
*/
@@ -195,25 +213,12 @@ public Long getNextOrderNumberSeedSequenceValue() {
}

/**
* @see org.openmrs.api.db.OrderDAO#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType, 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 List<Order> getActiveOrders(Patient patient, OrderType orderType, CareSetting careSetting, Date asOfDate) {

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

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

crit.add(Restrictions.eq("patient", patient));
if (careSetting != null) {
crit.add(Restrictions.eq("careSetting", careSetting));
}

//See javadocs on OrderService#getActiveOrders for the description of an active Order
crit.add(Restrictions.ne("action", Action.DISCONTINUE));
crit.add(Restrictions.eq("voided", false));
Criteria crit = createOrderCriteria(patient, careSetting, orderType, false, false);

Criterion startDateEqualToOrBeforeAsOfDate = Restrictions.le("startDate", asOfDate);
crit.add(startDateEqualToOrBeforeAsOfDate);
@@ -234,6 +239,38 @@ public List<Order> getActiveOrders(Patient patient, OrderType orderType, CareSet
return crit.list();
}

/**
* Creates and returns a Criteria Object filtering on the specified parameters
*
* @param patient
* @param careSetting
* @param orderType
* @param includeVoided
* @param includeDiscontinuationOrders
* @return
*/
private Criteria createOrderCriteria(Patient patient, CareSetting careSetting, OrderType orderType,
boolean includeVoided, boolean includeDiscontinuationOrders) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Order.class);
if (patient != null) {
criteria.add(Restrictions.eq("patient", patient));
}
if (careSetting != null) {
criteria.add(Restrictions.eq("careSetting", careSetting));
}
if (orderType != null) {
criteria.add(Restrictions.eq("orderType", orderType));
}
if (!includeVoided) {
criteria.add(Restrictions.eq("voided", false));
}
if (!includeDiscontinuationOrders) {
criteria.add(Restrictions.ne("action", Order.Action.DISCONTINUE));
}

return criteria;
}

/**
* @see org.openmrs.api.db.OrderDAO#getCareSetting(Integer)
*/
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
*/
package org.openmrs.api.handler;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@@ -62,9 +61,7 @@ public void handle(Patient patient, User originalVoidingUser, Date origParentVoi

//unvoid all the orders that got voided as a result of the patient getting voided
OrderService os = Context.getOrderService();
List<Patient> patients = new ArrayList<Patient>();
patients.add(patient);
List<Order> orders = os.getOrders(null, patients, null, null, null);
List<Order> orders = os.getAllOrdersByPatient(patient);
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
@@ -13,7 +13,6 @@
*/
package org.openmrs.api.handler;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@@ -67,9 +66,7 @@ public void handle(Patient patient, User voidingUser, Date voidedDate, String vo
}
//void all the orders associated with this patient
OrderService os = Context.getOrderService();
List<Patient> patients = new ArrayList<Patient>();
patients.add(patient);
List<Order> orders = os.getOrders(null, patients, null, null, null);
List<Order> orders = os.getAllOrdersByPatient(patient);
if (CollectionUtils.isNotEmpty(orders)) {
for (Order order : orders) {
if (!order.isVoided()) {
43 changes: 23 additions & 20 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
@@ -169,7 +169,6 @@ private void discontinueExistingOrdersIfNecessary(Order order) {
//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;
@@ -250,25 +249,29 @@ public Order getOrder(Integer orderId) throws APIException {
}

/**
* @see org.openmrs.api.OrderService#getOrders(org.openmrs.OrderType, java.util.List,
* java.util.List, java.util.List, java.util.List)
* @see OrderService#getOrders(org.openmrs.Patient, org.openmrs.CareSetting,
* org.openmrs.OrderType, boolean)
*/
@Transactional(readOnly = true)
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>();

if (concepts == null)
concepts = new Vector<Concept>();

if (orderers == null)
orderers = new Vector<User>();

if (encounters == null)
encounters = new Vector<Encounter>();

return dao.getOrders(orderType, patients, concepts, orderers, encounters);
@Override
public List<Order> getOrders(Patient patient, CareSetting careSetting, OrderType orderType, boolean includeVoided) {
if (patient == null) {
throw new IllegalArgumentException("Patient is required");
}
if (careSetting == null) {
throw new IllegalArgumentException("CareSetting is required");
}
return dao.getOrders(patient, careSetting, orderType, includeVoided, false);
}

/**
* @see OrderService#getAllOrdersByPatient(org.openmrs.Patient)
*/
@Override
public List<Order> getAllOrdersByPatient(Patient patient) {
if (patient == null) {
throw new IllegalArgumentException("Patient is required");
}
return dao.getOrders(patient, null, null, true, true);
}

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

return getOrders(null, patients, concepts, null, null);
return dao.getOrders(null, patients, concepts, new Vector<User>(), new Vector<Encounter>());
}

/**
28 changes: 7 additions & 21 deletions api/src/main/resources/org/openmrs/api/db/hibernate/Order.hbm.xml
Original file line number Diff line number Diff line change
@@ -41,51 +41,37 @@
</type>
</property>

<many-to-one name="careSetting" class="org.openmrs.CareSetting" not-null="true">
<column name="care_setting"/>
</many-to-one>
<many-to-one name="careSetting" column="care_setting" class="org.openmrs.CareSetting" not-null="true" />

<many-to-one name="orderType" class="org.openmrs.OrderType" not-null="true">
<column name="order_type"/>
</many-to-one>
<many-to-one name="orderType" column="order_type" class="org.openmrs.OrderType" not-null="true" />

<!-- bi-directional many-to-one association to Order -->
<many-to-one name="previousOrder" class="org.openmrs.Order">
<column name="previous_order_id" />
</many-to-one>
<!-- bi-directional many-to-one association to Concept -->
<many-to-one name="concept" class="org.openmrs.Concept" not-null="true">
<column name="concept_id" />
</many-to-one>
<many-to-one name="concept" column="concept_id" class="org.openmrs.Concept" not-null="true" />
<!-- bi-directional many-to-one association to Encounter -->
<many-to-one name="encounter" class="org.openmrs.Encounter" not-null="true">
<column name="encounter_id" />
</many-to-one>
<many-to-one name="encounter" column="encounter_id" class="org.openmrs.Encounter" not-null="true" />

<!-- bi-directional many-to-one association to Encounter -->
<many-to-one name="patient" class="org.openmrs.Patient" not-null="true">
<column name="patient_id" />
</many-to-one>
<many-to-one name="patient" column="patient_id" class="org.openmrs.Patient" not-null="true" />

<!-- bi-directional many-to-one association to Concept -->
<many-to-one name="orderReason" class="org.openmrs.Concept" not-null="false">
<column name="order_reason" />
</many-to-one>

<!-- bi-directional many-to-one association to Provider -->
<many-to-one name="orderer" class="org.openmrs.Provider">
<column name="orderer" />
</many-to-one>
<many-to-one name="orderer" class="org.openmrs.Provider" not-null="true" />

<!-- bi-directional many-to-one association to User -->
<many-to-one name="voidedBy" class="org.openmrs.User">
<column name="voided_by" />
</many-to-one>

<!-- bi-directional many-to-one association to User -->
<many-to-one name="creator" class="org.openmrs.User" not-null="true">
<column name="creator" />
</many-to-one>
<many-to-one name="creator" class="org.openmrs.User" not-null="true" />

<joined-subclass name="org.openmrs.DrugOrder" table="drug_order">

Loading