Search in sources :

Example 1 with ProgramDataElementDimensionItem

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);
}
Also used : ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) OptionSet(org.hisp.dhis.option.OptionSet)

Example 2 with ProgramDataElementDimensionItem

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);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem)

Example 3 with ProgramDataElementDimensionItem

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;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ReportingRate(org.hisp.dhis.common.ReportingRate) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)

Example 4 with ProgramDataElementDimensionItem

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));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with ProgramDataElementDimensionItem

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));
}
Also used : ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DataSet(org.hisp.dhis.dataset.DataSet) Constant(org.hisp.dhis.constant.Constant) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) Period(org.hisp.dhis.period.Period)

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