Skip to content

Commit

Permalink
Order.encounter should be required - TRUNK-4274
Browse files Browse the repository at this point in the history
TRUNK-4274 aadded @param encounter

TRUNK-4274 removed the changeset that is to be handled by TRUNK-4283
  • Loading branch information
k-joseph authored and wluyima committed Mar 6, 2014
1 parent 517b4fd commit ed4fd04
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
10 changes: 6 additions & 4 deletions api/src/main/java/org/openmrs/api/OrderService.java
Expand Up @@ -363,6 +363,7 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
* @param reasonCoded
* @param discontinueDate
* @param orderer
* @param encounter
* @return the new order that discontinued orderToDiscontinue
* @throws APIException if the <code>action</code> of orderToDiscontinue is
* <code>Order.Action.DISCONTINUE</code>
Expand All @@ -375,8 +376,8 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
* @should fail for a discontinuation order
*/
@Authorized(PrivilegeConstants.ADD_ORDERS)
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate, Provider orderer)
throws Exception;
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate, Provider orderer,
Encounter encounter) throws Exception;

/**
* Discontinues an order. Creates a new order that discontinues the orderToDiscontinue.
Expand All @@ -386,6 +387,7 @@ public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Dat
* @param reasonNonCoded
* @param discontinueDate
* @param orderer
* @param encounter
* @return the new order that discontinued orderToDiscontinue
* @throws APIException if the <code>action</code> of orderToDiscontinue is
* <code>Order.Action.DISCONTINUE</code>
Expand All @@ -396,8 +398,8 @@ public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Dat
* @should fail for a voided order
*/
@Authorized(PrivilegeConstants.ADD_ORDERS)
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer)
throws Exception;
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer,
Encounter encounter) throws Exception;

/**
* Creates or updates the given order frequency in the database
Expand Down
14 changes: 8 additions & 6 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Expand Up @@ -401,29 +401,31 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
}

/**
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider)
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date, org.openmrs.Provider, org.openmrs.Encounter)
*/
@Override
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate, Provider orderer)
throws Exception {
public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate, Provider orderer,
Encounter encounter) throws Exception {
stopOrder(orderToDiscontinue, discontinueDate);
Order newOrder = orderToDiscontinue.cloneForDiscontinuing();
newOrder.setOrderReason(reasonCoded);
newOrder.setOrderer(orderer);
newOrder.setEncounter(encounter);

return saveOrderInternal(newOrder);
}

/**
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, org.openmrs.Provider)
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date, org.openmrs.Provider, org.openmrs.Encounter)
*/
@Override
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer)
throws Exception {
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer,
Encounter encounter) throws Exception {
stopOrder(orderToDiscontinue, discontinueDate);
Order newOrder = orderToDiscontinue.cloneForDiscontinuing();
newOrder.setOrderReasonNonCoded(reasonNonCoded);
newOrder.setOrderer(orderer);
newOrder.setEncounter(encounter);
return saveOrderInternal(newOrder);
}

Expand Down
9 changes: 9 additions & 0 deletions api/src/main/resources/liquibase-update-to-latest.xml
Expand Up @@ -6420,6 +6420,15 @@
upgrade process if any unmapped text is found
</comment>
</changeSet>

<changeSet id="201402281648-TRUNK-4274" author="k-joseph">
<comment>Making order.encounter required</comment>
<ext:modifyColumn tableName="orders">
<column name="encounter_id" type="int">
<constraints nullable="false" />
</column>
</ext:modifyColumn>
</changeSet>

<changeSet id="201403011303-TRUNK-4198_1" author="harsha">
<preConditions onFail="MARK_RAN">
Expand Down
Expand Up @@ -54,7 +54,7 @@
<column name="concept_id" />
</many-to-one>
<!-- bi-directional many-to-one association to Encounter -->
<many-to-one name="encounter" class="org.openmrs.Encounter">
<many-to-one name="encounter" class="org.openmrs.Encounter" not-null="true">
<column name="encounter_id" />
</many-to-one>

