← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4289: Only loading relevant data sets in json at page init in data entry

 

------------------------------------------------------------
revno: 4289
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-08-13 12:41:20 +0200
message:
  Only loading relevant data sets in json at page init in data entry
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDataSetAssociationSet.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DataMartEngine.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/PageInitAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm


--
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-api/src/main/java/org/hisp/dhis/datamart/DataMartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartService.java	2011-07-01 07:12:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartService.java	2011-08-13 10:41:20 +0000
@@ -81,11 +81,10 @@
      * @param periodIds the period identifiers.
      * @param organisationUnitIds the organisation unit identifiers.
      * @param relatives the RelativePeriods.
-     * @param useIndexes indicates whether to create indexes on the data mart tables
-     *        after the export process.
+     * @param completeExport indicates whether this is a complete export.
      */
     void export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
-        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, RelativePeriods relatives, boolean useIndexes );
+        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, RelativePeriods relatives, boolean completeExport );
     
     // ----------------------------------------------------------------------
     // DataMartExport

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDataSetAssociationSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDataSetAssociationSet.java	2011-07-25 09:10:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDataSetAssociationSet.java	2011-08-13 10:41:20 +0000
@@ -29,6 +29,7 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -38,10 +39,21 @@
  */
 public class OrganisationUnitDataSetAssociationSet
 {
+    /**
+     * List of data set association sets.
+     */
     private List<Set<Integer>> dataSetAssociationSets = new ArrayList<Set<Integer>>();
     
+    /**
+     * Mapping between organisation unit identifier and index of association set in list.
+     */
     private Map<Integer, Integer> organisationUnitAssociationSetMap = new HashMap<Integer, Integer>();
 
+    /**
+     * Set of distinct data sets in all association sets.
+     */
+    private Set<Integer> distinctDataSets = new HashSet<Integer>();
+    
     public OrganisationUnitDataSetAssociationSet()
     {
     }
@@ -65,4 +77,14 @@
     {
         this.organisationUnitAssociationSetMap = organisationUnitAssociationSetMap;
     }
+
+    public Set<Integer> getDistinctDataSets()
+    {
+        return distinctDataSets;
+    }
+
+    public void setDistinctDataSets( Set<Integer> distinctDataSets )
+    {
+        this.distinctDataSets = distinctDataSets;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-08-11 14:01:50 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-08-13 10:41:20 +0000
@@ -423,9 +423,9 @@
     public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name,
         Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit )
     {
-        boolean _limit = limit && parent == null; // Can only limit in query if
-                                                  // parent is not set and we
-                                                  // get all units
+        // Can only limit in query if parent is not set and we get all units
+        
+        boolean _limit = limit && parent == null;
 
         final Collection<OrganisationUnit> result = organisationUnitStore.getOrganisationUnitsByNameAndGroups( name,
             groups, _limit );
@@ -464,6 +464,7 @@
             }
 
             set.getOrganisationUnitAssociationSetMap().put( entry.getKey(), index );
+            set.getDistinctDataSets().addAll( entry.getValue() );
         }
 
         return set;

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DataMartEngine.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DataMartEngine.java	2011-07-01 07:12:30 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DataMartEngine.java	2011-08-13 10:41:20 +0000
@@ -43,10 +43,9 @@
      * @param indicatorIds the indicator identifiers.
      * @param periodIds the period identifiers.
      * @param organisationUnitIds the organisation unit identifiers.
-     * @param useIndexes indicates whether to create indexes on the data mart tables
-     *        after the export process.
+     * @param completeExport indicates whether this is a complete export.
      * @param processState the state object.
      */
     void export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
-        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, boolean useIndexes, ProcessState processState );
+        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, boolean completeExport, ProcessState processState );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java	2011-08-02 11:11:03 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java	2011-08-13 10:41:20 +0000
@@ -152,7 +152,7 @@
 
     @Transactional
     public void export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
-        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, boolean useIndexes, ProcessState state )
+        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, boolean completeExport, ProcessState state )
     {
         final int cpuCores = SystemUtils.getCpuCores();
         
@@ -303,7 +303,7 @@
         // Create potential indexes
         // ---------------------------------------------------------------------
 
-        if ( useIndexes )
+        if ( completeExport )
         {
             aggregatedDataValueService.createIndex( true, isIndicators );
             

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2011-07-01 07:12:30 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2011-08-13 10:41:20 +0000
@@ -116,14 +116,14 @@
 
     @Transactional
     public void export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
-        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, RelativePeriods relatives, boolean useIndexes )
+        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, RelativePeriods relatives, boolean completeExport )
     {
         if ( relatives != null )
         {
             periodIds.addAll( getIdentifiers( Period.class, periodService.reloadPeriods( relatives.getRelativePeriods( 1, null, false ) ) ) );
         }
         
-        dataMartEngine.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, useIndexes, new OutputHolderState() );
+        dataMartEngine.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, completeExport, new OutputHolderState() );
     }
     
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/PageInitAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/PageInitAction.java	2011-07-25 08:52:10 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/PageInitAction.java	2011-08-13 10:41:20 +0000
@@ -157,14 +157,14 @@
         
         indicators = indicatorService.getIndicatorsWithDataSets();
         
-        dataSets = dataSetService.getAllDataSets();
-        
         OrganisationUnitDataSetAssociationSet organisationUnitSet = organisationUnitService.getOrganisationUnitDataSetAssociationSet();
         
         dataSetAssociationSets = organisationUnitSet.getDataSetAssociationSets();
         
         organisationUnitAssociationSetMap = organisationUnitSet.getOrganisationUnitAssociationSetMap();
         
