← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4687: mobile: added support for setting dataset as complete (validation is wip)

 

------------------------------------------------------------
revno: 4687
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-09-26 14:56:17 +0200
message:
  mobile: added support for setting dataset as complete (validation is wip)
removed:
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/saveError.vm
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/saveSuccess.vm
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/GetSectionFormAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/SaveSectionFormAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntry.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-light/src/main/java/org/hisp/dhis/light/action/GetSectionFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/GetSectionFormAction.java	2011-09-23 23:07:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/GetSectionFormAction.java	2011-09-26 12:56:17 +0000
@@ -27,20 +27,32 @@
 
 package org.hisp.dhis.light.action;
 
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 
+import org.apache.commons.collections.CollectionUtils;
+import org.hisp.dhis.dataanalysis.DataAnalysisService;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataset.CompleteDataSetRegistration;
+import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.dataset.Section;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.datavalue.DeflatedDataValue;
+import org.hisp.dhis.minmax.MinMaxDataElement;
+import org.hisp.dhis.minmax.MinMaxDataElementService;
+import org.hisp.dhis.minmax.validation.MinMaxValuesGenerationService;
+import org.hisp.dhis.options.SystemSettingManager;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.util.ListUtils;
 
 import com.opensymphony.xwork2.Action;
 
@@ -61,6 +73,13 @@
         this.organisationUnitService = organisationUnitService;
     }
 
+    private DataValueService dataValueService;
+
+    public void setDataValueService( DataValueService dataValueService )
+    {
+        this.dataValueService = dataValueService;
+    }
+
     private DataSetService dataSetService;
 
     public void setDataSetService( DataSetService dataSetService )
@@ -68,11 +87,46 @@
         this.dataSetService = dataSetService;
     }
 
-    private DataValueService dataValueService;
-
-    public void setDataValueService( DataValueService dataValueService )
-    {
-        this.dataValueService = dataValueService;
+    private CompleteDataSetRegistrationService registrationService;
+
+    public void setRegistrationService( CompleteDataSetRegistrationService registrationService )
+    {
+        this.registrationService = registrationService;
+    }
+
+    private DataAnalysisService stdDevOutlierAnalysisService;
+
+    public void setStdDevOutlierAnalysisService( DataAnalysisService stdDevOutlierAnalysisService )
+    {
+        this.stdDevOutlierAnalysisService = stdDevOutlierAnalysisService;
+    }
+
+    private DataAnalysisService minMaxOutlierAnalysisService;
+
+    public void setMinMaxOutlierAnalysisService( DataAnalysisService minMaxOutlierAnalysisService )
+    {
+        this.minMaxOutlierAnalysisService = minMaxOutlierAnalysisService;
+    }
+
+    private SystemSettingManager systemSettingManager;
+
+    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+    {
+        this.systemSettingManager = systemSettingManager;
+    }
+
+    private MinMaxValuesGenerationService minMaxValuesGenerationService;
+
+    public void setMinMaxValuesGenerationService( MinMaxValuesGenerationService minMaxValuesGenerationService )
+    {
+        this.minMaxValuesGenerationService = minMaxValuesGenerationService;
+    }
+
+    private MinMaxDataElementService minMaxDataElementService;
+
+    public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService )
+    {
+        this.minMaxDataElementService = minMaxDataElementService;
     }
 
     // -------------------------------------------------------------------------
@@ -91,6 +145,18 @@
         return organisationUnitId;
     }
 
+    private String periodId;
+
+    public void setPeriodId( String periodId )
+    {
+        this.periodId = periodId;
+    }
+
+    public String getPeriodId()
+    {
+        return periodId;
+    }
+
     private Integer dataSetId;
 
     public void setDataSetId( Integer dataSetId )
@@ -103,18 +169,6 @@
         return dataSetId;
     }
 
-    private String periodId;
-
-    public void setPeriodId( String periodId )
-    {
-        this.periodId = periodId;
-    }
-
-    public String getPeriodId()
-    {
-        return periodId;
-    }
-
     private DataSet dataSet;
 
     public DataSet getDataSet()
@@ -129,6 +183,32 @@
         return dataValues;
     }
 
+    private Map<String, String> validationErrors = new HashMap<String, String>();
+
+    public Map<String, String> getValidationErrors()
+    {
+        return validationErrors;
+    }
+
+    private Boolean complete = false;
+
+    public void setComplete( Boolean complete )
+    {
+        this.complete = complete;
+    }
+
+    public Boolean getComplete()
+    {
+        return complete;
+    }
+
+    private String page;
+
+    public String getPage()
+    {
+        return page;
+    }
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
@@ -157,6 +237,7 @@
                     if ( dataValue != null )
                     {
                         value = dataValue.getValue();
+//                        validateDataElement( organisationUnit, dataElement, optionCombo, period, value );
                     }
 
                     dataValues.put( key, value );
