Search in sources :

Example 1 with DataSetElement

use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.

the class DefaultDataElementCategoryService method getOperands.

@Override
public List<DataElementOperand> getOperands(DataSet dataSet, boolean includeTotals) {
    List<DataElementOperand> operands = Lists.newArrayList();
    for (DataSetElement element : dataSet.getDataSetElements()) {
        DataElementCategoryCombo categoryCombo = element.getResolvedCategoryCombo();
        if (includeTotals && !categoryCombo.isDefault()) {
            operands.add(new DataElementOperand(element.getDataElement()));
        }
        operands.addAll(getOperands(element.getDataElement(), element.getResolvedCategoryCombo()));
    }
    return operands;
}
Also used : DataSetElement(org.hisp.dhis.dataset.DataSetElement)

Example 2 with DataSetElement

use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.

the class PreheatServiceTest method testPreheatWithDataSetElements.

@Test
void testPreheatWithDataSetElements() {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = new HashMap<>();
    DataElement de1 = createDataElement('A');
    DataElement de2 = createDataElement('B');
    DataElement de3 = createDataElement('C');
    manager.save(de1);
    manager.save(de2);
    manager.save(de3);
    DataSet dataSet = createDataSet('A');
    dataSet.setAutoFields();
    dataSet.getDataSetElements().add(new DataSetElement(dataSet, de1));
    dataSet.getDataSetElements().add(new DataSetElement(dataSet, de2));
    dataSet.getDataSetElements().add(new DataSetElement(dataSet, de3));
    metadata.put(DataSet.class, new ArrayList<>());
    metadata.get(DataSet.class).add(dataSet);
    PreheatParams params = new PreheatParams();
    params.setPreheatIdentifier(PreheatIdentifier.UID);
    params.setPreheatMode(PreheatMode.REFERENCE);
    params.setObjects(metadata);
    preheatService.validate(params);
    Preheat preheat = preheatService.preheat(params);
    assertEquals(3, preheat.getIdentifierKeyCount(PreheatIdentifier.UID, DataElement.class));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) HashMap(java.util.HashMap) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) List(java.util.List) DataSetElement(org.hisp.dhis.dataset.DataSetElement) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with DataSetElement

use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.

the class DefaultCategoryService method getOperands.

@Override
@Transactional(readOnly = true)
public List<DataElementOperand> getOperands(DataSet dataSet, boolean includeTotals) {
    List<DataElementOperand> operands = Lists.newArrayList();
    for (DataSetElement element : dataSet.getDataSetElements()) {
        CategoryCombo categoryCombo = element.getResolvedCategoryCombo();
        if (includeTotals && !categoryCombo.isDefault()) {
            operands.add(new DataElementOperand(element.getDataElement()));
        }
        operands.addAll(getOperands(element.getDataElement(), element.getResolvedCategoryCombo()));
    }
    return operands;
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSetElement(org.hisp.dhis.dataset.DataSetElement) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DataSetElement

use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.

the class DataElementDeletionHandler method deleteDataSet.

private void deleteDataSet(DataSet dataSet) {
    Iterator<DataSetElement> elements = dataSet.getDataSetElements().iterator();
    while (elements.hasNext()) {
        DataSetElement element = elements.next();
        elements.remove();
        dataSet.removeDataSetElement(element);
        idObjectManager.updateNoAcl(element.getDataElement());
    }
}
Also used : DataSetElement(org.hisp.dhis.dataset.DataSetElement)

Example 5 with DataSetElement

use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.

the class DefaultDataSetReportService method getDefaultDataSetReport.

private List<Grid> getDefaultDataSetReport(DataSet dataSet, List<Period> periods, OrganisationUnit unit, Set<String> filters, boolean selectedUnitOnly) {
    ListMap<CategoryCombo, DataElement> map = new ListMap<>();
    for (DataSetElement element : dataSet.getDataSetElements()) {
        map.putValue(element.getResolvedCategoryCombo(), element.getDataElement());
    }
    DataSet tmpDataSet = new DataSet(dataSet.getName(), dataSet.getShortName(), dataSet.getPeriodType());
    tmpDataSet.setDataSetElements(dataSet.getDataSetElements());
    for (CategoryCombo categoryCombo : map.keySet()) {
        List<DataElement> dataElements = map.get(categoryCombo);
        String name = categoryCombo.isDefault() ? dataSet.getName() : categoryCombo.getName();
        Section section = new Section(name, dataSet, dataElements, null);
        tmpDataSet.getSections().add(section);
    }
    return getSectionDataSetReport(tmpDataSet, periods, unit, filters, selectedUnitOnly);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataSetElement(org.hisp.dhis.dataset.DataSetElement) Section(org.hisp.dhis.dataset.Section) ListMap(org.hisp.dhis.common.ListMap)

Aggregations

DataSetElement (org.hisp.dhis.dataset.DataSetElement)9 DataSet (org.hisp.dhis.dataset.DataSet)5 CategoryCombo (org.hisp.dhis.category.CategoryCombo)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 List (java.util.List)2 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 ListMap (org.hisp.dhis.common.ListMap)2 Section (org.hisp.dhis.dataset.Section)2 Test (org.junit.jupiter.api.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)1 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)1 RootNode (org.hisp.dhis.node.types.RootNode)1