=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2011-04-01 09:57:53 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2011-04-01 11:19:55 +0000 @@ -61,7 +61,6 @@ { public static final String VALUE_TYPE_STRING = "string"; - public static final String VALUE_TYPE_INT = "int"; public static final String VALUE_TYPE_NUMBER = "number"; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java 2011-04-01 11:00:44 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java 2011-04-01 11:19:55 +0000 @@ -27,6 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.List; import java.util.Map; import org.hisp.dhis.common.Grid; @@ -78,4 +79,18 @@ * @return a Grid. */ Grid getDefaultDataSetReport( DataSet dataSet, Period period, OrganisationUnit unit, boolean selectedUnitOnly, I18nFormat format, I18n i18n ); + + /** + * Generates a list of Grids representing a data set report. The data elements + * are grouped and sorted by their section in the data set. + * + * @param dataSet the data set. + * @param unit the organisation unit. + * @param period the period. + * @param selectedUnitOnly indicators whether to use captured or aggregated data. + * @param format the i18n format. + * @param i18n the i18n object. + * @return a Grid. + */ + List getSectionDataSetReport( DataSet dataSet, Period period, OrganisationUnit unit, boolean selectedUnitOnly, I18nFormat format, I18n i18n ); } === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-04-01 11:00:44 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-04-01 11:19:55 +0000 @@ -48,10 +48,13 @@ import org.hisp.dhis.common.GridHeader; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryCombo; +import org.hisp.dhis.dataelement.DataElementCategoryOption; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.comparator.DataElementCategoryOptionComboNameComparator; import org.hisp.dhis.dataelement.comparator.DataElementNameComparator; import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.Section; +import org.hisp.dhis.dataset.comparator.SectionOrderComparator; import org.hisp.dhis.datasetreport.DataSetReportService; import org.hisp.dhis.datavalue.DataValue; import org.hisp.dhis.datavalue.DataValueService; @@ -77,6 +80,7 @@ private static final String NULL_REPLACEMENT = ""; private static final String SEPARATOR = ":"; private static final String DEFAULT_HEADER = "Value"; + private static final String TOTAL_HEADER = "Total"; // ------------------------------------------------------------------------- // Dependencies @@ -215,6 +219,110 @@ return buffer.toString(); } + public List getSectionDataSetReport( DataSet dataSet, Period period, OrganisationUnit unit, boolean selectedUnitOnly, I18nFormat format, I18n i18n ) + { + String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, DEFAULT_AGGREGATION_STRATEGY ); + boolean realTime = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ); + + List
sections = new ArrayList
( dataSet.getSections() ); + Collections.sort( sections, new SectionOrderComparator() ); + + List grids = new ArrayList(); + + // --------------------------------------------------------------------- + // Create a grid for each section + // --------------------------------------------------------------------- + + for ( Section section : sections ) + { + Grid grid = new ListGrid().setTitle( section.getName() ); + + DataElementCategoryCombo categoryCombo = section.getCategoryCombo(); + + // ----------------------------------------------------------------- + // Grid headers + // ----------------------------------------------------------------- + + grid.addHeader( new GridHeader( i18n.getString( "dataelement" ), false, true ) ); // Data element header + + for ( DataElementCategoryOptionCombo optionCombo : categoryCombo.getOptionCombos() ) // Value headers + { + grid.addHeader( new GridHeader( optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false ) ); + } + + if ( categoryCombo.doSubTotals() && !selectedUnitOnly ) // Sub-total headers + { + for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() ) + { + grid.addHeader( new GridHeader( categoryOption.getName(), false, false ) ); + } + } + + if ( categoryCombo.doTotal() && !selectedUnitOnly ) // Total header + { + grid.addHeader( new GridHeader( TOTAL_HEADER, false, false ) ); + } + + // ----------------------------------------------------------------- + // Grid values + // ----------------------------------------------------------------- + + List dataElements = new ArrayList( section.getDataElements() ); + Collections.sort( dataElements, new DataElementNameComparator() ); + FilterUtils.filter( dataElements, new AggregatableDataElementFilter() ); + + for ( DataElement dataElement : dataElements ) + { + grid.addRow(); + grid.addValue( dataElement.getName() ); // Data element name + + for ( DataElementCategoryOptionCombo optionCombo : categoryCombo.getOptionCombos() ) // Values + { + Double value = null; + + if ( selectedUnitOnly ) + { + DataValue dataValue = dataValueService.getDataValue( unit, dataElement, period, optionCombo ); + value = dataValue != null && dataValue.getValue() != null ? Double.parseDouble( dataValue.getValue() ) : null; + } + else + { + value = realTime ? + aggregationService.getAggregatedDataValue( dataElement, optionCombo, period.getStartDate(), period.getEndDate(), unit ) : + aggregatedDataValueService.getAggregatedValue( dataElement, optionCombo, period, unit ); + } + + grid.addValue( value ); + } + + if ( categoryCombo.doSubTotals() && !selectedUnitOnly ) // Sub-total values + { + for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() ) + { + Double value = realTime ? + aggregationService.getAggregatedDataValue( dataElement, period.getStartDate(), period.getEndDate(), unit, categoryOption ) : + aggregatedDataValueService.getAggregatedValue( dataElement, categoryOption, period, unit ); + + grid.addValue( value ); + } + } + + if ( categoryCombo.doTotal() && !selectedUnitOnly ) // Total value + { + Double value = realTime ? + aggregationService.getAggregatedDataValue( dataElement, null, period.getStartDate(), period.getEndDate(), unit ) : + aggregatedDataValueService.getAggregatedValue( dataElement, period, unit ); + + grid.addValue( value ); + } + } + + grids.add( grid ); + } + + return grids; + } + public Grid getDefaultDataSetReport( DataSet dataSet, Period period, OrganisationUnit unit, boolean selectedUnitOnly, I18nFormat format, I18n i18n ) { List dataElements = new ArrayList( dataSet.getDataElements() ); === modified 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 2011-03-11 12:35:11 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportAction.java 2011-04-01 11:19:55 +0000 @@ -161,6 +161,5 @@ } return selectedDataSet.hasSections() ? RESULT_SECTION : RESULT_DEFAULT; - } } === modified 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 2011-04-01 11:00:44 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDefaultDataSetReportAction.java 2011-04-01 11:19:55 +0000 @@ -136,7 +136,7 @@ public String execute() throws Exception { - dataSetReportService.getDefaultDataSetReport( selectedDataSet, selectedPeriod, selectedOrgunit, selectedUnitOnly, format, i18n ); + grid = dataSetReportService.getDefaultDataSetReport( selectedDataSet, selectedPeriod, selectedOrgunit, selectedUnitOnly, format, i18n ); reportingUnit = selectedOrgunit.getName(); === modified 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 2011-03-20 13:35:54 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateSectionDataSetReportAction.java 2011-04-01 11:19:55 +0000 @@ -27,36 +27,16 @@ * 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.List; -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.DataElementCategoryCombo; -import org.hisp.dhis.dataelement.DataElementCategoryOption; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; 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.datasetreport.DataSetReportService; 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 com.opensymphony.xwork2.Action; @@ -65,22 +45,13 @@ */ public class GenerateSectionDataSetReportAction implements Action -{ - private static final String DEFAULT_HEADER = "Value"; - private static final String TOTAL_HEADER = "Total"; - +{ // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- - private DataValueService dataValueService; - - private SystemSettingManager systemSettingManager; - - private AggregatedDataValueService aggregatedDataValueService; - - private AggregationService aggregationService; - + private DataSetReportService dataSetReportService; + // ------------------------------------------------------------------------- // Input // ------------------------------------------------------------------------- @@ -108,23 +79,12 @@ private String reportingPeriod; // ------------------------------------------------------------------------- - // Comparator - // ------------------------------------------------------------------------- - - private Comparator dataElementComparator; - - public void setDataElementComparator( Comparator dataElementComparator ) - { - this.dataElementComparator = dataElementComparator; - } - - // ------------------------------------------------------------------------- // Getters && Setters // ------------------------------------------------------------------------- - public void setAggregationService( AggregationService aggregationService ) + public void setDataSetReportService( DataSetReportService dataSetReportService ) { - this.aggregationService = aggregationService; + this.dataSetReportService = dataSetReportService; } public String getReportingUnit() @@ -152,16 +112,6 @@ 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; @@ -176,11 +126,6 @@ { this.selectedPeriod = selectedPeriod; } - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } public void setSelectedUnitOnly( boolean selectedUnitOnly ) { @@ -194,103 +139,8 @@ public String execute() throws Exception { - String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, DEFAULT_AGGREGATION_STRATEGY ); - boolean realTime = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ); + grids = dataSetReportService.getSectionDataSetReport( selectedDataSet, selectedPeriod, selectedOrgunit, selectedUnitOnly, format, i18n ); - List
sections = new ArrayList
( selectedDataSet.getSections() ); - Collections.sort( sections, new SectionOrderComparator() ); - - // --------------------------------------------------------------------- - // Create a grid for each section - // --------------------------------------------------------------------- - - for ( Section section : sections ) - { - Grid grid = new ListGrid().setTitle( section.getName() ); - - DataElementCategoryCombo categoryCombo = section.getCategoryCombo(); - - // ----------------------------------------------------------------- - // Grid headers - // ----------------------------------------------------------------- - - grid.addHeader( new GridHeader( i18n.getString( "dataelement" ), false, true ) ); // Data element header - - for ( DataElementCategoryOptionCombo optionCombo : categoryCombo.getOptionCombos() ) // Value headers - { - grid.addHeader( new GridHeader( optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false ) ); - } - - if ( categoryCombo.doSubTotals() && !selectedUnitOnly ) // Sub-total headers - { - for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() ) - { - grid.addHeader( new GridHeader( categoryOption.getName(), false, false ) ); - } - } - - if ( categoryCombo.doTotal() && !selectedUnitOnly ) // Total header - { - grid.addHeader( new GridHeader( TOTAL_HEADER, false, false ) ); - } - - // ----------------------------------------------------------------- - // Grid values - // ----------------------------------------------------------------- - - 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() ); // Data element name - - for ( DataElementCategoryOptionCombo optionCombo : categoryCombo.getOptionCombos() ) // Values - { - Double value = null; - - if ( selectedUnitOnly ) - { - DataValue dataValue = dataValueService.getDataValue( selectedOrgunit, dataElement, selectedPeriod, optionCombo ); - value = dataValue != null && dataValue.getValue() != null ? Double.parseDouble( dataValue.getValue() ) : null; - } - else - { - value = realTime ? - aggregationService.getAggregatedDataValue( dataElement, optionCombo, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedOrgunit ) : - aggregatedDataValueService.getAggregatedValue( dataElement, optionCombo, selectedPeriod, selectedOrgunit ); - } - - grid.addValue( value ); - } - - if ( categoryCombo.doSubTotals() && !selectedUnitOnly ) // Sub-total values - { - for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() ) - { - Double value = realTime ? - aggregationService.getAggregatedDataValue( dataElement, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedOrgunit, categoryOption ) : - aggregatedDataValueService.getAggregatedValue( dataElement, categoryOption, selectedPeriod, selectedOrgunit ); - - grid.addValue( value ); - } - } - - if ( categoryCombo.doTotal() && !selectedUnitOnly ) // Total value - { - Double value = realTime ? - aggregationService.getAggregatedDataValue( dataElement, null, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedOrgunit ) : - aggregatedDataValueService.getAggregatedValue( dataElement, selectedPeriod, selectedOrgunit ); - - grid.addValue( value ); - } - } - - grids.add( grid ); - } - reportingUnit = selectedOrgunit.getName(); reportingPeriod = format.formatPeriod( selectedPeriod ); === 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-04-01 11:00:44 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-04-01 11:19:55 +0000 @@ -376,14 +376,8 @@ - - - - +