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;
}
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));
}
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();
}
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();
}
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));
}
Aggregations