← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11179: GIS, impl infrastructual facility data using analytics engine

 

------------------------------------------------------------
revno: 11179
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-06-09 21:12:02 +0200
message:
  GIS, impl infrastructual facility data using analytics engine
modified:
  dhis-2/dhis-web/dhis-web-mapping/pom.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetInfrastructuralDataElementMapValuesAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonInfrastructuralAggregatedMapValues.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-web/dhis-web-mapping/pom.xml'
--- dhis-2/dhis-web/dhis-web-mapping/pom.xml	2013-05-31 08:27:38 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/pom.xml	2013-06-09 19:12:02 +0000
@@ -40,7 +40,7 @@
     </dependency>
     <dependency>
       <groupId>org.hisp.dhis</groupId>
-      <artifactId>dhis-service-datamart-default</artifactId>
+      <artifactId>dhis-service-analytics</artifactId>
     </dependency>
     <dependency>
       <groupId>org.hisp.dhis</groupId>

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetInfrastructuralDataElementMapValuesAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetInfrastructuralDataElementMapValuesAction.java	2013-05-24 15:50:45 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetInfrastructuralDataElementMapValuesAction.java	2013-06-09 19:12:02 +0000
@@ -27,10 +27,24 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collection;
-
-import org.hisp.dhis.aggregation.AggregatedMapValue;
-import org.hisp.dhis.mapping.MappingService;
+import static org.hisp.dhis.common.NameableObjectUtils.getList;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hisp.dhis.analytics.AnalyticsService;
+import org.hisp.dhis.analytics.DataQueryParams;
+import org.hisp.dhis.configuration.ConfigurationService;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -45,13 +59,21 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private MappingService mappingService;
-
-    public void setMappingService( MappingService mappingService )
-    {
-        this.mappingService = mappingService;
-    }
-
+    @Autowired
+    private AnalyticsService analyticsService;
+
+    @Autowired
+    private PeriodService periodService;
+    
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+    
+    @Autowired
+    private DataElementService dataElementService;
+    
+    @Autowired
+    private ConfigurationService configurationService;
+    
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -74,9 +96,9 @@
     // Output
     // -------------------------------------------------------------------------
 
-    private Collection<AggregatedMapValue> object;
+    private Map<DataElement, Double> object = new HashMap<DataElement, Double>(); 
 
-    public Collection<AggregatedMapValue> getObject()
+    public Map<DataElement, Double> getObject()
     {
         return object;
     }
@@ -88,8 +110,34 @@
     public String execute()
         throws Exception
     {
-        object = mappingService.getInfrastructuralDataElementMapValues( periodId, organisationUnitId );
-
+        DataElementGroup group = configurationService.getConfiguration().getInfrastructuralDataElements();
+        
+        if ( group == null )
+        {
+            return SUCCESS;
+        }
+        
+        List<DataElement> dataElements = new ArrayList<DataElement>( group.getMembers() );
+        Period period = periodService.getPeriod( periodId );
+        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
+        
+        DataQueryParams params = new DataQueryParams();
+        params.setDataElements( dataElements );
+        params.setFilterPeriods( getList( period ) );
+        params.setFilterOrganisationUnits( getList( organisationUnit ) );
+        
+        Map<String, Double> map = analyticsService.getAggregatedDataValueMapping( params );
+        
+        for ( String deId : map.keySet() )
+        {
+            DataElement de = dataElementService.getDataElement( deId );
+            
+            if ( de != null )
+            {
+                object.put( de, map.get( deId ) );
+            }
+        }
+        
         return SUCCESS;
     }
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2013-05-24 13:32:24 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2013-06-09 19:12:02 +0000
@@ -59,7 +59,6 @@
 
     <bean id="org.hisp.dhis.mapping.action.GetInfrastructuralDataElementMapValuesAction"
         class="org.hisp.dhis.mapping.action.GetInfrastructuralDataElementMapValuesAction" scope="prototype">
-        <property name="mappingService" ref="org.hisp.dhis.mapping.MappingService" />
     </bean>
 
 <!-- Period -->

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonInfrastructuralAggregatedMapValues.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonInfrastructuralAggregatedMapValues.vm	2011-06-09 08:32:10 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonInfrastructuralAggregatedMapValues.vm	2013-06-09 19:12:02 +0000
@@ -1,1 +1,3 @@
-#set( $size = $object.size() ){"mapValues":[#foreach( $value in $object ){"dataElementName":"$!{value.dataElementName}","value":$!{value.value}}#if( $velocityCount < $size ),#end#end]}
\ No newline at end of file
+#set( $size = $object.size() )
+{"mapValues":[
+#foreach( $de in $object.keySet() ){"dataElementName":"$!encoder.jsonEncode(${de.name})","value":$!{object.get( $de )}}#if( $velocityCount < $size ),#end#end]}
\ No newline at end of file