Search in sources :

Example 61 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class DimensionalObjectUtilsTest method testGetDataElementOperandIdSchemeCodeMap.

@Test
void testGetDataElementOperandIdSchemeCodeMap() {
    DataElement deA = new DataElement("NameA");
    DataElement deB = new DataElement("NameB");
    deA.setUid("D123456789A");
    deB.setUid("D123456789B");
    deA.setCode("DCodeA");
    deB.setCode("DCodeB");
    CategoryOptionCombo ocA = new CategoryOptionCombo();
    ocA.setUid("C123456789A");
    ocA.setCode("CCodeA");
    DataElementOperand opA = new DataElementOperand(deA, ocA);
    DataElementOperand opB = new DataElementOperand(deB, ocA);
    List<DataElementOperand> operands = Lists.newArrayList(opA, opB);
    Map<String, String> map = DimensionalObjectUtils.getDataElementOperandIdSchemeMap(operands, IdScheme.CODE);
    assertEquals(3, map.size());
    assertEquals("DCodeA", map.get("D123456789A"));
    assertEquals("DCodeB", map.get("D123456789B"));
    assertEquals("CCodeA", map.get("C123456789A"));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 62 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class DataHandler method addDataElementOperandValues.

/**
 * Adds data element operand values to the given grid.
 *
 * @param params the {@link DataQueryParams}.
 * @param grid the grid.
 * @param totalType the operand {@link TotalType}.
 */
private void addDataElementOperandValues(DataQueryParams params, Grid grid, TotalType totalType) {
    List<DataElementOperand> operands = asTypedList(params.getDataElementOperands());
    operands = operands.stream().filter(o -> totalType.equals(o.getTotalType())).collect(Collectors.toList());
    if (operands.isEmpty()) {
        return;
    }
    List<DimensionalItemObject> dataElements = newArrayList(getDataElements(operands));
    List<DimensionalItemObject> categoryOptionCombos = newArrayList(getCategoryOptionCombos(operands));
    List<DimensionalItemObject> attributeOptionCombos = newArrayList(getAttributeOptionCombos(operands));
    // TODO Check if data was dim or filter
    DataQueryParams.Builder builder = newBuilder(params).removeDimension(DATA_X_DIM_ID).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DATA_X, dataElements));
    if (totalType.isCategoryOptionCombo()) {
        builder.addDimension(new BaseDimensionalObject(CATEGORYOPTIONCOMBO_DIM_ID, CATEGORY_OPTION_COMBO, categoryOptionCombos));
    }
    if (totalType.isAttributeOptionCombo()) {
        builder.addDimension(new BaseDimensionalObject(ATTRIBUTEOPTIONCOMBO_DIM_ID, ATTRIBUTE_OPTION_COMBO, attributeOptionCombos));
    }
    DataQueryParams operandParams = builder.build();
    Map<String, Object> aggregatedDataMap = getAggregatedDataValueMapObjectTyped(operandParams);
    aggregatedDataMap = convertDxToOperand(aggregatedDataMap, totalType);
    for (Map.Entry<String, Object> entry : aggregatedDataMap.entrySet()) {
        Object value = getRoundedValueObject(operandParams, entry.getValue());
        grid.addRow().addValues(entry.getKey().split(DIMENSION_SEP)).addValue(value);
        if (params.isIncludeNumDen()) {
            grid.addNullValues(NUMERATOR_DENOMINATOR_PROPERTIES_COUNT);
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) EventQueryParams.fromDataQueryParams(org.hisp.dhis.analytics.event.EventQueryParams.fromDataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) AnalyticsUtils.getRoundedValueObject(org.hisp.dhis.analytics.util.AnalyticsUtils.getRoundedValueObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) PeriodType.getPeriodTypeFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString) Map(java.util.Map) DataQueryParams.getPermutationDimensionalItemValueMap(org.hisp.dhis.analytics.DataQueryParams.getPermutationDimensionalItemValueMap) DataQueryParams.getPermutationOrgUnitGroupCountMap(org.hisp.dhis.analytics.DataQueryParams.getPermutationOrgUnitGroupCountMap) MultiValuedMap(org.apache.commons.collections4.MultiValuedMap) AnalyticsUtils.getDoubleMap(org.hisp.dhis.analytics.util.AnalyticsUtils.getDoubleMap) DimensionalObjectUtils.convertToDimItemValueMap(org.hisp.dhis.common.DimensionalObjectUtils.convertToDimItemValueMap) HashMap(java.util.HashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap)

Example 63 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class DataQueryServiceTest method testGetDimensionOperand.

