use of org.hisp.dhis.common.RepeatableStageParams in project dhis2-core by dhis2.
the class RepeatableStageParamsHelper method getRepeatableStageParams.
/**
* @param dimension
* @return RepeatableStageParams
* @throws InvalidRepeatableStageParamsException
*/
public static RepeatableStageParams getRepeatableStageParams(String dimension) throws InvalidRepeatableStageParamsException {
Pattern pattern = Arrays.stream(PS_PARAMS_PATTERN_LIST).filter(p -> p.matcher(dimension).find()).findFirst().orElse(Pattern.compile(""));
final Matcher matcher = pattern.matcher(dimension);
List<String> tokens;
switch(pattern.toString()) {
case PS_ASTERISK_REGEX:
return getRepeatableStageParams(0, Integer.MAX_VALUE);
case PS_INDEX_COUNT_REGEX:
tokens = getMatchedRepeatableStageParamTokens(matcher, 2);
return getRepeatableStageParams(Integer.parseInt(tokens.get(0)), Integer.parseInt(tokens.get(1)));
case PS_INDEX_REGEX:
return getRepeatableStageParams(Integer.parseInt(getDefaultIndex(matcher)), 1);
case PS_INDEX_COUNT_START_DATE_END_DATE_REGEX:
tokens = getMatchedRepeatableStageParamTokens(matcher, 4);
return getRepeatableStageParams(Integer.parseInt(tokens.get(0)), Integer.parseInt(tokens.get(1)), DateUtils.parseDate(tokens.get(2)), DateUtils.parseDate(tokens.get(3)));
case PS_INDEX_COUNT_RELATIVE_PERIOD_REGEX:
tokens = getMatchedRepeatableStageParamTokens(matcher, 3);
return getRepeatableStageParams(Integer.parseInt(tokens.get(0)), Integer.parseInt(tokens.get(1)), getRelativePeriods(tokens.get(2)));
case PS_START_DATE_END_DATE_REGEX:
tokens = getMatchedRepeatableStageParamTokens(matcher, 2);
return getRepeatableStageParams(DateUtils.parseDate(tokens.get(0)), DateUtils.parseDate(tokens.get(1).trim()));
case PS_RELATIVE_PERIOD_REGEX:
tokens = getMatchedRepeatableStageParamTokens(matcher, 1);
return getRepeatableStageParams(getRelativePeriods(tokens.get(0)));
default:
return new RepeatableStageParams();
}
}
use of org.hisp.dhis.common.RepeatableStageParams in project dhis2-core by dhis2.
the class AbstractAnalyticsService method getGrid.
protected Grid getGrid(EventQueryParams params) {
// ---------------------------------------------------------------------
// Decide access, add constraints and validate
// ---------------------------------------------------------------------
securityManager.decideAccessEventQuery(params);
params = securityManager.withUserConstraints(params);
queryValidator.validate(params);
// keywords as well as their periods are removed in the next step,
// params object is modified
List<DimensionItemKeywords.Keyword> periodKeywords = params.getDimensions().stream().map(DimensionalObject::getDimensionItemKeywords).filter(dimensionItemKeywords -> dimensionItemKeywords != null && !dimensionItemKeywords.isEmpty()).flatMap(dk -> dk.getKeywords().stream()).collect(Collectors.toList());
params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
// ---------------------------------------------------------------------
// Headers
// ---------------------------------------------------------------------
Grid grid = createGridWithHeaders(params);
for (DimensionalObject dimension : params.getDimensions()) {
grid.addHeader(new GridHeader(dimension.getDimension(), dimension.getDimensionDisplayName(), ValueType.TEXT, false, true));
}
for (QueryItem item : params.getItems()) {
/**
* Special case: If the request contains an item of Org Unit value
* type and the item UID is linked to coordinates (coordinateField),
* then create an Header of ValueType COORDINATE and type "Point"
*/
if (item.getValueType() == ValueType.ORGANISATION_UNIT && params.getCoordinateField().equals(item.getItem().getUid())) {
grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getDisplayProperty(params.getDisplayProperty()), COORDINATE, false, true, item.getOptionSet(), item.getLegendSet()));
} else if (hasNonDefaultRepeatableProgramStageOffset(item)) {
String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
RepeatableStageParams repeatableStageParams = item.getRepeatableStageParams();
String name = repeatableStageParams.getDimension();
grid.addHeader(new GridHeader(name, column, repeatableStageParams.simpleStageValueExpected() ? item.getValueType() : ValueType.REFERENCE, false, true, item.getOptionSet(), item.getLegendSet(), item.getProgramStage().getUid(), item.getRepeatableStageParams()));
} else {
final String uid = getItemUid(item);
final String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
grid.addHeader(new GridHeader(uid, column, item.getValueType(), false, true, item.getOptionSet(), item.getLegendSet()));
}
}
// ---------------------------------------------------------------------
// Data
// ---------------------------------------------------------------------
long count = 0;
if (!params.isSkipData() || params.analyzeOnly()) {
count = addEventData(grid, params);
}
// ---------------------------------------------------------------------
// Meta-data
// ---------------------------------------------------------------------
addMetadata(params, periodKeywords, grid);
if (params.hasDataIdScheme()) {
substituteData(grid);
}
if (params.isPaging()) {
Pager pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
grid.getMetaData().put(PAGER.getKey(), pager);
}
maybeApplyHeaders(params, grid);
return grid;
}
use of org.hisp.dhis.common.RepeatableStageParams in project dhis2-core by dhis2.
the class EnrollmentAnalyticsManagerTest method verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithReferenceTypeValue.
@Test
void verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithReferenceTypeValue() {
// Given
DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
QueryItem item = new QueryItem(dio);
item.setValueType(ValueType.COORDINATE);
item.setProgramStage(programStageWithRepeatableParams);
item.setProgram(programB);
RepeatableStageParams repeatableStageParams = new RepeatableStageParams();
repeatableStageParams.setStartIndex(0);
repeatableStageParams.setCount(100);
repeatableStageParams.setStartDate(DateUtils.parseDate("2022-01-01"));
repeatableStageParams.setEndDate(DateUtils.parseDate("2022-01-31"));
item.setRepeatableStageParams(repeatableStageParams);
// When
String columnSql = subject.getColumn(item);
// Then
assertThat(columnSql, is("(select json_agg(t1) from (select \"" + dataElementA.getUid() + "\", incidentdate, duedate, executiondate from analytics_event_" + programB.getUid() + " where analytics_event_" + programB.getUid() + ".pi = ax.pi and \"" + dataElementA.getUid() + "\" is not null and ps = '" + programStageWithRepeatableParams.getUid() + "' and executiondate >= '2022-01-01' and executiondate <= '2022-01-31' order by executiondate desc LIMIT 100 ) as t1)"));
}
use of org.hisp.dhis.common.RepeatableStageParams in project dhis2-core by dhis2.
the class GridTest method setUp.
@BeforeEach
void setUp() {
gridA = new ListGrid();
gridB = new ListGrid();
headerA = new GridHeader("ColA", "colA", ValueType.TEXT, false, true, null, null, "programStage", new RepeatableStageParams());
headerB = new GridHeader("ColB", "colB", ValueType.TEXT, false, true);
headerC = new GridHeader("ColC", "colC", ValueType.TEXT, true, false);
gridA.addHeader(headerA);
gridA.addHeader(headerB);
gridA.addHeader(headerC);
gridA.addRow();
gridA.addValue(11);
gridA.addValue(12);
gridA.addValue(13);
gridA.addRow();
gridA.addValue(21);
gridA.addValue(22);
gridA.addValue(23);
gridA.addRow();
gridA.addValue(31);
gridA.addValue(32);
gridA.addValue(33);
gridA.addRow();
gridA.addValue(41);
gridA.addValue(42);
gridA.addValue(43);
gridB.addRow();
gridB.addValue(11);
gridB.addValue(12);
gridB.addValue(13);
}
use of org.hisp.dhis.common.RepeatableStageParams in project dhis2-core by dhis2.
the class EnrollmentAnalyticsManagerTest method verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithNumberTypeValue.
@Test
void verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithNumberTypeValue() {
// Given
DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
QueryItem item = new QueryItem(dio);
item.setValueType(ValueType.COORDINATE);
item.setProgramStage(programStageWithRepeatableParams);
item.setProgram(programB);
RepeatableStageParams repeatableStageParams = new RepeatableStageParams();
repeatableStageParams.setStartIndex(0);
repeatableStageParams.setCount(1);
item.setRepeatableStageParams(repeatableStageParams);
// When
String columnSql = subject.getColumn(item);
// Then
assertThat(columnSql, is("(select \"" + dataElementA.getUid() + "\" from analytics_event_" + programB.getUid() + " where analytics_event_" + programB.getUid() + ".pi = ax.pi and \"" + dataElementA.getUid() + "\" is not null and ps = '" + programStageWithRepeatableParams.getUid() + "' order by executiondate desc limit 1 )"));
}
Aggregations