Search in sources :

Example 11 with ProgramDataElementDimensionItem

use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.

the class ProgramDataElementController method getObjectList.

@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams) throws QueryParserException {
    Schema schema = schemaService.getDynamicSchema(ProgramDataElementDimensionItem.class);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<Order> orders = orderParams.getOrders(schema);
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    List<ProgramDataElementDimensionItem> programDataElements;
    Query query = queryService.getQueryFromUrl(ProgramDataElementDimensionItem.class, filters, orders, options.getRootJunction());
    query.setDefaultOrder();
    if (options.contains("program")) {
        String programUid = options.get("program");
        programDataElements = programService.getGeneratedProgramDataElements(programUid);
        query.setObjects(programDataElements);
    }
    programDataElements = (List<ProgramDataElementDimensionItem>) queryService.query(query);
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        pager = new Pager(options.getPage(), programDataElements.size(), options.getPageSize());
        programDataElements = PagerUtils.pageCollection(programDataElements, pager);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    rootNode.addChild(fieldFilterService.filter(ProgramDataElementDimensionItem.class, programDataElements, fields));
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) RootNode(org.hisp.dhis.node.types.RootNode) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) Query(org.hisp.dhis.query.Query) Schema(org.hisp.dhis.schema.Schema) Pager(org.hisp.dhis.common.Pager) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with ProgramDataElementDimensionItem

use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.

the class DhisConvenienceTest method createProgramDataElement.

protected ProgramDataElementDimensionItem createProgramDataElement(char name) {
    Program pr = new Program();
    pr.setUid("P123456789" + name);
    pr.setCode("PCode" + name);
    DataElement de = new DataElement("Name" + name);
    de.setUid("D123456789" + name);
    de.setCode("DCode" + name);
    return new ProgramDataElementDimensionItem(pr, de);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem)

Example 13 with ProgramDataElementDimensionItem

use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.

the class QueryPlannerTest method setUpTest.

@Override
public void setUpTest() {
    PeriodType pt = new MonthlyPeriodType();
    itA = createIndicatorType('A');
    idObjectManager.save(itA);
    inA = createIndicator('A', itA);
    inB = createIndicator('B', itA);
    idObjectManager.save(inA);
    idObjectManager.save(inB);
    prA = createProgram('A');
    idObjectManager.save(prA);
    deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM);
    deB = createDataElement('B', ValueType.INTEGER, AggregationType.SUM);
    deC = createDataElement('C', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT);
    deD = createDataElement('D', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT);
    deE = createDataElement('E', ValueType.TEXT, AggregationType.NONE);
    deF = createDataElement('F', ValueType.TEXT, AggregationType.NONE);
    deG = createDataElement('G', ValueType.INTEGER, AggregationType.SUM);
    deH = createDataElement('H', ValueType.INTEGER, AggregationType.SUM);
    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    dataElementService.addDataElement(deC);
    dataElementService.addDataElement(deD);
    dataElementService.addDataElement(deE);
    dataElementService.addDataElement(deF);
    dataElementService.addDataElement(deG);
    dataElementService.addDataElement(deH);
    pdeA = new ProgramDataElementDimensionItem(prA, deA);
    pdeB = new ProgramDataElementDimensionItem(prA, deB);
    DataSet dsA = createDataSet('A', pt);
    DataSet dsB = createDataSet('B', pt);
    DataSet dsC = createDataSet('C', pt);
    DataSet dsD = createDataSet('D', pt);
    dataSetService.addDataSet(dsA);
    dataSetService.addDataSet(dsB);
    dataSetService.addDataSet(dsC);
    dataSetService.addDataSet(dsD);
    rrA = new ReportingRate(dsA);
    rrB = new ReportingRate(dsB);
    rrC = new ReportingRate(dsC);
    rrD = new ReportingRate(dsD);
    peA = PeriodType.getPeriodFromIsoString("201501");
    peB = PeriodType.getPeriodFromIsoString("201502");
    coc = categoryService.getDefaultDataElementCategoryOptionCombo();
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    ouC = createOrganisationUnit('C');
    ouD = createOrganisationUnit('D');
    ouE = createOrganisationUnit('E');
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    organisationUnitService.addOrganisationUnit(ouD);
    organisationUnitService.addOrganisationUnit(ouE);
    degA = createDataElementGroup('A');
    degA.addDataElement(deA);
    degA.addDataElement(deB);
    dataElementService.addDataElementGroup(degA);
    dgsA = createDataElementGroupSet('A');
    dgsA.getMembers().add(degA);
    dataElementService.addDataElementGroupSet(dgsA);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate)

Example 14 with ProgramDataElementDimensionItem

use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.

