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