@@ -164,6 +245,54 @@
             }
         }
 
+        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period,
+            organisationUnit );
+
+        complete = registration != null ? true : false;
+
         return SUCCESS;
     }
+
+    public void validateDataElement( OrganisationUnit organisationUnit, DataElement dataElement,
+        DataElementCategoryOptionCombo optionCombo, Period period, String value )
+    {
+        System.err.println( "====[ " + dataElement.getName() + " ]====" );
+
+        Collection<DeflatedDataValue> outliers;
+
+        MinMaxDataElement minMaxDataElement = minMaxDataElementService.getMinMaxDataElement( organisationUnit,
+            dataElement, optionCombo );
+
+        if ( minMaxDataElement == null )
+        {
+            Double factor = (Double) systemSettingManager.getSystemSetting(
+                SystemSettingManager.KEY_FACTOR_OF_DEVIATION, 2.0 );
+
+            Collection<DeflatedDataValue> stdDevs = stdDevOutlierAnalysisService.analyse( organisationUnit,
+                ListUtils.getCollection( dataElement ), ListUtils.getCollection( period ), factor );
+
+            Collection<DeflatedDataValue> minMaxs = minMaxOutlierAnalysisService.analyse( organisationUnit,
+                ListUtils.getCollection( dataElement ), ListUtils.getCollection( period ), null );
+
+            outliers = CollectionUtils.union( stdDevs, minMaxs );
+        }
+        else
+        {
+            System.err.println( "max: " + minMaxDataElement.getMax() );
+            System.err.println( "min: " + minMaxDataElement.getMin() );
+
+            outliers = minMaxValuesGenerationService.findOutliers( organisationUnit, ListUtils.getCollection( period ),
+                ListUtils.getCollection( minMaxDataElement ) );
+        }
+
+        System.out.println( "Found " + outliers.size() + " outliers." );
+
+        for ( DeflatedDataValue deflatedDataValue : outliers )
+        {
+            System.err.println( "max: " + deflatedDataValue.getMax() );
+            System.err.println( "min: " + deflatedDataValue.getMin() );
+        }
+
+        System.err.println( "value: " + value );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/SaveSectionFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/SaveSectionFormAction.java	2011-09-24 12:36:14 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/SaveSectionFormAction.java	2011-09-26 12:56:17 +0000
@@ -28,6 +28,7 @@
 package org.hisp.dhis.light.action;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
@@ -37,6 +38,11 @@
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.CompleteDataSetRegistration;
+import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.dataset.Section;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -94,6 +100,20 @@
         this.dataValueService = dataValueService;
     }
 
+    private DataSetService dataSetService;
+
+    public void setDataSetService( DataSetService dataSetService )
+    {
+        this.dataSetService = dataSetService;
+    }
+
+    private CompleteDataSetRegistrationService registrationService;
+
+    public void setRegistrationService( CompleteDataSetRegistrationService registrationService )
+    {
+        this.registrationService = registrationService;
+    }
+
     // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
@@ -105,6 +125,11 @@
         this.organisationUnitId = organisationUnitId;
     }
 
+    public Integer getOrganisationUnitId()
+    {
+        return organisationUnitId;
+    }
+
     private String periodId;
 
     public void setPeriodId( String periodId )
@@ -112,6 +137,61 @@
         this.periodId = periodId;
     }
 
+    public String getPeriodId()
+    {
+        return periodId;
+    }
+
+    private Integer dataSetId;
+
+    public void setDataSetId( Integer dataSetId )
+    {
+        this.dataSetId = dataSetId;
+    }
+
+    public Integer getDataSetId()
+    {
+        return dataSetId;
+    }
+
+    private DataSet dataSet;
+
+    public DataSet getDataSet()
+    {
+        return dataSet;
+    }
+
+    private Map<String, String> dataValues = new HashMap<String, String>();
+
+    public Map<String, String> getDataValues()
+    {
+        return dataValues;
+    }
+
+    private Boolean complete = false;
+
+    public void setComplete( Boolean complete )
+    {
+        this.complete = complete;
+    }
+
+    public Boolean getComplete()
+    {
+        return complete;
+    }
+
+    private Boolean validated;
+
+    public void setValidated( Boolean validated )
+    {
+        this.validated = validated;
+    }
+
+    public Boolean getValidated()
+    {
+        return validated;
+    }
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
@@ -125,6 +205,8 @@
 
         String storedBy = currentUserService.getCurrentUsername();
 
+        dataSet = dataSetService.getDataSet( dataSetId );
+
         if ( storedBy == null )
         {
             storedBy = "[unknown]";
@@ -172,6 +254,52 @@
             }
         }
 
