Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTWS - 405 - Add OrderFrequency resource #638

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/src/main/java/org/openmrs/api/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,26 @@ public <Ord extends Order> List<Ord> getActiveOrders(Patient patient, Class<Ord>
*/
public OrderFrequency getOrderFrequency(Integer orderFrequencyId);

/**
* Gets OrderFrequenecy that matches the specified uuid
*
* @param uuid the uuid to match against
* @return OrderFrequency
* @since 1.10
* @should return the order frequency that matched the specified uuid
*/
public OrderFrequency getOrderFrequencyByUuid(String uuid);

/**
* Gets OrderFrequency that matches the specified uuid
*
* @return List<OrderFrequency>
* @since 1.10
* @should return all the order frequencies
* @param includeRetired
*/
public List<OrderFrequency> getOrderFrequencies(boolean includeRetired);

/**
* Discontinues an order. Creates a new order that discontinues the orderToDiscontinue
*
Expand Down
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 @@ -119,4 +119,14 @@ public <Ord extends Order> List<Ord> getActiveOrders(Patient patient, Class<Ord>
* @See OrderService#getOrderFrequency
*/
public OrderFrequency getOrderFrequency(Integer orderFrequencyId);

/**
* @See OrderService#getOrderFrequencyByUuid
*/
public OrderFrequency getOrderFrequencyByUuid(String uuid);

/**
* @See OrderService#getOrderFrequencies
*/
List<OrderFrequency> getOrderFrequencies(boolean includeRetired);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.openmrs.api.db.hibernate;

import java.util.Collections;
import java.util.Date;
import java.util.List;

Expand All @@ -27,6 +28,7 @@
import org.hibernate.criterion.Restrictions;
import org.openmrs.CareSetting;
import org.openmrs.Concept;
import org.openmrs.ConceptMapType;
import org.openmrs.Encounter;
import org.openmrs.GlobalProperty;
import org.openmrs.Order;
Expand All @@ -37,6 +39,7 @@
import org.openmrs.api.APIException;
import org.openmrs.api.db.DAOException;
import org.openmrs.api.db.OrderDAO;
import org.openmrs.util.ConceptMapTypeComparator;
import org.openmrs.util.OpenmrsConstants;

/**
Expand Down Expand Up @@ -277,4 +280,24 @@ public List<CareSetting> getCareSettings(boolean includeRetired) {
public OrderFrequency getOrderFrequency(Integer orderFrequencyId) {
return (OrderFrequency) sessionFactory.getCurrentSession().get(OrderFrequency.class, orderFrequencyId);
}

/**
* @See OrderDAO#getOrderFrequencyByUuid
*/
@Override
public OrderFrequency getOrderFrequencyByUuid(String uuid) {
return (OrderFrequency) sessionFactory.getCurrentSession().createQuery("from OrderFrequency o where o.uuid = :uuid")
.setString("uuid", uuid).uniqueResult();
}

/**
* @See OrderDAO#getOrderFrequencies
*/
@Override
public List<OrderFrequency> getOrderFrequencies(boolean includeRetired) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(OrderFrequency.class);
if (!includeRetired)
criteria.add(Restrictions.eq("retired", false));
return criteria.list();
}
}
17 changes: 17 additions & 0 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,23 @@ public OrderFrequency getOrderFrequency(Integer orderFrequencyId) {
return dao.getOrderFrequency(orderFrequencyId);
}

/**
* @see OrderService#getOrderFrequencyByUuid(String)
*/
@Override
public OrderFrequency getOrderFrequencyByUuid(String uuid) {
return dao.getOrderFrequencyByUuid(uuid);
}

/**
* @see OrderService#getOrderFrequencies
* @param includeRetired
*/
@Override
public List<OrderFrequency> getOrderFrequencies(boolean includeRetired) {
return dao.getOrderFrequencies(includeRetired);
}

/**
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept,
* java.util.Date)
Expand Down
38 changes: 38 additions & 0 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.openmrs.Obs;
import org.openmrs.Order;
import org.openmrs.Order.Action;
import org.openmrs.OrderFrequency;
import org.openmrs.Patient;
import org.openmrs.TestOrder;
import org.openmrs.api.context.Context;
Expand Down Expand Up @@ -268,6 +269,43 @@ public void getOrderFrequency_shouldReturnTheOrderFrequencyThatMatchedTheSpecifi
.getUuid());
}

/**
* @verifies return the order frequency that matched the specified uuid
* @see OrderService#getOrderFrequencyByUuid(String)
*/
@Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next time use the behavior openmrs test generator plugin for your IDE to generate these tests see https://wiki.openmrs.org/display/docs/Generate+Test+Case+Plugin

I will fix this

public void getOrderFrequency_shouldReturnTheOrderFrequencyThatMatchedTheSpecifiedUuid() throws Exception {
Assert.assertEquals(1, Context.getOrderService().getOrderFrequencyByUuid("28090760-7c38-11e3-baa7-0800200c9a66")
.getOrderFrequencyId().intValue());
}

/**
* @verifies return all active order frequencies
* @see OrderService#getOrderFrequencyByUuid(String)
*/
@Test
public void getOrderFrequencies_shouldReturnAllActiveOrderFrequencies() throws Exception {
executeDataSet("org/openmrs/api/include/OrderServiceTest-getAllOrderFrequencies.xml");
List<OrderFrequency> orderFrequencies = Context.getOrderService().getOrderFrequencies(false);
Assert.assertEquals(2, orderFrequencies.size());
Assert.assertEquals("28090760-7c38-11e3-baa7-0800200c9a66", orderFrequencies.get(0).getUuid());
Assert.assertEquals("38090760-7c38-11e3-baa7-0800200c9a66", orderFrequencies.get(1).getUuid());
}

/**
* @verifies return all order frequencies. should include retired as well.
* @see OrderService#getOrderFrequencyByUuid(String)
*/
@Test
public void getOrderFrequencies_shouldReturnAllOrderFrequenciesIncludingRetired() throws Exception {
executeDataSet("org/openmrs/api/include/OrderServiceTest-getAllOrderFrequencies.xml");
List<OrderFrequency> orderFrequencies = Context.getOrderService().getOrderFrequencies(true);
Assert.assertEquals(3, orderFrequencies.size());
Assert.assertEquals("28090760-7c38-11e3-baa7-0800200c9a66", orderFrequencies.get(0).getUuid());
Assert.assertEquals("38090760-7c38-11e3-baa7-0800200c9a66", orderFrequencies.get(1).getUuid());
Assert.assertEquals("48090760-7c38-11e3-baa7-0800200c9a66", orderFrequencies.get(2).getUuid());
}

/**
* @verifies return all active orders for the specified patient
* @see OrderService#getActiveOrders(org.openmrs.Patient, Class, org.openmrs.CareSetting,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have added these directly to standardTestDataset.xml file

<dataset>
<order_frequency order_frequency_id="2" concept_id="113" creator="1" date_created="2008-08-15 13:52:53.0" retired="false" uuid="38090760-7c38-11e3-baa7-0800200c9a66" />
<order_frequency order_frequency_id="3" concept_id="113" creator="1" date_created="2008-08-15 13:52:53.0" retired="true" uuid="48090760-7c38-11e3-baa7-0800200c9a66" />
</dataset>