← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16706: Impl support for identifier schemes for data export. This is useful e.g. when dhis must export da...

 

------------------------------------------------------------
revno: 16706
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-09-12 17:26:18 +0200
message:
  Impl support for identifier schemes for data export. This is useful e.g. when dhis must export data to another system and the code property is used to map meta-data.
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportOptions.java
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataForm.vm
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importDataValue.vm
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importForm.vm
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/export.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2014-09-12 15:26:18 +0000
@@ -211,7 +211,10 @@
             "from dataapproval da " +
             "inner join dataapprovallevel dal on da.dataapprovallevelid = dal.dataapprovallevelid " +
             "inner join _dataelementstructure des on da.datasetid = des.datasetid and des.dataelementid = dv.dataelementid " +
-            "where da.periodid = dv.periodid and (";
+            "inner join dataset ds on des.datasetid = ds.datasetid " +
+            "where da.periodid = dv.periodid " +
+            "and ds.approvedata = true " +
+            "and (";
         
         for ( OrganisationUnitLevel level : levels )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java	2014-08-24 15:24:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java	2014-09-12 15:26:18 +0000
@@ -37,6 +37,7 @@
 
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.metadata.ExportOptions;
 import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.node.types.RootNode;
 import org.hisp.dhis.period.Period;
@@ -47,17 +48,17 @@
  */
 public interface DataValueSetService
 {
-    void writeDataValueSetXml( String dataSet, String period, String orgUnit, OutputStream out );
-
-    void writeDataValueSetXml( Set<String> dataSets, Date startDate, Date endDate, Set<String> orgUnits, boolean includeChildren, OutputStream out );
-
-    void writeDataValueSetJson( String ds, String period, String ou, OutputStream outputStream );
-
-    void writeDataValueSetJson( Set<String> dataSet, Date startDate, Date endDate, Set<String> ous, boolean includeChildren, OutputStream outputStream );
-
-    void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream );
+    void writeDataValueSetXml( String dataSet, String period, String orgUnit, OutputStream out, ExportOptions exportOptions );
+
+    void writeDataValueSetXml( Set<String> dataSets, Date startDate, Date endDate, Set<String> orgUnits, boolean includeChildren, OutputStream out, ExportOptions exportOptions );
+
+    void writeDataValueSetJson( String ds, String period, String ou, OutputStream outputStream, ExportOptions exportOptions );
+
+    void writeDataValueSetJson( Set<String> dataSet, Date startDate, Date endDate, Set<String> ous, boolean includeChildren, OutputStream outputStream, ExportOptions exportOptions );
+
+    void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream, ExportOptions exportOptions );
     
-    void writeDataValueSetCsv( Set<String> dataSets, Date startDate, Date endDate, Set<String> orgUnits, boolean includeChildren, Writer writer );
+    void writeDataValueSetCsv( Set<String> dataSets, Date startDate, Date endDate, Set<String> orgUnits, boolean includeChildren, Writer writer, ExportOptions exportOptions );
 
     RootNode getDataValueSetTemplate( DataSet dataSet, Period period, List<String> orgUnits,
         boolean writeComments, String ouScheme, String deScheme );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java	2014-08-24 15:24:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java	2014-09-12 15:26:18 +0000
@@ -29,6 +29,7 @@
  */
 
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dxf2.metadata.ExportOptions;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 
@@ -43,12 +44,13 @@
 public interface DataValueSetStore
 {
     public void writeDataValueSetXml( Set<DataSet> dataSets, Date completeDate, Period period,
-        OrganisationUnit orgUnit, Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream out );
+        OrganisationUnit orgUnit, Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream out, ExportOptions exportOptions );
 
-    public void writeDataValueSetCsv( Set<DataSet> dataSets, Set<Period> periods, Set<OrganisationUnit> orgUnits, Writer writer );
+    public void writeDataValueSetCsv( Set<DataSet> dataSets, Set<Period> periods, 
+        Set<OrganisationUnit> orgUnits, Writer writer, ExportOptions exportOptions );
 
     public void writeDataValueSetJson( Set<DataSet> dataSets, Date completeDate, Period period,
-        OrganisationUnit orgUnit, Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream out );
+        OrganisationUnit orgUnit, Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream out, ExportOptions exportOptions );
 
