Search in sources :

Example 1 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class QueryPlannerTest method planQueryAggregationTypeA.

/**
     * Split on two data elements. Set aggregation type average and value type
     * integer on query. Convert aggregation type from data elements to average 
     * and then to average integer.
     */
@Test
public void planQueryAggregationTypeA() {
    DataElement deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM);
    DataElement deB = createDataElement('B', ValueType.INTEGER, AggregationType.COUNT);
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB)).withOrganisationUnits(getList(ouA)).withPeriods(getList(createPeriod("200101"))).withAggregationType(AggregationType.AVERAGE).build();
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableName(ANALYTICS_TABLE_NAME).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    assertEquals(2, queryGroups.getAllQueries().size());
    for (DataQueryParams query : queryGroups.getAllQueries()) {
        assertNotNull(query.getAggregationType());
        assertEquals(AggregationType.AVERAGE_INT, query.getAggregationType());
    }
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 2 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class PredictorServiceTest method testGetPredictorCount.

@Test
public void testGetPredictorCount() {
    Set<DataElement> dataElementsA = new HashSet<>();
    dataElementsA.add(dataElementA);
    dataElementsA.add(dataElementB);
    Set<DataElement> dataElementsB = new HashSet<>();
    dataElementsB.add(dataElementC);
    dataElementsB.add(dataElementD);
    Set<DataElement> dataElementsD = new HashSet<>();
    dataElementsD.addAll(dataElementsA);
    dataElementsD.addAll(dataElementsB);
    Expression expression1 = new Expression("Expression1", "Expression1");
    Expression expression2 = new Expression("Expression2", "Expression2");
    Expression expression3 = new Expression("Expression3", "Expression3");
    expressionService.addExpression(expression1);
    expressionService.addExpression(expression2);
    expressionService.addExpression(expression3);
    Predictor predictorA = createPredictor(dataElementX, altCombo, "A", expressionA, expressionB, periodTypeMonthly, orgUnitLevel1, 6, 1, 0);
    Predictor predictorB = createPredictor(dataElementX, defaultCombo, "B", expressionA, expressionB, periodTypeMonthly, orgUnitLevel1, 6, 1, 0);
    Predictor predictorC = createPredictor(dataElementX, altCombo, "C", expressionA, expressionB, periodTypeMonthly, orgUnitLevel1, 6, 1, 0);
    predictorService.addPredictor(predictorA);
    predictorService.addPredictor(predictorB);
    predictorService.addPredictor(predictorC);
    assertNotNull(predictorService.getPredictorCount());
    assertEquals(3, predictorService.getPredictorCount());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Expression(org.hisp.dhis.expression.Expression) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 3 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class PreheatServiceTest method testPreheatWithDataSetElements.

@Test
public void testPreheatWithDataSetElements() {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = new HashMap<>();
    DataElement de1 = createDataElement('A');
    DataElement de2 = createDataElement('B');
    DataElement de3 = createDataElement('C');
    manager.save(de1);
    manager.save(de2);
    manager.save(de3);
    DataSet dataSet = createDataSet('A');
    dataSet.setAutoFields();
    dataSet.getDataSetElements().add(new DataSetElement(dataSet, de1));
    dataSet.getDataSetElements().add(new DataSetElement(dataSet, de2));
    dataSet.getDataSetElements().add(new DataSetElement(dataSet, de3));
    metadata.put(DataSet.class, new ArrayList<>());
    metadata.get(DataSet.class).add(dataSet);
    PreheatParams params = new PreheatParams();
    params.setPreheatIdentifier(PreheatIdentifier.UID);
    params.setPreheatMode(PreheatMode.REFERENCE);
    params.setObjects(metadata);
    preheatService.validate(params);
    Preheat preheat = preheatService.preheat(params);
    Map<String, IdentifiableObject> map = preheat.getMap().get(PreheatIdentifier.UID).get(DataElement.class);
    assertEquals(3, map.size());
}
Also used : HashMap(java.util.HashMap) DataSet(org.hisp.dhis.dataset.DataSet) DataSetElement(org.hisp.dhis.dataset.DataSetElement) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 4 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class PreheatServiceTest method testPreheatReferenceConnectAUTO.

@Test
public void testPreheatReferenceConnectAUTO() {
    DataElementGroup dataElementGroup = fromJson("preheat/degAAutoRef.json", DataElementGroup.class);
    defaultSetup();
    PreheatParams params = new PreheatParams();
    params.setPreheatIdentifier(PreheatIdentifier.AUTO);
    params.setPreheatMode(PreheatMode.REFERENCE);
    params.getObjects().put(DataElementGroup.class, Lists.newArrayList(dataElementGroup));
    preheatService.validate(params);
    Preheat preheat = preheatService.preheat(params);
    preheatService.connectReferences(dataElementGroup, preheat, PreheatIdentifier.AUTO);
    List<DataElement> members = new ArrayList<>(dataElementGroup.getMembers());
    assertEquals("DataElementA", members.get(0).getName());
    assertEquals("DataElementCodeA", members.get(0).getCode());
    assertEquals("DataElementB", members.get(1).getName());
    assertEquals("DataElementCodeB", members.get(1).getCode());
    assertEquals("DataElementC", members.get(2).getName());
    assertEquals("DataElementCodeC", members.get(2).getCode());
    assertEquals("FirstNameA", dataElementGroup.getUser().getFirstName());
    assertEquals("SurnameA", dataElementGroup.getUser().getSurname());
    assertEquals("UserCodeA", dataElementGroup.getUser().getCode());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class PreheatServiceTest method testCollectReferenceUidDEG2.

@Test
public void testCollectReferenceUidDEG2() {
    DataElementGroup deg1 = createDataElementGroup('A');
    DataElementGroup deg2 = createDataElementGroup('B');
    DataElement de1 = createDataElement('A');
    DataElement de2 = createDataElement('B');
    DataElement de3 = createDataElement('C');
    deg1.addDataElement(de1);
    deg1.addDataElement(de2);
    deg2.addDataElement(de3);
    Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences(Lists.newArrayList(deg1, deg2)).get(PreheatIdentifier.UID);
    assertTrue(references.containsKey(DataElement.class));
    assertEquals(3, references.get(DataElement.class).size());
    assertTrue(references.get(DataElement.class).contains(de1.getUid()));
    assertTrue(references.get(DataElement.class).contains(de2.getUid()));
    assertTrue(references.get(DataElement.class).contains(de3.getUid()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataSet(org.hisp.dhis.dataset.DataSet) LegendSet(org.hisp.dhis.legend.LegendSet) Set(java.util.Set) OptionSet(org.hisp.dhis.option.OptionSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DataElement (org.hisp.dhis.dataelement.DataElement)254 Test (org.junit.Test)137 DhisSpringTest (org.hisp.dhis.DhisSpringTest)99 User (org.hisp.dhis.user.User)51 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)47 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)44 DataSet (org.hisp.dhis.dataset.DataSet)39 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)36 ArrayList (java.util.ArrayList)31 List (java.util.List)31 ClassPathResource (org.springframework.core.io.ClassPathResource)26 HashSet (java.util.HashSet)23 Period (org.hisp.dhis.period.Period)20 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)19 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)18 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)16 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)15 DataValue (org.hisp.dhis.datavalue.DataValue)15 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)14 Matcher (java.util.regex.Matcher)13