Search in sources :

Example 86 with Program

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))));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) ListGrid(org.hisp.dhis.system.grid.ListGrid) Date(java.util.Date) ValueType(org.hisp.dhis.common.ValueType) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) EventChart(org.hisp.dhis.eventchart.EventChart) EventDataQueryService(org.hisp.dhis.analytics.event.EventDataQueryService) Period(org.hisp.dhis.period.Period) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) AnalyticsType(org.hisp.dhis.common.AnalyticsType) Set(java.util.Set) DimensionType(org.hisp.dhis.common.DimensionType) ZoneId(java.time.ZoneId) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LocalDate(java.time.LocalDate) Legend(org.hisp.dhis.legend.Legend) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) LegendSetService(org.hisp.dhis.legend.LegendSetService) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DataElementService(org.hisp.dhis.dataelement.DataElementService) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Program(org.hisp.dhis.program.Program) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) GridHeader(org.hisp.dhis.common.GridHeader) AnalyticsAggregationType(org.hisp.dhis.analytics.AnalyticsAggregationType) LegendSet(org.hisp.dhis.legend.LegendSet) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DimensionalObjectUtils(org.hisp.dhis.common.DimensionalObjectUtils) AggregationType(org.hisp.dhis.analytics.AggregationType) ProgramStageService(org.hisp.dhis.program.ProgramStageService) Grid(org.hisp.dhis.common.Grid) ProgramStage(org.hisp.dhis.program.ProgramStage) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DhisSpringTest(org.hisp.dhis.DhisSpringTest) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) PeriodType(org.hisp.dhis.period.PeriodType) ProgramService(org.hisp.dhis.program.ProgramService) EventDataQueryRequest(org.hisp.dhis.common.EventDataQueryRequest) EventDataQueryRequest(org.hisp.dhis.common.EventDataQueryRequest) Period(org.hisp.dhis.period.Period) HashSet(java.util.HashSet) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 87 with Program

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() + "\""));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DhisConvenienceTest.createOrganisationUnit(org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) Program(org.hisp.dhis.program.Program) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) PostgreSQLStatementBuilder(org.hisp.dhis.jdbc.statementbuilder.PostgreSQLStatementBuilder) DefaultProgramIndicatorSubqueryBuilder(org.hisp.dhis.analytics.event.data.programindicator.DefaultProgramIndicatorSubqueryBuilder) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) Period(org.hisp.dhis.period.Period) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DhisConvenienceTest.createProgramIndicator(org.hisp.dhis.DhisConvenienceTest.createProgramIndicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.jupiter.api.Test)

Example 88 with Program

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;
}
Also used : Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 89 with Program

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;
}
Also used : Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 90 with Program

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);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DhisConvenienceTest.createOrganisationUnit(org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit) Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) IdScheme(org.hisp.dhis.common.IdScheme) Test(org.junit.jupiter.api.Test)

Aggregations

Program (org.hisp.dhis.program.Program)344 Test (org.junit.jupiter.api.Test)160 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)123 ProgramStage (org.hisp.dhis.program.ProgramStage)109 ProgramInstance (org.hisp.dhis.program.ProgramInstance)79 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)68 Date (java.util.Date)47 Collectors (java.util.stream.Collectors)44 User (org.hisp.dhis.user.User)44 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)42 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)42 BeforeEach (org.junit.jupiter.api.BeforeEach)42 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)41 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)41 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)40 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)39 CategoryCombo (org.hisp.dhis.category.CategoryCombo)39 DataElement (org.hisp.dhis.dataelement.DataElement)39 Event (org.hisp.dhis.tracker.domain.Event)38 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)37