/** * Determines wether there exists any analytics period boundaries that has type "Event in program stage". * @return true if any boundary exists with type "Event in program stage" */ public boolean hasEventDateCohortBoundary() { for ( AnalyticsPeriodBoundary boundary : analyticsPeriodBoundaries ) { if ( boundary.isEnrollmentHavingEventDateCohortBoundary() ) { return true; } } return false; }
/** * Returns any analytics period boundaries that has type "Event in program stage", organized as a map * where the program stage is the key, and the list of boundaries for that program stage is the value. */ public Map<String, Set<AnalyticsPeriodBoundary>> getEventDateCohortBoundaryByProgramStage() { Map<String, Set<AnalyticsPeriodBoundary>> map = new HashMap<String, Set<AnalyticsPeriodBoundary>>(); for ( AnalyticsPeriodBoundary boundary : analyticsPeriodBoundaries ) { if ( boundary.isEnrollmentHavingEventDateCohortBoundary() ) { Matcher matcher = AnalyticsPeriodBoundary.COHORT_HAVING_PROGRAM_STAGE_PATTERN.matcher( boundary.getBoundaryTarget() ); Assert.isTrue( matcher.find(), "Can not parse program stage pattern for analyticsPeriodBoundary " + boundary.getUid() + " - boundaryTarget: " + boundary.getBoundaryTarget() ); String programStage = matcher.group( AnalyticsPeriodBoundary.PROGRAM_STAGE_REGEX_GROUP ); Assert.isTrue( programStage != null, "Can not find programStage for analyticsPeriodBoundary " + boundary.getUid() + " - boundaryTarget: " + boundary.getBoundaryTarget() ); if ( !map.containsKey( programStage ) ) { map.put( programStage, new HashSet<AnalyticsPeriodBoundary>() ); } map.get( programStage ).add( boundary ); } } return map; }
public String getBoundaryCondition( ProgramIndicator programIndicator, Date reportingStartDate, Date reportingEndDate, SqlHelper sqlHelper ) { String sql = ""; for ( AnalyticsPeriodBoundary boundary : programIndicator.getAnalyticsPeriodBoundaries() ) { if ( boundary.isCohortDateBoundary() && !boundary.isEnrollmentHavingEventDateCohortBoundary() ) { sql += sqlHelper.whereAnd() + " " + getBoundaryCondition( boundary, programIndicator, reportingStartDate, reportingEndDate ); } } if ( programIndicator.hasEventDateCohortBoundary() ) { sql += sqlHelper.whereAnd() + " " + getProgramIndicatorEventInProgramStageSql( programIndicator, reportingStartDate, reportingEndDate ); } return sql; }