=== 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 validationErrors = new HashMap(); + + public Map 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 outliers; + + MinMaxDataElement minMaxDataElement = minMaxDataElementService.getMinMaxDataElement( organisationUnit, + dataElement, optionCombo ); + + if ( minMaxDataElement == null ) + { + Double factor = (Double) systemSettingManager.getSystemSetting( + SystemSettingManager.KEY_FACTOR_OF_DEVIATION, 2.0 ); + + Collection stdDevs = stdDevOutlierAnalysisService.analyse( organisationUnit, + ListUtils.getCollection( dataElement ), ListUtils.getCollection( period ), factor ); + + Collection 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 dataValues = new HashMap(); + + public Map 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 @@ + + + + + + + - + + + - /dhis-web-light/main.vm - /dhis-web-light/saveSuccess.vm + /dhis-web-light/index.action + /dhis-web-light/main.vm + /dhis-web-light/dataEntry.vm === 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 @@ + #foreach( $section in $dataSet.sections )
@@ -23,8 +24,17 @@

- - + $complete + $validated + + + +

+
+ +
+

+

=== 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!