← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1282: Work in progress on gap analysis

 

------------------------------------------------------------
revno: 1282
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2009-12-23 19:55:58 +0100
message:
  Work in progress on gap analysis
added:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/GapAnalysisService.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataanalysis/DataAnalysisStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/jdbc/JdbcDataAnalysisStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml


--
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/dataanalysis/DataAnalysisStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataanalysis/DataAnalysisStore.java	2009-12-23 18:43:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataanalysis/DataAnalysisStore.java	2009-12-23 18:55:58 +0000
@@ -46,4 +46,7 @@
     
     Collection<DeflatedDataValue> getDeflatedDataValues( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo,
         Collection<Period> periods, OrganisationUnit organisationUnit, int lowerBound, int upperBound );
+    
+    Collection<DeflatedDataValue> getNonExistingDeflatedDataValues( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo,
+        Collection<Period> periods, OrganisationUnit organisationUnit );
 }

=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/GapAnalysisService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/GapAnalysisService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/GapAnalysisService.java	2009-12-23 18:55:58 +0000
@@ -0,0 +1,94 @@
+package org.hisp.dhis.dataanalysis;
+
+/*
+ * Copyright (c) 2004-${year}, 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 java.util.ArrayList;
+import java.util.Collection;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.datavalue.DeflatedDataValue;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class GapAnalysisService
+    implements DataAnalysisService
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private OrganisationUnitService organisationUnitService;
+    
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+    
+    private DataAnalysisStore dataAnalysisStore;
+    
+    public void setDataAnalysisStore( DataAnalysisStore dataAnalysisStore )
+    {
+        this.dataAnalysisStore = dataAnalysisStore;
+    }
+
+    // -------------------------------------------------------------------------
+    // DataAnalysisService implementation
+    // -------------------------------------------------------------------------
+
+    public Collection<DeflatedDataValue> analyse( OrganisationUnit organisationUnit,
+        Collection<DataElement> dataElements, Collection<Period> periods, Double stdDevFactor )
+    {
+        Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId() );
+        
+        Collection<DeflatedDataValue> outlierCollection = new ArrayList<DeflatedDataValue>();
+            
+        for ( DataElement dataElement : dataElements )
+        {
+            if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
+            {                    
+                Collection<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo().getOptionCombos();
+                
+                for ( DataElementCategoryOptionCombo categoryOptionCombo : categoryOptionCombos )
+                {
+                    for ( OrganisationUnit unit : units )
+                    {
+                        outlierCollection.addAll( dataAnalysisStore.getNonExistingDeflatedDataValues( 
+                            dataElement, categoryOptionCombo, periods, unit ) );
+                    }
+                }
+            }
+        }
+
+        return outlierCollection;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/jdbc/JdbcDataAnalysisStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/jdbc/JdbcDataAnalysisStore.java	2009-12-23 18:43:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/jdbc/JdbcDataAnalysisStore.java	2009-12-23 18:55:58 +0000
@@ -138,4 +138,48 @@
             holder.close();
         }
     }
+
+    public Collection<DeflatedDataValue> getNonExistingDeflatedDataValues( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo,
+        Collection<Period> periods, OrganisationUnit organisationUnit )
+    {
+        final StatementHolder holder = statementManager.getHolder();
+        
+        final ObjectMapper<DeflatedDataValue> mapper = new ObjectMapper<DeflatedDataValue>();
+        
+        final String periodIds = TextUtils.getCommaDelimitedString( ConversionUtils.getIdentifiers( Period.class, periods ) );
+        
+        try
+        {
+            //TODO minmax
+            
+            final String sql =
+                "SELECT dv.dataelementid, dv.periodid, dv.sourceid, dv.categoryoptioncomboid, dv.value, dv.storedby, dv.lastupdated, " +
+                "dv.comment, dv.followup, '1' AS minvalue, '2' AS maxvalue, de.name AS dataelementname, " +
+                "pe.startdate, pe.enddate, pt.name as periodtypename, ou.name AS sourcename, cc.categoryoptioncomboname " +
+                "FROM datavalue AS dv " +                
+                "JOIN dataelement AS de USING (dataelementid) " +
+                "RIGHT JOIN period AS pe USING (periodid) " +
+                "JOIN periodtype AS pt USING (periodtypeid) " +
+                "JOIN source AS sr USING (sourceid) " +
+                "JOIN organisationunit AS ou ON ou.organisationunitid=sr.sourceid " +
+                "LEFT JOIN categoryoptioncomboname AS cc USING (categoryoptioncomboid) " +
+                "WHERE dv.dataelementid='" + dataElement.getId() + "' " +
+                "AND dv.categoryoptioncomboid='" + categoryOptionCombo.getId() + "' " +
+                "AND dv.periodid IN (" + periodIds + ") " +
+                "AND pt.periodtypeid='" + dataElement.getPeriodType().getId() + "' " +
+                "AND dv.sourceid='" + organisationUnit.getId() + "' )";
+            
+            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
+            
+            return mapper.getCollection( resultSet, new DeflatedDataValueNameMinMaxRowMapper() );
+        }
+        catch ( SQLException ex )
+        {
+            throw new RuntimeException( "Failed to get deflated data values", ex );
+        }
+        finally
+        {
+            holder.close();
+        }
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2009-12-23 17:34:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2009-12-23 18:55:58 +0000
@@ -341,6 +341,14 @@
       ref="org.hisp.dhis.dataanalysis.jdbc.DataAnalysisStore"/>  
   </bean>
   
+  <bean id="org.hisp.dhis.dataanalysis.GapAnalysisService"
+    class="org.hisp.dhis.dataanalysis.GapAnalysisService">
+    <property name="organisationUnitService"
+      ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+    <property name="dataAnalysisStore"
+      ref="org.hisp.dhis.dataanalysis.jdbc.DataAnalysisStore"/>  
+  </bean>
+  
   <!-- Startup routine definitions -->
 	
   <bean id="org.hisp.dhis.period.PeriodTypePopulator"