Search in sources :

Example 16 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class DataQueryServiceTest method testGetFromUrlB.

@Test
void testGetFromUrlB() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getDimensionItem() + ";" + deB.getDimensionItem() + ";" + deC.getDimensionItem() + ";" + deD.getUid());
    Set<String> filterParams = new HashSet<>();
    filterParams.add("ou:" + ouA.getUid());
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).filter(filterParams).build();
    DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
    assertEquals(4, params.getDataElements().size());
    assertEquals(1, params.getFilterOrganisationUnits().size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 17 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class DataQueryServiceTest method testGetFromUrlD.

@Test
void testGetFromUrlD() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getDimensionItem() + ";" + deB.getDimensionItem() + ";" + patA.getDimensionItem() + ";" + patB.getDimensionItem());
    Set<String> filterParams = new HashSet<>();
    filterParams.add("ou:" + ouA.getDimensionItem());
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).filter(filterParams).build();
    DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
    assertEquals(2, params.getDataElements().size());
    assertEquals(2, params.getProgramAttributes().size());
    assertEquals(1, params.getFilterOrganisationUnits().size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 18 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class DimensionController method getRecommendedDimensions.

@GetMapping("/recommendations")
@ResponseBody
public RootNode getRecommendedDimensions(@RequestParam Set<String> dimension) {
    List<String> fields = newArrayList(contextService.getParameterValues("fields"));
    DataQueryRequest request = DataQueryRequest.newBuilder().dimension(dimension).build();
    if (fields.isEmpty()) {
        fields.addAll(Preset.defaultPreset().getFields());
    }
    List<DimensionalObject> dimensions = analyticsDimensionService.getRecommendedDimensions(request);
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.toCollectionNode(getEntityClass(), new FieldFilterParams(dimensions, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class AnalyticsController method getRawDataCsv.

@GetMapping(value = RESOURCE_PATH + RAW_DATA_PATH + ".csv")
public void getRawDataCsv(AggregateAnalyticsQueryCriteria criteria, DhisApiVersion apiVersion, HttpServletResponse response) throws Exception {
    final DataQueryRequest request = DataQueryRequest.newBuilder().fromCriteria(criteria).apiVersion(apiVersion).allowAllPeriods(true).build();
    DataQueryParams params = dataQueryService.getFromRequest(request);
    contextUtils.configureAnalyticsResponse(response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING, null, false, params.getLatestEndDate());
    Grid grid = analyticsService.getRawDataValues(params);
    GridUtils.toCsv(grid, response.getWriter());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Grid(org.hisp.dhis.common.Grid) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 20 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class DataQueryServiceTest method testGetFromUrlOrgUnitGroupSetAllItems.

@Test
void testGetFromUrlOrgUnitGroupSetAllItems() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getDimensionItem() + ";" + deB.getDimensionItem() + ";" + deC.getDimensionItem());
    dimensionParams.add("pe:2012;2012S1");
    dimensionParams.add(ouGroupSetA.getUid());
    Set<String> filterParams = new HashSet<>();
    filterParams.add("ou:" + ouA.getDimensionItem() + ";" + ouB.getDimensionItem() + ";" + ouC.getDimensionItem());
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).filter(filterParams).build();
    DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
    assertEquals(3, params.getDataElements().size());
    assertEquals(2, params.getPeriods().size());
    assertEquals(3, params.getFilterOrganisationUnits().size());
    assertEquals(3, params.getDimensionOptions(ouGroupSetA.getUid()).size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DataQueryRequest (org.hisp.dhis.common.DataQueryRequest)35 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)29 Test (org.junit.jupiter.api.Test)29 HashSet (java.util.HashSet)19 LinkedHashSet (java.util.LinkedHashSet)18 DhisSpringTest (org.hisp.dhis.DhisSpringTest)18 DimensionalObject (org.hisp.dhis.common.DimensionalObject)11 DimensionItemKeywords (org.hisp.dhis.common.DimensionItemKeywords)9 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 DataElement (org.hisp.dhis.dataelement.DataElement)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 Grid (org.hisp.dhis.common.Grid)2 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)2 Indicator (org.hisp.dhis.indicator.Indicator)2 IndicatorGroup (org.hisp.dhis.indicator.IndicatorGroup)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 LineString (org.geojson.LineString)1 MultiLineString (org.geojson.MultiLineString)1 Attribute (org.hisp.dhis.attribute.Attribute)1