Skip to content

Commit

Permalink
Merge c6bba8a into a7600d3
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcliff committed Oct 21, 2019
2 parents a7600d3 + c6bba8a commit b4dbff1
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 6 deletions.
22 changes: 22 additions & 0 deletions api/src/main/java/org/openmrs/api/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -812,4 +812,26 @@ public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, D
*/
@Authorized({ PrivilegeConstants.EDIT_ORDERS, PrivilegeConstants.ADD_ORDERS })
public OrderGroup saveOrderGroup(OrderGroup orderGroup) throws APIException;

/**
* Fetches all order groups for the specified patient
*
* @param patient the patient to match on
* @return list of matching OrderGroups
* @since 2.3
* @throws APIException
*/
@Authorized(PrivilegeConstants.GET_ORDERS)
public List<OrderGroup> getOrderGroupsByPatient(Patient patient) throws APIException;

/**
* Fetches all order groups for the specified encounter
*
* @param encounter the encounter to match on
* @return list of matching OrderGroups
* @since 2.3
* @throws APIException
*/
@Authorized(PrivilegeConstants.GET_ORDERS)
public List<OrderGroup> getOrderGroupsByEncounter(Encounter encounter) throws APIException;
}
10 changes: 10 additions & 0 deletions api/src/main/java/org/openmrs/api/db/OrderDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,14 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
* @see org.openmrs.api.OrderService#getOrderGroup(Integer)
*/
public OrderGroup getOrderGroupById(Integer orderGroupId) throws DAOException;

/**
* @see org.openmrs.api.OrderService#getOrderGroupsByPatient(Patient)
*/
public List<OrderGroup> getOrderGroupsByPatient(Patient patient) throws DAOException;

/**
* @see org.openmrs.api.OrderService#getOrderGroupsByEncounter(Encounter)
*/
public List<OrderGroup> getOrderGroupsByEncounter(Encounter encounter) throws DAOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
package org.openmrs.api.db.hibernate;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Calendar;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
Expand Down Expand Up @@ -635,4 +635,30 @@ public boolean isOrderTypeInUse(OrderType orderType) {
criteria.add(Restrictions.eq("orderType", orderType));
return !criteria.list().isEmpty();
}

/**
* @see OrderDAO#getOrderGroupsByPatient(Patient)
*/
@Override
public List<OrderGroup> getOrderGroupsByPatient(Patient patient) throws DAOException {
if (patient == null) {
throw new APIException("Patient cannot be null");
}
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(OrderGroup.class);
criteria.add(Restrictions.eq("patient", patient));
return criteria.list();
}

/**
* @see OrderDAO#getOrderGroupsByEncounter(Encounter)
*/
@Override
public List<OrderGroup> getOrderGroupsByEncounter(Encounter encounter) throws DAOException {
if (encounter == null) {
throw new APIException("Encounter cannot be null");
}
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(OrderGroup.class);
criteria.add(Restrictions.eq("encounter", encounter));
return criteria.list();
}
}
21 changes: 16 additions & 5 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
import org.openmrs.api.APIException;
import org.openmrs.api.AmbiguousOrderException;
import org.openmrs.api.CannotDeleteObjectInUseException;
import org.openmrs.api.CannotStopDiscontinuationOrderException;
import org.openmrs.api.CannotStopInactiveOrderException;
import org.openmrs.api.CannotUnvoidOrderException;
import org.openmrs.api.CannotUpdateObjectInUseException;
import org.openmrs.api.EditedOrderDoesNotMatchPreviousException;
import org.openmrs.api.GlobalPropertyListener;
import org.openmrs.api.MissingRequiredPropertyException;
import org.openmrs.api.OrderContext;
import org.openmrs.api.OrderEntryException;
import org.openmrs.api.OrderNumberGenerator;
import org.openmrs.api.OrderService;
import org.openmrs.api.UnchangeableObjectException;
import org.openmrs.api.context.Context;
import org.openmrs.api.db.OrderDAO;
import org.openmrs.api.CannotStopDiscontinuationOrderException;
import org.openmrs.api.CannotStopInactiveOrderException;
import org.openmrs.api.CannotUnvoidOrderException;
import org.openmrs.api.EditedOrderDoesNotMatchPreviousException;
import org.openmrs.api.OrderEntryException;
import org.openmrs.order.OrderUtil;
import org.openmrs.parameter.OrderSearchCriteria;
import org.openmrs.util.OpenmrsConstants;
Expand Down Expand Up @@ -484,6 +484,7 @@ public Order unvoidOrder(Order order) throws APIException {
return saveOrderInternal(order, null);
}

@Override
public Order updateOrderFulfillerStatus(Order order, Order.FulfillerStatus orderFulfillerStatus, String fullFillerComment) {
order.setFulfillerStatus(orderFulfillerStatus);
order.setFulfillerComment(fullFillerComment);
Expand Down Expand Up @@ -1050,4 +1051,14 @@ private List<Concept> getSetMembersOfConceptSetFromGP(String globalProperty) {
}
return Collections.emptyList();
}

@Override
public List<OrderGroup> getOrderGroupsByPatient(Patient patient) throws APIException {
return dao.getOrderGroupsByPatient(patient);
}

