← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19263: Program indicators, cleaned up unit tests

 

------------------------------------------------------------
revno: 19263
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-06-02 18:33:45 +0200
message:
  Program indicators, cleaned up unit tests
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/AddProgramIndicatorAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/UpdateProgramIndicatorAction.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/ProgramIndicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java	2015-06-02 15:19:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java	2015-06-02 16:33:45 +0000
@@ -98,17 +98,6 @@
         setAutoFields();
     }
 
-    public ProgramIndicator( String name, String description, Program program, String valueType, String expression )
-    {
-        this();
-        this.name = name;
-        this.description = description;
-        this.program = program;
-        program.getProgramIndicators().add( this );
-        this.valueType = valueType;
-        this.expression = expression;
-    }
-
     // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------

=== 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-06-02 15:19:55 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java	2015-06-02 16:33:45 +0000
@@ -232,8 +232,7 @@
             
             if ( value != null )
             {
-                result.put( programIndicator.getDisplayName(),
-                    getProgramIndicatorValue( programInstance, programIndicator ) );
+                result.put( programIndicator.getDisplayName(), value );
             }
         }
 

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2015-05-18 17:05:23 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2015-06-02 16:33:45 +0000
@@ -29,11 +29,10 @@
  */
 
 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_CONSTANT;
 import static org.hisp.dhis.program.ProgramIndicator.KEY_PROGRAM_VARIABLE;
 import static org.hisp.dhis.program.ProgramIndicator.VALUE_TYPE_DATE;
-import static org.hisp.dhis.program.ProgramIndicator.VALUE_TYPE_INT;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -228,7 +227,7 @@
 
         programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, programA, enrollmentDate,
             incidenDate, organisationUnit );
-
+        
         // TODO enroll twice?
 
         // ---------------------------------------------------------------------
@@ -270,6 +269,7 @@
         programStageInstances.add( stageInstanceA );
         programStageInstances.add( stageInstanceB );
         programInstance.setProgramStageInstances( programStageInstances );
+        programInstance.setProgram( programA );
 
         TrackedEntityDataValue dataValueA = new TrackedEntityDataValue( stageInstanceA, deA, "3" );
         TrackedEntityDataValue dataValueB = new TrackedEntityDataValue( stageInstanceA, deB, "2015-03-01" );
@@ -292,66 +292,52 @@
         // ProgramIndicator
         // ---------------------------------------------------------------------
 
-        indicatorA = new ProgramIndicator( "IndicatorA", "IndicatorDesA", programA, VALUE_TYPE_INT, "( "
-            + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.ENROLLMENT_DATE + "} - " + KEY_PROGRAM_VARIABLE + "{"
-            + ProgramIndicator.INCIDENT_DATE + "} )  / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid()
-            + "}" );
-        indicatorA.setUid( "UID-DATE" );
-        indicatorA.setShortName( "DATE" );
-
-        indicatorB = new ProgramIndicator( "IndicatorB", "IndicatorDesB", programA, ProgramIndicator.VALUE_TYPE_DATE,
-            "70" );
-        indicatorB.setRootDate( ProgramIndicator.INCIDENT_DATE );
-        indicatorB.setUid( "UID-INT" );
-        indicatorB.setShortName( "INT" );
-
-        indicatorC = new ProgramIndicator( "IndicatorC", "IndicatorDesB", programB, ProgramIndicator.VALUE_TYPE_INT,
-            "0" );
-        indicatorC.setUid( "UID-C" );
-        indicatorC.setShortName( "C" );
-
-        indicatorD = new ProgramIndicator( "IndicatorD", "IndicatorDesD", programB, ProgramIndicator.VALUE_TYPE_INT,
-            "0 + A + 4 + " + ProgramIndicator.KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.INCIDENT_DATE + "}" );
-        indicatorD.setUid( "UID-D" );
-        indicatorD.setShortName( "D" );
+        String expressionA = "( " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.ENROLLMENT_DATE + "} - " + KEY_PROGRAM_VARIABLE + "{"
+            + ProgramIndicator.INCIDENT_DATE + "} )  / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
+        indicatorA = createProgramIndicator( 'A', programA, expressionA );
+        programA.getProgramIndicators().add( indicatorA );
+
+        indicatorB = createProgramIndicator( 'B', programA, "70" );
+        indicatorB.setValueType( ProgramIndicator.VALUE_TYPE_DATE );
+        programA.getProgramIndicators().add( indicatorB );
+
+        indicatorC = createProgramIndicator( 'C', programA, "0" );
+        programA.getProgramIndicators().add( indicatorC );
+
+        String expressionD = "0 + A + 4 + " + ProgramIndicator.KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.INCIDENT_DATE + "}";
+        indicatorD = createProgramIndicator( 'D', programB, expressionD );
 
         String expressionE = KEY_DATAELEMENT + "{" + psA.getUid() + "." + deA.getUid() + "} + " + KEY_DATAELEMENT + "{"
             + psB.getUid() + "." + deA.getUid() + "} - " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} + " + KEY_ATTRIBUTE
             + "{" + atB.getUid() + "}";