-    void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream );
+    void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream, ExportOptions exportOptions );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2014-08-24 15:24:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2014-09-12 15:26:18 +0000
@@ -71,6 +71,7 @@
 import org.hisp.dhis.dxf2.importsummary.ImportCount;
 import org.hisp.dhis.dxf2.importsummary.ImportStatus;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.metadata.ExportOptions;
 import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.dxf2.pdfform.PdfDataEntryFormUtil;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
@@ -146,7 +147,7 @@
     //--------------------------------------------------------------------------
 
     @Override
-    public void writeDataValueSetXml( String dataSet, String period, String orgUnit, OutputStream out )
+    public void writeDataValueSetXml( String dataSet, String period, String orgUnit, OutputStream out, ExportOptions exportOptions )
     {
         DataSet dataSet_ = dataSetService.getDataSet( dataSet );
         Period period_ = PeriodType.getPeriodFromIsoString( period );
@@ -177,12 +178,12 @@
         period_ = periodService.reloadPeriod( period_ );
 
         dataValueSetStore.writeDataValueSetXml( newHashSet( dataSet_ ), completeDate, period_, orgUnit_, wrap( period_ ),
-            wrap( orgUnit_ ), out );
+            wrap( orgUnit_ ), out, exportOptions );
     }
 
     @Override
     public void writeDataValueSetXml( Set<String> dataSets, Date startDate, Date endDate, Set<String> orgUnits, 
-        boolean includeChildren, OutputStream out )
+        boolean includeChildren, OutputStream out, ExportOptions exportOptions )
     {
         Set<DataSet> ds = new HashSet<>( dataSetService.getDataSetsByUid( dataSets ) );
         Set<Period> pe = new HashSet<>( periodService.getPeriodsBetweenDates( startDate, endDate ) );
@@ -208,11 +209,11 @@
             ou = new HashSet<>( organisationUnitService.getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( ou ) ) );
         }
         
-        dataValueSetStore.writeDataValueSetXml( ds, null, null, null, pe, ou, out );
+        dataValueSetStore.writeDataValueSetXml( ds, null, null, null, pe, ou, out, exportOptions );
     }
 
     @Override
-    public void writeDataValueSetJson( String dataSet, String period, String orgUnit, OutputStream outputStream )
+    public void writeDataValueSetJson( String dataSet, String period, String orgUnit, OutputStream outputStream, ExportOptions exportOptions )
     {
         DataSet dataSet_ = dataSetService.getDataSet( dataSet );
         Period period_ = PeriodType.getPeriodFromIsoString( period );
@@ -243,18 +244,18 @@
         period_ = periodService.reloadPeriod( period_ );
 
         dataValueSetStore.writeDataValueSetJson( newHashSet( dataSet_ ), completeDate, period_, orgUnit_, wrap( period_ ),
-            wrap( orgUnit_ ), outputStream );
+            wrap( orgUnit_ ), outputStream, exportOptions );
     }
 
     @Override
-    public void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream )
+    public void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream, ExportOptions exportOptions )
     {
-        dataValueSetStore.writeDataValueSetJson( lastUpdated, outputStream );
+        dataValueSetStore.writeDataValueSetJson( lastUpdated, outputStream, exportOptions );
     }
 
     @Override
     public void writeDataValueSetJson( Set<String> dataSets, Date startDate, Date endDate, Set<String> orgUnits,
-        boolean includeChildren, OutputStream outputStream )
+        boolean includeChildren, OutputStream outputStream, ExportOptions exportOptions )
     {
         Set<DataSet> ds = new HashSet<>( dataSetService.getDataSetsByUid( dataSets ) );
         Set<Period> pe = new HashSet<>( periodService.getPeriodsBetweenDates( startDate, endDate ) );
@@ -280,12 +281,12 @@
             ou = new HashSet<>( organisationUnitService.getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( ou ) ) );
         }
 
