Skip to content

Commit

Permalink
Removed un necessary methods from order service or that will get redo…
Browse files Browse the repository at this point in the history
…ne during the order entry rework
  • Loading branch information
wluyima committed Dec 18, 2013
1 parent eddd540 commit 13f0fce
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 590 deletions.
115 changes: 2 additions & 113 deletions api/src/main/java/org/openmrs/api/OrderService.java
Expand Up @@ -30,19 +30,9 @@
import org.springframework.transaction.annotation.Transactional;

/**
* Contains methods pertaining to creating/deleting/voiding Orders and DrugOrders Use:<br/>
*
* @deprecated Will be removed in version 1.10
*
* <pre>
* Order order = new Order();
* order.set___(___);
* ...etc
* Context.getOrderService().saveOrder(order);
* </pre>
* Contains methods pertaining to creating/deleting/voiding Orders
*/
@Transactional
@Deprecated
public interface OrderService extends OpenmrsService {

/**
Expand Down Expand Up @@ -105,40 +95,12 @@ public interface OrderService extends OpenmrsService {
@Authorized(PrivilegeConstants.DELETE_ORDERS)
public Order voidOrder(Order order, String voidReason) throws APIException;

/**
* Mark the given order as discontinued. This should be used when patients are no longer on this
* Order. If this is was invalid Order, the {@link #voidOrder(Order, String)} method should
* probably be used.
*
* @param discontinueReason String reason for discontinuing this order
* @param order Order to discontinue
* @return The Order that was discontinued
* @throws APIException
*/
@Authorized(PrivilegeConstants.EDIT_ORDERS)
public Order discontinueOrder(Order order, Concept discontinueReason, Date discontinueDate) throws APIException;

/**
* Creates a collection of orders and an encounter to hold them. orders[i].encounter will be set
* to the new encounter. If there's an EncounterType with name "Regimen Change", then the
* newly-created encounter will have that type
*
* @param p the patient to add Orders to
* @param orders The Orders to add to the Patient (and to the makeshift Encounter)
* @throws APIException if there is no User with username Unknown or no Location with name
* Unknown or Unknown Location, or if there's no encounter type with name 'Regimen
* Change'
*/
@Authorized(value = { PrivilegeConstants.ADD_ORDERS, PrivilegeConstants.ADD_ENCOUNTERS }, requireAll = true)
public void createOrdersAndEncounter(Patient p, Collection<Order> orders) throws APIException;

/**
* Get order by internal primary key identifier
*
* @param orderId internal order identifier
* @return order with given internal identifier
* @throws APIException
* @see #getOrder(Integer, Class)
*/
@Transactional(readOnly = true)
@Authorized(PrivilegeConstants.VIEW_ORDERS)
Expand All @@ -157,7 +119,7 @@ public interface OrderService extends OpenmrsService {

/**
* 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
Expand All @@ -184,49 +146,6 @@ public interface OrderService extends OpenmrsService {
public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<Patient> patients,
List<Concept> concepts, List<User> orderers, List<Encounter> encounters);

/**
* Get all orders by the User that is marked as their orderer
*
* @return orders list
* @throws APIException
*/
@Transactional(readOnly = true)
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public List<Order> getOrdersByUser(User user) throws APIException;

/**
* Get all orders by Patient
*
* @return orders list
* @throws APIException
*/
@Transactional(readOnly = true)
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public List<Order> getOrdersByPatient(Patient patient) throws APIException;

/**
* Get drug orders for a given patient
*
* @param patient the owning Patient of the returned orders
* @param includeVoided true/false whether or not to include voided drug orders
* @return List of drug orders for the given patient
* @should return list of drug orders with given status
*/
@Transactional(readOnly = true)
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public List<DrugOrder> getDrugOrdersByPatient(Patient patient, boolean includeVoided);

/**
* Un-discontinue order record. Reverse a previous call to
* {@link #discontinueOrder(Order, Concept, Date)}
*
* @param order order to be un-discontinued
* @see #discontinueOrder(Order, Concept, Date)
* @return The Order that was undiscontinued
*/
@Authorized(PrivilegeConstants.EDIT_ORDERS)
public Order undiscontinueOrder(Order order) throws APIException;

/**
* Unvoid order record. Reverse a previous call to {@link #voidOrder(Order, String)}
*
Expand All @@ -236,34 +155,4 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
@Authorized(PrivilegeConstants.DELETE_ORDERS)
public Order unvoidOrder(Order order) throws APIException;

/**
* Get all orders for the given <code>patient</code>
*
* @return orders list
* @throws APIException
*/
@Transactional(readOnly = true)
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public List<DrugOrder> getDrugOrdersByPatient(Patient patient) throws APIException;

/**
* The standard regimens are currently stored in the application context file. See xml elements
* after the "STANDARD REGIMENS" comment in the web spring servlet:
* /web/WEB-INF/openmrs-servlet.xml (These really should be in the non-web spring app context:
* /metadata/api/spring/applicationContext.xml)
*
* @return list of RegimenSuggestion objects that have been predefined
*/
@Transactional(readOnly = true)
@Authorized(PrivilegeConstants.VIEW_ORDERS)
public List<RegimenSuggestion> getStandardRegimens();

/**
* Gets all orders contained in an encounter
*
* @param encounter the encounter in which to search for orders
* @return orders contained in the given encounter
*/
@Transactional(readOnly = true)
public List<Order> getOrdersByEncounter(Encounter encounter);
}
1 change: 0 additions & 1 deletion api/src/main/java/org/openmrs/api/db/OrderDAO.java
Expand Up @@ -46,7 +46,6 @@ public interface OrderDAO {
public void deleteOrder(Order order) throws DAOException;

/**
* @see org.openmrs.api.OrderService#getOrder(Integer, Class)
* @see org.openmrs.api.OrderService#getOrder(Integer)
*/
public <Ord extends Order> Ord getOrder(Integer orderId, Class<Ord> classType) throws DAOException;
Expand Down
Expand Up @@ -13,6 +13,7 @@
*/
package org.openmrs.api.handler;

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

Expand Down Expand Up @@ -66,7 +67,9 @@ public void handle(Patient patient, User voidingUser, Date voidedDate, String vo
}
//void all the orders associated with this patient
OrderService os = Context.getOrderService();
List<Order> orders = os.getOrdersByPatient(patient);
List<Patient> patients = new ArrayList<Patient>();
patients.add(patient);
List<Order> orders = os.getOrders(Order.class, patients, null, null, null);
if (CollectionUtils.isNotEmpty(orders)) {
for (Order order : orders) {
if (!order.isVoided()) {
Expand Down
158 changes: 0 additions & 158 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Expand Up @@ -13,31 +13,23 @@
*/
package org.openmrs.api.impl;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Vector;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Concept;
import org.openmrs.DrugOrder;
import org.openmrs.Encounter;
import org.openmrs.EncounterType;
import org.openmrs.GlobalProperty;
import org.openmrs.Location;
import org.openmrs.Order;
import org.openmrs.Patient;
import org.openmrs.User;
import org.openmrs.aop.RequiredDataAdvice;
import org.openmrs.api.APIException;
import org.openmrs.api.OrderNumberGenerator;
import org.openmrs.api.OrderService;
import org.openmrs.api.context.Context;
import org.openmrs.api.db.OrderDAO;
import org.openmrs.api.handler.SaveHandler;
import org.openmrs.order.DrugOrderSupport;
import org.openmrs.order.RegimenSuggestion;
import org.openmrs.util.OpenmrsConstants;
import org.openmrs.util.PrivilegeConstants;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -129,73 +121,6 @@ public Order unvoidOrder(Order order) throws APIException {
return saveOrder(order);
}

/**
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept,
* java.util.Date)
*/
public Order discontinueOrder(Order order, Concept discontinueReason, Date discontinueDate) throws APIException {
order.setDiscontinued(Boolean.TRUE);
order.setDiscontinuedReason(discontinueReason);
order.setDiscontinuedDate(discontinueDate);
order.setDiscontinuedBy(Context.getAuthenticatedUser());

return saveOrder(order);
}

/**
* @see org.openmrs.api.OrderService#undiscontinueOrder(org.openmrs.Order)
*/
public Order undiscontinueOrder(Order order) throws APIException {
order.setDiscontinued(Boolean.FALSE);
order.setDiscontinuedBy(null);
order.setDiscontinuedDate(null);
order.setDiscontinuedReason(null);

return saveOrder(order);
}

/**
* TODO: Refactor, generalize, or remove this method
*
* @see org.openmrs.api.OrderService#createOrdersAndEncounter(org.openmrs.Patient,
* java.util.Collection)
*/
public void createOrdersAndEncounter(Patient p, Collection<Order> orders) throws APIException {

// Get unknown user (or the authenticated user)
User unknownUser = Context.getUserService().getUserByUsername("Unknown");
// TODO: fix this hack
if (unknownUser == null) {
unknownUser = Context.getAuthenticatedUser();
}

// Get unknown location
Location unknownLocation = Context.getLocationService().getDefaultLocation();

if (unknownUser == null || unknownLocation == null) {
throw new APIException("Couldn't find a Location and a User named 'Unknown'.");
}

EncounterType encounterType = Context.getEncounterService().getEncounterType("Regimen Change");
if (encounterType == null) {
throw new APIException("Couldn't find an encounter type 'Regimen Change'");
}

Encounter e = new Encounter();
e.setPatient(p);
e.setProvider(unknownUser.getPerson());
e.setLocation(unknownLocation);
e.setEncounterDatetime(new Date());
// TODO: Remove hardcoded encounter type
e.setEncounterType(encounterType);
RequiredDataAdvice.recursivelyHandle(SaveHandler.class, e, null);
for (Order order : orders) {
e.addOrder(order);
order.setEncounter(e);
}
Context.getEncounterService().saveEncounter(e);
}

/**
* @see org.openmrs.api.OrderService#getOrder(java.lang.Integer)
*/
Expand Down Expand Up @@ -235,96 +160,13 @@ public <Ord extends Order> List<Ord> getOrders(Class<Ord> orderClassType, List<P
return dao.getOrders(orderClassType, patients, concepts, orderers, encounters);
}

/**
* @see org.openmrs.api.OrderService#getOrdersByUser(org.openmrs.User)
*/
public List<Order> getOrdersByUser(User user) throws APIException {
if (user == null)
throw new APIException("Unable to get orders if I am not given a user");

List<User> users = new Vector<User>();
users.add(user);

return getOrders(Order.class, null, null, users, null);
}

/**
* @see org.openmrs.api.OrderService#getOrdersByPatient(org.openmrs.Patient)
*/
public List<Order> getOrdersByPatient(Patient patient) throws APIException {
if (patient == null)
throw new APIException("Unable to get orders if I am not given a patient");

List<Patient> patients = new Vector<Patient>();
patients.add(patient);

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

/**
* @see org.openmrs.api.OrderService#getDrugOrdersByPatient(org.openmrs.Patient, boolean)
*/
@SuppressWarnings("unchecked")
public List<DrugOrder> getDrugOrdersByPatient(Patient patient, boolean includeVoided) {
if (patient == null)
throw new APIException("Unable to get drug orders if not given a patient");

List<Patient> patients = new Vector<Patient>();
patients.add(patient);

return getOrders(DrugOrder.class, patients, null, null, null);
}

/**
* @see org.openmrs.api.OrderService#getDrugOrdersByPatient(org.openmrs.Patient)
*/
public List<DrugOrder> getDrugOrdersByPatient(Patient patient) throws APIException {
List<Patient> patients = new Vector<Patient>();
patients.add(patient);

return getOrders(DrugOrder.class, patients, null, null, null);
}

/**
* @see org.openmrs.api.OrderService#getStandardRegimens()
*/
public List<RegimenSuggestion> getStandardRegimens() {
DrugOrderSupport dos = null;
List<RegimenSuggestion> standardRegimens = null;

try {
dos = DrugOrderSupport.getInstance();
}
catch (Exception e) {
log.error("Error getting instance of DrugOrderSupport object", e);
}

if (dos != null) {
standardRegimens = dos.getStandardRegimens();
} else {
log.error("DrugOrderSupport object is null after new instance");
}

return standardRegimens;
}

/**
* @see org.openmrs.api.OrderService#getOrderByUuid(java.lang.String)
*/
public Order getOrderByUuid(String uuid) throws APIException {
return dao.getOrderByUuid(uuid);
}

/**
* @see org.openmrs.api.OrderService#getOrdersByEncounter(org.openmrs.Encounter)
*/
public List<Order> getOrdersByEncounter(Encounter encounter) {
List<Encounter> encounters = new Vector<Encounter>();
encounters.add(encounter);

return getOrders(Order.class, null, null, null, encounters);
}

/**
* @see org.openmrs.api.OrderNumberGenerator#getNewOrderNumber()
*/
Expand Down

0 comments on commit 13f0fce

Please sign in to comment.