@Override
public List<OrderGroup> getOrderGroupsByEncounter(Encounter encounter) throws APIException {
return dao.getOrderGroupsByEncounter(encounter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package org.openmrs.api.db.hibernate;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

Expand All @@ -17,9 +18,13 @@

import org.junit.Before;
import org.junit.Test;
import org.openmrs.Encounter;
import org.openmrs.Order;
import org.openmrs.OrderGroup;
import org.openmrs.Patient;
import org.openmrs.api.APIException;
import org.openmrs.api.builder.OrderBuilder;
import org.openmrs.api.context.Context;
import org.openmrs.test.BaseContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -65,4 +70,129 @@ public void saveOrderGroup_shouldSaveOrderGroup() {
}

}

/**
* @see {@link HibernateOrderDAO#getOrderGroupsByEncounter(Encounter)}
* @throws Exception
*/
@Test(expected = APIException.class)
public void getOrderGroupsByEncounter_shouldFailGivenNullEncounter() {
dao.getOrderGroupsByEncounter(null);
}

/**
* @see {@link HibernateOrderDAO#getOrderGroupsByPatient(Patient)}
* @throws Exception
*/
@Test(expected = APIException.class)
public void getOrderGroupsByPatient_shouldFailGivenNullPatient() {
dao.getOrderGroupsByPatient(null);
}

/**
* @see {@link HibernateOrderDAO#getOrderGroupsByEncounter(Encounter)}
* @throws Exception
*/
@Test
public void getOrderGroupsByEncounter_shouldGetOrderGroupsFromAnEncounter() {
OrderGroup orderGroupA = new OrderGroup();
OrderGroup orderGroupB = new OrderGroup();
OrderGroup orderGroupC = new OrderGroup();

Encounter existingEncounter1 = Context.getEncounterService().getEncounter(3);

orderGroupA.setEncounter(existingEncounter1);
orderGroupB.setEncounter(existingEncounter1);
orderGroupC.setEncounter(existingEncounter1);

assertEquals(0, dao.getOrderGroupsByEncounter(existingEncounter1).size());

dao.saveOrderGroup(orderGroupA);
dao.saveOrderGroup(orderGroupB);
dao.saveOrderGroup(orderGroupC);

assertEquals(3, dao.getOrderGroupsByEncounter(existingEncounter1).size());
}

/**
* @see {@link HibernateOrderDAO#getOrderGroupsByEncounter(Encounter)}
* @throws Exception
*/
@Test
public void getOrderGroupsByEncounter_shouldGetOrderGroupsFrommMultipleEncounters() {
OrderGroup orderGroupA = new OrderGroup();
OrderGroup orderGroupB = new OrderGroup();
OrderGroup orderGroupC = new OrderGroup();

Encounter existingEncounter1 = Context.getEncounterService().getEncounter(3);
Encounter existingEncounter2 = Context.getEncounterService().getEncounter(4);

orderGroupA.setEncounter(existingEncounter1);
orderGroupB.setEncounter(existingEncounter2);
orderGroupC.setEncounter(existingEncounter1);

assertEquals(0, dao.getOrderGroupsByEncounter(existingEncounter1).size());
assertEquals(0, dao.getOrderGroupsByEncounter(existingEncounter2).size());

dao.saveOrderGroup(orderGroupA);
dao.saveOrderGroup(orderGroupB);
dao.saveOrderGroup(orderGroupC);

assertEquals(2, dao.getOrderGroupsByEncounter(existingEncounter1).size());
assertEquals(1, dao.getOrderGroupsByEncounter(existingEncounter2).size());
}

/**
* @see {@link HibernateOrderDAO#getOrderGroupsByPatient(Patient)}
* @throws Exception
*/
@Test
public void getOrderGroupsByPatient_shouldGetOrderGroupsFromMultiplePatients() {
OrderGroup orderGroupA = new OrderGroup();
OrderGroup orderGroupB = new OrderGroup();
OrderGroup orderGroupC = new OrderGroup();

Patient existingPatient1 = Context.getPatientService().getPatient(7);
Patient existingPatient2 = Context.getPatientService().getPatient(8);

orderGroupA.setPatient(existingPatient1);
orderGroupB.setPatient(existingPatient1);
orderGroupC.setPatient(existingPatient2);

assertEquals(0, dao.getOrderGroupsByPatient(existingPatient1).size());
assertEquals(0, dao.getOrderGroupsByPatient(existingPatient2).size());

dao.saveOrderGroup(orderGroupA);
dao.saveOrderGroup(orderGroupB);
dao.saveOrderGroup(orderGroupC);

assertEquals(2, dao.getOrderGroupsByPatient(existingPatient1).size());
assertEquals(1, dao.getOrderGroupsByPatient(existingPatient2).size());

}

/**
* @see {@link HibernateOrderDAO#getOrderGroupsByPatient(Patient)}
* @throws Exception
*/
@Test
public void getOrderGroupsByPatient_shouldGetOrderGroupsGivenPatient() {
OrderGroup orderGroupA = new OrderGroup();
OrderGroup orderGroupB = new OrderGroup();
OrderGroup orderGroupC = new OrderGroup();

Patient existingPatient1 = Context.getPatientService().getPatient(7);

orderGroupA.setPatient(existingPatient1);
orderGroupB.setPatient(existingPatient1);
orderGroupC.setPatient(existingPatient1);

assertEquals(0, dao.getOrderGroupsByPatient(existingPatient1).size());

dao.saveOrderGroup(orderGroupA);
dao.saveOrderGroup(orderGroupB);
dao.saveOrderGroup(orderGroupC);

assertEquals(3, dao.getOrderGroupsByPatient(existingPatient1).size());
}
}

0 comments on commit b4dbff1

Please sign in to comment.