use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class EventDataQueryServiceTest method testGetPeriods.
@Test
void testGetPeriods() {
Set<String> dimensionParams = new HashSet<>();
dimensionParams.add("ou:" + ouA.getUid() + ";");
dimensionParams.add("pe:LAST_WEEK;TODAY:LAST_UPDATED;20220101_20220201:INCIDENT_DATE");
EventDataQueryRequest request = EventDataQueryRequest.builder().program(prA.getUid()).dimension(dimensionParams).build();
EventQueryParams params = dataQueryService.getFromRequest(request);
DimensionalObject pe = params.getDimension("pe");
assertEquals(3, pe.getItems().size());
assertTrue(streamOfPeriods(pe).anyMatch(Period::isDefault));
assertTrue(streamOfPeriods(pe).map(Period::getDateField).anyMatch(s -> s.equals("LAST_UPDATED")));
assertTrue(streamOfPeriods(pe).map(Period::getDateField).anyMatch(s -> s.equals("INCIDENT_DATE")));
assertTrue(streamOfPeriods(pe).filter(period -> "INCIDENT_DATE".equals(period.getDateField())).anyMatch(period -> period.getStartDate().equals(of(2022, 1, 1)) && period.getEndDate().equals(of(2022, 2, 1))));
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class EventsAnalyticsManagerTest method verifySortClauseHandlesProgramIndicators.
@Test
void verifySortClauseHandlesProgramIndicators() {
Program program = createProgram('P');
ProgramIndicator piA = createProgramIndicator('A', program, ".", ".");
piA.setUid("TLKx7vllb1I");
ProgramIndicator piB = createProgramIndicator('B', program, ".", ".");
piA.setUid("CCKx3gllb2P");
OrganisationUnit ouA = createOrganisationUnit('A');
Period peA = PeriodType.getPeriodFromIsoString("201501");
DataElement deA = createDataElement('A');
deA.setUid("ZE4cgllb2P");
DataQueryParams params = DataQueryParams.newBuilder().withDataType(DataType.NUMERIC).withTableName("analytics").withPeriodType(QuarterlyPeriodType.NAME).withAggregationType(AnalyticsAggregationType.fromAggregationType(AggregationType.DEFAULT)).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.PROGRAM_INDICATOR, getList(piA, piB))).addFilter(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.DATA_X, getList(peA))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA))).build();
final EventQueryParams.Builder eventQueryParamsBuilder = new EventQueryParams.Builder(params).withProgram(program).addAscSortItem(new QueryItem(piA)).addDescSortItem(new QueryItem(piB)).addAscSortItem(new QueryItem(deA));
final String sql = subject.getEventsOrEnrollmentsSql(eventQueryParamsBuilder.build(), 100);
assertThat(sql, containsString("order by \"" + piA.getUid() + "\" asc,\"" + deA.getUid() + "\" asc,\"" + piB.getUid() + "\""));
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class LabelMapperTest method mockProgramStageWithoutLabels.
private ProgramStage mockProgramStageWithoutLabels() {
final ProgramStage programStage = new ProgramStage();
final Program program = new Program();
programStage.setProgram(program);
return programStage;
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class LabelMapperTest method mockProgramStageWithLabels.
private ProgramStage mockProgramStageWithLabels() {
final ProgramStage programStage = new ProgramStage();
programStage.setExecutionDateLabel("execution date label");
final Program program = new Program();
program.setEnrollmentDateLabel("enrollment date label");
program.setIncidentDateLabel("incident date label");
programStage.setProgram(program);
return programStage;
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class DefaultEventAnalyticsServiceTest method testOutputSchemeWhenNoSchemeIsSet.
@Test
void testOutputSchemeWhenNoSchemeIsSet() {
// Given mock variables
final IdScheme noScheme = null;
final OrganisationUnit mockOrgUnit = createOrganisationUnit('A');
final Program mockProgram = createProgram('A', null, null, Sets.newHashSet(mockOrgUnit), null);
final EventQueryParams mockParams = mockEventQueryParams(mockOrgUnit, mockProgram, noScheme);
// Given mock calls
doNothing().when(securityManager).decideAccessEventQuery(mockParams);
when(securityManager.withUserConstraints(mockParams)).thenReturn(mockParams);
doNothing().when(eventQueryValidator).validate(mockParams);
when(queryPlanner.planEventQuery(any(EventQueryParams.class))).thenReturn(mockParams);
// When
defaultEventAnalyticsService.getEvents(mockParams);
// Then
verify(schemaIdResponseMapper, never()).getSchemeIdResponseMap(mockParams);
}
Aggregations