=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/MenuAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/MenuAction.java 2012-01-09 11:55:36 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/MenuAction.java 2012-01-22 19:37:21 +0000 @@ -28,7 +28,14 @@ package org.hisp.dhis.light.action; import com.opensymphony.xwork2.Action; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; +import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.message.MessageService; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; public class MenuAction implements Action @@ -44,6 +51,34 @@ this.messageService = messageService; } + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + private DataSetService dataSetService; + + public void setDataSetService( DataSetService dataSetService ) + { + this.dataSetService = dataSetService; + } + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + private I18nFormat format; + + public void setFormat( I18nFormat format ) + { + this.format = format; + } + // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- @@ -55,6 +90,60 @@ return unreadMessageConversationCount; } + private Integer organisationUnitId; + + public void setOrganisationUnitId( Integer organisationUnitId ) + { + this.organisationUnitId = organisationUnitId; + } + + private OrganisationUnit organisationUnit; + + public OrganisationUnit getOrganisationUnit() + { + return organisationUnit; + } + + private String periodId; + + public void setPeriodId( String periodId ) + { + this.periodId = periodId; + } + + private Period period; + + public Period getPeriod() + { + return period; + } + + private Integer dataSetId; + + public void setDataSetId( Integer dataSetId ) + { + this.dataSetId = dataSetId; + } + + private DataSet dataSet; + + public DataSet getDataSet() + { + return dataSet; + } + + private boolean complete; + + public void setComplete( boolean complete ) + { + this.complete = complete; + } + + public boolean isComplete() + { + return complete; + } + // ------------------------------------------------------------------------- // Action Implementation // ------------------------------------------------------------------------- @@ -62,6 +151,16 @@ @Override public String execute() { + if ( complete ) + { + organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId ); + + period = periodService.getPeriodByExternalId( periodId ); + period.setName( format.formatPeriod( period ) ); + + dataSet = dataSetService.getDataSet( dataSetId ); + } + unreadMessageConversationCount = messageService.getUnreadMessageConversationCount(); return SUCCESS; === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetOverviewAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetOverviewAction.java 2012-01-13 10:16:31 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetOverviewAction.java 2012-01-22 19:37:21 +0000 @@ -29,19 +29,17 @@ import com.opensymphony.xwork2.Action; import org.apache.commons.lang.Validate; -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.light.dataentry.utils.FormUtils; +import org.hisp.dhis.dataset.Section; +import org.hisp.dhis.i18n.I18nFormat; +import org.hisp.dhis.light.utils.FormUtils; 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.hisp.dhis.user.CurrentUserService; import java.util.ArrayList; -import java.util.Date; import java.util.List; /** @@ -54,13 +52,6 @@ // Dependencies // ------------------------------------------------------------------------- - private CurrentUserService currentUserService; - - public void setCurrentUserService( CurrentUserService currentUserService ) - { - this.currentUserService = currentUserService; - } - private OrganisationUnitService organisationUnitService; public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) @@ -75,13 +66,6 @@ this.dataSetService = dataSetService; } - private CompleteDataSetRegistrationService registrationService; - - public void setRegistrationService( CompleteDataSetRegistrationService registrationService ) - { - this.registrationService = registrationService; - } - private PeriodService periodService; public void setPeriodService( PeriodService periodService ) @@ -101,6 +85,13 @@ return formUtils; } + private I18nFormat format; + + public void setFormat( I18nFormat format ) + { + this.format = format; + } + // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- @@ -117,6 +108,13 @@ return organisationUnitId; } + private OrganisationUnit organisationUnit; + + public OrganisationUnit getOrganisationUnit() + { + return organisationUnit; + } + private String periodId; public void setPeriodId( String periodId ) @@ -129,6 +127,13 @@ return periodId; } + private Period period; + + public Period getPeriod() + { + return period; + } + private Integer dataSetId; public void setDataSetId( Integer dataSetId ) @@ -148,33 +153,30 @@ return dataSet; } - private Boolean complete; - - public void setComplete( Boolean complete ) - { - this.complete = complete; - } - - public Boolean getComplete() - { - return complete; - } - - private Boolean formComplete; - - public Boolean getFormComplete() - { - return formComplete; - } - - public void setFormComplete( Boolean formComplete ) - { - this.formComplete = formComplete; + private Integer sectionId; + + public void setSectionId( Integer sectionId ) + { + this.sectionId = sectionId; + } + + private String sectionName; + + public String getSectionName() + { + return sectionName; + } + + private List validationRuleViolations = new ArrayList(); + + public List getValidationRuleViolations() + { + return validationRuleViolations; } private boolean validated; - public boolean getValidated() + public boolean isValidated() { return validated; } @@ -184,13 +186,6 @@ this.validated = validated; } - private List validationRuleViolations = new ArrayList(); - - public List getValidationRuleViolations() - { - return validationRuleViolations; - } - // ------------------------------------------------------------------------- // Action Implementation // ------------------------------------------------------------------------- @@ -202,38 +197,29 @@ Validate.notNull( periodId ); Validate.notNull( dataSetId ); - OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId ); - - Period period = periodService.getPeriodByExternalId( periodId ); + organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId ); + + period = periodService.getPeriodByExternalId( periodId ); + + period.setName( format.formatPeriod( period ) ); dataSet = dataSetService.getDataSet( dataSetId ); - CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period, - organisationUnit ); - - complete = registration != null ? true : false; - - if ( formComplete != null ) - { - if ( formComplete && !complete ) - { - registration = new CompleteDataSetRegistration(); - registration.setDataSet( dataSet ); - registration.setPeriod( period ); - registration.setSource( organisationUnit ); - registration.setDate( new Date() ); - registration.setStoredBy( currentUserService.getCurrentUsername() ); - - registrationService.saveCompleteDataSetRegistration( registration ); - - complete = true; - } - else if ( !formComplete && complete ) - { - registrationService.deleteCompleteDataSetRegistration( registration ); - - complete = false; - } + if ( sectionId != null ) + { + for ( Section section : dataSet.getSections() ) + { + if ( section.getId() == sectionId ) + { + sectionName = section.getName(); + + break; + } + } + } + else + { + sectionName = "Default"; } validationRuleViolations = formUtils.getValidationRuleViolations( organisationUnit, dataSet, period ); === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java 2012-01-04 12:55:23 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java 2012-01-22 19:37:21 +0000 @@ -29,7 +29,7 @@ import com.opensymphony.xwork2.Action; import org.apache.commons.lang.Validate; -import org.hisp.dhis.light.dataentry.utils.FormUtils; +import org.hisp.dhis.light.utils.FormUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; import org.hisp.dhis.user.CurrentUserService; === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java 2012-01-04 12:55:23 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java 2012-01-22 19:37:21 +0000 @@ -36,7 +36,7 @@ import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.dataset.Section; import org.hisp.dhis.datavalue.DeflatedDataValue; -import org.hisp.dhis.light.dataentry.utils.FormUtils; +import org.hisp.dhis.light.utils.FormUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; === added file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/MarkComplete.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/MarkComplete.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/MarkComplete.java 2012-01-22 19:37:21 +0000 @@ -0,0 +1,136 @@ +package org.hisp.dhis.light.dataentry.action; + +import com.opensymphony.xwork2.Action; +import org.apache.commons.lang.Validate; +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.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; +import org.hisp.dhis.user.CurrentUserService; + +import java.util.Date; + +/** + * @author Morten Olav Hansen + */ +public class MarkComplete + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private CurrentUserService currentUserService; + + public void setCurrentUserService( CurrentUserService currentUserService ) + { + this.currentUserService = currentUserService; + } + + private CompleteDataSetRegistrationService registrationService; + + public void setRegistrationService( CompleteDataSetRegistrationService registrationService ) + { + this.registrationService = registrationService; + } + + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + private DataSetService dataSetService; + + public void setDataSetService( DataSetService dataSetService ) + { + this.dataSetService = dataSetService; + } + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + // ------------------------------------------------------------------------- + // Input & Output + // ------------------------------------------------------------------------- + + private Integer organisationUnitId; + + public void setOrganisationUnitId( Integer organisationUnitId ) + { + this.organisationUnitId = organisationUnitId; + } + + public Integer getOrganisationUnitId() + { + 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 ) + { + this.dataSetId = dataSetId; + } + + public Integer getDataSetId() + { + return dataSetId; + } + + // ------------------------------------------------------------------------- + // Action Implementation + // ------------------------------------------------------------------------- + + @Override + public String execute() throws Exception + { + Validate.notNull( organisationUnitId ); + Validate.notNull( periodId ); + Validate.notNull( dataSetId ); + + OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId ); + + Period period = periodService.getPeriodByExternalId( periodId ); + + DataSet dataSet = dataSetService.getDataSet( dataSetId ); + + CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period, + organisationUnit ); + + if ( registration == null ) + { + registration = new CompleteDataSetRegistration(); + registration.setDataSet( dataSet ); + registration.setPeriod( period ); + registration.setSource( organisationUnit ); + registration.setDate( new Date() ); + registration.setStoredBy( currentUserService.getCurrentUsername() ); + + registrationService.saveCompleteDataSetRegistration( registration ); + } + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java 2012-01-16 18:30:37 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java 2012-01-22 19:37:21 +0000 @@ -44,7 +44,7 @@ import org.hisp.dhis.datavalue.DataValueService; import org.hisp.dhis.datavalue.DeflatedDataValue; import org.hisp.dhis.i18n.I18n; -import org.hisp.dhis.light.dataentry.utils.FormUtils; +import org.hisp.dhis.light.utils.FormUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; === removed directory 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils' === removed file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/FormUtils.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/FormUtils.java 2011-12-27 13:06:26 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/FormUtils.java 1970-01-01 00:00:00 +0000 @@ -1,319 +0,0 @@ -/* - * Copyright (c) 2004-2012, 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. - */ - -package org.hisp.dhis.light.dataentry.utils; - -import org.apache.commons.collections.CollectionUtils; -import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; -import org.hisp.dhis.dataanalysis.DataAnalysisService; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; -import org.hisp.dhis.datavalue.DeflatedDataValue; -import org.hisp.dhis.expression.ExpressionService; -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.period.Period; -import org.hisp.dhis.system.filter.OrganisationUnitWithDataSetsFilter; -import org.hisp.dhis.system.util.FilterUtils; -import org.hisp.dhis.system.util.ListUtils; -import org.hisp.dhis.validation.ValidationResult; -import org.hisp.dhis.validation.ValidationRule; -import org.hisp.dhis.validation.ValidationRuleService; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; - -import java.util.*; - -/** - * @author mortenoh - */ -public class FormUtils -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private DataValueService dataValueService; - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - 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; - } - - private ValidationRuleService validationRuleService; - - public void setValidationRuleService( ValidationRuleService validationRuleService ) - { - this.validationRuleService = validationRuleService; - } - - private ExpressionService expressionService; - - public void setExpressionService( ExpressionService expressionService ) - { - this.expressionService = expressionService; - } - - // ------------------------------------------------------------------------- - // Utils - // ------------------------------------------------------------------------- - - @SuppressWarnings( "unchecked" ) - public Map getValidationViolations( OrganisationUnit organisationUnit, Collection dataElements, - Period period ) - { - Map validationErrorMap = new HashMap(); - - Collection minmaxs = minMaxDataElementService.getMinMaxDataElements( organisationUnit, dataElements ); - Collection deflatedDataValues; - - if ( minmaxs == null ) - { - Double factor = (Double) systemSettingManager.getSystemSetting( - SystemSettingManager.KEY_FACTOR_OF_DEVIATION, 2.0 ); - - Collection stdDevs = stdDevOutlierAnalysisService.analyse( organisationUnit, - dataElements, ListUtils.getCollection( period ), factor ); - - Collection minMaxs = minMaxOutlierAnalysisService.analyse( organisationUnit, - dataElements, ListUtils.getCollection( period ), null ); - - deflatedDataValues = CollectionUtils.union( stdDevs, minMaxs ); - } - else - { - deflatedDataValues = minMaxValuesGenerationService.findOutliers( organisationUnit, - ListUtils.getCollection( period ), minmaxs ); - } - - for ( DeflatedDataValue deflatedDataValue : deflatedDataValues ) - { - String key = String.format( "DE%dOC%d", deflatedDataValue.getDataElementId(), - deflatedDataValue.getCategoryOptionComboId() ); - validationErrorMap.put( key, deflatedDataValue ); - } - - return validationErrorMap; - } - - public List getValidationRuleViolations( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) - { - List validationRuleResults = new ArrayList( validationRuleService.validate( - dataSet, period, organisationUnit ) ); - - List validationRuleViolations = new ArrayList( validationRuleResults.size() ); - - for ( ValidationResult result : validationRuleResults ) - { - ValidationRule rule = result.getValidationRule(); - - StringBuffer sb = new StringBuffer(); - sb.append( expressionService.getExpressionDescription( rule.getLeftSide().getExpression() ) ); - sb.append( " " + rule.getOperator().getMathematicalOperator() + " " ); - sb.append( expressionService.getExpressionDescription( rule.getRightSide().getExpression() ) ); - - validationRuleViolations.add( sb.toString() ); - } - - return validationRuleViolations; - } - - public Map getDataValueMap( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) - { - Map dataValueMap = new HashMap(); - List values = new ArrayList( dataValueService.getDataValues( organisationUnit, period, - dataSet.getDataElements() ) ); - - for ( DataValue dataValue : values ) - { - DataElement dataElement = dataValue.getDataElement(); - DataElementCategoryOptionCombo optionCombo = dataValue.getOptionCombo(); - - String key = String.format( "DE%dOC%d", dataElement.getId(), optionCombo.getId() ); - String value = dataValue.getValue(); - - dataValueMap.put( key, value ); - } - - return dataValueMap; - } - - public List organisationUnitWithDataSetsFilter( Collection organisationUnits ) - { - List ous = new ArrayList( organisationUnits ); - FilterUtils.filter( ous, new OrganisationUnitWithDataSetsFilter() ); - - return ous; - } - - // ------------------------------------------------------------------------- - // Static Utils - // ------------------------------------------------------------------------- - - public static boolean isNumber( String value ) - { - try - { - Double.parseDouble( value ); - } catch ( NumberFormatException e ) - { - return false; - } - - return true; - } - - public static boolean isInteger( String value ) - { - try - { - Integer.parseInt( value ); - } catch ( NumberFormatException e ) - { - return false; - } - - return true; - } - - public static boolean isPositiveInteger( String value ) - { - return valueHigher( value, 0 ); - } - - public static boolean isNegativeInteger( String value ) - { - return valueLower( value, 0 ); - } - - public static boolean valueHigher( String value, int max ) - { - int integerValue; - - try - { - integerValue = Integer.parseInt( value ); - - if ( integerValue > max ) - { - return true; - } - } catch ( NumberFormatException e ) - { - } - - return false; - } - - public static boolean valueLower( String value, int min ) - { - int integerValue; - - try - { - integerValue = Integer.parseInt( value ); - - if ( integerValue < min ) - { - return true; - } - } catch ( NumberFormatException e ) - { - } - - return false; - } - - public static boolean isBoolean( String value ) - { - return value.equals( "true" ) || value.equals( "false" ); - } - - public static boolean isDate( String value ) - { - DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay(); - - try - { - sdf.parseDateTime( value ); - return true; - } catch ( IllegalArgumentException e ) - { - } - - return false; - } - - public static List sortedCategoryOptionCombos( Collection categoryOptionCombos ) - { - List sortedCategoryOptionCombos = new ArrayList( categoryOptionCombos ); - Collections.sort( sortedCategoryOptionCombos, new IdentifiableObjectNameComparator() ); - - return sortedCategoryOptionCombos; - } -} === added directory 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils' === added file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java 2012-01-22 19:37:21 +0000 @@ -0,0 +1,319 @@ +/* + * Copyright (c) 2004-2012, 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. + */ + +package org.hisp.dhis.light.utils; + +import org.apache.commons.collections.CollectionUtils; +import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; +import org.hisp.dhis.dataanalysis.DataAnalysisService; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.datavalue.DeflatedDataValue; +import org.hisp.dhis.expression.ExpressionService; +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.period.Period; +import org.hisp.dhis.system.filter.OrganisationUnitWithDataSetsFilter; +import org.hisp.dhis.system.util.FilterUtils; +import org.hisp.dhis.system.util.ListUtils; +import org.hisp.dhis.validation.ValidationResult; +import org.hisp.dhis.validation.ValidationRule; +import org.hisp.dhis.validation.ValidationRuleService; +import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.ISODateTimeFormat; + +import java.util.*; + +/** + * @author mortenoh + */ +public class FormUtils +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private DataValueService dataValueService; + + public void setDataValueService( DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + + 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; + } + + private ValidationRuleService validationRuleService; + + public void setValidationRuleService( ValidationRuleService validationRuleService ) + { + this.validationRuleService = validationRuleService; + } + + private ExpressionService expressionService; + + public void setExpressionService( ExpressionService expressionService ) + { + this.expressionService = expressionService; + } + + // ------------------------------------------------------------------------- + // Utils + // ------------------------------------------------------------------------- + + @SuppressWarnings( "unchecked" ) + public Map getValidationViolations( OrganisationUnit organisationUnit, Collection dataElements, + Period period ) + { + Map validationErrorMap = new HashMap(); + + Collection minmaxs = minMaxDataElementService.getMinMaxDataElements( organisationUnit, dataElements ); + Collection deflatedDataValues; + + if ( minmaxs == null ) + { + Double factor = (Double) systemSettingManager.getSystemSetting( + SystemSettingManager.KEY_FACTOR_OF_DEVIATION, 2.0 ); + + Collection stdDevs = stdDevOutlierAnalysisService.analyse( organisationUnit, + dataElements, ListUtils.getCollection( period ), factor ); + + Collection minMaxs = minMaxOutlierAnalysisService.analyse( organisationUnit, + dataElements, ListUtils.getCollection( period ), null ); + + deflatedDataValues = CollectionUtils.union( stdDevs, minMaxs ); + } + else + { + deflatedDataValues = minMaxValuesGenerationService.findOutliers( organisationUnit, + ListUtils.getCollection( period ), minmaxs ); + } + + for ( DeflatedDataValue deflatedDataValue : deflatedDataValues ) + { + String key = String.format( "DE%dOC%d", deflatedDataValue.getDataElementId(), + deflatedDataValue.getCategoryOptionComboId() ); + validationErrorMap.put( key, deflatedDataValue ); + } + + return validationErrorMap; + } + + public List getValidationRuleViolations( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) + { + List validationRuleResults = new ArrayList( validationRuleService.validate( + dataSet, period, organisationUnit ) ); + + List validationRuleViolations = new ArrayList( validationRuleResults.size() ); + + for ( ValidationResult result : validationRuleResults ) + { + ValidationRule rule = result.getValidationRule(); + + StringBuffer sb = new StringBuffer(); + sb.append( expressionService.getExpressionDescription( rule.getLeftSide().getExpression() ) ); + sb.append( " " + rule.getOperator().getMathematicalOperator() + " " ); + sb.append( expressionService.getExpressionDescription( rule.getRightSide().getExpression() ) ); + + validationRuleViolations.add( sb.toString() ); + } + + return validationRuleViolations; + } + + public Map getDataValueMap( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) + { + Map dataValueMap = new HashMap(); + List values = new ArrayList( dataValueService.getDataValues( organisationUnit, period, + dataSet.getDataElements() ) ); + + for ( DataValue dataValue : values ) + { + DataElement dataElement = dataValue.getDataElement(); + DataElementCategoryOptionCombo optionCombo = dataValue.getOptionCombo(); + + String key = String.format( "DE%dOC%d", dataElement.getId(), optionCombo.getId() ); + String value = dataValue.getValue(); + + dataValueMap.put( key, value ); + } + + return dataValueMap; + } + + public List organisationUnitWithDataSetsFilter( Collection organisationUnits ) + { + List ous = new ArrayList( organisationUnits ); + FilterUtils.filter( ous, new OrganisationUnitWithDataSetsFilter() ); + + return ous; + } + + // ------------------------------------------------------------------------- + // Static Utils + // ------------------------------------------------------------------------- + + public static boolean isNumber( String value ) + { + try + { + Double.parseDouble( value ); + } catch ( NumberFormatException e ) + { + return false; + } + + return true; + } + + public static boolean isInteger( String value ) + { + try + { + Integer.parseInt( value ); + } catch ( NumberFormatException e ) + { + return false; + } + + return true; + } + + public static boolean isPositiveInteger( String value ) + { + return valueHigher( value, 0 ); + } + + public static boolean isNegativeInteger( String value ) + { + return valueLower( value, 0 ); + } + + public static boolean valueHigher( String value, int max ) + { + int integerValue; + + try + { + integerValue = Integer.parseInt( value ); + + if ( integerValue > max ) + { + return true; + } + } catch ( NumberFormatException e ) + { + } + + return false; + } + + public static boolean valueLower( String value, int min ) + { + int integerValue; + + try + { + integerValue = Integer.parseInt( value ); + + if ( integerValue < min ) + { + return true; + } + } catch ( NumberFormatException e ) + { + } + + return false; + } + + public static boolean isBoolean( String value ) + { + return value.equals( "true" ) || value.equals( "false" ); + } + + public static boolean isDate( String value ) + { + DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay(); + + try + { + sdf.parseDateTime( value ); + return true; + } catch ( IllegalArgumentException e ) + { + } + + return false; + } + + public static List sortedCategoryOptionCombos( Collection categoryOptionCombos ) + { + List sortedCategoryOptionCombos = new ArrayList( categoryOptionCombos ); + Collections.sort( sortedCategoryOptionCombos, new IdentifiableObjectNameComparator() ); + + return sortedCategoryOptionCombos; + } +} === 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 2012-01-16 18:30:37 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2012-01-22 19:37:21 +0000 @@ -5,9 +5,16 @@ + + + + + + + - + @@ -45,12 +52,20 @@ + + + + + + + - - - - + === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties 2012-01-16 18:30:37 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties 2012-01-22 19:37:21 +0000 @@ -44,4 +44,6 @@ reply=Reply write_feedback=Write feedback form_complete=Form complete -successfully_saved_section=Successfully Saved +completed=Completed +saved_section=Saved Section +sections=Sections === 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 2012-01-12 07:01:26 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml 2012-01-22 19:37:21 +0000 @@ -40,12 +40,16 @@ - /mobile/dataEntry.action?organisationUnitId=${organisationUnitId}&dataSetId=${dataSetId}&periodId=${periodId}&validated=${validated} + /mobile/dataEntry.action?organisationUnitId=${organisationUnitId}&dataSetId=${dataSetId}&periodId=${periodId}&sectionId=${sectionId}&validated=${validated} /dhis-web-light/main.vm /dhis-web-light/dataEntrySection.vm F_DATAVALUE_ADD,F_DATAVALUE_UPDATE,F_DATAVALUE_DELETE + + /mobile/index.action?organisationUnitId=${organisationUnitId}&dataSetId=${dataSetId}&periodId=${periodId}&complete=true + + === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntryOverview.vm' --- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntryOverview.vm 2012-01-21 11:53:35 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntryOverview.vm 2012-01-22 19:37:21 +0000 @@ -5,34 +5,25 @@ #set( $dataSetName = $dataSet.name ) #end -

