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;
}
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;
}
Aggregations