Search in sources :

Example 11 with DataElementCategoryCombo

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

the class AnalyticsDataSetReportStore method getAggregatedSubTotals.

@Override
public Map<String, Object> getAggregatedSubTotals(DataSet dataSet, Period period, OrganisationUnit unit, Set<String> dimensions) {
    Map<String, Object> dataMap = new HashMap<>();
    for (Section section : dataSet.getSections()) {
        List<DataElement> dataElements = new ArrayList<>(section.getDataElements());
        Set<DataElementCategory> categories = new HashSet<>();
        for (DataElementCategoryCombo categoryCombo : section.getCategoryCombos()) {
            categories.addAll(categoryCombo.getCategories());
        }
        FilterUtils.filter(dataElements, AggregatableDataElementFilter.INSTANCE);
        if (dataElements.isEmpty() || categories == null || categories.isEmpty()) {
            continue;
        }
        for (DataElementCategory category : categories) {
            if (category.isDefault()) {
                // No need for sub-total for default
                continue;
            }
            if (!category.isDataDimension()) {
                log.warn("Could not get sub-total for category: " + category.getUid() + " for data set report: " + dataSet + ", not a data dimension");
                continue;
            }
            DataQueryParams.Builder params = DataQueryParams.newBuilder().withDataElements(dataElements).withPeriod(period).withOrganisationUnit(unit).withCategory(category);
            if (dimensions != null) {
                params.addFilters(dataQueryService.getDimensionalObjects(dimensions, null, null, null, false, IdScheme.UID));
            }
            Map<String, Object> map = analyticsService.getAggregatedDataValueMapping(params.build());
            for (Entry<String, Object> entry : map.entrySet()) {
                String[] split = entry.getKey().split(SEPARATOR);
                dataMap.put(split[0] + SEPARATOR + split[3], entry.getValue());
            }
        }
    }
    return dataMap;
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Section(org.hisp.dhis.dataset.Section) DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) HashSet(java.util.HashSet)

Example 12 with DataElementCategoryCombo

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

the class AnalyticsUtilsTest method testGetByDataDimensionType.

