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: 5188d611ef24
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: 97d5100edb59
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 28, 2014

  1. Applying auto format changes

    wluyima committed Jan 28, 2014
    Copy the full SHA
    19968f8 View commit details
  2. Added unit test for ensuring orders.orderer is converted to provider …

    …instead of user - TRUNK-4202
    wluyima committed Jan 28, 2014
    Copy the full SHA
    97d5100 View commit details
Original file line number Diff line number Diff line change
@@ -220,11 +220,11 @@ public <Ord extends Order> List<Ord> getActiveOrders(Patient patient, Class<Ord>
Criterion stopAndAutoExpDateAreBothNull = Restrictions.and(Restrictions.isNull("dateStopped"), Restrictions
.isNull("autoExpireDate"));
dateStoppedAndAutoExpDateDisjunction.add(stopAndAutoExpDateAreBothNull);

Criterion dateStoppedEqualToOrAfterAsOfDate = Restrictions.and(Restrictions.isNull("dateStopped"), Restrictions.ge(
"autoExpireDate", asOfDate));
dateStoppedAndAutoExpDateDisjunction.add(dateStoppedEqualToOrAfterAsOfDate);

dateStoppedAndAutoExpDateDisjunction.add(Restrictions.ge("dateStopped", asOfDate));

crit.add(dateStoppedAndAutoExpDateDisjunction);
6 changes: 4 additions & 2 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ public void purgeOrder_shouldDeleteObsThatReference() throws Exception {
@Test
@Verifies(value = "should always return unique orderNumbers when called multiple times without saving orders", method = "getNewOrderNumber()")
public void getNewOrderNumber_shouldAlwaysReturnUniqueOrderNumbersWhenCalledMultipleTimesWithoutSavingOrders()
throws Exception {
throws Exception {

executeDataSet("org/openmrs/api/include/OrderServiceTest-globalProperties.xml");

@@ -267,7 +267,9 @@ public void getOrderHistoryByOrderNumber_shouldReturnAllOrderHistoryForGivenOrde
*/
@Test
public void getOrderFrequency_shouldReturnTheOrderFrequencyThatMatchedTheSpecifiedId() throws Exception {
Assert.assertEquals("28090760-7c38-11e3-baa7-0800200c9a66", Context.getOrderService().getOrderFrequency(1).getUuid());
Assert
.assertEquals("28090760-7c38-11e3-baa7-0800200c9a66", Context.getOrderService().getOrderFrequency(1)
.getUuid());
}

/**
Original file line number Diff line number Diff line change
@@ -17,12 +17,15 @@
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openmrs.util.DatabaseUtil;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -106,7 +109,7 @@ public void shouldMigrateDrugOrders() throws IOException, SQLException {
}

@Test(expected = Exception.class)
public void shouldFailIfAnyDrugOrderUnitsNotMappedToConceptsAreFound() throws IOException, Exception {
public void shouldFailIfAnyDrugOrderUnitsNotMappedToConceptsAreFound() throws Exception {
//sanity check that we have some unmapped drug order dose units
upgradeTestUtil.executeDataset("/org/openmrs/util/databasechange/standardTest-1.9.7-dataSet.xml");
Set<String> uniqueUnits = DatabaseUtil.getUniqueNonNullColumnValues("units", "drug_order", String.class,
@@ -121,7 +124,7 @@ public void shouldFailIfAnyDrugOrderUnitsNotMappedToConceptsAreFound() throws IO
}

@Test(expected = Exception.class)
public void shouldFailIfAnyDrugOrderFrequenciesNotMappedToConceptsAreFound() throws IOException, Exception {
public void shouldFailIfAnyDrugOrderFrequenciesNotMappedToConceptsAreFound() throws Exception {
//sanity check that we have some unmapped drug order frequencies
upgradeTestUtil.executeDataset("/org/openmrs/util/databasechange/standardTest-1.9.7-dataSet.xml");
Set<String> uniqueFrequencies = DatabaseUtil.getUniqueNonNullColumnValues("frequency", "drug_order", String.class,
@@ -135,7 +138,7 @@ public void shouldFailIfAnyDrugOrderFrequenciesNotMappedToConceptsAreFound() thr
}

@Test
public void shouldPassIfAllExistingDrugOrderUnitsAndFrequenciesAreMappedToConcepts() throws IOException, Exception {
public void shouldPassIfAllExistingDrugOrderUnitsAndFrequenciesAreMappedToConcepts() throws Exception {
//sanity check that we have some drug order dose units and frequencies in the test dataset
upgradeTestUtil.executeDataset("/org/openmrs/util/databasechange/standardTest-1.9.7-dataSet.xml");
Set<String> uniqueUnits = DatabaseUtil.getUniqueNonNullColumnValues("units", "drug_order", String.class,
@@ -155,11 +158,125 @@ public void shouldPassIfAllExistingDrugOrderUnitsAndFrequenciesAreMappedToConcep
upgradeTestUtil.upgrade();
}

@Test
@Ignore
public void shouldConvertOrderersToBeingProvidersInsteadOfUsers() throws Exception {
upgradeTestUtil.executeDataset("/org/openmrs/util/databasechange/standardTest-1.9.7-dataSet.xml");
upgradeTestUtil.executeDataset("/org/openmrs/util/databasechange/database1_9To1_10UpgradeTest-dataSet.xml");
upgradeTestUtil.executeDataset("/org/openmrs/util/databasechange/UpgradeTest-convertOrdererToProvider.xml");

//Sanity check that we have 3 orders where orderer has no provider account
Set<Integer> personIdsWithNoProviderAccount = new HashSet<Integer>();
List<OrderAndPerson> ordersAndOrderersWithNoProviderAccount = new ArrayList<OrderAndPerson>();
List<List<Object>> rows = DatabaseUtil.executeSQL(upgradeTestUtil.getConnection(),
"select o.order_id, u.person_id from orders o join users u on o.orderer = u.user_id "
+ "where u.person_id not in (select distinct person_id from provider)", true);
for (List<Object> row : rows) {
ordersAndOrderersWithNoProviderAccount.add(new OrderAndPerson((Integer) row.get(0), (Integer) row.get(1)));
personIdsWithNoProviderAccount.add((Integer) row.get(1));
}
Assert.assertEquals(3, ordersAndOrderersWithNoProviderAccount.size());
Assert.assertEquals(2, personIdsWithNoProviderAccount.size());
Assert.assertThat(personIdsWithNoProviderAccount, Matchers.hasItems(101, 102));

//Sanity check that we have 1 order where orderer has a provider account
rows = DatabaseUtil.executeSQL(upgradeTestUtil.getConnection(),
"select o.order_id, o.orderer, u.person_id from orders o join users u on o.orderer = u.user_id "
+ "where u.person_id in (select distinct person_id from provider)", true);
List<OrderAndPerson> ordersAndOrderersWithAProviderAccount = new ArrayList<OrderAndPerson>();
for (List<Object> row : rows) {
ordersAndOrderersWithAProviderAccount.add(new OrderAndPerson((Integer) row.get(0), (Integer) row.get(1)));
}
Assert.assertEquals(7, ordersAndOrderersWithAProviderAccount.size());

//Sanity check that we have 2 order with null orderer
rows = DatabaseUtil.executeSQL(upgradeTestUtil.getConnection(),
"select order_id from orders where orderer is null ", true);
List<Integer> ordersWithNullOrderer = new ArrayList<Integer>();
for (List<Object> row : rows) {
ordersWithNullOrderer.add((Integer) row.get(0));
}
Assert.assertEquals(2, ordersWithNullOrderer.size());

Set<Integer> originalProviderIds = DatabaseUtil.getUniqueNonNullColumnValues("provider_id", "provider",
Integer.class, upgradeTestUtil.getConnection());

upgradeTestUtil.insertGlobalProperty("orderEntry.unitsToConceptsMappings",
"mg:111,tab(s):112,1/day x 7 days/week:113,2/day x 7 days/week:114");

upgradeTestUtil.upgrade();

Set<Integer> newProviderIds = DatabaseUtil.getUniqueNonNullColumnValues("provider_id", "provider", Integer.class,
upgradeTestUtil.getConnection());
//A provider account should have been created for each user with none
Assert.assertEquals(originalProviderIds.size() + 2, newProviderIds.size());

//Should still have the 2 orders with null orderer
rows = DatabaseUtil.executeSQL(upgradeTestUtil.getConnection(),
"select order_id from orders where orderer is null ", true);
List<Integer> newOrdersWithNullOrderer = new ArrayList<Integer>();
for (List<Object> row : rows) {
newOrdersWithNullOrderer.add((Integer) row.get(0));
}
Assert.assertEquals(2, newOrdersWithNullOrderer.size());
Assert.assertEquals(ordersWithNullOrderer, newOrdersWithNullOrderer);

//That correct providers were set for each order, i.e the person record for the provider
//should match the that of the user account before upgrade
for (OrderAndPerson op : ordersAndOrderersWithAProviderAccount) {
rows = DatabaseUtil.executeSQL(upgradeTestUtil.getConnection(),
"select p.provider_id, p.person_id from provider p join orders o on p.provider_id = o.orderer where order_id = "
+ op.getOrderId(), true);
Assert.assertEquals(op.getPersonId(), rows.get(0).get(1));
//The provider account should be an existing one prior to upgrade
Assert.assertFalse(originalProviderIds.contains(rows.get(0).get(0)));
}

//That correct providers were set for each order, i.e the person record for the created provider
//should match the that of the user account before upgrade
for (OrderAndPerson op : ordersAndOrderersWithNoProviderAccount) {
rows = DatabaseUtil.executeSQL(upgradeTestUtil.getConnection(),
"select p.provider_id, p.person_id from provider p join orders o on p.provider_id = o.orderer where order_id = "
+ op.getOrderId(), true);
Assert.assertEquals(op.getPersonId(), rows.get(0).get(1));
//The provider account should be new
Assert.assertFalse(newProviderIds.contains(rows.get(0).get(0)));
}
}

private Map<String, String> row(String... values) {
Map<String, String> row = new HashMap<String, String>();
for (int i = 0; i < values.length; i += 2) {
row.put(values[i], values[i + 1]);
}
return row;
}

private class OrderAndPerson {

private Integer orderId;

private Integer personId;

OrderAndPerson(Integer orderId, Integer personId) {
this.orderId = orderId;
this.personId = personId;
}

Integer getOrderId() {
return orderId;
}

void setOrderId(Integer orderId) {
this.orderId = orderId;
}

Integer getPersonId() {
return personId;
}

void setPersonId(Integer personId) {
this.personId = personId;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
<person person_id="101" gender="M" birthdate="1948-01-01 00:00:00.0" birthdate_estimated="0" dead="0" creator="1" date_created="2005-01-01 00:00:00.0" voided="0" uuid="ca1b19c2-3ed6-4f63-b8c0-f762dc8d7563"/>
<person person_id="102" gender="M" birthdate="1958-01-01 00:00:00.0" birthdate_estimated="0" dead="0" creator="1" date_created="2005-01-01 00:00:00.0" voided="0" uuid="da1b19c2-3ed6-4f63-b8c0-f762dc8d7564"/>

<users user_id="101" person_id="101" system_id="9-8" username="user1" password="rr6d1655327d385e11a04e1632b4f33ceb8fafd2" salt="6d32c5fd9fde391c755f1f4dfd5e1d6e3debe6" creator="1" date_created="2008-08-15 15:46:47.0" uuid="d1d8f5c2-e131-11de-babe-001e378eb67d"/>
<users user_id="102" person_id="102" system_id="7-6" username="user2" password="aaeda5c0cc3837151b2d61cfeab54a91fb0c27d" salt="52af4c437a47cd778a54f6564d71b3cd6e8e5ca" creator="1" date_created="2008-08-15 15:57:09.0" uuid="b98a1558-e131-11de-babe-001e378eb67e"/>

<orders order_id="6" order_type_id="2" urgency="ROUTINE" concept_id="5497" orderer="1" start_date="2009-04-08 00:00:00.0" creator="1" date_created="2009-04-08 00:00:00.0" discontinued="0" voided="0" patient_id="2" uuid="121de0a3-05c4-444a-be03-e01b4c4b914a" />
<orders order_id="7" order_type_id="2" urgency="ROUTINE" concept_id="5497" orderer="1" start_date="2009-05-08 00:00:00.0" creator="1" date_created="2009-05-08 00:00:00.0" discontinued="0" voided="0" patient_id="2" uuid="21de0a3-05c4-444a-be03-e01b4c4b914b" />
<orders order_id="8" order_type_id="2" urgency="ROUTINE" concept_id="5497" orderer="101" start_date="2009-06-08 00:00:00.0" creator="1" date_created="2009-06-08 00:00:00.0" discontinued="0" voided="0" patient_id="2" uuid="321de0a3-05c4-444a-be03-e01b4c4b914c" />
<orders order_id="9" order_type_id="2" urgency="ROUTINE" concept_id="5497" orderer="101" start_date="2009-07-08 00:00:00.0" creator="1" date_created="2009-07-08 00:00:00.0" discontinued="0" voided="0" patient_id="2" uuid="321de0a3-05c4-444a-be03-e01b4c4b914d" />
<orders order_id="10" order_type_id="2" urgency="ROUTINE" concept_id="5497" orderer="102" start_date="2009-08-08 00:00:00.0" creator="1" date_created="2009-08-08 00:00:00.0" discontinued="0" voided="0" patient_id="2" uuid="521de0a3-05c4-444a-be03-e01b4c4b914e" />
<orders order_id="11" order_type_id="2" urgency="ROUTINE" concept_id="5497" start_date="2009-09-08 00:00:00.0" creator="1" date_created="2009-09-08 00:00:00.0" discontinued="0" voided="0" patient_id="2" uuid="621de0a3-05c4-444a-be03-e01b4c4b914f" />
<orders order_id="12" order_type_id="2" urgency="ROUTINE" concept_id="5497" start_date="2009-10-08 00:00:00.0" creator="1" date_created="2009-10-08 00:00:00.0" discontinued="0" voided="0" patient_id="2" uuid="721de0a3-05c4-444a-be03-e01b4c4b914g" />
</dataset>