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