@Test
public void testGetByDataDimensionType() {
    Program prA = createProgram('A');
    DataElement deA = createDataElement('A', new DataElementCategoryCombo());
    DataElement deB = createDataElement('B', new DataElementCategoryCombo());
    ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
    ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
    ProgramIndicator piA = createProgramIndicator('A', prA, null, null);
    List<DimensionalItemObject> list = Lists.newArrayList(deA, deB, pdeA, pdeB, piA);
    assertEquals(Lists.newArrayList(deA, deB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(pdeA, pdeB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(piA), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_INDICATOR, list));
    assertEquals(Lists.newArrayList(), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_ATTRIBUTE, list));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 13 with DataElementCategoryCombo

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

the class ReportTableTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    dataElements = new ArrayList<>();
    categoryOptionCombos = new ArrayList<>();
    indicators = new ArrayList<>();
    reportingRates = new ArrayList<>();
    periods = new ArrayList<>();
    units = new ArrayList<>();
    relativeUnits = new ArrayList<>();
    groups = new ArrayList<>();
    montlyPeriodType = PeriodType.getPeriodTypeByName(MonthlyPeriodType.NAME);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementA.setId('A');
    dataElementB.setId('B');
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    deGroupSetA = createDataElementGroupSet('A');
    deGroupA = createDataElementGroup('A');
    deGroupB = createDataElementGroup('B');
    deGroupA.getGroupSets().add(deGroupSetA);
    deGroupB.getGroupSets().add(deGroupSetA);
    deGroupSetA.getMembers().add(deGroupA);
    deGroupSetA.getMembers().add(deGroupB);
    categoryOptionComboA = createCategoryOptionCombo('A', 'A', 'B');
    categoryOptionComboB = createCategoryOptionCombo('B', 'C', 'D');
    categoryOptionComboA.setId('A');
    categoryOptionComboB.setId('B');
    categoryOptionCombos.add(categoryOptionComboA);
    categoryOptionCombos.add(categoryOptionComboB);
    categoryCombo = new DataElementCategoryCombo("CategoryComboA", DataDimensionType.DISAGGREGATION);
    categoryCombo.setId('A');
    categoryCombo.setOptionCombos(new HashSet<>(categoryOptionCombos));
    indicatorType = createIndicatorType('A');
    indicatorA = createIndicator('A', indicatorType);
    indicatorB = createIndicator('B', indicatorType);
    indicatorA.setId('A');
    indicatorB.setId('B');
    indicators.add(indicatorA);
    indicators.add(indicatorB);
    DataSet dataSetA = createDataSet('A', montlyPeriodType);
    DataSet dataSetB = createDataSet('B', montlyPeriodType);
    dataSetA.setId('A');
    dataSetB.setId('B');
    reportingRateA = new ReportingRate(dataSetA);
    reportingRateB = new ReportingRate(dataSetB);
    reportingRates.add(reportingRateA);
    reportingRates.add(reportingRateB);
    periodA = createPeriod(montlyPeriodType, getDate(2008, 1, 1), getDate(2008, 1, 31));
    periodB = createPeriod(montlyPeriodType, getDate(2008, 2, 1), getDate(2008, 2, 28));
    periodA.setId('A');
    periodB.setId('B');
    periods.add(periodA);
    periods.add(periodB);
    relatives = new RelativePeriods();
    relatives.setLastMonth(true);
    relatives.setThisYear(true);
    List<Period> rp = relatives.getRelativePeriods();
    periodC = rp.get(0);
    periodD = rp.get(1);
    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B', unitA);
    unitC = createOrganisationUnit('C', unitA);
    unitA.setId('A');
    unitB.setId('B');
    unitC.setId('C');
    unitA.getChildren().add(unitB);
    unitA.getChildren().add(unitC);
    units.add(unitA);
    units.add(unitB);
    relativeUnits.add(unitA);
    ouGroupSetA = createOrganisationUnitGroupSet('A');
    ouGroupA = createOrganisationUnitGroup('A');
    ouGroupB = createOrganisationUnitGroup('B');
    ouGroupA.getGroupSets().add(ouGroupSetA);
    ouGroupB.getGroupSets().add(ouGroupSetA);
    ouGroupA.setId('A');
    ouGroupB.setId('B');
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupA);
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupB);
    groups.add(ouGroupA);
    groups.add(ouGroupB);
    i18nFormat = new MockI18nFormat();
}
Also used : MockI18nFormat(org.hisp.dhis.mock.MockI18nFormat) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) RelativePeriods(org.hisp.dhis.period.RelativePeriods) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) Period(org.hisp.dhis.period.Period)

Example 14 with DataElementCategoryCombo

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

the class DefaultAdxDataService method parseADXDataValueToDxf.

