Search in sources :

Example 31 with DataQueryRequest

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

the class DataQueryServiceTest method testGetFromUrlWithCodeA.

@Test
@Disabled("Not working for composite identifiers with non-UID identifier schemes")
void testGetFromUrlWithCodeA() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getCode() + ";" + deB.getCode() + ";" + patA.getDimensionItem(IdScheme.CODE) + ";" + patB.getDimensionItem(IdScheme.CODE));
    Set<String> filterParams = new HashSet<>();
    filterParams.add("ou:" + ouA.getCode());
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).filter(filterParams).inputIdScheme(IdScheme.CODE).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) Disabled(org.junit.jupiter.api.Disabled)

Example 32 with DataQueryRequest

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

the class DataQueryServiceTest method testGetFromUrlNoPeriodsAllowAllPeriods.

@Test
void testGetFromUrlNoPeriodsAllowAllPeriods() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getUid() + ";" + deB.getUid() + ";" + deC.getUid() + ";" + deD.getUid());
    dimensionParams.add("pe");
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).allowAllPeriods(true).build();
    DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
    assertEquals(0, params.getPeriods().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 33 with DataQueryRequest

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

the class AnalyticsController method getJrxml.

@GetMapping(value = RESOURCE_PATH + ".jrxml")
public void getJrxml(AggregateAnalyticsQueryCriteria criteria, DhisApiVersion apiVersion, HttpServletResponse response) throws Exception {
    final DataQueryRequest request = DataQueryRequest.newBuilder().fromCriteria(criteria).apiVersion(apiVersion).skipMeta(true).build();
    DataQueryParams params = dataQueryService.getFromRequest(request);
    contextUtils.configureAnalyticsResponse(response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING, "data.jrxml", false, params.getLatestEndDate());
    Grid grid = analyticsService.getAggregatedDataValues(params);
    GridUtils.toJrxml(grid, null, 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 34 with DataQueryRequest

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

the class AnalyticsController method getRawDataJson.

// -------------------------------------------------------------------------
// Raw data
// -------------------------------------------------------------------------
@GetMapping(value = RESOURCE_PATH + RAW_DATA_PATH + ".json")
@ResponseBody
public Grid getRawDataJson(AggregateAnalyticsQueryCriteria criteria, DhisApiVersion apiVersion, HttpServletResponse response) {
    final DataQueryRequest request = DataQueryRequest.newBuilder().fromCriteria(criteria).apiVersion(apiVersion).allowAllPeriods(true).build();
    DataQueryParams params = dataQueryService.getFromRequest(request);
    contextUtils.configureAnalyticsResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING, null, false, params.getLatestEndDate());
    return analyticsService.getRawDataValues(params);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 35 with DataQueryRequest

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

the class GeoFeatureService method getGeoFeatures.

/**
 * Returns a list of {@link GeoFeature}. Returns null if not modified based
 * on the request.
 *
 * @param parameters the {@link Parameters} passing from controller.
 * @return a list of geo features or null.
 */
public List<GeoFeature> getGeoFeatures(Parameters parameters) {
    Attribute geoJsonAttribute = validateCoordinateField(parameters.getCoordinateField());
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add(parameters.getOrganisationUnit());
    dimensionParams.add(parameters.getOrganisationUnitGroupId());
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).aggregationType(AggregationType.SUM).displayProperty(parameters.getDisplayProperty()).relativePeriodDate(parameters.getRelativePeriodDate()).userOrgUnit(parameters.getUserOrgUnit()).apiVersion(parameters.getApiVersion()).build();
    DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
    boolean useOrgUnitGroup = parameters.getOrganisationUnit() == null;
    DimensionalObject dimensionalObject = params.getDimension(useOrgUnitGroup ? ORGUNIT_GROUP_DIM_ID : ORGUNIT_DIM_ID);
    if (dimensionalObject == null) {
        throw new IllegalArgumentException("Dimension is present in query without any valid dimension options");
    }
    List<DimensionalItemObject> dimensionalItemObjects = DimensionalObjectUtils.asTypedList(dimensionalObject.getItems());
    dimensionalItemObjects = dimensionalItemObjects.stream().filter(object -> validateDimensionalItemObject(object, geoJsonAttribute)).collect(Collectors.toList());
    boolean modified = !ContextUtils.clearIfNotModified(parameters.getRequest(), parameters.getResponse(), dimensionalItemObjects);
    if (!modified) {
        return null;
    }
    return getGeoFeatures(params, dimensionalItemObjects, parameters.isIncludeGroupSets(), useOrgUnitGroup, geoJsonAttribute);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Attribute(org.hisp.dhis.attribute.Attribute) MultiLineString(org.geojson.MultiLineString) LineString(org.geojson.LineString) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) HashSet(java.util.HashSet) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

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