-
-        indicatorE = new ProgramIndicator( "IndicatorE", "IndicatorDesE", programB, VALUE_TYPE_INT, expressionE );
+        indicatorE = createProgramIndicator( 'E', programB, expressionE );
 
         String expressionF = "(" + KEY_DATAELEMENT + "{" + psB.getUid() + "." + deB.getUid() + "} - " + KEY_DATAELEMENT
             + "{" + psA.getUid() + "." + deB.getUid() + "} ) + " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} + "
             + KEY_ATTRIBUTE + "{" + atB.getUid() + "}";
-
-        indicatorF = new ProgramIndicator( "IndicatorF", "IndicatorDesF", programB, VALUE_TYPE_INT, expressionF );
+        indicatorF = createProgramIndicator( 'F', programB, expressionF );
 
         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 = new ProgramIndicator( "IndicatorG", "IndicatorDesG", programB, VALUE_TYPE_INT, expressionG );
+        indicatorG = createProgramIndicator( 'G', programB, expressionG );
 
         String expressionH = "(" + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.CURRENT_DATE + "} - "
             + KEY_DATAELEMENT + "{" + psA.getUid() + "." + deB.getUid() + "} ) + " + KEY_DATAELEMENT + "{"
             + psA.getUid() + "." + deA.getUid() + "}";
-
-        indicatorH = new ProgramIndicator( "IndicatorH", "IndicatorDesH", programB, VALUE_TYPE_INT, expressionH );
+        indicatorH = createProgramIndicator( 'H', programB, expressionH );
 
         String expressionI = "(" + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.CURRENT_DATE + "} - "
             + KEY_DATAELEMENT + "{" + psA.getUid() + "." + deB.getUid() + "} ) + " + KEY_DATAELEMENT + "{"
             + psA.getUid() + "." + deA.getUid() + "}";
-
-        indicatorI = new ProgramIndicator( "IndicatorI", "IndicatorDesI", programB, VALUE_TYPE_DATE, expressionI );
-        indicatorI.setRootDate( ProgramIndicator.INCIDENT_DATE );
+        indicatorI = createProgramIndicator( 'I', programB, expressionI );
+        indicatorI.setValueType( VALUE_TYPE_DATE );
 
         String expressionJ = "(" + KEY_ATTRIBUTE + "{" + atC.getUid() + "}  - " + KEY_PROGRAM_VARIABLE + "{"
             + ProgramIndicator.ENROLLMENT_DATE + "} ) + " + KEY_DATAELEMENT + "{" + psA.getUid() + "." + deA.getUid()
             + "} * " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
-
-        indicatorJ = new ProgramIndicator( "IndicatorJ", "IndicatorDesJ", programB, VALUE_TYPE_DATE, expressionJ );
-        indicatorJ.setRootDate( ProgramIndicator.INCIDENT_DATE );
+        indicatorJ = createProgramIndicator( 'J', programB, expressionJ );
+        indicatorJ.setValueType( VALUE_TYPE_DATE );
     }
 
     // -------------------------------------------------------------------------