Expand Down
7 changes: 5 additions & 2 deletions api/src/test/java/org/openmrs/OrderEntryIntegrationTest.java
Expand Up @@ -130,19 +130,22 @@ public void shouldDiscontinueAnActiveOrder() throws Exception {
executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinueReason.xml");

Order firstOrderToDiscontinue = orderService.getOrder(3);
Encounter encounter = Context.getEncounterService().getEncounter(3);
assertTrue(OrderUtil.isOrderActive(firstOrderToDiscontinue, null));
Patient patient = firstOrderToDiscontinue.getPatient();
int ordersCount = orderService.getActiveOrders(patient, null, null, null).size();

Concept discontinueReason = Context.getConceptService().getConcept(1);
Order discontinuationOrder1 = orderService.discontinueOrder(firstOrderToDiscontinue, discontinueReason, null, null);
Order discontinuationOrder1 = orderService.discontinueOrder(firstOrderToDiscontinue, discontinueReason, null, null,
encounter);
assertEquals(firstOrderToDiscontinue, discontinuationOrder1.getPreviousOrder());

//Lets discontinue another order with reason being a string instead of concept
Order secondOrderToDiscontinue = orderService.getOrder(5);
assertEquals(patient, secondOrderToDiscontinue.getPatient());
assertTrue(OrderUtil.isOrderActive(secondOrderToDiscontinue, null));
Order discontinuationOrder2 = orderService.discontinueOrder(secondOrderToDiscontinue, "Testing", null, null);
Order discontinuationOrder2 = orderService.discontinueOrder(secondOrderToDiscontinue, "Testing", null, null,
encounter);
assertEquals(secondOrderToDiscontinue, discontinuationOrder2.getPreviousOrder());

//Lets discontinue another order by saving a DC order
Expand Down
35 changes: 26 additions & 9 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Expand Up @@ -41,6 +41,7 @@
import org.openmrs.ConceptName;
import org.openmrs.Drug;
import org.openmrs.DrugOrder;
import org.openmrs.Encounter;
import org.openmrs.Obs;
import org.openmrs.Order;
import org.openmrs.Order.Action;
Expand All @@ -64,6 +65,8 @@ public class OrderServiceTest extends BaseContextSensitiveTest {

private PatientService patientService;

private EncounterService encounterService;

@Rule
public ExpectedException expectedException = ExpectedException.none();

Expand All @@ -79,6 +82,10 @@ public void setup() {
if (conceptService == null) {
conceptService = Context.getConceptService();
}

if (encounterService == null) {
encounterService = Context.getEncounterService();
}
}

/**
Expand Down Expand Up @@ -482,11 +489,13 @@ public void getActiveOrders_shouldDefaultToOrderClassIfNoOrderClassIsSpecified()
@Verifies(value = "populate correct attributes on the discontinue and discontinued orders", method = "discontinueOrder(Order, String, Date)")
public void discontinueOrderWithNonCodedReason_shouldPopulateCorrectAttributesOnBothOrders() throws Exception {
Order order = orderService.getOrderByOrderNumber("111");
Encounter encounter = encounterService.getEncounter(3);
assertTrue(OrderUtil.isOrderActive(order, null));
Date discontinueDate = new Date();
String discontinueReasonNonCoded = "Test if I can discontinue this";

Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate, null);
Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate, null,
encounter);

Assert.assertEquals(order.getDateStopped(), discontinueDate);
Assert.assertNotNull(discontinueOrder);
Expand All @@ -505,10 +514,11 @@ public void discontinueOrderWithConcept_shouldPopulateCorrectAttributesOnBothOrd
executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinueReason.xml");

Order order = orderService.getOrderByOrderNumber("111");
Encounter encounter = encounterService.getEncounter(3);
Date discontinueDate = new Date();
Concept concept = Context.getConceptService().getConcept(1);

Order discontinueOrder = orderService.discontinueOrder(order, concept, discontinueDate, null);
Order discontinueOrder = orderService.discontinueOrder(order, concept, discontinueDate, null, encounter);

Assert.assertEquals(order.getDateStopped(), discontinueDate);
Assert.assertNotNull(discontinueOrder);
Expand All @@ -527,8 +537,9 @@ public void discontinueOrderWithNonCodedReason_shouldFailForADiscontinueOrder()
executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinuedOrder.xml");
OrderService orderService = Context.getOrderService();
Order discontinueOrder = orderService.getOrder(26);
Encounter encounter = encounterService.getEncounter(3);

orderService.discontinueOrder(discontinueOrder, "Test if I can discontinue this", null, null);
orderService.discontinueOrder(discontinueOrder, "Test if I can discontinue this", null, null, encounter);
}

/**
Expand All @@ -541,8 +552,9 @@ public void discontinueOrderWithConcept_shouldFailForADiscontinueOrder() throws
executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinueReason.xml");
OrderService orderService = Context.getOrderService();
Order discontinueOrder = orderService.getOrder(26);
Encounter encounter = encounterService.getEncounter(3);

orderService.discontinueOrder(discontinueOrder, (Concept) null, null, null);
orderService.discontinueOrder(discontinueOrder, (Concept) null, null, null, encounter);
}

/**
Expand Down Expand Up @@ -626,7 +638,8 @@ public void discontinueOrder_shouldRejectAFutureDiscontinueDate() throws Excepti
Patient patient = Context.getPatientService().getPatient(2);
CareSetting careSetting = orderService.getCareSetting(1);
Order orderToDiscontinue = orderService.getActiveOrders(patient, Order.class, careSetting, null).get(0);
orderService.discontinueOrder(orderToDiscontinue, new Concept(), cal.getTime(), null);
Encounter encounter = encounterService.getEncounter(3);
orderService.discontinueOrder(orderToDiscontinue, new Concept(), cal.getTime(), null, encounter);
}

/**
Expand All @@ -639,7 +652,8 @@ public void discontinueOrder_shouldFailIfDiscontinueDateIsInTheFuture() throws E
cal.add(Calendar.HOUR_OF_DAY, 1);
Order orderToDiscontinue = orderService.getActiveOrders(Context.getPatientService().getPatient(2), Order.class,
orderService.getCareSetting(1), null).get(0);
orderService.discontinueOrder(orderToDiscontinue, "Testing", cal.getTime(), null);
Encounter encounter = encounterService.getEncounter(3);
orderService.discontinueOrder(orderToDiscontinue, "Testing", cal.getTime(), null, encounter);
}

/**
Expand Down Expand Up @@ -702,8 +716,9 @@ public void saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDru
@Test(expected = APIException.class)
public void discontinueOrder_shouldFailForAStoppedOrder() throws Exception {
Order orderToDiscontinue = orderService.getOrder(1);
Encounter encounter = encounterService.getEncounter(3);
assertNotNull(orderToDiscontinue.getDateStopped());
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null, null);
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null, null, encounter);
}

/**
Expand All @@ -713,8 +728,9 @@ public void discontinueOrder_shouldFailForAStoppedOrder() throws Exception {
@Test(expected = APIException.class)
public void discontinueOrder_shouldFailForAVoidedOrder() throws Exception {
Order orderToDiscontinue = orderService.getOrder(8);
Encounter encounter = encounterService.getEncounter(3);
assertTrue(orderToDiscontinue.isVoided());
orderService.discontinueOrder(orderToDiscontinue, "testing", null, null);
orderService.discontinueOrder(orderToDiscontinue, "testing", null, null, encounter);
}

/**
Expand All @@ -724,9 +740,10 @@ public void discontinueOrder_shouldFailForAVoidedOrder() throws Exception {
@Test(expected = APIException.class)
public void discontinueOrder_shouldFailForAnExpiredOrder() throws Exception {
Order orderToDiscontinue = orderService.getOrder(6);
Encounter encounter = encounterService.getEncounter(3);
assertNotNull(orderToDiscontinue.getAutoExpireDate());
assertTrue(orderToDiscontinue.getAutoExpireDate().before(new Date()));
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null, null);
orderService.discontinueOrder(orderToDiscontinue, Context.getConceptService().getConcept(1), null, null, encounter);
}

/**
Expand Down

0 comments on commit ed4fd04

Please sign in to comment.