-        dataValueSetStore.writeDataValueSetJson( ds, null, null, null, pe, ou, outputStream );
+        dataValueSetStore.writeDataValueSetJson( ds, null, null, null, pe, ou, outputStream, exportOptions );
     }
 
     @Override
     public void writeDataValueSetCsv( Set<String> dataSets, Date startDate, Date endDate, Set<String> orgUnits,
-        boolean includeChildren, Writer writer )
+        boolean includeChildren, Writer writer, ExportOptions exportOptions )
     {
         Set<DataSet> ds = new HashSet<>( dataSetService.getDataSetsByUid( dataSets ) );
         Set<Period> pe = new HashSet<>( periodService.getPeriodsBetweenDates( startDate, endDate ) );
@@ -311,7 +312,7 @@
             ou = new HashSet<>( organisationUnitService.getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( ou ) ) );
         }
 
-        dataValueSetStore.writeDataValueSetCsv( ds, pe, ou, writer );
+        dataValueSetStore.writeDataValueSetCsv( ds, pe, ou, writer, exportOptions );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	2014-08-26 09:26:55 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	2014-09-12 15:26:18 +0000
@@ -46,6 +46,7 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dxf2.datavalue.DataValue;
+import org.hisp.dhis.dxf2.metadata.ExportOptions;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
@@ -74,41 +75,47 @@
 
     @Override
     public void writeDataValueSetXml( Set<DataSet> dataSets, Date completeDate, Period period, OrganisationUnit orgUnit,
-        Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream out )
+        Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream out, ExportOptions exportOptions )
     {
         DataValueSet dataValueSet = new StreamingDataValueSet( XMLFactory.getXMLWriter( out ) );
 
-        writeDataValueSet( getDataValueSql( dataSets, periods, orgUnits ), dataSets, completeDate, period, orgUnit, periods, orgUnits, dataValueSet );
+        writeDataValueSet( getDataValueSql( dataSets, periods, orgUnits, exportOptions ), dataSets, completeDate, period, orgUnit, periods, orgUnits, dataValueSet );
 
         StreamUtils.closeOutputStream( out );
     }
 
     @Override
     public void writeDataValueSetJson( Set<DataSet> dataSets, Date completeDate, Period period, OrganisationUnit orgUnit, 
-        Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream outputStream )
+        Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream outputStream, ExportOptions exportOptions )
     {
         DataValueSet dataValueSet = new StreamingJsonDataValueSet( outputStream );
 
-        writeDataValueSet( getDataValueSql( dataSets, periods, orgUnits ), dataSets, completeDate, period, orgUnit, periods, orgUnits, dataValueSet );
+        writeDataValueSet( getDataValueSql( dataSets, periods, orgUnits, exportOptions ), dataSets, completeDate, period, orgUnit, periods, orgUnits, dataValueSet );
 
         StreamUtils.closeOutputStream( outputStream );
     }
 
     @Override
-    public void writeDataValueSetCsv( Set<DataSet> dataSets, Set<Period> periods, Set<OrganisationUnit> orgUnits, Writer writer )
+    public void writeDataValueSetCsv( Set<DataSet> dataSets, Set<Period> periods, Set<OrganisationUnit> orgUnits, Writer writer, ExportOptions exportOptions )
     {
         DataValueSet dataValueSet = new StreamingCsvDataValueSet( new CsvWriter( writer, CSV_DELIM ) );
 
-        writeDataValueSet( getDataValueSql( dataSets, periods, orgUnits ), dataSets, null, null, null, periods, orgUnits, dataValueSet );
+        writeDataValueSet( getDataValueSql( dataSets, periods, orgUnits, exportOptions ), dataSets, null, null, null, periods, orgUnits, dataValueSet );
     }
 
     @Override
