← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16108: Event analytics, unit testing

 

------------------------------------------------------------
revno: 16108
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-07-12 23:07:29 +0200
message:
  Event analytics, unit testing
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeDimension.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataElementDimension.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.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/program/AddProgramAction.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/ProgramStage.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java	2014-06-12 10:39:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java	2014-07-12 21:07:29 +0000
@@ -120,7 +120,7 @@
 
     public ProgramStage( String name, Program program )
     {
-        this();
+        setAutoFields();
         this.name = name;
         this.program = program;
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeDimension.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeDimension.java	2014-04-21 11:05:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeDimension.java	2014-07-12 21:07:29 +0000
@@ -54,6 +54,12 @@
     public TrackedEntityAttributeDimension()
     {
     }
+    
+    public TrackedEntityAttributeDimension( TrackedEntityAttribute attribute, String filter )
+    {
+        this.attribute = attribute;
+        this.filter = filter;
+    }
 
     // -------------------------------------------------------------------------
     // Logic

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataElementDimension.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataElementDimension.java	2014-04-21 11:05:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataElementDimension.java	2014-07-12 21:07:29 +0000
@@ -55,6 +55,12 @@
     public TrackedEntityDataElementDimension()
     {
     }
+
+    public TrackedEntityDataElementDimension( DataElement dataElement, String filter )
+    {
+        this.dataElement = dataElement;
+        this.filter = filter;
+    }
     
     // -------------------------------------------------------------------------
     // Logic

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2014-05-10 11:18:29 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2014-07-12 21:07:29 +0000
@@ -31,8 +31,10 @@
 import java.util.Set;
 
 import org.hisp.dhis.analytics.SortOrder;
+import org.hisp.dhis.common.BaseAnalyticalObject;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.program.Program;
 
 /**
  * @author Lars Helge Overland
@@ -57,4 +59,6 @@
      */
     EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, Set<String> dimension, Set<String> filter, 
         String ouMode, Set<String> asc, Set<String> desc, boolean skipMeta, boolean hierarchyMeta, boolean coordinatesOnly, Integer page, Integer pageSize, I18nFormat format );
+    
+    EventQueryParams getFromAnalyticalObject( BaseAnalyticalObject object, Program program, I18nFormat format );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java	2014-07-12 18:15:50 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java	2014-07-12 21:07:29 +0000
@@ -30,6 +30,7 @@
 
 import static org.hisp.dhis.system.util.CollectionUtils.asSet;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -37,14 +38,24 @@
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.analytics.event.EventAnalyticsService;
 import org.hisp.dhis.analytics.event.EventQueryParams;
+import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.eventchart.EventChart;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.program.ProgramStageDataElementService;
+import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -55,7 +66,11 @@
     extends DhisSpringTest
 {
     private Program prA;
+    private ProgramStage psA;
 
+    private Period peA;
+    private Period peB;
+    
     private OrganisationUnit ouA;
     private OrganisationUnit ouB;
     
@@ -72,6 +87,12 @@
     private ProgramService programService;
 
     @Autowired
+    private ProgramStageService programStageService;
+    
+    @Autowired
+    private ProgramStageDataElementService programStageDataElementService;
+    
+    @Autowired
     private DataElementService dataElementService;
 
     @Autowired
@@ -79,10 +100,13 @@
     
     @Autowired
     private TrackedEntityAttributeService attributeService;
-
+    
     @Override
     public void setUpTest()
     {
+        peA = PeriodType.getPeriodFromIsoString( "201401" );
+        peB = PeriodType.getPeriodFromIsoString( "201402" );
+        
         ouA = createOrganisationUnit( 'A' );
         ouB = createOrganisationUnit( 'B' );
 
@@ -101,8 +125,14 @@
         attributeService.addTrackedEntityAttribute( atA );
         attributeService.addTrackedEntityAttribute( atB );
 
-        prA = createProgram( 'A', null, asSet( atA, atB ), asSet( ouA, ouB ) );
-        programService.addProgram( prA );        
+        psA = createProgramStage( 'A', asSet( deA, deB ) );
+        programStageService.saveProgramStage( psA );
+                
+        prA = createProgram( 'A', asSet( psA ), asSet( atA, atB ), asSet( ouA, ouB ) );
+        programService.addProgram( prA );
+        
+        programStageDataElementService.addProgramStageDataElement( new ProgramStageDataElement( psA, deA, false ) );
+        programStageDataElementService.addProgramStageDataElement( new ProgramStageDataElement( psA, deB, false ) );
     }
 
     @Test
@@ -120,6 +150,57 @@
         
         assertEquals( prA, params.getProgram() );
         assertEquals( 1, params.getOrganisationUnits().size() );
-        assertEquals( 2, params.getFilterPeriods().size() );
+        assertEquals( 1, params.getItems().size() );
+        assertEquals( 2, params.getFilterPeriods().size() );
+    }
+    
+    @Test
+    public void testGetFromAnalyticalObjectA()
+    {
+        EventChart chart = new EventChart();
+        chart.setProgram( prA );
+        
+        chart.getColumnDimensions().add( atA.getUid() );
+        chart.getRowDimensions().add( DimensionalObject.ORGUNIT_DIM_ID );
+        chart.getFilterDimensions().add( DimensionalObject.PERIOD_DIM_ID );
+        
+        chart.getAttributeDimensions().add( new TrackedEntityAttributeDimension( atA, "LE:5" ) );
+        chart.getPeriods().add( peA );
+        chart.getPeriods().add( peB );
+        chart.getOrganisationUnits().add( ouA );
+        chart.getOrganisationUnits().add( ouB );
+        
+        EventQueryParams params = analyticsService.getFromAnalyticalObject( chart, prA, null );
+        
+        assertNotNull( params );
+        assertEquals( 1, params.getItems().size() );
+        assertEquals( 2, params.getOrganisationUnits().size() );
+        assertEquals( 2, params.getFilterPeriods().size() );
+    }
+    
+    @Test
+    public void testGetFromAnalyticalObjectB()
+    {
+        EventChart chart = new EventChart();
+        chart.setProgram( prA );
+        
+        chart.getColumnDimensions().add( atA.getUid() );
+        chart.getColumnDimensions().add( deA.getUid() );
+        chart.getRowDimensions().add( DimensionalObject.PERIOD_DIM_ID );
+        chart.getFilterDimensions().add( DimensionalObject.ORGUNIT_DIM_ID );
+        
+        chart.getAttributeDimensions().add( new TrackedEntityAttributeDimension( atA, "LE:5" ) );
+        chart.getDataElementDimensions().add( new TrackedEntityDataElementDimension( deA, "GE:100" ) );
+        chart.getPeriods().add( peA );
+        chart.getPeriods().add( peB );
+        chart.getOrganisationUnits().add( ouA );
+        chart.getOrganisationUnits().add( ouB );
+        
+        EventQueryParams params = analyticsService.getFromAnalyticalObject( chart, prA, null );
+        
+        assertNotNull( params );
+        assertEquals( 2, params.getItems().size() );
+        assertEquals( 2, params.getPeriods().size() );
+        assertEquals( 2, params.getFilterOrganisationUnits().size() );
     }
 }

