← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20671: Removed unused program indicator code

 

------------------------------------------------------------
revno: 20671
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-10-13 15:10:18 +0200
message:
  Removed unused program indicator code
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.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-09-07 20:02:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java	2015-10-13 13:10:18 +0000
@@ -29,7 +29,6 @@
  */
 
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author Chau Thu Tran
@@ -100,24 +99,6 @@
     List<ProgramIndicator> getAllProgramIndicators();
 
     /**
-     * Calculate a program indicator value based on program instance and an
-     * indicator.
-     *
-     * @param programIndicator ProgramIndicator
-     * @param programInstance  ProgramInstance
-     * @return Indicator value
-     */
-    Double getProgramIndicatorValue( ProgramIndicator programIndicator, ProgramInstance programInstance );
-
-    /**
-     * Get indicator values of all program indicators defined for a TrackedEntityInstance
-     *
-     * @param programInstance ProgramInstance
-     * @return a mapping of indicator display name and indicator value.
-     */
-    Map<String, Double> getProgramIndicatorValues( ProgramInstance programInstance );
-
-    /**
      * Get description of an indicator expression.
      *
      * @param expression An expression string

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java	2015-10-12 18:52:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java	2015-10-13 13:10:18 +0000
@@ -29,8 +29,6 @@
  */
 
 import com.google.common.io.ByteSource;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.system.scheduling.Scheduler;
 import org.springframework.transaction.annotation.Transactional;
@@ -46,8 +44,6 @@
 public class DefaultFileResourceService
     implements FileResourceService
 {
-    private static final Log log = LogFactory.getLog( DefaultFileResourceService.class );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java	2015-10-04 20:21:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java	2015-10-13 13:10:18 +0000
@@ -31,8 +31,6 @@
 import static org.apache.commons.lang3.StringUtils.trim;
 import static org.hisp.dhis.i18n.I18nUtils.i18n;
 
-import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -55,13 +53,8 @@
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.system.util.DateUtils;
-import org.hisp.dhis.system.util.MathUtils;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
-import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
-import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
-import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue;
-import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -80,8 +73,6 @@
         put( DaysBetweenSqlFunction.KEY, new DaysBetweenSqlFunction() ).
         put( ConditionalSqlFunction.KEY, new ConditionalSqlFunction() ).build();
 
-    private static final String NULL_REPLACEMENT = "null";
-    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -107,20 +98,6 @@
         this.dataElementService = dataElementService;
     }
 
-    private TrackedEntityDataValueService dataValueService;
-
-    public void setDataValueService( TrackedEntityDataValueService dataValueService )
-    {
-        this.dataValueService = dataValueService;
-    }
-
-    private ProgramStageInstanceService programStageInstanceService;
-
-    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
-    {
-        this.programStageInstanceService = programStageInstanceService;
-    }
-
     private TrackedEntityAttributeService attributeService;
 
     public void setAttributeService( TrackedEntityAttributeService attributeService )
@@ -128,13 +105,6 @@
         this.attributeService = attributeService;
     }
 
-    private TrackedEntityAttributeValueService attributeValueService;
-
-    public void setAttributeValueService( TrackedEntityAttributeValueService attributeValueService )
-    {
-        this.attributeValueService = attributeValueService;
-    }
-
     private ConstantService constantService;
 
     public void setConstantService( ConstantService constantService )
@@ -221,176 +191,6 @@
 
     @Override
     @Transactional
