Skip to content

Commit

Permalink
feat: stored by as dimension [DHIS2-4902] (dhis2#8361)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnespolino authored Aug 10, 2021
1 parent 79d39e9 commit 28a408e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum ColumnDataType
{
CHARACTER_11( "character(11)" ),
CHARACTER_50( "character(50)" ),
VARCHAR_255( "varchar(255)" ),
TEXT( "text" ),
DATE( "date" ),
TIMESTAMP( "timestamp" ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public interface EventAnalyticsService

String ITEM_EVENT_DATE = "eventdate";

String ITEM_STORED_BY = "storedby";

String ITEM_ENROLLMENT_DATE = "enrollmentdate";

String ITEM_INCIDENT_DATE = "incidentdate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public class DefaultEventAnalyticsService

private static final String NAME_EVENT_DATE = "Event date";

private static final String NAME_STORED_BY = "Stored by";

private static final String NAME_ENROLLMENT_DATE = "Enrollment date";

private static final String NAME_INCIDENT_DATE = "Incident date";
Expand Down Expand Up @@ -693,7 +695,8 @@ protected Grid createGridWithHeaders( EventQueryParams params )
.addHeader( new GridHeader( ITEM_EVENT, NAME_EVENT, TEXT, false, true ) )
.addHeader( new GridHeader( ITEM_PROGRAM_STAGE, NAME_PROGRAM_STAGE, TEXT, false, true ) )
.addHeader( new GridHeader( ITEM_EVENT_DATE,
LabelMapper.getEventDateLabel( params.getProgramStage(), NAME_EVENT_DATE ), DATE, false, true ) );
LabelMapper.getEventDateLabel( params.getProgramStage(), NAME_EVENT_DATE ), DATE, false, true ) )
.addHeader( new GridHeader( ITEM_STORED_BY, NAME_STORED_BY, TEXT, false, true ) );

if ( params.getProgram().isRegistration() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private SqlRowSet queryForRows( final String sql )
protected String getSelectClause( EventQueryParams params )
{
ImmutableList.Builder<String> cols = new ImmutableList.Builder<String>()
.add( "psi", "ps", "executiondate" );
.add( "psi", "ps", "executiondate", "storedby" );

if ( params.getProgram().isRegistration() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.hisp.dhis.analytics.ColumnDataType.GEOMETRY;
import static org.hisp.dhis.analytics.ColumnDataType.TEXT;
import static org.hisp.dhis.analytics.ColumnDataType.TIMESTAMP;
import static org.hisp.dhis.analytics.ColumnDataType.VARCHAR_255;
import static org.hisp.dhis.analytics.ColumnNotNullConstraint.NOT_NULL;
import static org.hisp.dhis.analytics.util.AnalyticsSqlUtils.getClosingParentheses;
import static org.hisp.dhis.analytics.util.AnalyticsSqlUtils.quote;
Expand Down Expand Up @@ -103,6 +104,8 @@ public JdbcEventAnalyticsTableManager( IdentifiableObjectManager idObjectManager
databaseInfo, jdbcTemplate );
}

public static final String STORED_BY_COL_NAME = "storedby";

private static final List<AnalyticsTableColumn> FIXED_COLS = ImmutableList.of(
new AnalyticsTableColumn( quote( "psi" ), CHARACTER_11, NOT_NULL, "psi.uid" ),
new AnalyticsTableColumn( quote( "pi" ), CHARACTER_11, NOT_NULL, "pi.uid" ),
Expand All @@ -115,6 +118,7 @@ public JdbcEventAnalyticsTableManager( IdentifiableObjectManager idObjectManager
new AnalyticsTableColumn( quote( "completeddate" ), TIMESTAMP, "psi.completeddate" ),
new AnalyticsTableColumn( quote( "created" ), TIMESTAMP, "psi.created" ),
new AnalyticsTableColumn( quote( "lastupdated" ), TIMESTAMP, "psi.lastupdated" ),
new AnalyticsTableColumn( quote( STORED_BY_COL_NAME ), VARCHAR_255, "psi.storedby" ),
new AnalyticsTableColumn( quote( "pistatus" ), CHARACTER_50, "pi.status" ),
new AnalyticsTableColumn( quote( "psistatus" ), CHARACTER_50, "psi.status" ),
new AnalyticsTableColumn( quote( "psigeometry" ), GEOMETRY, "psi.geometry" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class EventsAnalyticsManagerTest extends EventAnalyticsTest

private final static String TABLE_NAME = "analytics_event";

private final static String DEFAULT_COLUMNS_WITH_REGISTRATION = "psi,ps,executiondate,enrollmentdate,incidentdate,tei,pi,ST_AsGeoJSON(psigeometry, 6) as geometry,longitude,latitude,ouname,oucode";
private final static String DEFAULT_COLUMNS_WITH_REGISTRATION = "psi,ps,executiondate,storedby,enrollmentdate,incidentdate,tei,pi,ST_AsGeoJSON(psigeometry, 6) as geometry,longitude,latitude,ouname,oucode";

@Before
public void setUp()
Expand All @@ -137,7 +137,7 @@ public void verifyGetEventSqlWithProgramWithNoRegistration()

verify( jdbcTemplate ).queryForRowSet( sql.capture() );

String expected = "select psi,ps,executiondate,ST_AsGeoJSON(psigeometry, 6) as geometry,longitude,latitude,ouname,oucode,ax.\"monthly\",ax.\"ou\" from "
String expected = "select psi,ps,executiondate,storedby,ST_AsGeoJSON(psigeometry, 6) as geometry,longitude,latitude,ouname,oucode,ax.\"monthly\",ax.\"ou\" from "
+ getTable( programA.getUid() )
+ " as ax where ax.\"monthly\" in ('2000Q1') and (ax.\"uidlevel0\" in ('ouabcdefghA') ) limit 101";

Expand All @@ -157,7 +157,7 @@ public void verifyGetEventSqlWithOrgUnitTypeDataElement()

verify( jdbcTemplate ).queryForRowSet( sql.capture() );

String expected = "select psi,ps,executiondate,enrollmentdate,incidentdate,tei,pi,ST_AsGeoJSON(psigeometry, 6) "
String expected = "select psi,ps,executiondate,storedby,enrollmentdate,incidentdate,tei,pi,ST_AsGeoJSON(psigeometry, 6) "
+
"as geometry,longitude,latitude,ouname,oucode,ax.\"monthly\",ax.\"ou\",\"" + dataElement.getUid() + "_name"
+ "\" " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void verifyGetTableWithCategoryCombo()
assertThat( tables, hasSize( 1 ) );

new AnalyticsTableAsserter.Builder( tables.get( 0 ) ).withTableType( AnalyticsTableType.EVENT )
.withTableName( TABLE_PREFIX + program.getUid().toLowerCase() ).withColumnSize( 42 )
.withTableName( TABLE_PREFIX + program.getUid().toLowerCase() ).withColumnSize( 43 )
.withDefaultColumns( subject.getFixedColumns() ).addColumns( periodColumns )
.addColumn( categoryA.getUid(), CHARACTER_11, "acs.", categoryA.getCreated() )
.addColumn( categoryB.getUid(), CHARACTER_11, "acs.", categoryB.getCreated() ).build().verify();
Expand Down Expand Up @@ -283,7 +283,7 @@ public void verifyGetTableWithDataElements()

new AnalyticsTableAsserter.Builder( tables.get( 0 ) )
.withTableName( TABLE_PREFIX + program.getUid().toLowerCase() ).withTableType( AnalyticsTableType.EVENT )
.withColumnSize( 49 ).addColumns( periodColumns )
.withColumnSize( 50 ).addColumns( periodColumns )
.addColumn( d1.getUid(), TEXT, toAlias( aliasD1, d1.getUid() ) ) // ValueType.TEXT
.addColumn( d2.getUid(), DOUBLE, toAlias( aliasD2, d2.getUid() ) ) // ValueType.PERCENTAGE
.addColumn( d3.getUid(), INTEGER, toAlias( aliasD3, d3.getUid() ) ) // ValueType.BOOLEAN
Expand Down Expand Up @@ -337,7 +337,7 @@ public void verifyGetTableWithTrackedEntityAttribute()

new AnalyticsTableAsserter.Builder( tables.get( 0 ) )
.withTableName( TABLE_PREFIX + program.getUid().toLowerCase() ).withTableType( AnalyticsTableType.EVENT )
.withColumnSize( 44 ).addColumns( periodColumns )
.withColumnSize( 45 ).addColumns( periodColumns )
.addColumn( d1.getUid(), TEXT, toAlias( aliasD1, d1.getUid() ) ) // ValueType.TEXT
.addColumn( tea1.getUid(), TEXT, String.format( aliasTea1, "ou.uid", tea1.getId(), tea1.getUid() ) ) // ValueType.ORGANISATION_UNIT
// Second Geometry column created from the OU column above
Expand Down

0 comments on commit 28a408e

Please sign in to comment.