dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20959
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9801: Ad-hoc aggregated reports in Tabular reports (WIP).
------------------------------------------------------------
revno: 9801
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-02-13 22:16:11 +0700
message:
Ad-hoc aggregated reports in Tabular reports (WIP).
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateAggregateReportAction.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/i18n.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-01-30 07:54:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-02-13 15:16:11 +0000
@@ -111,7 +111,7 @@
Collection<Integer> orgunitIds, Date startDate, Date endDate, int status, Integer max, Integer min );
Grid getAggregateReport( int position, ProgramStage programStage, Collection<Integer> orgunitIds,
- String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters, Collection<Period> periods,
+ String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters, List<Period> periods,
String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format, I18n i18n );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java 2013-01-30 07:54:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java 2013-02-13 15:16:11 +0000
@@ -102,7 +102,7 @@
Collection<Integer> orgunitIds, Date startDate, Date endDate, int status, Integer min, Integer max );
Grid getAggregateReport( int position, ProgramStage programStage, Collection<Integer> orgunitIds,
- String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters, Collection<Period> periods,
+ String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters, List<Period> periods,
String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format, I18n i18n );
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-01-30 07:54:43 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-02-13 15:16:11 +0000
@@ -347,7 +347,7 @@
@Override
public Grid getAggregateReport( int position, ProgramStage programStage, Collection<Integer> orgunitIds,
- String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters, Collection<Period> periods,
+ String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters, List<Period> periods,
String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format, I18n i18n )
{
return programStageInstanceStore.getAggregateReport( position, programStage, orgunitIds, facilityLB,
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2013-02-12 15:57:46 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2013-02-13 15:16:11 +0000
@@ -26,6 +26,8 @@
*/
package org.hisp.dhis.program.hibernate;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Collection;
@@ -67,6 +69,7 @@
import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.system.util.TextUtils;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.rowset.SqlRowSet;
/**
@@ -394,7 +397,7 @@
public Grid getAggregateReport( int position, ProgramStage programStage, Collection<Integer> orgunitIds,
String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters,
- Collection<Period> periods, String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format,
+ List<Period> periods, String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format,
I18n i18n )
{
String sql = "";
@@ -420,10 +423,18 @@
{
String orgunitName = organisationUnitService.getOrganisationUnit( orgunitIds.iterator().next() )
.getDisplayName();
- grid.setSubtitle( subTitle + i18n.getString( "orgunit" ) + ": " + orgunitName );
+
+ String filterDataDes = getFilterDataDescription( deFilters );
+ if ( !filterDataDes.isEmpty() )
+ {
+ filterDataDes = "; " + i18n.getString( "data_filter" ) + ": " + filterDataDes;
+ }
+ grid.setSubtitle( subTitle + i18n.getString( "orgunit" ) + ": " + orgunitName + filterDataDes);
}
// Filter is only one period
- else if ( position == PatientAggregateReport.POSITION_ROW_ORGUNIT_COLUMN_DATA
+ else if ( position == PatientAggregateReport.POSITION_ROW_ORGUNIT
+ || position == PatientAggregateReport.POSITION_ROW_ORGUNIT_COLUMN_DATA
+ || position == PatientAggregateReport.POSITION_ROW_DATA_COLUMN_ORGUNIT
|| position == PatientAggregateReport.POSITION_ROW_DATA )
{
@@ -439,7 +450,14 @@
String endDate = format.formatDate( period.getEndDate() );
periodName += startDate + " -> " + endDate;
}
- grid.setSubtitle( subTitle + i18n.getString( "period" ) + ": " + periodName );
+
+ String filterDataDes = getFilterDataDescription( deFilters );
+ if ( !filterDataDes.isEmpty() )
+ {
+ filterDataDes = "; " + i18n.getString( "data_filter" ) + ": " + filterDataDes;
+ }
+
+ grid.setSubtitle( subTitle + i18n.getString( "period" ) + ": " + periodName + filterDataDes);
}
else
{
@@ -491,7 +509,7 @@
subTitle += filterOrgunitDes + filterPeriodDes + filterDataDes;
if ( subTitle.isEmpty() )
{
- grid.setSubtitle( i18n.getString( "filter" ) + ": [" + i18n.getString( "none" ) + "]");
+ grid.setSubtitle( i18n.getString( "filter" ) + ": [" + i18n.getString( "none" ) + "]" );
}
else
{
@@ -535,8 +553,6 @@
// type = 5
else if ( position == PatientAggregateReport.POSITION_ROW_ORGUNIT )
{
- List<Period> firstPeriod = new ArrayList<Period>();
- firstPeriod.add( periods.iterator().next() );
sql = getAggregateReportSQL5( position, programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, deSum,
periods.iterator().next(), aggregateType, limit, useCompletedEvents, format );
}
@@ -545,10 +561,8 @@
else if ( (position == PatientAggregateReport.POSITION_ROW_PERIOD_COLUMN_DATA || position == PatientAggregateReport.POSITION_ROW_DATA_COLUMN_PERIOD)
&& deGroupBy != null )
{
- deValues = dataElementService.getDataElement( deGroupBy ).getOptionSet().getOptions();
-
sql = getAggregateReportSQL6( programStage, orgunitIds.iterator().next(), facilityLB, filterSQL, deGroupBy,
- deSum, deValues, periods, aggregateType, limit, useCompletedEvents, format );
+ deSum, periods, aggregateType, limit, useCompletedEvents, format );
}
// Type = 6 && NOT group-by
@@ -583,7 +597,7 @@
sql = getAggregateReportSQL8( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, periods
.iterator().next(), aggregateType, limit, useCompletedEvents, format );
}
-
+
SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
// Type ==2 && ==9 && ==10
@@ -1086,13 +1100,30 @@
* with group-by
**/
private String getAggregateReportSQL6( ProgramStage programStage, Integer root, String facilityLB,
- String filterSQL, Integer deGroupBy, Integer deSum, Collection<String> deValues, Collection<Period> periods,
+ String filterSQL, Integer deGroupBy, Integer deSum, Collection<Period> periods,
String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format )
{
String sql = "";
-
Collection<Integer> orgunitIds = getOrganisationUnits( root, facilityLB );
+ String dataValueSql = "select DISTINCT(value) from patientdatavalue where dataelementid=" + deGroupBy;
+ Collection<String> deValues = new HashSet<String>();
+ try
+ {
+ deValues = jdbcTemplate.query( dataValueSql, new RowMapper<String>()
+ {
+ public String mapRow( ResultSet rs, int rowNum )
+ throws SQLException
+ {
+ return rs.getString( 1 );
+ }
+ } );
+ }
+ catch ( Exception ex )
+ {
+ ex.printStackTrace();
+ }
+
for ( Period period : periods )
{
String periodName = "";
@@ -1139,7 +1170,6 @@
sql += "FROM programstageinstance psi JOIN patientdatavalue pdv ";
sql += " on psi.programstageinstanceid = pdv.programstageinstanceid ";
sql += "WHERE ";
- sql += " psi.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds ) + " ) AND ";
sql += " psi.programstageid=" + programStage.getId() + " ";
if ( useCompletedEvents )
{
@@ -1157,7 +1187,7 @@
{
sql += " LIMIT " + limit;
}
-
+
return sql;
}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateAggregateReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateAggregateReportAction.java 2013-01-30 07:54:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateAggregateReportAction.java 2013-02-13 15:16:11 +0000
@@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -43,6 +44,7 @@
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.period.RelativePeriods;
+import org.hisp.dhis.period.comparator.PeriodComparator;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageInstanceService;
import org.hisp.dhis.program.ProgramStageService;
@@ -281,7 +283,7 @@
// Get periods
// ---------------------------------------------------------------------
- Collection<Period> periods = new HashSet<Period>();
+ List<Period> periods = new ArrayList<Period>();
// Create period from start-date and end-date
@@ -349,64 +351,64 @@
if ( relativePeriods.contains( "reportingMonth" ) )
{
rp.clear().setReportingMonth( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
if ( relativePeriods.contains( "last3Months" ) )
{
rp.clear().setLast3Months( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
if ( relativePeriods.contains( "last12Months" ) )
{
rp.clear().setLast12Months( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
if ( relativePeriods.contains( "reportingQuarter" ) )
{
rp.clear().setReportingQuarter( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
if ( relativePeriods.contains( "last4Quarters" ) )
{
rp.clear().setLast4Quarters( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
if ( relativePeriods.contains( "lastSixMonth" ) )
{
rp.clear().setLastSixMonth( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
if ( relativePeriods.contains( "last2SixMonths" ) )
{
rp.clear().setLast2SixMonths( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
if ( relativePeriods.contains( "thisYear" ) )
{
rp.clear().setThisYear( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
if ( relativePeriods.contains( "lastYear" ) )
{
rp.clear().setLastYear( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
if ( relativePeriods.contains( "last5Years" ) )
{
rp.clear().setLast5Years( true );
- periods.addAll( periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) ) );
+ periods.addAll( periodService.reloadPeriods( rp.getRelativePeriods() ) );
}
-
- return periods;
+
+ return setNames(periods);
}
private List<Period> setNames( List<Period> periods )
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2013-02-12 15:57:46 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2013-02-13 15:16:11 +0000
@@ -549,4 +549,6 @@
runing_validation_rules = Validation rules are being processed, please wait ...
program_enrollment = Program enrollment
sum_avg_of = Sum/Avg of
-filter = Filter
\ No newline at end of file
+filter = Filter
+multiple_periods_selected_as_filter = Multiple periods selected as filter. The first one is being used.
+multiple_orgunits_selected_as_filter = Multiple organisation units selected as filter. The first one is being used.
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js 2013-02-12 15:57:46 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js 2013-02-13 15:16:11 +0000
@@ -1232,7 +1232,7 @@
Ext.getCmp('levelCombobox').setValue( f.level );
TR.store.aggregateDataelement.add(
- {'value': f.deSumId,'name': deSumName}
+ {'value': f.deSumId,'name': f.deSumName}
);
// Program stage
@@ -2210,6 +2210,36 @@
return false;
}
+ // Check orgunit by period
+ if( Ext.getCmp('positionOrgunitCbx').getValue() == 3
+ && ( TR.state.orgunitIds.length > 1
+ || Ext.getCmp('userOrgunitChildren').getValue() ))
+ {
+ TR.util.notification.error(TR.i18n.multiple_orgunits_selected_as_filter, TR.i18n.multiple_orgunits_selected_as_filter);
+ }
+
+ // Check filter by period
+ if( Ext.getCmp('positionPeriodCbx').getValue() == 3 )
+ {
+ var noPeriod = TR.store.dateRange.data.length + TR.cmp.params.fixedperiod.selected.store.data.length;
+
+ var relativePeriodList = TR.cmp.params.relativeperiod.checkbox;
+ Ext.Array.each(relativePeriodList, function(item) {
+ if(item.getValue() && !item.hidden
+ &&( item.paramName=='last3Months'
+ || item.paramName=='last12Months'
+ || item.paramName=='last4Quarters'
+ || item.paramName=='last2SixMonths'
+ || item.paramName=='last5Years' ) ){
+ noPeriod += 2;
+ }
+ });
+
+ if( noPeriod > 1 ){
+ TR.util.notification.error(TR.i18n.multiple_periods_selected_as_filter, TR.i18n.multiple_periods_selected_as_filter);
+ }
+ }
+
return true;
},
response: function(r) {
@@ -3763,7 +3793,7 @@
TR.state.orgunitIds = [];
for( var i in r.childNodes){
- TR.state.orgunitIds.push( r.childNodes[0].data.localid );
+ TR.state.orgunitIds.push( r.childNodes[i].data.localid );
}
});
}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/i18n.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/i18n.vm 2013-02-11 15:09:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/i18n.vm 2013-02-13 15:16:11 +0000
@@ -159,4 +159,6 @@
invalid_position: '$encoder.jsEscape($i18n.getString( 'invalid_position' ) , "'")',
sum_avg_of: '$encoder.jsEscape($i18n.getString( 'sum_avg_of' ) , "'")',
select_a_dataelement_for_sum_avg_operator: '$encoder.jsEscape($i18n.getString( 'select_a_dataelement_for_sum_avg_operator' ) , "'")',
+multiple_periods_selected_as_filter: '$encoder.jsEscape($i18n.getString( 'multiple_periods_selected_as_filter' ) , "'")',
+multiple_orgunits_selected_as_filter: '$encoder.jsEscape($i18n.getString( 'multiple_orgunits_selected_as_filter' ) , "'")',
};
\ No newline at end of file