-    public Double getProgramIndicatorValue( ProgramIndicator indicator, ProgramInstance programInstance )
-    {
-        StringBuffer buffer = new StringBuffer();
-
-        String expression = indicator.getExpression();
-
-        Matcher matcher = ProgramIndicator.EXPRESSION_PATTERN.matcher( expression );
-
-        int valueCount = 0;
-        int zeroPosValueCount = 0;
-
-        while ( matcher.find() )
-        {
-            String key = matcher.group( 1 );
-            String uid = matcher.group( 2 );
-
-            if ( ProgramIndicator.KEY_DATAELEMENT.equals( key ) )
-            {
-                String de = matcher.group( 3 );
-                ProgramStage programStage = programStageService.getProgramStage( uid );
-                DataElement dataElement = dataElementService.getDataElement( de );
-
-                if ( programStage != null && dataElement != null )
-                {
-                    ProgramStageInstance psi = programStageInstanceService.getProgramStageInstance( programInstance, programStage );
-
-                    TrackedEntityDataValue dataValue = dataValueService.getTrackedEntityDataValue( psi, dataElement );
-
-                    String value = null;
-                    
-                    if ( dataValue == null )
-                    {
-                        value = NULL_REPLACEMENT;
-                    }
-                    else
-                    {
-                        value = dataValue.getValue();
-                    }
-                    
-                    matcher.appendReplacement( buffer, value );
-
-                    valueCount++;
-                    zeroPosValueCount = isZeroOrPositive( value ) ? (zeroPosValueCount + 1) : zeroPosValueCount;
-                }
-                else
-                {
-                    return null;
-                }
-            }
-            else if ( ProgramIndicator.KEY_ATTRIBUTE.equals( key ) )
-            {
-                TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid );
-
-                if ( attribute != null )
-                {
-                    TrackedEntityAttributeValue attributeValue = attributeValueService.getTrackedEntityAttributeValue(
-                        programInstance.getEntityInstance(), attribute );
-
-                    String value = null;
-                    
-                    if ( attributeValue == null )
-                    {
-                        value = NULL_REPLACEMENT;
-                    }
-                    else
-                    {
-                        value = attributeValue.getValue();
-                    }
-                    
-                    matcher.appendReplacement( buffer, value );
-
-                    valueCount++;
-                    zeroPosValueCount = isZeroOrPositive( value ) ? (zeroPosValueCount + 1) : zeroPosValueCount;
-                }
-                else
-                {
-                    return null;
-                }
-            }
-            else if ( ProgramIndicator.KEY_CONSTANT.equals( key ) )
-            {
-                Constant constant = constantService.getConstant( uid );
-
-                if ( constant != null )
-                {
-                    matcher.appendReplacement( buffer, String.valueOf( constant.getValue() ) );
-                }
-                else
-                {
-                    return null;
-                }
-            }
-            else if ( ProgramIndicator.KEY_PROGRAM_VARIABLE.equals( key ) )
-            {
-                Date currentDate = new Date();
-                Date date = null;
-
-                if ( ProgramIndicator.VAR_ENROLLMENT_DATE.equals( uid ) )
-                {
-                    date = programInstance.getEnrollmentDate();
-                }
-                else if ( ProgramIndicator.VAR_INCIDENT_DATE.equals( uid ) )
-                {
-                    date = programInstance.getIncidentDate();
-                }
-                else if ( ProgramIndicator.VAR_CURRENT_DATE.equals( uid ) )
-                {
-                    date = currentDate;
-                }
-
-                // TODO ProgramIndicator.VAR_EXECUTION_DATE, DUE_DATE
-
-                if ( date != null )
-                {
-                    matcher.appendReplacement( buffer, DateUtils.daysBetween( currentDate, date ) + "" );
-                }
-            }
-        }
-
-        expression = TextUtils.appendTail( matcher, buffer );
-
-        // ---------------------------------------------------------------------
-        // Value count variable
-        // ---------------------------------------------------------------------
-
-        buffer = new StringBuffer();
-        matcher = ProgramIndicator.VALUECOUNT_PATTERN.matcher( expression );
-
-        while ( matcher.find() )
-        {
-            String var = matcher.group( 1 );
-
-            if ( ProgramIndicator.VAR_VALUE_COUNT.equals( var ) )
-            {
-                matcher.appendReplacement( buffer, String.valueOf( valueCount ) );
-            }
-            else if ( ProgramIndicator.VAR_ZERO_POS_VALUE_COUNT.equals( var ) )
-            {
-                matcher.appendReplacement( buffer, String.valueOf( zeroPosValueCount ) );
-            }
-        }
-
-        expression = TextUtils.appendTail( matcher, buffer );
-        
-        return MathUtils.calculateExpression( expression );
-    }
-
-    @Override
-    @Transactional
-    public Map<String, Double> getProgramIndicatorValues( ProgramInstance programInstance )
-    {
-        Map<String, Double> result = new HashMap<>();
-
-        Set<ProgramIndicator> programIndicators = programInstance.getProgram().getProgramIndicators();
-
-        for ( ProgramIndicator programIndicator : programIndicators )
-        {
-            Double value = getProgramIndicatorValue( programIndicator, programInstance );
-
-            if ( value != null )
-            {
-                result.put( programIndicator.getDisplayName(), value );
-            }
-        }
-
-        return result;
-    }
-
-    @Override
-    @Transactional
     public String getExpressionDescription( String expression )
     {
         if ( expression == null )
@@ -805,9 +605,4 @@
     {
         return "coalesce(" + column + ",0)";
     }
-    
-    private boolean isZeroOrPositive( String value )
-    {
-        return MathUtils.isNumeric( value ) && Double.valueOf( value ) >= 0d;
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2015-10-12 12:23:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2015-10-13 13:10:18 +0000
@@ -1118,12 +1118,9 @@
     <property name="programIndicatorStore" ref="org.hisp.dhis.program.ProgramIndicatorStore" />
     <property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
     <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
-    <property name="dataValueService" ref="org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueService" />
-    <property name="programStageInstanceService" ref="org.hisp.dhis.program.ProgramStageInstanceService" />
     <property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
     <property name="attributeService" ref="org.hisp.dhis.trackedentity.TrackedEntityAttributeService" />
     <property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
-    <property name="attributeValueService" ref="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService" />
     <property name="statementBuilder" ref="statementBuilder" />
   </bean>
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2015-09-27 20:01:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2015-10-13 13:10:18 +0000
@@ -29,7 +29,6 @@
  */
 
 import static org.hisp.dhis.program.ProgramIndicator.KEY_ATTRIBUTE;
-import static org.hisp.dhis.program.ProgramIndicator.KEY_CONSTANT;
 import static org.hisp.dhis.program.ProgramIndicator.KEY_DATAELEMENT;
 import static org.hisp.dhis.program.ProgramIndicator.KEY_PROGRAM_VARIABLE;
 import static org.junit.Assert.assertEquals;
@@ -39,7 +38,6 @@
 
 import java.util.Date;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
 
 import org.hisp.dhis.DhisSpringTest;
@@ -142,14 +140,6 @@
 
     private ProgramIndicator indicatorE;
 
-    private ProgramIndicator indicatorF;
-
-    private ProgramIndicator indicatorG;
-
-    private ProgramIndicator indicatorH;
-
-    private ProgramIndicator indicatorI;
-
     @Override
     public void setUpTest()
     {
@@ -295,26 +285,6 @@
             + "{" + atB.getUid() + "}";
         String filterE = KEY_DATAELEMENT + "{" + psA.getUid() + "." + deA.getUid() + "} + " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} > 10";
         indicatorE = createProgramIndicator( 'E', programB, expressionE, filterE );
-
-        String expressionF = "(" + KEY_DATAELEMENT + "{" + psB.getUid() + "." + deB.getUid() + "} - " + KEY_DATAELEMENT
-            + "{" + psA.getUid() + "." + deB.getUid() + "} ) + " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} + "
-            + KEY_ATTRIBUTE + "{" + atB.getUid() + "}";
-        indicatorF = createProgramIndicator( 'F', programB, expressionF, null );
-
-        String expressionG = "((" + KEY_DATAELEMENT + "{" + psB.getUid() + "." + deB.getUid() + "} - " + KEY_DATAELEMENT
-            + "{" + psA.getUid() + "." + deB.getUid() + "} ) + " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} + "
-            + KEY_ATTRIBUTE + "{" + atB.getUid() + "}) * " + KEY_CONSTANT + "{" + constantA.getUid() + "}";
-        indicatorG = createProgramIndicator( 'G', programB, expressionG, null );
-
-        String expressionH = "(" + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_CURRENT_DATE + "} - "
-            + KEY_DATAELEMENT + "{" + psA.getUid() + "." + deB.getUid() + "} ) + " + KEY_DATAELEMENT + "{"
-            + psA.getUid() + "." + deA.getUid() + "}";
-        indicatorH = createProgramIndicator( 'H', programB, expressionH, null );
-
-        String expressionI = "(" + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_CURRENT_DATE + "} - "
-            + KEY_DATAELEMENT + "{" + psA.getUid() + "." + deB.getUid() + "} ) + " + KEY_DATAELEMENT + "{"
-            + psA.getUid() + "." + deA.getUid() + "}";
-        indicatorI = createProgramIndicator( 'I', programB, expressionI, null );
     }
 
     // -------------------------------------------------------------------------