-    public void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream )
+    public void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream, ExportOptions exportOptions )
     {
+        String deScheme = exportOptions.getDataElementIdSchemeFallback().toString().toLowerCase();
+        String ouScheme = exportOptions.getOrgUnitIdSchemeFallback().toString().toLowerCase();
+        String ocScheme = exportOptions.getCategoryOptionComboIdSchemeFallback().toString().toLowerCase();
+        
         DataValueSet dataValueSet = new StreamingJsonDataValueSet( outputStream );
 
         final String sql =
-            "select de.uid as deuid, pe.startdate as pestart, pt.name as ptname, ou.uid as ouuid, coc.uid as cocuid, aoc.uid as aocuid, dv.value, dv.storedby, dv.created, dv.lastupdated, dv.comment, dv.followup " +
+            "select de." + deScheme + " as deid, pe.startdate as pestart, pt.name as ptname, ou." + ouScheme + " as ouid, " +
+            "coc." + ocScheme + " as cocid, aoc." + ocScheme + " as aocid, " + 
+            "dv.value, dv.storedby, dv.created, dv.lastupdated, dv.comment, dv.followup " +
             "from datavalue dv " +
             "join dataelement de on (dv.dataelementid=de.dataelementid) " +
             "join period pe on (dv.periodid=pe.periodid) " +
@@ -138,11 +145,11 @@
                 DataValue dataValue = dataValueSet.getDataValueInstance();
                 PeriodType pt = PeriodType.getPeriodTypeByName( rs.getString( "ptname" ) );
 
-                dataValue.setDataElement( rs.getString( "deuid" ) );
+                dataValue.setDataElement( rs.getString( "deid" ) );
                 dataValue.setPeriod( pt.createPeriod( rs.getDate( "pestart" ), calendar ).getIsoDate() );
-                dataValue.setOrgUnit( rs.getString( "ouuid" ) );
-                dataValue.setCategoryOptionCombo( rs.getString( "cocuid" ) );
-                dataValue.setAttributeOptionCombo( rs.getString( "aocuid" ) );
+                dataValue.setOrgUnit( rs.getString( "ouid" ) );
+                dataValue.setCategoryOptionCombo( rs.getString( "cocid" ) );
+                dataValue.setAttributeOptionCombo( rs.getString( "aocid" ) );
                 dataValue.setValue( rs.getString( "value" ) );
                 dataValue.setStoredBy( rs.getString( "storedby" ) );
                 dataValue.setCreated( getLongDateString( rs.getDate( "created" ) ) );
@@ -160,10 +167,18 @@
     // DataValueSetStore implementation
     //--------------------------------------------------------------------------
 
-    private String getDataValueSql( Set<DataSet> dataSets, Collection<Period> periods, Collection<OrganisationUnit> orgUnits )
+    private String getDataValueSql( Set<DataSet> dataSets, Collection<Period> periods, Collection<OrganisationUnit> orgUnits, ExportOptions exportOptions )
     {
+        exportOptions = exportOptions != null ? exportOptions : new ExportOptions();
+        
+        String deScheme = exportOptions.getDataElementIdSchemeFallback().toString().toLowerCase();
+        String ouScheme = exportOptions.getOrgUnitIdSchemeFallback().toString().toLowerCase();
+        String ocScheme = exportOptions.getCategoryOptionComboIdSchemeFallback().toString().toLowerCase();
+        
         return
-            "select de.uid as deuid, pe.startdate as pestart, pt.name as ptname, ou.uid as ouuid, coc.uid as cocuid, aoc.uid as aocuid, dv.value, dv.storedby, dv.created, dv.lastupdated, dv.comment, dv.followup " +
+            "select de." + deScheme + " as deid, pe.startdate as pestart, pt.name as ptname, ou." + ouScheme + " as ouid, " +
+            "coc." + ocScheme + " as cocid, aoc." + ocScheme + " as aocid, " +
+            "dv.value, dv.storedby, dv.created, dv.lastupdated, dv.comment, dv.followup " +
             "from datavalue dv " +
             "join dataelement de on (dv.dataelementid=de.dataelementid) " +
             "join period pe on (dv.periodid=pe.periodid) " +

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportOptions.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportOptions.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportOptions.java	2014-09-12 15:26:18 +0000
@@ -0,0 +1,122 @@
+package org.hisp.dhis.dxf2.metadata;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class ExportOptions
+{
+    private IdentifiableProperty dataElementIdScheme;
+
+    private IdentifiableProperty orgUnitIdScheme;
+    
+    private IdentifiableProperty categoryOptionComboIdScheme;
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public ExportOptions()
+    {
+    }
+    
+    public ExportOptions( IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, IdentifiableProperty categoryOptionComboIdScheme )
+    {
+        this.dataElementIdScheme = dataElementIdScheme;
+        this.orgUnitIdScheme = orgUnitIdScheme;
+        this.categoryOptionComboIdScheme = categoryOptionComboIdScheme;
+    }
+
+    // -------------------------------------------------------------------------
+    // toString
+    // -------------------------------------------------------------------------
+
+    public String toString()
+    {
+        return "[Data element id scheme: " + dataElementIdScheme + 
+            ", org unit id scheme: " + orgUnitIdScheme + 
+            ", category option combo id scheme: " + categoryOptionComboIdScheme + "]";
+    }
+
+    // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    public IdentifiableProperty getDataElementIdSchemeFallback()
+    {
+        return dataElementIdScheme != null ? dataElementIdScheme : IdentifiableProperty.UID;
+    }
+    
+    public IdentifiableProperty getOrgUnitIdSchemeFallback()
+    {
+        return orgUnitIdScheme != null ? orgUnitIdScheme : IdentifiableProperty.UID;
+    }
+    
+    public IdentifiableProperty getCategoryOptionComboIdSchemeFallback()
+    {
+        return categoryOptionComboIdScheme != null ? categoryOptionComboIdScheme : IdentifiableProperty.UID;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    public IdentifiableProperty getDataElementIdScheme()
+    {
+        return dataElementIdScheme;
+    }
+
+    public void setDataElementIdScheme( IdentifiableProperty dataElementIdScheme )
+    {
+        this.dataElementIdScheme = dataElementIdScheme;
+    }
+
+    public IdentifiableProperty getOrgUnitIdScheme()
+    {
+        return orgUnitIdScheme;
+    }
+
+    public void setOrgUnitIdScheme( IdentifiableProperty orgUnitIdScheme )
+    {
+        this.orgUnitIdScheme = orgUnitIdScheme;
+    }
+
+    public IdentifiableProperty getCategoryOptionComboIdScheme()
+    {
+        return categoryOptionComboIdScheme;
+    }
+
+    public void setCategoryOptionComboIdScheme( IdentifiableProperty categoryOptionComboIdScheme )
+    {
+        this.categoryOptionComboIdScheme = categoryOptionComboIdScheme;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java	2014-03-31 06:42:29 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java	2014-09-12 15:26:18 +0000
@@ -36,7 +36,7 @@
  */
 public class ImportOptions
 {
-    private IdentifiableProperty dataElementIdScheme;
+    private IdentifiableProperty dataElementIdScheme = IdentifiableProperty.UID;
 
     private IdentifiableProperty orgUnitIdScheme = IdentifiableProperty.UID;
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java	2014-09-12 15:26:18 +0000
@@ -43,6 +43,7 @@
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
 import org.hisp.dhis.dxf2.importsummary.ImportStatus;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.metadata.ExportOptions;
 import org.hisp.dhis.dxf2.utils.ImportSummaryResponseExtractor;
 import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.setting.SystemSettingManager;
@@ -205,7 +206,7 @@
             {
                 request.getHeaders().setContentType( MediaType.APPLICATION_JSON );
                 request.getHeaders().add( HEADER_AUTHORIZATION, CodecUtils.getBasicAuthString( config.getRemoteServerUsername(), config.getRemoteServerPassword() ) );
-                dataValueSetService.writeDataValueSetJson( lastSuccessTime, request.getBody() );
+                dataValueSetService.writeDataValueSetJson( lastSuccessTime, request.getBody(), new ExportOptions() );
             }            
         };
         

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java	2014-08-24 15:45:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java	2014-09-12 15:26:18 +0000
@@ -51,6 +51,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.metadata.ExportOptions;
 import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -94,6 +95,7 @@
         @RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
         @RequestParam Set<String> orgUnit,
         @RequestParam( required = false ) boolean children,
+        ExportOptions exportOptions,
         HttpServletResponse response ) throws IOException
     {
         response.setContentType( CONTENT_TYPE_XML );
@@ -107,13 +109,13 @@
 
             log.info( "Get XML data value set for data set: " + ds + ", period: " + period + ", org unit: " + ou );
 
-            dataValueSetService.writeDataValueSetXml( ds, period, ou, response.getOutputStream() );
+            dataValueSetService.writeDataValueSetXml( ds, period, ou, response.getOutputStream(), exportOptions );
         }
         else
         {
             log.info( "Get XML bulk data value set for start date: " + startDate + ", end date: " + endDate );
             
-            dataValueSetService.writeDataValueSetXml( dataSet, startDate, endDate, orgUnit, children, response.getOutputStream() );
+            dataValueSetService.writeDataValueSetXml( dataSet, startDate, endDate, orgUnit, children, response.getOutputStream(), exportOptions );
         }
     }
 
@@ -125,6 +127,7 @@
         @RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
         @RequestParam Set<String> orgUnit,
         @RequestParam( required = false ) boolean children,
+        ExportOptions exportOptions,
         HttpServletResponse response ) throws IOException
     {
         response.setContentType( CONTENT_TYPE_JSON );
@@ -138,13 +141,13 @@
 
             log.info( "Get JSON data value set for data set: " + ds + ", period: " + period + ", org unit: " + ou );
 
-            dataValueSetService.writeDataValueSetJson( ds, period, ou, response.getOutputStream() );
+            dataValueSetService.writeDataValueSetJson( ds, period, ou, response.getOutputStream(), exportOptions );
         }
         else
         {
             log.info( "Get JSON bulk data value set for start date: " + startDate + ", end date: " + endDate );
             
-            dataValueSetService.writeDataValueSetJson( dataSet, startDate, endDate, orgUnit, children, response.getOutputStream() );
+            dataValueSetService.writeDataValueSetJson( dataSet, startDate, endDate, orgUnit, children, response.getOutputStream(), exportOptions );
         }
     }
 
@@ -155,13 +158,14 @@
         @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
         @RequestParam Set<String> orgUnit,
         @RequestParam( required = false ) boolean children,
+        ExportOptions exportOptions,
         HttpServletResponse response ) throws IOException
     {
         log.info( "Get CSV bulk data value set for start date: " + startDate + ", end date: " + endDate );
 
         response.setContentType( CONTENT_TYPE_CSV );
         
-        dataValueSetService.writeDataValueSetCsv( dataSet, startDate, endDate, orgUnit, children, response.getWriter() );
+        dataValueSetService.writeDataValueSetCsv( dataSet, startDate, endDate, orgUnit, children, response.getWriter(), exportOptions );
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java	2014-08-24 15:24:33 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java	2014-09-12 15:26:18 +0000
@@ -36,16 +36,16 @@
 
 import java.io.OutputStreamWriter;
 import java.io.Writer;
-import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.struts2.ServletActionContext;
+import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
 import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.dxf2.metadata.ExportOptions;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
 import org.hisp.dhis.util.ContextUtils;
@@ -108,6 +108,27 @@
         this.exportFormat = exportFormat;
     }
 