private void parseADXDataValueToDxf(XMLReader adxReader, XMLStreamWriter dxfWriter, Map<String, String> groupAttributes, ImportOptions importOptions, CachingMap<String, DataElement> dataElementMap, IdentifiableObjectCallable<DataElement> dataElementCallable) throws XMLStreamException, AdxException {
    Map<String, String> dvAttributes = adxReader.readAttributes();
    log.debug("Processing data value: " + dvAttributes);
    if (!dvAttributes.containsKey(AdxDataService.DATAELEMENT)) {
        throw new AdxException(AdxDataService.DATAELEMENT + " attribute is required on 'dataValue'");
    }
    if (!dvAttributes.containsKey(AdxDataService.VALUE)) {
        throw new AdxException(AdxDataService.VALUE + " attribute is required on 'dataValue'");
    }
    IdentifiableProperty dataElementIdScheme = importOptions.getIdSchemes().getDataElementIdScheme().getIdentifiableProperty();
    String dataElementStr = trimToNull(dvAttributes.get(AdxDataService.DATAELEMENT));
    final DataElement dataElement = dataElementMap.get(dataElementStr, dataElementCallable.setId(dataElementStr));
    if (dataElement == null) {
        throw new AdxException(dvAttributes.get(AdxDataService.DATAELEMENT), "No matching dataElement");
    }
    // process ADX data value attributes
    if (!dvAttributes.containsKey(AdxDataService.CATOPTCOMBO)) {
        log.debug("No category option combo present");
        //TODO expand to allow for category combos part of DataSetElements.
        DataElementCategoryCombo categoryCombo = dataElement.getDataElementCategoryCombo();
        convertAttributesToDxf(dvAttributes, AdxDataService.CATOPTCOMBO, categoryCombo, dataElementIdScheme);
    }
    // 'annotation' element
    if (!dataElement.getValueType().isNumeric()) {
        adxReader.moveToStartElement(AdxDataService.ANNOTATION, AdxDataService.DATAVALUE);
        if (adxReader.isStartElement(AdxDataService.ANNOTATION)) {
            String textValue = adxReader.getElementValue();
            dvAttributes.put(AdxDataService.VALUE, textValue);
        } else {
            throw new AdxException(dvAttributes.get(AdxDataService.DATAELEMENT), "DataElement expects text annotation");
        }
    }
    log.debug("Processing data value as DXF: " + dvAttributes);
    dxfWriter.writeStartElement("dataValue");
    // write the group attributes through to DXF stream
    for (String attribute : groupAttributes.keySet()) {
        dxfWriter.writeAttribute(attribute, groupAttributes.get(attribute));
    }
    // pass through the remaining attributes to DXF
    for (String attribute : dvAttributes.keySet()) {
        dxfWriter.writeAttribute(attribute, dvAttributes.get(attribute));
    }
    // dataValue
    dxfWriter.writeEndElement();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) IdentifiableProperty(org.hisp.dhis.common.IdentifiableProperty)

Example 15 with DataElementCategoryCombo

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

the class ObjectUtilsTest method testGetAll.

@Test
public void testGetAll() {
    DataElementCategory ctA = new DataElementCategory("CategoryA", DataDimensionType.DISAGGREGATION);
    DataElementCategory ctB = new DataElementCategory("CategoryB", DataDimensionType.DISAGGREGATION);
    DataElementCategory ctC = new DataElementCategory("CategoryC", DataDimensionType.DISAGGREGATION);
    DataElementCategory ctD = new DataElementCategory("CategoryD", DataDimensionType.DISAGGREGATION);
    DataElementCategoryCombo ccA = new DataElementCategoryCombo("CategoryComboA", DataDimensionType.DISAGGREGATION);
    DataElementCategoryCombo ccB = new DataElementCategoryCombo("CategoryComboB", DataDimensionType.DISAGGREGATION);
    ccA.addDataElementCategory(ctA);
    ccA.addDataElementCategory(ctB);
    ccB.addDataElementCategory(ctC);
    ccB.addDataElementCategory(ctD);
    List<DataElementCategoryCombo> ccs = Lists.newArrayList(ccA, ccB);
    Set<DataElementCategory> cts = ObjectUtils.getAll(ccs, cc -> cc.getCategories());
    assertEquals(4, cts.size());
    assertTrue(cts.contains(ctA));
    assertTrue(cts.contains(ctB));
    assertTrue(cts.contains(ctC));
    assertTrue(cts.contains(ctD));
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Test(org.junit.Test)

Aggregations

DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)32 DataElement (org.hisp.dhis.dataelement.DataElement)14 DataSet (org.hisp.dhis.dataset.DataSet)12 ArrayList (java.util.ArrayList)11 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)10 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)8 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)8 Section (org.hisp.dhis.dataset.Section)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)5 List (java.util.List)4 Map (java.util.Map)4 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)3 SectionOrderComparator (org.hisp.dhis.dataset.comparator.SectionOrderComparator)3 OptionSet (org.hisp.dhis.option.OptionSet)3 Period (org.hisp.dhis.period.Period)3 Program (org.hisp.dhis.program.Program)3