@@ -363,9 +349,11 @@
     {
         int idA = programIndicatorService.addProgramIndicator( indicatorA );
         int idB = programIndicatorService.addProgramIndicator( indicatorB );
+        int idC = programIndicatorService.addProgramIndicator( indicatorC );
 
         assertNotNull( programIndicatorService.getProgramIndicator( idA ) );
         assertNotNull( programIndicatorService.getProgramIndicator( idB ) );
+        assertNotNull( programIndicatorService.getProgramIndicator( idC ) );
     }
 
     @Test
@@ -430,26 +418,6 @@
         assertTrue( equals( programIndicatorService.getAllProgramIndicators(), indicatorB, indicatorA ) );
     }
 
-    @Test
-    public void testGetProgramIndicatorByShortName()
-    {
-        programIndicatorService.addProgramIndicator( indicatorB );
-        programIndicatorService.addProgramIndicator( indicatorA );
-
-        assertEquals( "INT", programIndicatorService.getProgramIndicatorByShortName( "INT" ).getShortName() );
-        assertEquals( "DATE", programIndicatorService.getProgramIndicatorByShortName( "DATE" ).getShortName() );
-    }
-
-    @Test
-    public void testGetProgramIndicatorByUid()
-    {
-        programIndicatorService.addProgramIndicator( indicatorB );
-        programIndicatorService.addProgramIndicator( indicatorA );
-
-        assertEquals( "UID-INT", programIndicatorService.getProgramIndicatorByUid( "UID-INT" ).getUid() );
-        assertEquals( "UID-DATE", programIndicatorService.getProgramIndicatorByUid( "UID-DATE" ).getUid() );
-    }
-
     // -------------------------------------------------------------------------
     // Logic tests
     // -------------------------------------------------------------------------
@@ -509,9 +477,10 @@
     {
         programIndicatorService.addProgramIndicator( indicatorA );
         programIndicatorService.addProgramIndicator( indicatorB );
+        programIndicatorService.addProgramIndicator( indicatorC );
 
         Map<String, String> indicatorMap = programIndicatorService.getProgramIndicatorValues( programInstance );
-        assertEquals( 2, indicatorMap.keySet().size() );
+        assertEquals( 3, indicatorMap.keySet().size() );
         assertEquals( "10.0", indicatorMap.get( "IndicatorA" ) );
         assertEquals( DateUtils.getMediumDateString( enrollmentDate ), indicatorMap.get( "IndicatorB" ) );
     }
@@ -527,7 +496,6 @@
 
         description = programIndicatorService.getExpressionDescription( indicatorA.getExpression() );
         assertEquals( "( Enrollment date - Incident date )  / ConstantA", description );
-
     }
 
     @Test

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2015-05-18 17:05:23 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2015-06-02 16:33:45 +0000
@@ -84,6 +84,7 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramStageInstance;
@@ -1246,6 +1247,23 @@
         return programStage;
     }
 
+    public static ProgramIndicator createProgramIndicator( char uniqueCharacter, Program program, String expression )
+    {
+        ProgramIndicator indicator = new ProgramIndicator();
+        indicator.setAutoFields();
+        indicator.setName( "Indicator" + uniqueCharacter );
+        indicator.setShortName( "IndicatorShort" + uniqueCharacter  );
+        indicator.setCode( "IndicatorCode" + uniqueCharacter  );
+        indicator.setDescription( "IndicatorDescription" + uniqueCharacter );
+        indicator.setProgram( program );
+        indicator.setValueType( ProgramIndicator.VALUE_TYPE_INT );
+        indicator.setExpression( expression );
+        indicator.setFilter( null );
+        indicator.setRootDate( ProgramIndicator.INCIDENT_DATE );
+        
+        return indicator;
+    }
+    
     public static TrackedEntity createTrackedEntity( char uniqueChar )
     {
         TrackedEntity trackedEntity = new TrackedEntity();

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/AddProgramIndicatorAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/AddProgramIndicatorAction.java	2015-03-29 20:22:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/AddProgramIndicatorAction.java	2015-06-02 16:33:45 +0000
@@ -121,6 +121,13 @@
         this.expression = expression;
     }
 
