Skip to content

Commit

Permalink
fix: Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge committed Nov 26, 2024
1 parent c1b20d7 commit c51fb14
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import static org.hisp.dhis.common.DimensionalObject.ITEM_SEP;
import static org.hisp.dhis.common.DimensionalObject.OPTION_SEP;
import static org.hisp.dhis.expression.ExpressionService.SYMBOL_WILDCARD;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -50,6 +53,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Triple;
Expand All @@ -59,9 +63,6 @@
import org.hisp.dhis.eventvisualization.EventRepetition;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramStage;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.NoArgsConstructor;

/**
* @author Lars Helge Overland
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,30 +421,8 @@ private List<AnalyticsTableColumn> getColumns(Program program) {
columns.addAll(getOrganisationUnitGroupSetColumns());
columns.addAll(getAttributeCategoryOptionGroupSetColumns());
columns.addAll(getPeriodTypeColumns("dps"));

columns.addAll(
program.getAnalyticsDataElements().stream()
.map(de -> getColumnForDataElement(de, false))
.flatMap(Collection::stream)
.toList());

columns.addAll(
program.getAnalyticsDataElementsWithLegendSet().stream()
.map(de -> getColumnForDataElement(de, true))
.flatMap(Collection::stream)
.toList());

columns.addAll(
program.getNonConfidentialTrackedEntityAttributes().stream()
.map(tea -> getColumnForTrackedEntityAttribute(tea, false))
.flatMap(Collection::stream)
.toList());

columns.addAll(
program.getNonConfidentialTrackedEntityAttributesWithLegendSet().stream()
.map(tea -> getColumnForTrackedEntityAttribute(tea, true))
.flatMap(Collection::stream)
.toList());
columns.addAll(getDataElementColumns(program));
columns.addAll(getAttributeColumns(program));

if (program.isRegistration()) {
columns.add(EventAnalyticsColumn.TRACKED_ENTITY);
Expand All @@ -469,6 +447,27 @@ protected AnalyticsTableColumn getPartitionColumn() {
.build();
}

/**
* Returns columns for data elements of the given program.
*
* @param program the {@link Program}.
* @return a list of {@link AnalyticsTableColumn}.
*/
private List<AnalyticsTableColumn> getDataElementColumns(Program program) {
List<AnalyticsTableColumn> columns = new ArrayList<>();
columns.addAll(
program.getAnalyticsDataElements().stream()
.map(de -> getColumnForDataElement(de, false))
.flatMap(Collection::stream)
.toList());
columns.addAll(
program.getAnalyticsDataElementsWithLegendSet().stream()
.map(de -> getColumnForDataElement(de, true))
.flatMap(Collection::stream)
.toList());
return columns;
}

/**
* Returns a column for the given data element. If the value type of the data element is {@link
* ValueType#ORGANISATION_UNIT}, an extra column will be included.
Expand Down Expand Up @@ -545,6 +544,34 @@ private List<AnalyticsTableColumn> getColumnForOrgUnitDataElement(
return columns;
}

/**
* Returns columns for attributes of the given program.
*
* @param program the {@link Program}.
* @return a list of {@link AnalyticsTableColumn}.
*/
private List<AnalyticsTableColumn> getAttributeColumns(Program program) {
List<AnalyticsTableColumn> columns = new ArrayList<>();
columns.addAll(
program.getNonConfidentialTrackedEntityAttributes().stream()
.map(tea -> getColumnForTrackedEntityAttribute(tea, false))
.flatMap(Collection::stream)
.toList());
columns.addAll(
program.getNonConfidentialTrackedEntityAttributesWithLegendSet().stream()
.map(tea -> getColumnForTrackedEntityAttribute(tea, true))
.flatMap(Collection::stream)
.toList());
return columns;
}

/**
* Returns a list of columns based on the given attribute.
*
* @param attribute the {@link TrackedEntityAttribute}.
* @param withLegendSet indicates whether the attribute has a legend set.
* @return a list of {@link AnaylyticsTableColumn}.
*/
private List<AnalyticsTableColumn> getColumnForTrackedEntityAttribute(
TrackedEntityAttribute attribute, boolean withLegendSet) {
List<AnalyticsTableColumn> columns = new ArrayList<>();
Expand Down

0 comments on commit c51fb14

Please sign in to comment.