Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Code readability [DHIS2-16705] #19451

Merged
merged 45 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a1261b9
fix: Update code
larshelge Dec 2, 2024
bf145f6
fix: Update code
larshelge Dec 2, 2024
2c933d8
fix: Update code
larshelge Dec 2, 2024
754da7f
fix: Update code
larshelge Dec 2, 2024
5e164c7
fix: Update code
larshelge Dec 2, 2024
4edfd49
fix: Update code
larshelge Dec 2, 2024
c82b6f7
fix: Update code
larshelge Dec 2, 2024
aa7625b
fix: Update code
larshelge Dec 2, 2024
c0d12da
fix: Update code
larshelge Dec 2, 2024
392d07d
Merge branch 'master' into lars-dev
larshelge Dec 2, 2024
057cdf0
fix: Update code
larshelge Dec 2, 2024
60c8ad6
fix: Update code
larshelge Dec 2, 2024
ee780bb
fix: Update code
larshelge Dec 2, 2024
db9651b
fix: Update code
larshelge Dec 2, 2024
8002118
fix: Update code
larshelge Dec 2, 2024
7fc3b92
fix: Update code
larshelge Dec 2, 2024
43a69e3
fix: Update code
larshelge Dec 2, 2024
c2b8afc
Merge branch 'master' into lars-dev
larshelge Dec 2, 2024
3f162fb
fix: Update code
larshelge Dec 2, 2024
6024282
fix: Update code
larshelge Dec 2, 2024
35a8daa
fix: Update code
larshelge Dec 2, 2024
41ca710
fix: Update code
larshelge Dec 2, 2024
7d7360d
fix: Update code
larshelge Dec 2, 2024
4fff29e
fix: Update code
larshelge Dec 2, 2024
2125b91
fix: Update code
larshelge Dec 2, 2024
3858aa7
fix: Update code
larshelge Dec 2, 2024
64c4765
Merge branch 'master' into lars-dev
larshelge Dec 3, 2024
4a7452f
Revert "feat: skipAnalytics and ConfidentialFlag only for QUERY Analy…
larshelge Dec 4, 2024
a0fc292
Merge branch 'master' into lars-dev
larshelge Dec 4, 2024
1efcccc
Merge branch 'master' into lars-dev
larshelge Dec 4, 2024
f6a2245
Merge branch 'master' into lars-dev
larshelge Dec 4, 2024
e8ccde7
Merge branch 'master' into lars-dev
larshelge Dec 5, 2024
90aa73e
Merge branch 'master' into lars-dev
larshelge Dec 10, 2024
16429cc
fix: Update code
larshelge Dec 10, 2024
d0df6ce
Merge branch 'master' into lars-dev
larshelge Dec 10, 2024
912c69e
Merge branch 'master' into lars-dev
larshelge Dec 10, 2024
5dab606
Merge branch 'master' into lars-dev
larshelge Dec 11, 2024
ea86360
Merge branch 'master' into lars-dev
larshelge Dec 11, 2024
35a2526
fix: Update code
larshelge Dec 11, 2024
022ab1a
Merge branch 'master' into lars-dev
larshelge Dec 11, 2024
82deae7
fix: Update code
larshelge Dec 11, 2024
284e86a
fix: Update code
larshelge Dec 11, 2024
3608b81
fix: Update code
larshelge Dec 11, 2024
e47ed4d
fix: Update code
larshelge Dec 11, 2024
0f7e863
fix: Update code
larshelge Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static java.lang.String.join;
import static java.util.stream.Collectors.groupingBy;
import static org.apache.commons.collections4.CollectionUtils.emptyIfNull;
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
import static org.hisp.dhis.analytics.AnalyticsTableType.TRACKED_ENTITY_INSTANCE;
import static org.hisp.dhis.analytics.table.JdbcEventAnalyticsTableManager.EXPORTABLE_EVENT_STATUSES;
import static org.hisp.dhis.analytics.util.AnalyticsUtils.getColumnType;
Expand Down Expand Up @@ -176,25 +177,27 @@ private List<AnalyticsTableColumn> getColumns(
(Map<String, List<Program>>) params.getExtraParam("", PROGRAMS_BY_TET_KEY);

List<AnalyticsTableColumn> columns = new ArrayList<>(getFixedColumns());

String enrolledInProgramExpression =
"""
\s exists(select 1 from ${enrollment} en_0 \
where en_0.trackedentityid = te.trackedentityid \
and en_0.programid = ${programId})""";

emptyIfNull(programsByTetUid.get(trackedEntityType.getUid()))
.forEach(
program ->
columns.add(
AnalyticsTableColumn.builder()
.name(program.getUid())
.dataType(BOOLEAN)
.selectExpression(
replaceQualify(
enrolledInProgramExpression,
Map.of("programId", String.valueOf(program.getId()))))
.build()));
List<Program> programs = programsByTetUid.get(trackedEntityType.getUid());

if (isNotEmpty(programs)) {
String enrolledInProgramExpression =
"""
\s exists(select 1 from ${enrollment} en_0 \
where en_0.trackedentityid = te.trackedentityid \
and en_0.programid = ${programId})""";

programs.forEach(
program ->
columns.add(
AnalyticsTableColumn.builder()
.name(program.getUid())
.dataType(BOOLEAN)
.selectExpression(
replaceQualify(
enrolledInProgramExpression,
Map.of("programId", String.valueOf(program.getId()))))
.build()));
}

List<TrackedEntityAttribute> trackedEntityAttributes =
getAllTrackedEntityAttributes(trackedEntityType, programsByTetUid)
Expand Down Expand Up @@ -271,7 +274,6 @@ private List<AnalyticsTableColumn> getFixedColumns() {
columns.addAll(getOrganisationUnitLevelColumns());
columns.add(getOrganisationUnitNameHierarchyColumn());
columns.addAll(getFixedNonGroupByColumns());

return columns;
}

Expand Down Expand Up @@ -308,18 +310,23 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti
left join analytics_rs_organisationunitgroupsetstructure ougs on te.organisationunitid=ougs.organisationunitid""",
Map.of()));

((List<TrackedEntityAttribute>)
params.getExtraParam(trackedEntityType.getUid(), ALL_NON_CONFIDENTIAL_TET_ATTRIBUTES))
.forEach(
tea ->
sql.append(
replaceQualify(
"""
\s left join ${trackedentityattributevalue} ${teaUid} on ${teaUid}.trackedentityid=te.trackedentityid \
and ${teaUid}.trackedentityattributeid = ${teaId}""",
Map.of(
"teaUid", quote(tea.getUid()),
"teaId", String.valueOf(tea.getId())))));
List<TrackedEntityAttribute> attributes =
((List<TrackedEntityAttribute>)
params.getExtraParam(trackedEntityType.getUid(), ALL_NON_CONFIDENTIAL_TET_ATTRIBUTES));

if (isNotEmpty(attributes)) {
attributes.forEach(
tea ->
sql.append(
replaceQualify(
"""
\s left join ${trackedentityattributevalue} ${teaUid} on ${teaUid}.trackedentityid=te.trackedentityid \
and ${teaUid}.trackedentityattributeid = ${teaId}""",
Map.of(
"teaUid", quote(tea.getUid()),
"teaId", String.valueOf(tea.getId())))));
}

sql.append(
replaceQualify(
"""
Expand Down
Loading