+    private String filter;
+
+    public void setFilter( String filter )
+    {
+        this.filter = filter;
+    }
+
     private String rootDate;
 
     public void setRootDate( String rootDate )
@@ -143,6 +150,7 @@
         {
             Pattern pattern = Pattern.compile( "[(+|-|*|\\)]+" );
             Matcher matcher = pattern.matcher( expression );
+            
             if ( matcher.find() && matcher.start() != 0 )
             {
                 expression = "+" + expression;
@@ -150,12 +158,19 @@
         }
 
         Program program = programService.getProgram( programId );
-        ProgramIndicator programIndicator = new ProgramIndicator( name, description, program, valueType, expression );
-        programIndicator.setShortName( shortName );
-        programIndicator.setCode( code );
-        programIndicator.setRootDate( rootDate );
+        
+        ProgramIndicator indicator = new ProgramIndicator();
+        indicator.setName( name );
+        indicator.setShortName( shortName );
+        indicator.setCode( code );
+        indicator.setDescription( description );
+        indicator.setProgram( program );
+        indicator.setValueType( valueType );
+        indicator.setExpression( expression );
+        indicator.setFilter( filter );
+        indicator.setRootDate( rootDate );
 
-        programIndicatorService.addProgramIndicator( programIndicator );
+        programIndicatorService.addProgramIndicator( indicator );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/UpdateProgramIndicatorAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/UpdateProgramIndicatorAction.java	2015-02-18 13:48:37 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/UpdateProgramIndicatorAction.java	2015-06-02 16:33:45 +0000
@@ -72,6 +72,13 @@
         this.name = name;
     }
 
+    private String shortName;
+
+    public void setShortName( String shortName )
+    {
+        this.shortName = shortName;
+    }
+
     private String code;
 
     public void setCode( String code )
@@ -100,6 +107,13 @@
         this.expression = expression;
     }
 
+    private String filter;
+
+    public void setFilter( String filter )
+    {
+        this.filter = filter;
+    }
+
     private String rootDate;
 
     public void setRootDate( String rootDate )
@@ -107,13 +121,6 @@
         this.rootDate = rootDate;
     }
 
-    private String shortName;
-
-    public void setShortName( String shortName )
-    {
-        this.shortName = shortName;
-    }
-
     private Integer programId;
 
     public Integer getProgramId()
@@ -136,25 +143,27 @@
         {
             Pattern pattern = Pattern.compile( "[(+|-|*|\\)]+" );
             Matcher matcher = pattern.matcher( expression );
+            
             if ( matcher.find() && matcher.start() != 0 )
             {
                 expression = "+" + expression;
             }
         }
 
-        ProgramIndicator programIndicator = programIndicatorService.getProgramIndicator( id );
-
-        programIndicator.setName( name );
-        programIndicator.setShortName( shortName );
-        programIndicator.setCode( code );
-        programIndicator.setDescription( description );
-        programIndicator.setExpression( expression );
-        programIndicator.setValueType( valueType );
-        programIndicator.setRootDate( rootDate );
-
-        programIndicatorService.updateProgramIndicator( programIndicator );
-
-        programId = programIndicator.getProgram().getId();
+        ProgramIndicator indicator = programIndicatorService.getProgramIndicator( id );
+
+        indicator.setName( name );
+        indicator.setShortName( shortName );
+        indicator.setCode( code );
+        indicator.setDescription( description );
+        indicator.setValueType( valueType );
+        indicator.setExpression( expression );
+        indicator.setFilter( filter );
+        indicator.setRootDate( rootDate );
+
+        programIndicatorService.updateProgramIndicator( indicator );
+
+        programId = indicator.getProgram().getId();
 
         return SUCCESS;
     }