← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2042: Added relative periods to period chart

 

------------------------------------------------------------
revno: 2042
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Fri 2010-06-25 12:31:20 +0200
message:
  Added relative periods to period chart
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartService.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartInternalProcess.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceMultiDimensionTest.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/CreateChartAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/SaveChartAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartPeriodModeForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/chart.js


--
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/chart/Chart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2010-06-21 14:17:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2010-06-25 10:31:20 +0000
@@ -83,6 +83,14 @@
     private RelativePeriods relatives;
 
     // -------------------------------------------------------------------------
+    // Transient properties
+    // -------------------------------------------------------------------------
+
+    private List<Period> relativePeriods = new ArrayList<Period>();
+    
+    private List<Period> allPeriods = new ArrayList<Period>();
+    
+    // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
 
@@ -94,7 +102,13 @@
     {
         this.title = title;
     }
-
+    
+    public void init()
+    {
+        allPeriods.addAll( periods );
+        allPeriods.addAll( relativePeriods );        
+    }
+    
     // -------------------------------------------------------------------------
     // hashCode, equals, toString
     // -------------------------------------------------------------------------
@@ -326,4 +340,24 @@
     {
         this.relatives = relatives;
     }
+
+    public List<Period> getRelativePeriods()
+    {
+        return relativePeriods;
+    }
+
+    public void setRelativePeriods( List<Period> relativePeriods )
+    {
+        this.relativePeriods = relativePeriods;
+    }
+
+    public List<Period> getAllPeriods()
+    {
+        return allPeriods;
+    }
+
+    public void setAllPeriods( List<Period> allPeriods )
+    {
+        this.allPeriods = allPeriods;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartService.java	2010-06-23 22:12:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartService.java	2010-06-25 10:31:20 +0000
@@ -39,6 +39,7 @@
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.RelativePeriods;
 
 /**
  * @author Lars Helge Overland
@@ -58,6 +59,18 @@
      * @return the number of exported values.
      */
     int export( int id );
+
+    /**
+     * Exports to data mart for the given arguments.
+     * 
+     * @param dataElementIds the data element identifiers.
+     * @param indicatorIds the indicator identifiers.
+     * @param periodIds the period identifiers.
+     * @param organisationUnitIds the organisation unit identifiers.
+     * @return the number of exported values.
+     */
+    int export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
+        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
     
     /**
      * Exports to data mart for the given arguments.
@@ -66,10 +79,11 @@
      * @param indicatorIds the indicator identifiers.
      * @param periodIds the period identifiers.
      * @param organisationUnitIds the organisation unit identifiers.
+     * @param relatives the RelativePeriods.
      * @return the number of exported values.
      */
     int export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
-        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
+        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, RelativePeriods relatives );
 
     // ----------------------------------------------------------------------
     // AggregatedDataValue

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartInternalProcess.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartInternalProcess.java	2010-06-24 11:50:08 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartInternalProcess.java	2010-06-25 10:31:20 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.RelativePeriods;
 import org.hisp.dhis.system.process.AbstractStatementInternalProcess;
 
 /**
@@ -74,6 +75,7 @@
     private Collection<Integer> indicatorIds;
     private Collection<Integer> periodIds;
     private Collection<Integer> organisationUnitIds;
+    private RelativePeriods relatives;
     
     public void setExport( DataMartExport export )
     {
@@ -81,6 +83,7 @@
         this.indicatorIds = getIdentifiers( Indicator.class, export.getIndicators() );
         this.periodIds = getIdentifiers( Period.class, export.getPeriods() );
         this.organisationUnitIds = getIdentifiers( OrganisationUnit.class, export.getOrganisationUnits() );
+        this.relatives = export.getRelatives();
     }
 
     // -------------------------------------------------------------------------
@@ -106,7 +109,7 @@
         }
         else
         {
-            dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds );
+            dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, relatives );
         }
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2010-06-23 22:12:43 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2010-06-25 10:31:20 +0000
@@ -48,6 +48,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.RelativePeriods;
 import org.hisp.dhis.system.process.OutputHolderState;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -94,6 +95,13 @@
     // -------------------------------------------------------------------------
 
     @Transactional
+    public int export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
+        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        return export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, null );
+    }
+    
+    @Transactional
     public int export( int id )
     {
         DataMartExport dataMartExport = getDataMartExport( id );
@@ -115,8 +123,13 @@
     
     @Transactional
     public int export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
-        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, RelativePeriods relatives )
     {
+        if ( relatives != null )
+        {
+            periodIds.addAll( getIdentifiers( Period.class, periodService.reloadPeriods( relatives.getRelativePeriods( 1, null, false ) ) ) );
+        }
+        
         return dataMartEngine.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, new OutputHolderState() );
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceMultiDimensionTest.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceMultiDimensionTest.java	2010-06-17 21:08:46 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceMultiDimensionTest.java	2010-06-25 10:31:20 +0000
@@ -256,7 +256,7 @@
         // Test
         // ---------------------------------------------------------------------
 
-        dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds );
+        dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, null );
         
         assertEquals( 90.0, dataMartStore.getAggregatedValue( dataElementA, categoryOptionComboA, periodA, unitB ) );
         assertEquals( 70.0, dataMartStore.getAggregatedValue( dataElementA, categoryOptionComboA, periodB, unitB ) );
@@ -310,7 +310,7 @@
         // Test
         // ---------------------------------------------------------------------
 
-        dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds );
+        dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, null );
 
         assertEquals( 90.0, dataMartStore.getAggregatedValue( dataElementA, categoryOptionComboA, periodA, unitB ) );
         assertEquals( 70.0, dataMartStore.getAggregatedValue( dataElementA, categoryOptionComboA, periodB, unitB ) );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2010-06-25 10:31:20 +0000
@@ -149,7 +149,10 @@
     {
         Chart chart = getChart( id );
         
-        chart.setFormat( format );
+        chart.setRelativePeriods( periodService.reloadPeriods( chart.getRelatives().getRelativePeriods( 1, null, false ) ) );
+        
+        chart.setFormat( format );        
+        chart.init();
         
         return getJFreeChart( chart, true );
     }
@@ -172,6 +175,8 @@
         chart.setOrganisationUnits( organisationUnits );
         chart.setFormat( format );
         
+        chart.init();
+        
         return getJFreeChart( chart, false );
     }
     
@@ -423,7 +428,7 @@
         
         if ( chart != null )
         {
-            Period selectedPeriod = chart.getPeriods().get( 0 );
+            Period selectedPeriod = chart.getAllPeriods().get( 0 );
             OrganisationUnit selectedOrganisationUnit = chart.getOrganisationUnits().get( 0 );
             
             for ( Indicator indicator : chart.getIndicators() )
@@ -438,7 +443,7 @@
                     // Regular dataset
                     // ---------------------------------------------------------
 
-                    for ( Period period : chart.getPeriods() )
+                    for ( Period period : chart.getAllPeriods() )
                     {
                         final Double value = dataMartService.getAggregatedValue( indicator, period, selectedOrganisationUnit );
 
@@ -460,7 +465,7 @@
                     
                     if ( chart.isRegression() )
                     {
-                        for ( Period period : chart.getPeriods() )
+                        for ( Period period : chart.getAllPeriods() )
                         {
                             final double value = regression.predict( columnIndex++ );
                             
@@ -542,9 +547,9 @@
         {
             subTitle.setText( chart.getOrganisationUnits().get( 0 ).getName() );
         }
-        else if ( chart.isDimension( DIMENSION_ORGANISATIONUNIT ) && chart.getPeriods().size() > 0 )
+        else if ( chart.isDimension( DIMENSION_ORGANISATIONUNIT ) && chart.getAllPeriods().size() > 0 )
         {
-            subTitle.setText( format.formatPeriod( chart.getPeriods().get( 0 ) ) );
+            subTitle.setText( format.formatPeriod( chart.getAllPeriods().get( 0 ) ) );
         }
         
         return subTitle;

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/CreateChartAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/CreateChartAction.java	2010-06-24 11:50:08 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/CreateChartAction.java	2010-06-25 10:31:20 +0000
@@ -103,7 +103,7 @@
         
         DataMartInternalProcess process = (DataMartInternalProcess) executor.getProcess();
 
-        DataMartExport export = new DataMartExport( null, new HashSet<DataElement>(), chart.getIndicators(), chart.getOrganisationUnits(), chart.getPeriods(), null );
+        DataMartExport export = new DataMartExport( null, new HashSet<DataElement>(), chart.getIndicators(), chart.getOrganisationUnits(), chart.getPeriods(), chart.getRelatives() );
         
         process.setExport( export );
         

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/SaveChartAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/SaveChartAction.java	2010-06-23 17:50:25 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/SaveChartAction.java	2010-06-25 10:31:20 +0000
@@ -256,7 +256,7 @@
 
     public String execute()
     {
-        Chart chart = new Chart();
+        Chart chart = id == null ? new Chart() : chartService.getChart( id );
 
         List<Indicator> indicators = new ArrayList<Indicator>();
         List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
@@ -274,7 +274,6 @@
         
         Collections.sort( periods, new AscendingPeriodComparator() );
         
-        chart.setId( id != null ? id : 0 );
         chart.setTitle( title );
         chart.setType( type );
         chart.setSize( size );
@@ -287,8 +286,6 @@
         chart.setPeriods( periods );
         chart.setOrganisationUnits( organisationUnits );
 
-        //TODO currently not in use
-        
         RelativePeriods relatives = new RelativePeriods();
         
         relatives.setReportingMonth( reportingMonth );
@@ -305,7 +302,7 @@
         
         chart.setRelatives( relatives );
         
-        chartService.saveOrUpdate( chart );
+        chartService.saveChart( chart );
         
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm	2010-02-18 15:41:11 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm	2010-06-25 10:31:20 +0000
@@ -132,7 +132,7 @@
     <tr>
         <td colspan="2" style="height:15px"></td>
     </tr>
-    
+        
     <!-- Submit -->
     
     <tr>        

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartPeriodModeForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartPeriodModeForm.vm	2010-03-08 07:57:10 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartPeriodModeForm.vm	2010-06-25 10:31:20 +0000
@@ -48,6 +48,55 @@
     <td colspan="2" style="height:15px"></td>
 </tr>
 
+<!-- Relative periods -->
+
+<tr>
+	<th colspan="2">$i18n.getString( "relative_periods" )</th>
+</tr>
+<tr>
+	<td colspan="2">
+	    <label for="reportingMonth">$i18n.getString( "reporting_month" )</label>
+		<input type="checkbox" id="reportingMonth" name="reportingMonth" value="true"#if( $!chart.relatives.isReportingMonth() ) checked#end>&nbsp;
+		<label for="last3Months">$i18n.getString( "last_3_months" )</label>
+		<input type="checkbox" id="last3Months" name="last3Months" value="true""#if( $!chart.relatives.isLast3Months() ) checked#end>&nbsp;
+		<label for="last6Months">$i18n.getString( "last_6_months" )</label>
+		<input type="checkbox" id="last6Months" name="last6Months" value="true"#if( $!chart.relatives.isLast6Months() ) checked#end>&nbsp;
+		<label for="last12Months">$i18n.getString( "last_12_months" )</label>
+		<input type="checkbox" id="last12Months" name="last12Months" value="true"#if( $!chart.relatives.isLast12Months() ) checked#end>
+	</td>
+</tr>
+<tr>
+	<td style="height:5px"></td>
+</tr>
+<tr>
+    <td colspan="2">
+    	<label for="last3To6Months">$i18n.getString( "last_3_to_6_months" )</label>
+        <input type="checkbox" id="last3To6Months" name="last3To6Months" value="true"#if( $!chart.relatives.isLast3To6Months() ) checked#end>&nbsp;
+        <label for="last6To9Months">$i18n.getString( "last_6_to_9_months" )</label>
+        <input type="checkbox" id="last6To9Months" name="last6To9Months" value="true""#if( $!chart.relatives.isLast6To9Months() ) checked#end>&nbsp;
+        <label for="last9To12Months">$i18n.getString( "last_9_to_12_months" )</label>
+        <input type="checkbox" id="last9To12Months" name="last9To12Months" value="true"#if( $!chart.relatives.isLast9To12Months() ) checked#end>&nbsp;
+        <label for="last12IndividualMonths">$i18n.getString( "last_12_individual_months" )</label>
+        <input type="checkbox" id="last12IndividualMonths" name="last12IndividualMonths" value="true"#if( $!chart.relatives.isLast12IndividualMonths() ) checked#end>           
+    </td>
+</tr>
+<tr>
+    <td style="height:5px"></td>
+</tr>
+<tr>
+    <td colspan="2">
+        <label for="soFarThisYear">$i18n.getString( "so_far_this_year" )</label>
+        <input type="checkbox" id="soFarThisYear" name="soFarThisYear" value="true"#if( $!chart.relatives.isSoFarThisYear() ) checked#end>&nbsp;
+        <label for="individualMonthsThisYear">$i18n.getString( "individual_months_this_year" )</label>
+        <input type="checkbox" id="individualMonthsThisYear" name="individualMonthsThisYear" value="true"#if( $!chart.relatives.isIndividualMonthsThisYear() ) checked#end>&nbsp;
+        <label for="individualQuartersThisYear">$i18n.getString( "individual_quarters_this_year" )</label>
+        <input type="checkbox" id="individualQuartersThisYear" name="individualQuartersThisYear" value="true"#if( $!chart.relatives.isIndividualQuartersThisYear() ) checked#end>           
+    </td>
+</tr>
+<tr>
+    <td style="height:15px"></td>
+</tr>
+
 <!-- OrganisationUnit -->
 
 <tr>

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/chart.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/chart.js	2010-03-11 12:12:36 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/chart.js	2010-06-25 10:31:20 +0000
@@ -151,7 +151,7 @@
         return false;
     }
     
-    if ( !hasElements( "selectedPeriods" ) ) //&& !relativePeriodsChecked() )
+    if ( !hasElements( "selectedPeriods" ) && !relativePeriodsChecked() )
     {
         setMessage( i18n_must_select_at_least_one_period );
         
@@ -166,14 +166,12 @@
     if ( isChecked( "reportingMonth" ) == true ||
          isChecked( "last3Months" ) == true ||
          isChecked( "last6Months" ) == true ||
-         isChecked( "last9Months" ) == true ||
          isChecked( "last12Months" ) == true ||
          isChecked( "last3To6Months" ) == true ||
          isChecked( "last6To9Months" ) == true ||
          isChecked( "last9To12Months" ) == true ||
          isChecked( "last12IndividualMonths" ) == true ||
          isChecked( "soFarThisYear" ) == true ||
-         isChecked( "soFarThisFinancialYear" ) == true ||
          isChecked( "individualMonthsThisYear" ) == true ||
          isChecked( "individualQuartersThisYear" ) == true )
     {