=== 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	2014-07-12 18:15:50 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2014-07-12 21:07:29 +0000
@@ -107,6 +107,7 @@
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
 import org.hisp.dhis.relationship.RelationshipType;
@@ -1162,7 +1163,7 @@
         return userGroup;
     }
 
-    protected static Program createProgram( char uniqueCharacter, Set<ProgramStage> programStages,
+    public static Program createProgram( char uniqueCharacter, Set<ProgramStage> programStages,
         OrganisationUnit unit )
     {
         Set<OrganisationUnit> units = new HashSet<>();
@@ -1171,7 +1172,7 @@
         return createProgram( uniqueCharacter, programStages, null, units );
     }
     
-    protected static Program createProgram( char uniqueCharacter, Set<ProgramStage> programStages,
+    public static Program createProgram( char uniqueCharacter, Set<ProgramStage> programStages,
         Set<TrackedEntityAttribute> attributes, Set<OrganisationUnit> organisationUnits )
     {
         Program program = new Program();
@@ -1218,7 +1219,6 @@
     public static ProgramStage createProgramStage( char uniqueCharacter, int minDays, boolean irregular )
     {
         ProgramStage programStage = new ProgramStage();
-        programStage.setAutoFields();
 
         programStage.setName( "ProgramStage" + uniqueCharacter );
         programStage.setDescription( "description" + uniqueCharacter );
@@ -1227,6 +1227,22 @@
 
         return programStage;
     }
+    
+    public static ProgramStage createProgramStage( char uniqueCharacter, Set<DataElement> dataElements )
+    {
+        ProgramStage programStage = createProgramStage( uniqueCharacter, 0 );
+        
+        if ( dataElements != null )
+        {
+            for ( DataElement dataElement : dataElements )
+            {
+                ProgramStageDataElement psd = new ProgramStageDataElement( programStage, dataElement, false );
+                programStage.getProgramStageDataElements().add( psd );
+            }
+        }
+        
+        return programStage;
+    }
 
     public static TrackedEntity createTrackedEntity( char uniqueChar )
     {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java	2014-06-21 09:02:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java	2014-07-12 21:07:29 +0000
@@ -304,6 +304,7 @@
             RelationshipType relationshipType = relationshipTypeService.getRelationshipType( relationshipTypeId );
             program.setRelationshipType( relationshipType );
         }
+        
         program.setRelationshipFromA( relationshipFromA );
         program.setRelationshipText( relationshipText );
 
@@ -312,6 +313,7 @@
             TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity( trackedEntityId );
             program.setTrackedEntity( trackedEntity );
         }
+        
         programService.addProgram( program );
 
         int index = 0;