+        dataSets = dataSetService.getDataSets( organisationUnitSet.getDistinctDataSets() );
+        
         for ( Indicator indicator : indicators )
         {
             indicator.setExplodedNumerator( expressionService.explodeExpression( indicator.getNumerator() ) );

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-08-10 10:56:58 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-08-13 10:41:20 +0000
@@ -68,10 +68,10 @@
     for ( k in matcher )
     {
         var match = matcher[k];
-        var operand = match.replace( /[\[\]]/g, '' ); // Remove brackets from
-                                                        // expression to
-                                                        // simplify extraction
-                                                        // of identifiers
+        
+        // Remove brackets from expression to simplify extraction of identifiers
+        
+        var operand = match.replace( /[\[\]]/g, '' ); 
 
         var dataElementId = operand.substring( 0, operand.indexOf( SEPARATOR ) );
         var categoryOptionComboId = operand.substring( operand.indexOf( SEPARATOR ) + 1, operand.length );
@@ -80,8 +80,7 @@
 
         var value = $( fieldId ) && $( fieldId ).val() ? $( fieldId ).val() : '0';
 
-        expression = expression.replace( match, value ); // TODO signed
-                                                            // numbers
+        expression = expression.replace( match, value ); // TODO signed numbers
     }
 
     return expression;
@@ -127,8 +126,8 @@
             }
             if ( isValidZeroNumber( value ) )
             {
-                // If value is 0 and zero is not significant for data element,
-                // skip value
+                // If value = 0 and zero not significant for data element, skip
+                
                 if ( significantZeros.indexOf( dataElementId ) == -1 )
                 {
                     $( fieldId ).css( 'background-color', COLOR_GREEN );

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-08-12 16:38:31 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-08-13 10:41:20 +0000
@@ -224,9 +224,7 @@
     {
         $( '#selectedDataSetId' ).val( dataSetId );
 
-        if ( periodId && periodId != -1 && dataEntryFormIsLoaded ) // TODO if
-                                                                    // period
-                                                                    // valid
+        if ( periodId && periodId != -1 && dataEntryFormIsLoaded )
         {
             showLoader();
             loadDataValues();
@@ -374,59 +372,53 @@
     $( '[name="min"]' ).html( '' );
     $( '[name="max"]' ).html( '' );
 
-    $
-            .getJSON(
-                    'getDataValues.action',
-                    {
-                        periodId : periodId,
-                        dataSetId : dataSetId
-                    },
-                    function( json )
-                    {
-                        // Set data values, works for select lists too as data
-                        // value = select value
-
-                        $.each( json.dataValues, function( i, value )
-                        {
-                            var fieldId = '#' + value.id + '-val';
-
-                            if ( $( fieldId ) )
-                            {
-                                $( fieldId ).val( value.val );
-                            }
-
-                            dataValueMap[value.id] = value.val;
-                        } );
-
-                        // Set min-max values and colorize violation fields
-
-                        $
-                                .each(
-                                        json.minMaxDataElements,
-                                        function( i, value )
-                                        {
-                                            var minId = value.id + '-min';
-                                            var maxId = value.id + '-max';
-
-                                            var valFieldId = '#' + value.id + '-val';
-
-                                            var dataValue = dataValueMap[value.id];
-
-                                            if ( dataValue
-                                                    && ( ( value.min && new Number( dataValue ) < new Number( value.min ) ) || ( value.max && new Number(
-                                                            dataValue ) > new Number( value.max ) ) ) )
-                                            {
-                                                $( valFieldId ).css( 'background-color', COLOR_ORANGE );
-                                            }
-
-                                            currentMinMaxValueMap[minId] = value.min;
-                                            currentMinMaxValueMap[maxId] = value.max;
-                                        } );
-
-                        // Update indicator values in form
-
-                        updateIndicators();
-                    } );
+    $.getJSON( 'getDataValues.action', {
+            periodId : periodId,
+        	dataSetId : dataSetId
+        },
+        function( json )
+        {
+            // Set data values, works for select lists too as data
+            // value = select value
+
+            $.each( json.dataValues, function( i, value )
+            {
+                var fieldId = '#' + value.id + '-val';
+
+                if ( $( fieldId ) )
+                {
+                    $( fieldId ).val( value.val );
+                }
+
+                dataValueMap[value.id] = value.val;
+            } );
+
+            // Set min-max values and colorize violation fields
+
+            $.each( json.minMaxDataElements, function( i, value ) 
+            {
+                var minId = value.id + '-min';
+                var maxId = value.id + '-max';
+
+                var valFieldId = '#' + value.id + '-val';
+
+                var dataValue = dataValueMap[value.id];
+
+                if ( dataValue
+                        && ( ( value.min && new Number( dataValue ) < new Number( value.min ) ) || ( value.max && new Number(
+                                dataValue ) > new Number( value.max ) ) ) )
+                {
+                    $( valFieldId ).css( 'background-color', COLOR_ORANGE );
+                }
+
+                currentMinMaxValueMap[minId] = value.min;
+                currentMinMaxValueMap[maxId] = value.max;
+            } );
+
+            // Update indicator values in form
+
+            updateIndicators();
+        } );
 }
 
 function displayEntryFormCompleted()

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm	2011-07-28 09:34:27 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm	2011-08-13 10:41:20 +0000
@@ -33,7 +33,7 @@
 dataElements = {
 #set( $size2 = $dataElements.size() )
 #foreach( $dataElement in $dataElements )
-"${dataElement.id}":{"name":"${dataElement.name}","type":"$encoder.jsonEncode( ${dataElement.getDetailedNumberType()} )" 
+"${dataElement.id}":{"name":"$encoder.jsonEncode( ${dataElement.name} )","type":"$encoder.jsonEncode( ${dataElement.getDetailedNumberType()} )" 
 }#if( $velocityCount < $size2 ),#end
 #end };