=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/comparator/DataElementCategoryOptionComboNameComparator.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/comparator/DataElementCategoryOptionComboNameComparator.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/comparator/DataElementCategoryOptionComboNameComparator.java 2011-03-11 12:35:11 +0000 @@ -0,0 +1,45 @@ +package org.hisp.dhis.dataelement.comparator; + +/* + * Copyright (c) 2004-2010, 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.Comparator; + +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; + +/** + * @author Chau Thu Tran + * @version $Id$ + */ +public class DataElementCategoryOptionComboNameComparator + implements Comparator +{ + public int compare( DataElementCategoryOptionCombo categoryOptionCombo1, DataElementCategoryOptionCombo categoryOptionCombo2 ) + { + return categoryOptionCombo1.getName().compareToIgnoreCase( categoryOptionCombo2.getName() ); + } +} === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml 2011-03-03 06:16:22 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml 2011-03-11 12:35:11 +0000 @@ -317,7 +317,6 @@ - aggregatedDataValueMap = dataSetReportService.getAggregatedValueMap( dataSet, unit, period, selectedUnitOnly ); - - DataEntryForm dataEntryForm = dataSet.getDataEntryForm(); - - customDataEntryFormCode = dataSetReportService.prepareReportContent( dataEntryForm.getHtmlCode(), aggregatedDataValueMap ); - - reportingUnit = unit.getName(); - - reportingPeriod = format.formatPeriod( period ); - - return SUCCESS; - } - - return ERROR; + { + Map aggregatedDataValueMap = dataSetReportService.getAggregatedValueMap( selectedDataSet, selectedOrgunit, selectedPeriod, + selectedUnitOnly ); + + DataEntryForm dataEntryForm = selectedDataSet.getDataEntryForm(); + + customDataEntryFormCode = dataSetReportService.prepareReportContent( dataEntryForm.getHtmlCode(), + aggregatedDataValueMap ); + + reportingUnit = selectedOrgunit.getName(); + + reportingPeriod = format.formatPeriod( selectedPeriod ); + + return SUCCESS; } } === added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportAction.java 2011-03-11 12:35:11 +0000 @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2004-2010, 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.reporting.dataset.action; + +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.oust.manager.SelectionTreeManager; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Chau Thu Tran + * @version $Id GenerateDataSetReportAction.java Mar 09, 2011 9:02:43 AM $ + */ +public class GenerateDataSetReportAction + implements Action +{ + private final static String RESULT_CUSTOM = "customDataSetReport"; + private final static String RESULT_SECTION = "sectionDataSetReport"; + private final static String RESULT_DEFAULT = "defaultDataSetReport"; + + // ------------------------------------------------------------------------- + // Dependency + // ------------------------------------------------------------------------- + + private SelectionTreeManager selectionTreeManager; + + private DataSetService dataSetService; + + private PeriodService periodService; + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private Integer dataSetId; + + private String periodId; + + private boolean selectedUnitOnly; + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private OrganisationUnit selectedOrgunit; + + private DataSet selectedDataSet; + + private Period selectedPeriod; + + // ------------------------------------------------------------------------- + // Getters && Setters + // ------------------------------------------------------------------------- + + public Integer getDataSetId() + { + return dataSetId; + } + + public boolean isSelectedUnitOnly() + { + return selectedUnitOnly; + } + + public void setSelectedUnitOnly( boolean selectedUnitOnly ) + { + this.selectedUnitOnly = selectedUnitOnly; + } + + public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager ) + { + this.selectionTreeManager = selectionTreeManager; + } + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + public OrganisationUnit getSelectedOrgunit() + { + return selectedOrgunit; + } + + public DataSet getSelectedDataSet() + { + return selectedDataSet; + } + + public Period getSelectedPeriod() + { + return selectedPeriod; + } + + public void setPeriodId( String periodId ) + { + this.periodId = periodId; + } + + public void setDataSetId( Integer dataSetId ) + { + this.dataSetId = dataSetId; + } + + public void setDataSetService( DataSetService dataSetService ) + { + this.dataSetService = dataSetService; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + @Override + public String execute() + throws Exception + { + selectedOrgunit = selectionTreeManager.getSelectedOrganisationUnit(); + + if ( dataSetId == null || periodId == null || selectedOrgunit == null ) + { + return ERROR; + } + + selectedDataSet = dataSetService.getDataSet( dataSetId ); + + selectedPeriod = periodService.getPeriodByExternalId( periodId ); + + if ( selectedDataSet.hasDataEntryForm() ) + { + return RESULT_CUSTOM; + } + + return selectedDataSet.hasSections() ? RESULT_SECTION : RESULT_DEFAULT; + + } +} === added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDefaultDataSetReportAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDefaultDataSetReportAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDefaultDataSetReportAction.java 2011-03-11 12:35:11 +0000 @@ -0,0 +1,286 @@ +package org.hisp.dhis.reporting.dataset.action; + +/* + * Copyright (c) 2004-2010, 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 static org.hisp.dhis.options.SystemSettingManager.AGGREGATION_STRATEGY_REAL_TIME; +import static org.hisp.dhis.options.SystemSettingManager.DEFAULT_AGGREGATION_STRATEGY; +import static org.hisp.dhis.options.SystemSettingManager.KEY_AGGREGATION_STRATEGY; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.hisp.dhis.aggregation.AggregatedDataValueService; +import org.hisp.dhis.aggregation.AggregationService; +import org.hisp.dhis.common.Grid; +import org.hisp.dhis.common.GridHeader; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataelement.comparator.DataElementCategoryOptionComboNameComparator; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.i18n.I18nFormat; +import org.hisp.dhis.options.SystemSettingManager; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.system.filter.AggregatableDataElementFilter; +import org.hisp.dhis.system.grid.ListGrid; +import org.hisp.dhis.system.util.FilterUtils; +import org.hisp.dhis.system.util.MathUtils; + +import com.opensymphony.xwork2.Action; + +/** + * @author Chau Thu Tran + */ +public class GenerateDefaultDataSetReportAction + implements Action +{ + private static final String DEFAULT_HEADER = "Value"; + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private DataValueService dataValueService; + + private SystemSettingManager systemSettingManager; + + private AggregatedDataValueService aggregatedDataValueService; + + private AggregationService aggregationService; + + // ------------------------------------------------------------------------- + // Comparator + // ------------------------------------------------------------------------- + + private Comparator dataElementComparator; + + public void setDataElementComparator( Comparator dataElementComparator ) + { + this.dataElementComparator = dataElementComparator; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private OrganisationUnit selectedOrgunit; + + private DataSet selectedDataSet; + + private Period selectedPeriod; + + private boolean selectedUnitOnly; + + private I18nFormat format; + + private I18n i18n; + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private Grid grid; + + private String reportingUnit; + + private String reportingPeriod; + + // ------------------------------------------------------------------------- + // Getters && Setters + // ------------------------------------------------------------------------- + + public void setAggregationService( AggregationService aggregationService ) + { + this.aggregationService = aggregationService; + } + + public void setSelectedOrgunit( OrganisationUnit selectedOrgunit ) + { + this.selectedOrgunit = selectedOrgunit; + } + + public void setSelectedDataSet( DataSet selectedDataSet ) + { + this.selectedDataSet = selectedDataSet; + } + + public void setSelectedPeriod( Period selectedPeriod ) + { + this.selectedPeriod = selectedPeriod; + } + + public String getReportingUnit() + { + return reportingUnit; + } + + public String getReportingPeriod() + { + return reportingPeriod; + } + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + + public void setFormat( I18nFormat format ) + { + this.format = format; + } + + public Grid getGrid() + { + return grid; + } + + public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService ) + { + this.aggregatedDataValueService = aggregatedDataValueService; + } + + public void setSystemSettingManager( SystemSettingManager systemSettingManager ) + { + this.systemSettingManager = systemSettingManager; + } + + public void setDataValueService( DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + + public void setSelectedUnitOnly( boolean selectedUnitOnly ) + { + this.selectedUnitOnly = selectedUnitOnly; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + List dataElements = new ArrayList( selectedDataSet.getDataElements() ); + + if ( dataElements.size() == 0 ) + { + return SUCCESS; + } + + Collections.sort( dataElements, dataElementComparator ); + FilterUtils.filter( dataElements, new AggregatableDataElementFilter() ); + + String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, + DEFAULT_AGGREGATION_STRATEGY ); + + // --------------------------------------------------------------------- + // Get the category-option-combos + // --------------------------------------------------------------------- + + Set optionCombos = new HashSet(); + + for ( DataElement dataElement : dataElements ) + { + optionCombos.addAll( dataElement.getCategoryCombo().getOptionCombos() ); + } + + List orderedOptionCombos = new ArrayList( + optionCombos ); + + Collections.sort( orderedOptionCombos, new DataElementCategoryOptionComboNameComparator() ); + + // --------------------------------------------------------------------- + // Create a GRID + // --------------------------------------------------------------------- + + grid = new ListGrid().setTitle( selectedDataSet.getName() ); + grid.setSubtitle( format.formatPeriod( selectedPeriod ) ); + + // --------------------------------------------------------------------- + // Headers for GRID + // --------------------------------------------------------------------- + + grid.addHeader( new GridHeader( i18n.getString( "dataelement" ), false, true ) ); + + for ( DataElementCategoryOptionCombo optionCombo : orderedOptionCombos ) + { + grid.addHeader( new GridHeader( optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false ) ); + } + + // --------------------------------------------------------------------- + // Values for GRID + // --------------------------------------------------------------------- + + for ( DataElement dataElement : dataElements ) + { + grid.addRow(); + + grid.addValue( dataElement.getName() ); + + for ( DataElementCategoryOptionCombo optionCombo : orderedOptionCombos ) + { + String value = ""; + + if ( selectedUnitOnly ) + { + DataValue dataValue = dataValueService.getDataValue( selectedOrgunit, dataElement, + selectedPeriod, optionCombo ); + value = (dataValue != null) ? dataValue.getValue() : null; + } + else + { + Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService + .getAggregatedDataValue( dataElement, optionCombo, selectedPeriod.getStartDate(), + selectedPeriod.getEndDate(), selectedOrgunit ) + : aggregatedDataValueService.getAggregatedValue( dataElement, optionCombo, selectedPeriod, + selectedOrgunit ); + + value = (aggregatedValue != null) ? String.valueOf( MathUtils.getRounded( aggregatedValue, 0 ) ) + : null; + } + + grid.addValue( value ); + + } + } + + reportingUnit = selectedOrgunit.getName(); + + reportingPeriod = format.formatPeriod( selectedPeriod ); + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateSectionDataSetReportAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateSectionDataSetReportAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateSectionDataSetReportAction.java 2011-03-11 12:35:11 +0000 @@ -0,0 +1,292 @@ +package org.hisp.dhis.reporting.dataset.action; + +/* + * Copyright (c) 2004-2010, 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 static org.hisp.dhis.options.SystemSettingManager.AGGREGATION_STRATEGY_REAL_TIME; +import static org.hisp.dhis.options.SystemSettingManager.DEFAULT_AGGREGATION_STRATEGY; +import static org.hisp.dhis.options.SystemSettingManager.KEY_AGGREGATION_STRATEGY; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.hisp.dhis.aggregation.AggregatedDataValueService; +import org.hisp.dhis.aggregation.AggregationService; +import org.hisp.dhis.common.Grid; +import org.hisp.dhis.common.GridHeader; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataelement.comparator.DataElementCategoryOptionComboNameComparator; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.Section; +import org.hisp.dhis.dataset.comparator.SectionOrderComparator; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.i18n.I18nFormat; +import org.hisp.dhis.options.SystemSettingManager; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.system.filter.AggregatableDataElementFilter; +import org.hisp.dhis.system.grid.ListGrid; +import org.hisp.dhis.system.util.FilterUtils; +import org.hisp.dhis.system.util.MathUtils; + +import com.opensymphony.xwork2.Action; + +/** + * @author Chau Thu Tran + */ +public class GenerateSectionDataSetReportAction + implements Action +{ + private static final String DEFAULT_HEADER = "Value"; + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private DataValueService dataValueService; + + private SystemSettingManager systemSettingManager; + + private AggregatedDataValueService aggregatedDataValueService; + + private AggregationService aggregationService; + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private OrganisationUnit selectedOrgunit; + + private DataSet selectedDataSet; + + private Period selectedPeriod; + + private boolean selectedUnitOnly; + + private I18nFormat format; + + private I18n i18n; + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private List grids; + + private String reportingUnit; + + private String reportingPeriod; + + // ------------------------------------------------------------------------- + // Comparator + // ------------------------------------------------------------------------- + + private Comparator dataElementComparator; + + public void setDataElementComparator( Comparator dataElementComparator ) + { + this.dataElementComparator = dataElementComparator; + } + + // ------------------------------------------------------------------------- + // Getters && Setters + // ------------------------------------------------------------------------- + + public void setAggregationService( AggregationService aggregationService ) + { + this.aggregationService = aggregationService; + } + + public String getReportingUnit() + { + return reportingUnit; + } + + public String getReportingPeriod() + { + return reportingPeriod; + } + + public List getGrids() + { + return grids; + } + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + + public void setFormat( I18nFormat format ) + { + this.format = format; + } + + public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService ) + { + this.aggregatedDataValueService = aggregatedDataValueService; + } + + public void setSystemSettingManager( SystemSettingManager systemSettingManager ) + { + this.systemSettingManager = systemSettingManager; + } + + public void setSelectedOrgunit( OrganisationUnit selectedOrgunit ) + { + this.selectedOrgunit = selectedOrgunit; + } + + public void setSelectedDataSet( DataSet selectedDataSet ) + { + this.selectedDataSet = selectedDataSet; + } + + public void setSelectedPeriod( Period selectedPeriod ) + { + this.selectedPeriod = selectedPeriod; + } + + public void setDataValueService( DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + + public void setSelectedUnitOnly( boolean selectedUnitOnly ) + { + this.selectedUnitOnly = selectedUnitOnly; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, + DEFAULT_AGGREGATION_STRATEGY ); + + // --------------------------------------------------------------------- + // Get option-combo by sectionId + // --------------------------------------------------------------------- + + List
sections = new ArrayList
( selectedDataSet.getSections() ); + + Collections.sort( sections, new SectionOrderComparator() ); + + Map> optionCombosMap = new HashMap>(); + + for ( Section section : sections ) + { + List optionCombos = new ArrayList( section + .getDataElements().iterator().next().getCategoryCombo().getOptionCombos() ); + + Collections.sort( optionCombos, new DataElementCategoryOptionComboNameComparator() ); + + optionCombosMap.put( section.getId(), optionCombos ); + } + + // --------------------------------------------------------------------- + // Create a grid for each section + // --------------------------------------------------------------------- + + grids = new ArrayList(); + + for ( Section section : sections ) + { + Grid grid = new ListGrid().setTitle( section.getName() ); + + List optionComnbos = optionCombosMap.get( section.getId() ); + + // --------------------------------------------------------------------- + // Headers for GRID + // --------------------------------------------------------------------- + + grid.addHeader( new GridHeader( i18n.getString( "dataelement" ), false, true ) ); + + for ( DataElementCategoryOptionCombo optionCombo : optionComnbos ) + { + grid.addHeader( new GridHeader( optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false ) ); + } + + // --------------------------------------------------------------------- + // Values for GRID + // --------------------------------------------------------------------- + + List dataElements = new ArrayList( section.getDataElements() ); + Collections.sort( dataElements, dataElementComparator ); + FilterUtils.filter( dataElements, new AggregatableDataElementFilter() ); + + for ( DataElement dataElement : dataElements ) + { + grid.addRow(); + grid.addValue( dataElement.getName() ); + + for ( DataElementCategoryOptionCombo optionCombo : optionComnbos ) + { + String value = ""; + + if ( selectedUnitOnly ) + { + DataValue dataValue = dataValueService.getDataValue( selectedOrgunit, dataElement, + selectedPeriod, optionCombo ); + value = (dataValue != null) ? dataValue.getValue() : null; + } + else + { + Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService + .getAggregatedDataValue( dataElement, optionCombo, selectedPeriod.getStartDate(), + selectedPeriod.getEndDate(), selectedOrgunit ) + : aggregatedDataValueService.getAggregatedValue( dataElement, optionCombo, + selectedPeriod, selectedOrgunit ); + + value = (aggregatedValue != null) ? String.valueOf( MathUtils.getRounded( aggregatedValue, + 0 ) ) : null; + } + + grid.addValue( value ); + } + } + + grids.add( grid ); + } + + reportingUnit = selectedOrgunit.getName(); + + reportingPeriod = format.formatPeriod( selectedPeriod ); + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GetDataSetReportOptionsAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GetDataSetReportOptionsAction.java 2011-01-18 08:27:37 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GetDataSetReportOptionsAction.java 2011-03-11 12:35:11 +0000 @@ -35,8 +35,6 @@ import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.dataset.comparator.DataSetNameComparator; import org.hisp.dhis.period.PeriodType; -import org.hisp.dhis.system.util.Filter; -import org.hisp.dhis.system.util.FilterUtils; import com.opensymphony.xwork2.Action; @@ -70,14 +68,6 @@ public String execute() { dataSets = new ArrayList( dataSetService.getAllDataSets() ); - - FilterUtils.filter( dataSets, new Filter() // Temporary hack until dataset report supports section and default forms - { - public boolean retain( DataSet dataSet ) - { - return dataSet != null && dataSet.getDataEntryForm() != null; - } - }); Collections.sort( dataSets, new DataSetNameComparator() ); === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-02-23 19:20:08 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-03-11 12:35:11 +0000 @@ -376,19 +376,58 @@ ref="org.hisp.dhis.dataset.DataSetService"/> + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + generateCustomDataSetReport + generateSectionDataSetReport + generateDefaultDataSetReport + showDataSetReportForm + + /popup.vm showDataSetReportForm /dhis-web-reporting/previewCustomDataSetReportForm.vm ../dhis-web-commons/util/jquery.jqprint.0.3.js + + + + /popup.vm + showDataSetReportForm + /dhis-web-reporting/previewSectionDataSetReportForm.vm + ../dhis-web-commons/util/jquery.jqprint.0.3.js + + + + + /popup.vm + showDataSetReportForm + /dhis-web-reporting/previewDefaultDataSetReportForm.vm + ../dhis-web-commons/util/jquery.jqprint.0.3.js + === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm 2011-01-24 17:01:24 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm 2011-03-11 12:35:11 +0000 @@ -1,7 +1,7 @@

$i18n.getString( "dataset_report" )

-
+ === added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/previewDefaultDataSetReportForm.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/previewDefaultDataSetReportForm.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/previewDefaultDataSetReportForm.vm 2011-03-11 12:35:11 +0000 @@ -0,0 +1,15 @@ + +

$i18n.getString('reporting_unit'): $reportingUnit   $i18n.getString('reporting_period'): $reportingPeriod

+

+ +
+#parse( "dhis-web-commons/ajax/htmlGrid.vm" ) +
+ + === added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/previewSectionDataSetReportForm.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/previewSectionDataSetReportForm.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/previewSectionDataSetReportForm.vm 2011-03-11 12:35:11 +0000 @@ -0,0 +1,41 @@ +

$i18n.getString('reporting_unit'): $reportingUnit   $i18n.getString('reporting_period'): $reportingPeriod

+

+ +
+#foreach( $grid in $grids ) + +

$!encoder.htmlEncode( $grid.title )

+
$!encoder.htmlEncode( $grid.subtitle )
+ +
+ + + #foreach( $header in $grid.getVisibleHeaders() ) + + #end + + + + + #set( $mark = false ) + #foreach( $row in $grid.getVisibleRows() ) + + #foreach( $col in $row ) + #set( $index = ( $velocityCount - 1 ) ) + + #end + + #set( $mark = !$mark ) + #end + +
$!encoder.htmlEncode( $header.name )
$!encoder.htmlEncode( $col )
+#end + + + \ No newline at end of file