use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class EventQueryPlannerTest method setUpTest.
@Override
public void setUpTest() {
prA = createProgram('A');
prA.setUid("programuida");
idObjectManager.save(prA);
deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
deB = createDataElement('B', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
deC = createDataElement('C', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT, DataElementDomain.TRACKER);
deD = createDataElement('D', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT, DataElementDomain.TRACKER);
idObjectManager.save(deA);
idObjectManager.save(deB);
idObjectManager.save(deC);
idObjectManager.save(deD);
pdeA = new ProgramDataElementDimensionItem(prA, deA);
pdeB = new ProgramDataElementDimensionItem(prA, deB);
pdeC = new ProgramDataElementDimensionItem(prA, deC);
pdeD = new ProgramDataElementDimensionItem(prA, deD);
atA = createTrackedEntityAttribute('A');
atB = createTrackedEntityAttribute('B');
idObjectManager.save(atA);
idObjectManager.save(atB);
patA = new ProgramTrackedEntityAttributeDimensionItem(prA, atA);
patB = new ProgramTrackedEntityAttributeDimensionItem(prA, atB);
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B', ouA);
ouC = createOrganisationUnit('C', ouA);
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
organisationUnitService.addOrganisationUnit(ouC);
lsA = createLegendSet('A');
idObjectManager.save(lsA);
osA = new OptionSet("OptionSetA", ValueType.TEXT);
idObjectManager.save(osA);
}
use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class DefaultDimensionService method getProgramDataElementDimensionItem.
/**
* Returns a {@link ProgramDataElementDimensionItem}.
*
* @param idScheme the identifier scheme.
* @param programId the program identifier.
* @param dataElementId the data element identifier.
*/
private ProgramDataElementDimensionItem getProgramDataElementDimensionItem(IdScheme idScheme, String programId, String dataElementId) {
Program program = idObjectManager.getObject(Program.class, idScheme, programId);
DataElement dataElement = idObjectManager.getObject(DataElement.class, idScheme, dataElementId);
if (program == null || dataElement == null) {
return null;
}
return new ProgramDataElementDimensionItem(program, dataElement);
}
use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class DefaultDimensionService method getDataDimensionalItemObject.
@Override
public DimensionalItemObject getDataDimensionalItemObject(IdScheme idScheme, String dimensionItem) {
if (DimensionalObjectUtils.isCompositeDimensionalObject(dimensionItem)) {
String id0 = splitSafe(dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 0);
String id1 = splitSafe(dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 1);
String id2 = splitSafe(dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 2);
DataElementOperand operand = null;
ReportingRate reportingRate = null;
ProgramDataElementDimensionItem programDataElement = null;
ProgramTrackedEntityAttributeDimensionItem programAttribute = null;
if ((operand = getDataElementOperand(idScheme, id0, id1, id2)) != null) {
return operand;
} else if ((reportingRate = getReportingRate(idScheme, id0, id1)) != null) {
return reportingRate;
} else if ((programDataElement = getProgramDataElementDimensionItem(idScheme, id0, id1)) != null) {
return programDataElement;
} else if ((programAttribute = getProgramAttributeDimensionItem(idScheme, id0, id1)) != null) {
return programAttribute;
}
} else if (!idScheme.is(IdentifiableProperty.UID) || CodeGenerator.isValidUid(dimensionItem)) {
DimensionalItemObject itemObject = idObjectManager.get(DataDimensionItem.DATA_DIMENSION_CLASSES, idScheme, dimensionItem);
if (itemObject != null) {
return itemObject;
}
}
return null;
}
use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class DimensionServiceTest method testGetDimensionalItemObject.
@Test
public void testGetDimensionalItemObject() {
String idA = deA.getUid();
String idB = prA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + deA.getUid();
String idC = prA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + atA.getUid();
String idD = dsA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + ReportingRateMetric.REPORTING_RATE.name();
String idE = dsA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + "UNKNOWN_METRIC";
String idF = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
String idG = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD;
String idH = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + "UNKNOWN_SYMBOL";
String idI = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
String idJ = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD;
String idK = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
ProgramTrackedEntityAttributeDimensionItem ptaA = new ProgramTrackedEntityAttributeDimensionItem(prA, atA);
ReportingRate rrA = new ReportingRate(dsA, ReportingRateMetric.REPORTING_RATE);
DataElementOperand deoA = new DataElementOperand(deA, cocA);
DataElementOperand deoB = new DataElementOperand(deA, null);
DataElementOperand deoC = new DataElementOperand(deA, cocA, cocA);
DataElementOperand deoD = new DataElementOperand(deA, cocA, null);
DataElementOperand deoE = new DataElementOperand(deA, null, cocA);
assertNotNull(dimensionService.getDataDimensionalItemObject(idA));
assertEquals(deA, dimensionService.getDataDimensionalItemObject(idA));
assertNotNull(dimensionService.getDataDimensionalItemObject(idB));
assertEquals(pdeA, dimensionService.getDataDimensionalItemObject(idB));
assertNotNull(dimensionService.getDataDimensionalItemObject(idC));
assertEquals(ptaA, dimensionService.getDataDimensionalItemObject(idC));
assertNotNull(dimensionService.getDataDimensionalItemObject(idD));
assertEquals(rrA, dimensionService.getDataDimensionalItemObject(idD));
assertNull(dimensionService.getDataDimensionalItemObject(idE));
assertNotNull(dimensionService.getDataDimensionalItemObject(idF));
assertEquals(deoA, dimensionService.getDataDimensionalItemObject(idF));
assertNotNull(dimensionService.getDataDimensionalItemObject(idG));
assertEquals(deoB, dimensionService.getDataDimensionalItemObject(idG));
assertNull(dimensionService.getDataDimensionalItemObject(idH));
assertNotNull(dimensionService.getDataDimensionalItemObject(idI));
assertEquals(deoC, dimensionService.getDataDimensionalItemObject(idI));
assertNotNull(dimensionService.getDataDimensionalItemObject(idJ));
assertEquals(deoD, dimensionService.getDataDimensionalItemObject(idJ));
assertNotNull(dimensionService.getDataDimensionalItemObject(idK));
assertEquals(deoE, dimensionService.getDataDimensionalItemObject(idK));
}
use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class ExpressionServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
Period peJan = createPeriod("2017-01");
Period peFeb = createPeriod("2017-02");
Period peMar = createPeriod("2017-03");
Period peApril = createPeriod("2017-04");
periodService.addPeriod(peJan);
periodService.addPeriod(peFeb);
periodService.addPeriod(peMar);
periodService.addPeriod(peApril);
categoryOptionA = new DataElementCategoryOption("Under 5");
categoryOptionB = new DataElementCategoryOption("Over 5");
categoryOptionC = new DataElementCategoryOption("Male");
categoryOptionD = new DataElementCategoryOption("Female");
categoryService.addDataElementCategoryOption(categoryOptionA);
categoryService.addDataElementCategoryOption(categoryOptionB);
categoryService.addDataElementCategoryOption(categoryOptionC);
categoryService.addDataElementCategoryOption(categoryOptionD);
categoryA = new DataElementCategory("Age", DataDimensionType.DISAGGREGATION);
categoryB = new DataElementCategory("Gender", DataDimensionType.DISAGGREGATION);
categoryA.getCategoryOptions().add(categoryOptionA);
categoryA.getCategoryOptions().add(categoryOptionB);
categoryB.getCategoryOptions().add(categoryOptionC);
categoryB.getCategoryOptions().add(categoryOptionD);
categoryService.addDataElementCategory(categoryA);
categoryService.addDataElementCategory(categoryB);
categoryCombo = new DataElementCategoryCombo("Age and gender", DataDimensionType.DISAGGREGATION);
categoryCombo.getCategories().add(categoryA);
categoryCombo.getCategories().add(categoryB);
categoryService.addDataElementCategoryCombo(categoryCombo);
categoryService.generateOptionCombos(categoryCombo);
List<DataElementCategoryOptionCombo> optionCombos = Lists.newArrayList(categoryCombo.getOptionCombos());
cocA = optionCombos.get(0);
cocB = optionCombos.get(1);
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
deD = createDataElement('D');
deE = createDataElement('E', categoryCombo);
dataElementService.addDataElement(deA);
dataElementService.addDataElement(deB);
dataElementService.addDataElement(deC);
dataElementService.addDataElement(deD);
dataElementService.addDataElement(deE);
coc = categoryService.getDefaultDataElementCategoryOptionCombo();
coc.getId();
optionCombos.add(coc);
opA = new DataElementOperand(deA, coc);
opB = new DataElementOperand(deB, coc);
idObjectManager.save(opA);
idObjectManager.save(opB);
period = createPeriod(getDate(2000, 1, 1), getDate(2000, 2, 1));
prA = createProgram('A');
idObjectManager.save(prA);
teaA = createTrackedEntityAttribute('A');
pteaA = new ProgramTrackedEntityAttributeDimensionItem(prA, teaA);
pdeA = new ProgramDataElementDimensionItem(prA, deA);
piA = createProgramIndicator('A', prA, null, null);
idObjectManager.save(teaA);
idObjectManager.save(pdeA);
idObjectManager.save(piA);
unitA = createOrganisationUnit('A');
unitB = createOrganisationUnit('B');
unitC = createOrganisationUnit('C');
organisationUnitService.addOrganisationUnit(unitA);
organisationUnitService.addOrganisationUnit(unitB);
organisationUnitService.addOrganisationUnit(unitC);
constantA = new Constant("ConstantA", 2.0);
constantService.saveConstant(constantA);
groupA = createOrganisationUnitGroup('A');
groupA.addOrganisationUnit(unitA);
groupA.addOrganisationUnit(unitB);
groupA.addOrganisationUnit(unitC);
organisationUnitGroupService.addOrganisationUnitGroup(groupA);
DataSet dataSetA = createDataSet('A');
dataSetA.setUid("a23dataSetA");
dataSetA.addOrganisationUnit(unitA);
dataSetService.addDataSet(dataSetA);
reportingRate = new ReportingRate(dataSetA);
expressionA = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
expressionB = "#{" + deC.getUid() + SEPARATOR + coc.getUid() + "}-#{" + deD.getUid() + SEPARATOR + coc.getUid() + "}";
expressionC = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+#{" + deE.getUid() + "}-10";
expressionD = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+" + SYMBOL_DAYS;
expressionE = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*C{" + constantA.getUid() + "}";
expressionF = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}";
expressionG = expressionF + "+#{" + deB.getUid() + "}-#{" + deC.getUid() + "}";
expressionH = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*OUG{" + groupA.getUid() + "}";
expressionI = "#{" + opA.getDimensionItem() + "}*" + "#{" + deB.getDimensionItem() + "}+" + "C{" + constantA.getUid() + "}+5-" + "D{" + pdeA.getDimensionItem() + "}+" + "A{" + pteaA.getDimensionItem() + "}-10+" + "I{" + piA.getDimensionItem() + "}";
expressionJ = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
expressionK = "1.5*AVG(" + expressionJ + ")";
expressionL = "AVG(" + expressionJ + ")+1.5*STDDEV(" + expressionJ + ")";
expressionM = "#{" + deA.getUid() + SEPARATOR + SYMBOL_WILDCARD + "}-#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}";
expressionN = "#{" + deA.getUid() + SEPARATOR + cocA.getUid() + SEPARATOR + cocB.getUid() + "}-#{" + deB.getUid() + SEPARATOR + cocA.getUid() + "}";
expressionR = "#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}" + " + R{" + reportingRate.getUid() + ".REPORTING_RATE}";
descriptionA = "Expression A";
descriptionB = "Expression B";
dataElements.add(deA);
dataElements.add(deB);
dataElements.add(deC);
dataElements.add(deD);
dataElements.add(deE);
dataValueService.addDataValue(createDataValue(deA, period, unitA, "10", coc, coc));
dataValueService.addDataValue(createDataValue(deB, period, unitA, "5", coc, coc));
}
Aggregations