@Test
void testGetDimensionOperand() {
    DataElementOperand opA = new DataElementOperand(deA, cocA);
    DataElementOperand opB = new DataElementOperand(deB, cocA);
    DataElementOperand opC = new DataElementOperand(deC, cocA);
    List<DimensionalItemObject> items = Lists.newArrayList(opA, opB, opC);
    List<String> itemUids = DimensionalObjectUtils.getDimensionalItemIds(items);
    DimensionalObject actual = dataQueryService.getDimension(DimensionalObject.DATA_X_DIM_ID, itemUids, null, null, null, false, false, IdScheme.UID);
    assertEquals(DimensionalObject.DATA_X_DIM_ID, actual.getDimension());
    assertEquals(DimensionType.DATA_X, actual.getDimensionType());
    assertEquals(DataQueryParams.DISPLAY_NAME_DATA_X, actual.getDimensionDisplayName());
    assertEquals(items, actual.getItems());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 64 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToNameForDataValueSet.

@Test
void testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToNameForDataValueSet() {
    // Given
    final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
    final OrganisationUnit orUnitStub = stubOrgUnit();
    final Period periodStub = stubPeriod();
    final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub, DATA_VALUE_SET);
    theDataQueryParams.setOutputOrgUnitIdScheme(NAME);
    // When
    final Map<String, String> responseMap = schemaIdResponseMapper.getSchemeIdResponseMap(theDataQueryParams);
    // Then
    final String orgUnitUid = orUnitStub.getUid();
    final String periodIsoDate = periodStub.getIsoDate();
    final DataElement dataElementA = dataElementOperandsStub.get(0).getDataElement();
    final DataElement dataElementB = dataElementOperandsStub.get(1).getDataElement();
    final CategoryOptionCombo categoryOptionComboC = dataElementOperandsStub.get(0).getCategoryOptionCombo();
    assertThat(responseMap.get(orgUnitUid), is(equalTo(orUnitStub.getName())));
    assertThat(responseMap.get(periodIsoDate), is(equalTo(periodStub.getUid())));
    assertThat(responseMap.get(dataElementA.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(dataElementB.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) Period(org.hisp.dhis.period.Period) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) PeriodType.getPeriodFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodFromIsoString) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 65 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputDataElementIdSchemeOverridesOutputOrgUnitIdSchemeForDataValueSet.

@Test
void testGetSchemeIdResponseMapWhenOutputDataElementIdSchemeOverridesOutputOrgUnitIdSchemeForDataValueSet() {
    // Given
    final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
    final OrganisationUnit orUnitStub = stubOrgUnit();
    final Period periodStub = stubPeriod();
    final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub, DATA_VALUE_SET);
    theDataQueryParams.setOutputIdScheme(NAME);
    // Overriding output id schema and setting CODE for Data
    // Element/Operands
    theDataQueryParams.setOutputDataElementIdScheme(CODE);
    // When
    final Map<String, String> responseMap = schemaIdResponseMapper.getSchemeIdResponseMap(theDataQueryParams);
    // Then
    final String orgUnitUid = orUnitStub.getUid();
    final String periodIsoDate = periodStub.getIsoDate();
    final DataElement dataElementA = dataElementOperandsStub.get(0).getDataElement();
    final DataElement dataElementB = dataElementOperandsStub.get(1).getDataElement();
    final CategoryOptionCombo categoryOptionComboC = dataElementOperandsStub.get(0).getCategoryOptionCombo();
    assertThat(responseMap.get(orgUnitUid), is(equalTo(orUnitStub.getName())));
    assertThat(responseMap.get(periodIsoDate), is(equalTo(periodStub.getName())));
    assertThat(responseMap.get(dataElementA.getUid()), is(equalTo(dataElementA.getCode())));
    assertThat(responseMap.get(dataElementB.getUid()), is(equalTo(dataElementB.getCode())));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(equalTo(categoryOptionComboC.getCode())));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(equalTo(categoryOptionComboC.getCode())));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) Period(org.hisp.dhis.period.Period) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) PeriodType.getPeriodFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodFromIsoString) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Aggregations

DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)75 DataElement (org.hisp.dhis.dataelement.DataElement)36 Test (org.junit.jupiter.api.Test)30 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)25 Period (org.hisp.dhis.period.Period)24 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)23 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)19 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)17 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)14 PeriodType.getPeriodFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodFromIsoString)14 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)13 Indicator (org.hisp.dhis.indicator.Indicator)11 HashMap (java.util.HashMap)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)10 IndicatorType (org.hisp.dhis.indicator.IndicatorType)10 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)9 DataSet (org.hisp.dhis.dataset.DataSet)9 ArrayList (java.util.ArrayList)8 DataValue (org.hisp.dhis.datavalue.DataValue)8 List (java.util.List)7