@@ -400,40 +370,6 @@
     // -------------------------------------------------------------------------
 
     @Test
-    public void testGetProgramIndicatorValue()
-    {
-        programIndicatorService.addProgramIndicator( indicatorB );
-        programIndicatorService.addProgramIndicator( indicatorA );
-        programIndicatorService.addProgramIndicator( indicatorE );
-        programIndicatorService.addProgramIndicator( indicatorF );
-        programIndicatorService.addProgramIndicator( indicatorG );
-        programIndicatorService.addProgramIndicator( indicatorH );
-        programIndicatorService.addProgramIndicator( indicatorI );
-
-        Double valueINT = programIndicatorService.getProgramIndicatorValue( indicatorA, programInstance );
-        assertEquals( 10.0, valueINT, 0.01 );
-
-        Double valueE = programIndicatorService.getProgramIndicatorValue( indicatorE, programInstance );
-        assertEquals( 9.0, valueE, 0.01 );
-
-        Double valueF = programIndicatorService.getProgramIndicatorValue( indicatorF, programInstance );
-        assertEquals( 9.0, valueF, 0.01 );
-
-        Double valueG = programIndicatorService.getProgramIndicatorValue( indicatorG, programInstance );
-        assertEquals( 63.0, valueG, 0.01 );
-    }
-
-    @Test
-    public void testGetProgramIndicatorValues()
-    {
-        programIndicatorService.addProgramIndicator( indicatorA );
-        programIndicatorService.addProgramIndicator( indicatorB );
-
-        Map<String, Double> indicatorMap = programIndicatorService.getProgramIndicatorValues( programInstance );
-        assertEquals( 10.0, indicatorMap.get( "IndicatorA" ), 0.01 );
-    }
-
-    @Test
     public void testGetExpressionDescription()
     {
         programIndicatorService.addProgramIndicator( indicatorB );