+        for ( Section section : dataSet.getSections() )
+        {
+            for ( DataElement dataElement : section.getDataElements() )
+            {
+                for ( DataElementCategoryOptionCombo optionCombo : dataElement.getCategoryCombo().getOptionCombos() )
+                {
+                    DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, period,
+                        optionCombo );
+
+                    String key = String.format( "DE%dOC%d", dataElement.getId(), optionCombo.getId() );
+                    String value = "";
+
+                    if ( dataValue != null )
+                    {
+                        value = dataValue.getValue();
+                    }
+
+                    dataValues.put( key, value );
+                }
+            }
+        }
+
+        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period,
+            organisationUnit );
+
+        if ( registration == null && complete )
+        {
+            registration = new CompleteDataSetRegistration();
+            registration.setDataSet( dataSet );
+            registration.setPeriod( period );
+            registration.setSource( organisationUnit );
+            registration.setDate( new Date() );
+
+            registrationService.saveCompleteDataSetRegistration( registration );
+        }
+        else if ( registration != null && !complete )
+        {
+            registrationService.deleteCompleteDataSetRegistration( registration );
+        }
+
+        if ( validated == null || !validated )
+        {
+            validated = true;
+            return ERROR;
+        }
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2011-09-23 23:07:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2011-09-26 12:56:17 +0000
@@ -22,14 +22,24 @@
     <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
     <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
     <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
+    <property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" />
+
+    <property name="stdDevOutlierAnalysisService" ref="org.hisp.dhis.dataanalysis.StdDevOutlierAnalysisService" />
+    <property name="minMaxOutlierAnalysisService" ref="org.hisp.dhis.dataanalysis.MinMaxOutlierAnalysisService" />
+    <property name="minMaxValuesGenerationService" ref="org.hisp.dhis.minmax.validation.MinMaxValuesGenerationService" />
+    <property name="minMaxDataElementService" ref="org.hisp.dhis.minmax.MinMaxDataElementService" />
+    <property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
   </bean>
 
-  <bean id="org.hisp.dhis.light.action.SaveSectionFormAction" class="org.hisp.dhis.light.action.SaveSectionFormAction">
+  <bean id="org.hisp.dhis.light.action.SaveSectionFormAction" class="org.hisp.dhis.light.action.SaveSectionFormAction"
+    scope="prototype">
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
     <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
     <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
     <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
     <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
+    <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+    <property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" />
   </bean>
 
   <bean id="org.hisp.dhis.light.action.ProvideContentAction" class="org.hisp.dhis.light.action.ProvideContentAction"

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml	2011-09-23 23:07:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml	2011-09-26 12:56:17 +0000
@@ -33,8 +33,9 @@
     </action>
 
     <action name="saveSectionForm" class="org.hisp.dhis.light.action.SaveSectionFormAction">
-      <result name="success" type="velocity">/dhis-web-light/main.vm</result>
-      <param name="page">/dhis-web-light/saveSuccess.vm</param>
+      <result name="success" type="redirect">/dhis-web-light/index.action</result>
+      <result name="error" type="velocity">/dhis-web-light/main.vm</result>
+      <param name="page">/dhis-web-light/dataEntry.vm</param>
     </action>
 
     <action name="dashboard" class="org.hisp.dhis.light.action.ProvideContentAction">

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntry.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntry.vm	2011-09-23 23:07:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntry.vm	2011-09-26 12:56:17 +0000
@@ -6,6 +6,7 @@
 <input type="hidden" id="organisationUnitId" name="organisationUnitId" value="$organisationUnitId" />
 <input type="hidden" id="dataSetId" name="dataSetId" value="$dataSetId" />
 <input type="hidden" id="periodId" name="periodId" value="$periodId" />
+<input type="hidden" id="validated" name="validated" value="#if($validated)true#{else}false#end" />
 
 #foreach( $section in $dataSet.sections )
 <div class="header-box">
@@ -23,8 +24,17 @@
 
 <div class="header-box">
 	<p>
-		<input type="submit" style="width: 48%" value="Save"/>
-		<input type="reset" style="width: 48%" value="Clear"/>
+		$complete
+		$validated
+
+		<input type="checkbox" id="complete" name="complete" value="true" #if($complete)checked="true"#end style="width: 15px;" />
+		<label for="complete">DataSet is complete</label>
+	</p>
+</div>
+
+<div class="header-box" align="center">
+	<p>
+		<input type="submit" style="width: 100%;" value="Save"/> <br />
 	</p>
 </div>
 

=== removed file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/saveError.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/saveError.vm	2011-09-23 23:07:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/saveError.vm	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-
-ERROR!

=== removed file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/saveSuccess.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/saveSuccess.vm	2011-09-23 23:07:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/saveSuccess.vm	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-
-SUCCESS!