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

fix: programIndicators are now prefixed by programId in tei dimensions endpoint [DHIS2-16368] #16014

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -47,8 +47,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.hisp.dhis.ApiTest;
import org.hisp.dhis.Constants;
import org.hisp.dhis.actions.analytics.AnalyticsEnrollmentsActions;
Expand Down Expand Up @@ -322,4 +324,34 @@ public void shouldReturnAllDataElements() {
.body("dimensions", hasSize(equalTo(dataElements.size())))
.body("dimensions.uid", everyItem(in(distinctDataElements)));
}

@Test
void ProgramIndicatorsShouldHavePrefix() {
analyticsTeiActions
.query()
.getDimensions(
Constants.TRACKED_ENTITY_TYPE,
new QueryParamsBuilder().add("filter", "dimensionType:eq:PROGRAM_INDICATOR"))
.validate()
.statusCode(200)
.body("dimensions", hasSize(greaterThanOrEqualTo(1)))
.body("dimensions.id", everyItem(containsExactlyOne('.')));
}

public static TypeSafeDiagnosingMatcher<String> containsExactlyOne(Character character) {
return new TypeSafeDiagnosingMatcher<>() {
@Override
protected boolean matchesSafely(String item, Description mismatchDescription) {
if (item != null) {
return item.chars().filter(ch -> ch == character).count() == 1;
}
return false;
}

@Override
public void describeTo(Description description) {
description.appendText("a string that contains exactly one " + character);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.common.PrefixedDimension;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.program.ProgramIndicator;
import org.hisp.dhis.program.ProgramStageDataElement;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
Expand All @@ -42,7 +43,8 @@ public class TeiAnalyticsPrefixStrategy implements PrefixStrategy {
@Override
public String apply(PrefixedDimension pDimension) {
if (pDimension.getItem() instanceof DataElement
|| pDimension.getItem() instanceof ProgramStageDataElement) {
|| pDimension.getItem() instanceof ProgramStageDataElement
|| pDimension.getItem() instanceof ProgramIndicator) {
return pDimension.getPrefix();
}
return StringUtils.EMPTY;
Expand Down
Loading