Search in sources :

Example 11 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator 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)

Example 12 with ProgramIndicator

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

the class AddProgramStageSectionAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    ProgramStage programStage = programStageService.getProgramStage(programStageId);
    // ---------------------------------------------------------------------
    // Section
    // ---------------------------------------------------------------------
    List<DataElement> dataElements = new ArrayList<>();
    for (Integer id : dataElementIds) {
        dataElements.add(dataElementService.getDataElement(id));
    }
    ProgramStageSection programStageSection = new ProgramStageSection(StringUtils.trimToNull(name), dataElements, programStage.getProgramStageSections().size());
    programStageSection.setAutoFields();
    // ---------------------------------------------------------------------
    // Program indicators
    // ---------------------------------------------------------------------
    List<ProgramIndicator> programIndicators = new ArrayList<>();
    for (Integer id : selectedIndicators) {
        ProgramIndicator indicator = programIndicatorService.getProgramIndicator(id);
        programIndicators.add(indicator);
    }
    programStageSection.setProgramIndicators(programIndicators);
    programStageSection.setProgramStage(programStage);
    // ---------------------------------------------------------------------
    // Update program stage
    // ---------------------------------------------------------------------
    Set<ProgramStageSection> sections = programStage.getProgramStageSections();
    sections.add(programStageSection);
    programStage.setProgramStageSections(sections);
    programStageService.updateProgramStage(programStage);
    return SUCCESS;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) ArrayList(java.util.ArrayList) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 13 with ProgramIndicator

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

the class UpdateProgramStageSectionAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    // ---------------------------------------------------------------------
    // Section
    // ---------------------------------------------------------------------
    ProgramStageSection section = programStageSectionService.getProgramStageSection(id);
    section.setName(StringUtils.trimToNull(name));
    List<DataElement> dataElements = new ArrayList<>();
    for (Integer id : dataElementIds) {
        dataElements.add(dataElementService.getDataElement(id));
    }
    section.setDataElements(dataElements);
    // ---------------------------------------------------------------------
    // Program indicators
    // ---------------------------------------------------------------------
    List<ProgramIndicator> programIndicators = new ArrayList<>();
    for (Integer id : selectedIndicators) {
        ProgramIndicator indicator = programIndicatorService.getProgramIndicator(id);
        programIndicators.add(indicator);
    }
    section.setProgramIndicators(programIndicators);
    programStageSectionService.updateProgramStageSection(section);
    return SUCCESS;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Aggregations

ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)13 DataElement (org.hisp.dhis.dataelement.DataElement)6 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)5 ArrayList (java.util.ArrayList)3 ProgramDataElementDimensionItem (org.hisp.dhis.program.ProgramDataElementDimensionItem)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 QueryItem (org.hisp.dhis.common.QueryItem)2 Program (org.hisp.dhis.program.Program)2 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)2 ProgramTrackedEntityAttributeDimensionItem (org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashMap (java.util.HashMap)1 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)1 DimensionType (org.hisp.dhis.common.DimensionType)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 MapMap (org.hisp.dhis.common.MapMap)1 SetMap (org.hisp.dhis.common.SetMap)1