Search in sources :

Example 1 with BaseDimensionalItemObject

use of org.hisp.dhis.common.BaseDimensionalItemObject in project dhis2-core by dhis2.

the class DataDimensionExtractor method getBaseDimensionalItemObject.

private BaseDimensionalItemObject getBaseDimensionalItemObject(final MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> atomicObjects, final DimensionalItemId id) {
    BaseDimensionalItemObject dimensionalItemObject = null;
    switch(id.getDimensionItemType()) {
        case DATA_ELEMENT:
            DataElement dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            if (dataElement != null) {
                dimensionalItemObject = cloneIfNeeded(dataElement, id);
            }
            break;
        case INDICATOR:
            final Indicator indicator = (Indicator) atomicObjects.getValue(Indicator.class, id.getId0());
            if (indicator != null) {
                dimensionalItemObject = cloneIfNeeded(indicator, id);
            }
            break;
        case DATA_ELEMENT_OPERAND:
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            final CategoryOptionCombo categoryOptionCombo = id.getId1() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId1());
            final CategoryOptionCombo attributeOptionCombo = id.getId2() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId2());
            if (dataElement != null && (id.getId1() != null) == (categoryOptionCombo != null) && (id.getId2() != null) == (attributeOptionCombo != null)) {
                dimensionalItemObject = new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
            }
            break;
        case REPORTING_RATE:
            final DataSet dataSet = (DataSet) atomicObjects.getValue(DataSet.class, id.getId0());
            if (dataSet != null) {
                dimensionalItemObject = new ReportingRate(dataSet, ReportingRateMetric.valueOf(id.getId1()));
            }
            break;
        case PROGRAM_DATA_ELEMENT:
            Program program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId1());
            if (program != null && dataElement != null) {
                dimensionalItemObject = new ProgramDataElementDimensionItem(program, dataElement);
            }
            break;
        case PROGRAM_ATTRIBUTE:
            program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            final TrackedEntityAttribute attribute = (TrackedEntityAttribute) atomicObjects.getValue(TrackedEntityAttribute.class, id.getId1());
            if (program != null && attribute != null) {
                dimensionalItemObject = new ProgramTrackedEntityAttributeDimensionItem(program, attribute);
            }
            break;
        case PROGRAM_INDICATOR:
            final ProgramIndicator programIndicator = (ProgramIndicator) atomicObjects.getValue(ProgramIndicator.class, id.getId0());
            if (programIndicator != null) {
                dimensionalItemObject = cloneIfNeeded(programIndicator, id);
            }
            break;
        default:
            log.warn("Unrecognized DimensionItemType " + id.getDimensionItemType().name() + " in getItemObjectMap");
            break;
    }
    return dimensionalItemObject;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject)

Example 2 with BaseDimensionalItemObject

use of org.hisp.dhis.common.BaseDimensionalItemObject 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)"));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) RepeatableStageParams(org.hisp.dhis.common.RepeatableStageParams) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 3 with BaseDimensionalItemObject

use of org.hisp.dhis.common.BaseDimensionalItemObject in project dhis2-core by dhis2.

the class EnrollmentAnalyticsManagerTest method verifyGetCoordinateColumnWithNoProgram.

@Test
void verifyGetCoordinateColumnWithNoProgram() {
    // Given
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    QueryItem item = new QueryItem(dio);
    item.setValueType(ValueType.COORDINATE);
    item.setProgramStage(programStage);
    // When
    String columnSql = subject.getCoordinateColumn(item);
    // Then
    assertThat(columnSql, is(EMPTY));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 4 with BaseDimensionalItemObject

use of org.hisp.dhis.common.BaseDimensionalItemObject in project dhis2-core by dhis2.

the class EventAnalyticsTest method createRequestParams.

protected EventQueryParams createRequestParams(ProgramStage withProgramStage, ValueType withQueryItemValueType) {
    EventQueryParams.Builder params = new EventQueryParams.Builder(_createRequestParams());
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    params.withProgram(programA);
    if (withProgramStage != null) {
        params.withProgramStage(programStage);
    }
    if (withQueryItemValueType != null) {
        QueryItem queryItem = new QueryItem(dio);
        if (withProgramStage != null) {
            queryItem.setProgramStage(programStage);
        }
        queryItem.setProgram(programA);
        queryItem.setValueType(withQueryItemValueType);
        params.addItem(queryItem);
    }
    return params.build();
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject)

Example 5 with BaseDimensionalItemObject

use of org.hisp.dhis.common.BaseDimensionalItemObject in project dhis2-core by dhis2.

the class AbstractJdbcEventAnalyticsManagerTest method verifyGetSelectSqlWithNonTextDataElement.

@Test
void verifyGetSelectSqlWithNonTextDataElement() {
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    QueryItem item = new QueryItem(dio);
    item.setValueType(ValueType.NUMBER);
    String column = subject.getSelectSql(new QueryFilter(), item, from, to);
    assertThat(column, is("ax.\"" + dataElementA.getUid() + "\""));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) QueryFilter(org.hisp.dhis.common.QueryFilter) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) Test(org.junit.jupiter.api.Test)

Aggregations

BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)21 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)17 Test (org.junit.jupiter.api.Test)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 QueryItem (org.hisp.dhis.common.QueryItem)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)3 QueryFilter (org.hisp.dhis.common.QueryFilter)3 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)2 RepeatableStageParams (org.hisp.dhis.common.RepeatableStageParams)2 ReportingRate (org.hisp.dhis.common.ReportingRate)2 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)2 ProgramDataElementDimensionItem (org.hisp.dhis.program.ProgramDataElementDimensionItem)2 ProgramTrackedEntityAttributeDimensionItem (org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 DimensionResponse (org.hisp.dhis.analytics.dimension.DimensionResponse)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 ValueTypedDimensionalItemObject (org.hisp.dhis.common.ValueTypedDimensionalItemObject)1 DataElement (org.hisp.dhis.dataelement.DataElement)1