← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5753: Data set report, displaying automatic data element totals for custom form report

 

------------------------------------------------------------
revno: 5753
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-01-19 13:19:18 +0100
message:
  Data set report, displaying automatic data element totals for custom form report
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java


--
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-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	2012-01-04 09:10:17 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java	2012-01-19 12:19:18 +0000
@@ -27,7 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.dataentryform.DataEntryFormService.IDENTIFIER_PATTERN;
+import static org.hisp.dhis.dataentryform.DataEntryFormService.*;
 import static org.hisp.dhis.dataentryform.DataEntryFormService.INDICATOR_PATTERN;
 import static org.hisp.dhis.dataentryform.DataEntryFormService.INPUT_PATTERN;
 import static org.hisp.dhis.options.SystemSettingManager.AGGREGATION_STRATEGY_REAL_TIME;
@@ -395,6 +395,17 @@
                     map.put( dataElement.getId() + SEPARATOR + categoryOptionCombo.getId(), value );
                 }
             }
+            
+            Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? 
+                aggregationService.getAggregatedDataValue( dataElement, null, period.getStartDate(), period.getEndDate(), unit ) : 
+                aggregatedDataValueService.getAggregatedValue( dataElement, period, unit );
+                
+            String value = format.formatValue( aggregatedValue );
+            
+            if ( value != null )
+            {
+                map.put( String.valueOf( dataElement.getId() ), value );
+            }
         }
 
         return map;
@@ -464,6 +475,7 @@
             String inputHtml = inputMatcher.group( 1 );
 
             Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
+            Matcher dataElementTotalMatcher = DATAELEMENT_TOTAL_PATTERN.matcher( inputHtml );
             Matcher indicatorMatcher = INDICATOR_PATTERN.matcher( inputHtml );
 
             // -----------------------------------------------------------------
@@ -481,6 +493,16 @@
 
                 inputMatcher.appendReplacement( buffer, dataValue );
             }
+            else if ( dataElementTotalMatcher.find() && dataElementTotalMatcher.groupCount() > 0 )
+            {
+                Integer dataElementId = Integer.parseInt( dataElementTotalMatcher.group( 1 ) );
+                
+                String dataValue = dataValues.get( String.valueOf( dataElementId ) );
+
+                dataValue = dataValue != null ? dataValue : NULL_REPLACEMENT;
+
+                inputMatcher.appendReplacement( buffer, dataValue );
+            }
             else if ( indicatorMatcher.find() && indicatorMatcher.groupCount() > 0 )
             {
                 Integer indicatorId = Integer.parseInt( indicatorMatcher.group( 1 ) );