← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19027: Program indicator service, added method for getting program indicator value based on program stag...

 

------------------------------------------------------------
revno: 19027
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-04-27 13:16:44 +0200
message:
  Program indicator service, added method for getting program indicator value based on program stage instance
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.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-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java	2015-03-29 20:22:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java	2015-04-27 11:16:44 +0000
@@ -103,8 +103,18 @@
     Collection<ProgramIndicator> getAllProgramIndicators();
 
     /**
-     * Calculate an program indicator value based on program instance and an
-     * indicator defined for a TrackedEntityInstance
+     * Calculate a program indicator value based on program stage instance and an
+     * indicator.
+     *
+     * @param programInstance  ProgramInstance
+     * @param programIndicator ProgramIndicator
+     * @return Indicator value
+     */
+    String getProgramIndicatorValue( ProgramStageInstance programStageInstance, ProgramIndicator programIndicator );
+    
+    /**
+     * Calculate a program indicator value based on program instance and an
+     * indicator.
      *
      * @param programInstance  ProgramInstance
      * @param programIndicator ProgramIndicator

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java	2015-04-24 17:41:07 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java	2015-04-27 11:16:44 +0000
@@ -181,9 +181,17 @@
     }
 
     @Override
+    public String getProgramIndicatorValue( ProgramStageInstance programStageInstance, ProgramIndicator programIndicator )
+    {
+        Double value = getValue( null, programStageInstance, programIndicator );
+
+        return value != null ? String.valueOf( value ) : null;
+    }
+    
+    @Override
     public String getProgramIndicatorValue( ProgramInstance programInstance, ProgramIndicator programIndicator )
     {
-        Double value = getValue( programInstance, programIndicator );
+        Double value = getValue( programInstance, null, programIndicator );
 
         if ( value != null )
         {
@@ -432,7 +440,16 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    private Double getValue( ProgramInstance programInstance, ProgramIndicator indicator )
+    /**
+     * Get value for the given arguments. If programStageInstance argument is null, 
+     * the program stage instance will be retrieved based on the given program
+     * instance in combination with the program stage from the indicator expression.
+     * 
+     * @param programInstance the program instance, can be null.
+     * @param programStageInstance the program stage instance, can be null.
+     * @param indicator the indicator, must be not null.
+     */
+    private Double getValue( ProgramInstance programInstance, ProgramStageInstance programStageInstance, ProgramIndicator indicator )
     {
         StringBuffer buffer = new StringBuffer();
 
@@ -456,11 +473,11 @@
 
                 if ( programStage != null && dataElement != null )
                 {
-                    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(
-                        programInstance, programStage );
+                    ProgramStageInstance psi = programStageInstance != null ?
+                        programStageInstance :
+                        programStageInstanceService.getProgramStageInstance( programInstance, programStage );
 
-                    TrackedEntityDataValue dataValue = dataValueService.getTrackedEntityDataValue(
-                        programStageInstance, dataElement );
+                    TrackedEntityDataValue dataValue = dataValueService.getTrackedEntityDataValue( psi, dataElement );
 
                     if ( dataValue == null )
                     {