the class DefaultValidationService method getDimensionalItemObjects.

/**
     * Gets all required DimensionalItemObjects from their UIDs.
     *
     * @param expressionIdMap UIDs of DimensionalItemObjects to get.
     * @return map of the DimensionalItemObjects.
     */
private Map<String, DimensionalItemObject> getDimensionalItemObjects(SetMap<Class<? extends DimensionalItemObject>, String> expressionIdMap) {
    // 1. Get ids for all the individual IdentifiableObjects within the DimensionalItemObjects:
    SetMap<Class<? extends IdentifiableObject>, String> idsToGet = new SetMap<>();
    getIdentifiableObjectIds(idsToGet, expressionIdMap, DataElementOperand.class, DataElement.class, DataElementCategoryOptionCombo.class);
    getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramDataElementDimensionItem.class, Program.class, DataElement.class);
    getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramTrackedEntityAttributeDimensionItem.class, Program.class, TrackedEntityAttribute.class);
    getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramIndicator.class, ProgramIndicator.class);
    // 2. Look up all the IdentifiableObjects (each class all together, for best performance):
    MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> idMap = new MapMap<>();
    for (Map.Entry<Class<? extends IdentifiableObject>, Set<String>> e : idsToGet.entrySet()) {
        idMap.putEntries(e.getKey(), idObjectManager.get(e.getKey(), e.getValue()).stream().collect(Collectors.toMap(o -> o.getUid(), o -> o)));
    }
    // 3. Build the map of DimensionalItemObjects:
    Map<String, DimensionalItemObject> dimObjects = new HashMap<>();
    for (Map.Entry<Class<? extends DimensionalItemObject>, Set<String>> e : expressionIdMap.entrySet()) {
        for (String id : e.getValue()) {
            if (e.getKey() == DataElementOperand.class) {
                DataElementOperand deo = new DataElementOperand((DataElement) idMap.getValue(DataElement.class, getIdPart(id, 0)), (DataElementCategoryOptionCombo) idMap.getValue(DataElementCategoryOptionCombo.class, getIdPart(id, 1)));
                if (deo.getDataElement() != null && (deo.getCategoryOptionCombo() != null || getIdPart(id, 1) == null)) {
                    dimObjects.put(id, deo);
                }
            } else if (e.getKey() == ProgramDataElementDimensionItem.class) {
                ProgramDataElementDimensionItem pde = new ProgramDataElementDimensionItem((Program) idMap.getValue(Program.class, getIdPart(id, 0)), (DataElement) idMap.getValue(DataElement.class, getIdPart(id, 1)));
                if (pde.getProgram() != null && pde.getDataElement() != null) {
                    dimObjects.put(id, pde);
                }
            } else if (e.getKey() == ProgramTrackedEntityAttributeDimensionItem.class) {
                ProgramTrackedEntityAttributeDimensionItem pa = new ProgramTrackedEntityAttributeDimensionItem((Program) idMap.getValue(Program.class, getIdPart(id, 0)), (TrackedEntityAttribute) idMap.getValue(TrackedEntityAttribute.class, getIdPart(id, 1)));
                if (pa.getProgram() != null && pa.getAttribute() != null) {
                    dimObjects.put(id, pa);
                }
            } else if (e.getKey() == ProgramIndicator.class) {
                ProgramIndicator pi = (ProgramIndicator) idMap.getValue(ProgramIndicator.class, id);
                if (pi != null) {
                    dimObjects.put(id, pi);
                }
            }
        }
    }
    return dimObjects;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataSet(org.hisp.dhis.dataset.DataSet) ImmutableSet(com.google.common.collect.ImmutableSet) Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) MapMap(org.hisp.dhis.common.MapMap) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) SetMap(org.hisp.dhis.common.SetMap) SetMap(org.hisp.dhis.common.SetMap) MapMap(org.hisp.dhis.common.MapMap)

Aggregations

ProgramDataElementDimensionItem (org.hisp.dhis.program.ProgramDataElementDimensionItem)14 DataElement (org.hisp.dhis.dataelement.DataElement)8 Program (org.hisp.dhis.program.Program)6 ProgramTrackedEntityAttributeDimensionItem (org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)6 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)4 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)4 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)4 DataSet (org.hisp.dhis.dataset.DataSet)3 Test (org.junit.Test)3 ReportingRate (org.hisp.dhis.common.ReportingRate)2 Constant (org.hisp.dhis.constant.Constant)2 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)2 OptionSet (org.hisp.dhis.option.OptionSet)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Map (java.util.Map)1 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 Color (org.hisp.dhis.color.Color)1 ColorSet (org.hisp.dhis.color.ColorSet)1 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)1