Search in sources :

Example 1 with AnalyticsPeriodBoundary

use of org.hisp.dhis.program.AnalyticsPeriodBoundary in project dhis2-core by dhis2.

the class DhisConvenienceTest method createProgramIndicator.

public static ProgramIndicator createProgramIndicator(char uniqueCharacter, AnalyticsType analyticsType, Program program, String expression, String filter) {
    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.setExpression(expression);
    indicator.setAnalyticsType(analyticsType);
    indicator.setFilter(filter);
    Set<AnalyticsPeriodBoundary> boundaries = new HashSet<>();
    if (analyticsType == AnalyticsType.EVENT) {
        boundaries.add(new AnalyticsPeriodBoundary(AnalyticsPeriodBoundary.EVENT_DATE, AnalyticsPeriodBoundaryType.BEFORE_END_OF_REPORTING_PERIOD, null, 0));
        boundaries.add(new AnalyticsPeriodBoundary(AnalyticsPeriodBoundary.EVENT_DATE, AnalyticsPeriodBoundaryType.AFTER_START_OF_REPORTING_PERIOD, null, 0));
    } else if (analyticsType == AnalyticsType.ENROLLMENT) {
        boundaries.add(new AnalyticsPeriodBoundary(AnalyticsPeriodBoundary.ENROLLMENT_DATE, AnalyticsPeriodBoundaryType.BEFORE_END_OF_REPORTING_PERIOD, null, 0));
        boundaries.add(new AnalyticsPeriodBoundary(AnalyticsPeriodBoundary.ENROLLMENT_DATE, AnalyticsPeriodBoundaryType.AFTER_START_OF_REPORTING_PERIOD, null, 0));
    }
    for (AnalyticsPeriodBoundary boundary : boundaries) {
        boundary.setAutoFields();
    }
    indicator.setAnalyticsPeriodBoundaries(boundaries);
    return indicator;
}
Also used : AnalyticsPeriodBoundary(org.hisp.dhis.program.AnalyticsPeriodBoundary) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) HashSet(java.util.HashSet)

Example 2 with AnalyticsPeriodBoundary

use of org.hisp.dhis.program.AnalyticsPeriodBoundary in project dhis2-core by dhis2.

the class EnrollmentTimeFieldSqlRenderer method getProgramIndicatorEventInProgramStageSql.

private String getProgramIndicatorEventInProgramStageSql(ProgramIndicator programIndicator, Date reportingStartDate, Date reportingEndDate) {
    Assert.isTrue(programIndicator.hasEventDateCohortBoundary(), "Can not get event date cohort boundaries for program indicator:" + programIndicator.getUid());
    Map<String, Set<AnalyticsPeriodBoundary>> map = programIndicator.getEventDateCohortBoundaryByProgramStage();
    final SimpleDateFormat format = new SimpleDateFormat();
    format.applyPattern(Period.DEFAULT_DATE_FORMAT);
    String sql = "";
    for (String programStage : map.keySet()) {
        Set<AnalyticsPeriodBoundary> boundaries = map.get(programStage);
        String eventTableName = "analytics_event_" + programIndicator.getProgram().getUid();
        sql += " exists(select 1 from " + eventTableName + " where " + eventTableName + ".pi = " + ANALYTICS_TBL_ALIAS + ".pi and executiondate is not null ";
        for (AnalyticsPeriodBoundary boundary : boundaries) {
            sql += " and executiondate " + (boundary.getAnalyticsPeriodBoundaryType().isStartBoundary() ? ">=" : "<") + " cast( '" + format.format(boundary.getBoundaryDate(reportingStartDate, reportingEndDate)) + "' as date )";
        }
        sql += " limit 1)";
    }
    return sql;
}
Also used : Set(java.util.Set) AnalyticsPeriodBoundary(org.hisp.dhis.program.AnalyticsPeriodBoundary) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

AnalyticsPeriodBoundary (org.hisp.dhis.program.AnalyticsPeriodBoundary)2 SimpleDateFormat (java.text.SimpleDateFormat)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TextUtils.getQuotedCommaDelimitedString (org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString)1 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)1 DateUtils.getMediumDateString (org.hisp.dhis.util.DateUtils.getMediumDateString)1