$encoder.htmlEncode( $dataSetName )

-
-#if( $complete == true ) -

$i18n.getString( "form_complete" )

-#end +

$dataSetName

+

+ $period.name
+ $organisationUnit.name +

#if( $validated == true )
-

$i18n.getString( "successfully_saved_section" )

-
-#end - -#* -#if( $validationRuleViolations.size() > 0 ) -
-

$i18n.getString("validation_rule_violation_warnings")

+

$i18n.getString( "saved_section" )

- #foreach( $validationRuleViolation in $validationRuleViolations ) - $validationRuleViolation
- #end + $sectionName

#end -*# - -#if( $complete != true) + +

$i18n.getString( "sections" )

+

    #if( $dataSet.sections.size() > 0 ) @@ -46,24 +37,19 @@ #end

-#else -
-#end -
+ -#if( $complete == false )

-#end
@@ -74,3 +60,29 @@
  • $i18n.getString("home")
  • + + + + + + + + + + + + +#* This might get reactivated later, as configurable setting? *# + +#* +#if( $validationRuleViolations.size() > 0 ) +
    +

    $i18n.getString("validation_rule_violation_warnings")

    +

    + #foreach( $validationRuleViolation in $validationRuleViolations ) + $validationRuleViolation
    + #end +

    +
    +#end +*# === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm' --- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm 2012-01-21 11:53:35 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm 2012-01-22 19:37:21 +0000 @@ -1,3 +1,21 @@ + +#if( $dataSet.alternativeName ) + #set( $dataSetName = $dataSet.alternativeName ) +#else + #set( $dataSetName = $dataSet.name ) +#end + +#if( $complete == true ) +
    +

    $i18n.getString("completed")

    +

    + $dataSetName
    + $period.name
    + $organisationUnit.name +

    +
    +#end +

    $i18n.getString( "menu" )