+    private IdentifiableProperty dataElementIdScheme;
+
+    public void setDataElementIdScheme( IdentifiableProperty dataElementIdScheme )
+    {
+        this.dataElementIdScheme = dataElementIdScheme;
+    }
+
+    private IdentifiableProperty orgUnitIdScheme;
+
+    public void setOrgUnitIdScheme( IdentifiableProperty orgUnitIdScheme )
+    {
+        this.orgUnitIdScheme = orgUnitIdScheme;
+    }
+
+    private IdentifiableProperty categoryOptionComboIdScheme;
+
+    public void setCategoryOptionComboIdScheme( IdentifiableProperty categoryOptionComboIdScheme )
+    {
+        this.categoryOptionComboIdScheme = categoryOptionComboIdScheme;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -117,6 +138,8 @@
     {
         //TODO reimplement to use web api
         
+        ExportOptions exportOptions = new ExportOptions( dataElementIdScheme, orgUnitIdScheme, categoryOptionComboIdScheme );
+        
         Set<String> orgUnits = new HashSet<>( IdentifiableObjectUtils.getUids( selectionTreeManager.getSelectedOrganisationUnits() ) );
                 
         HttpServletResponse response = ServletActionContext.getResponse();
@@ -127,13 +150,15 @@
             
             Writer writer = new OutputStreamWriter( getZipOut( response, getFileName( EXTENSION_CSV ) ) );
             
-            dataValueSetService.writeDataValueSetCsv( selectedDataSets, getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, true, writer );
+            dataValueSetService.writeDataValueSetCsv( selectedDataSets, getMediumDate( startDate ), 
+                getMediumDate( endDate ), orgUnits, true, writer, exportOptions );
         }
         else
         {
             ContextUtils.configureResponse( response, CONTENT_TYPE_XML, true, getFileName( EXTENSION_XML_ZIP ), true );
             
-            dataValueSetService.writeDataValueSetXml( selectedDataSets, getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, true, getZipOut( response, getFileName( EXTENSION_XML ) ) );
+            dataValueSetService.writeDataValueSetXml( selectedDataSets, getMediumDate( startDate ), 
+                getMediumDate( endDate ), orgUnits, true, getZipOut( response, getFileName( EXTENSION_XML ) ), exportOptions );
         }
         
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties	2014-08-24 22:46:25 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties	2014-09-12 15:26:18 +0000
@@ -313,7 +313,6 @@
 programs=Programs
 program_stages=Program Stages
 format=Format
-orgunit_scheme=OrgUnit Scheme
 compression=Compression
 compression_gzip=Gzip
 compression_zip=Zip
@@ -326,6 +325,7 @@
 enable=Enable
 disable=Disable
 org_unit_id_scheme=Org unit ID scheme
+category_id_scheme=Category ID scheme
 uid=UID
 name=Name
 code=Code
@@ -352,6 +352,7 @@
 filtered_metadata_export=Meta-Data Detailed Export
 apply=Apply
 sort=Sort
+options=Options
 add_new_filter=Add new Filter
 ad_hoc_export=Ad hoc export
 create_new_filter=Create new Filter

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataForm.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataForm.vm	2014-02-04 09:38:57 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataForm.vm	2014-09-12 15:26:18 +0000
@@ -35,7 +35,8 @@
   	</tr>
 	
 </table>	
-	<table width="708">
+
+<table width="708">
 	
     <colgroup>
         <col width="325">
@@ -58,8 +59,7 @@
 		<td colspan="2" height="15"></td>
 	</tr>
     
-    
-    </table>
+</table>
 	
 <table width="325">
 

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm	2013-09-08 17:26:58 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm	2014-09-12 15:26:18 +0000
@@ -53,23 +53,7 @@
     <tr>
         <td colspan="3" height="15"></td>
     </tr>
-    	
-	<!-- Timespan -->
-	
-	<tr>
-		<th>$i18n.getString( "start_date" )</th>
-		<td></td>
-		<th>$i18n.getString( "end_date" )</th>
-	</tr>	
-    <tr>
-  		<td><input type="text" id="startDate" name="startDate" value="$!startDate" style="width:230px"></td>
-		<td></td>
-  		<td><input type="text" id="endDate" name="endDate" value="$!endDate" style="width:230px"></td>
-  	</tr>
-  	<tr>
-		<td colspan="3" height="15"></td>
-	</tr>
-  	  
+      	  
 	<!-- DataSets -->
 	
 	<tr>
@@ -90,13 +74,59 @@
 		<td>
 			<select multiple id="selectedDataSets" name="selectedDataSets" style="height: 200px; width: 100%; margin-top: 22px;"></select>
 		</td>
-	</tr>	
+	</tr>
+</table>
+
+<table style="padding-bottom: 15px">
+	<col width="140">
+	<col>
+	<tr>
+		<th colspan="2">$i18n.getString( "options" )</th>
+	</tr>
+	<tr>
+		<td>$i18n.getString( "start_date" )</td>
+		<td><input type="text" id="startDate" name="startDate" value="$!startDate" style="width:190px"></td>
+	</tr>
+	<tr>
+		<td>$i18n.getString( "end_date" )</td>
+		<td><input type="text" id="endDate" name="endDate" value="$!endDate" style="width:190px"></td>
+	</tr>
+	<tr>
+		<td></td>
+		<td><a href="javascript:toggleOptions()">$i18n.getString( "more_options" )</a></td>
+	</tr>
+	<tr class="moreOptions" style="display:none">
+		<td>$i18n.getString( "data_element_id_scheme" )</td>	
+		<td><select id="dataElementIdScheme" name="dataElementIdScheme" style="width:190px">
+			<option value="UID">$i18n.getString( "uid" )</option>
+			<option value="CODE">$i18n.getString( "code" )</option>
+			<option value="NAME">$i18n.getString( "name" )</option>
+	    </select></td>
+	</tr>
+	<tr class="moreOptions" style="display:none">
+		<td>$i18n.getString( "org_unit_id_scheme" )</td>	
+		<td><select id="orgUnitIdScheme" name="orgUnitIdScheme" style="width:190px">
+			<option value="UID">$i18n.getString( "uid" )</option>
+			<option value="CODE">$i18n.getString( "code" )</option>
+			<option value="NAME">$i18n.getString( "name" )</option>
+	    </select></td>
+	</tr>
+	<tr class="moreOptions" style="display:none">
+		<td>$i18n.getString( "category_id_scheme" )</td>	
+		<td><select id="categoryOptionComboIdScheme" name="categoryOptionComboIdScheme" style="width:190px">
+			<option value="UID">$i18n.getString( "uid" )</option>
+			<option value="CODE">$i18n.getString( "code" )</option>
+	    </select></td>
+	</tr>
+</table>
+
+<table>
 	
 	<!-- Submit -->
 	
 	<tr>		
-		<td><input type="button" value="$i18n.getString( 'export_as_xml' )" style="width:48%" onclick="exportDataValue( 'xml' )">
-		<input type="button" value="$i18n.getString( 'export_as_csv' )" style="width:48%" onclick="exportDataValue( 'csv' )"></td>
+		<td><input type="button" value="$i18n.getString( 'export_as_xml' )" style="width:120px" onclick="exportDataValue( 'xml' )">
+		<input type="button" value="$i18n.getString( 'export_as_csv' )" style="width:120px" onclick="exportDataValue( 'csv' )"></td>
 		<td></td>
 		<td></td>
 	</tr>

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importDataValue.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importDataValue.vm	2013-09-03 18:28:38 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importDataValue.vm	2014-09-12 15:26:18 +0000
@@ -33,16 +33,16 @@
 	<td>$i18n.getString( "data_element_id_scheme" )</td>	
 	<td><select id="dataElementIdScheme" name="dataElementIdScheme" style="width:190px">
 		<option value="UID">$i18n.getString( "uid" )</option>
+		<option value="CODE">$i18n.getString( "code" )</option>
 		<option value="NAME">$i18n.getString( "name" )</option>
-		<option value="CODE">$i18n.getString( "code" )</option>
     </select></td>
 </tr>
 <tr class="moreOptions" style="display:none">
 	<td>$i18n.getString( "org_unit_id_scheme" )</td>	
 	<td><select id="orgUnitIdScheme" name="orgUnitIdScheme" style="width:190px">
 		<option value="UID">$i18n.getString( "uid" )</option>
+		<option value="CODE">$i18n.getString( "code" )</option>
 		<option value="NAME">$i18n.getString( "name" )</option>
-		<option value="CODE">$i18n.getString( "code" )</option>
     </select></td>
 </tr>
 <tr class="moreOptions" style="display:none">

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importForm.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importForm.vm	2011-07-13 06:40:49 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importForm.vm	2014-09-12 15:26:18 +0000
@@ -136,3 +136,4 @@
 
 <span id="message"></span>
 <span id="info"></span>
+

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/export.js'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/export.js	2014-02-04 09:38:57 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/export.js	2014-09-12 15:26:18 +0000
@@ -14,6 +14,11 @@
 	}
 }
 
+function toggleOptions()
+{
+	$( ".moreOptions" ).toggle();
+}
+
 // -----------------------------------------------------------------------------
 // MetaDataExport
 // -----------------------------------------------------------------------------
@@ -36,9 +41,10 @@
 }
 
 
-//-----------------------------------------------------------------------------
-//DataExport
-//-----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
+// DataExport
+// -----------------------------------------------------------------------------
+
 function submitDataExportForm()
 {
     if ( validateDataExportForm() )