Search in sources :

Example 31 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class EventAnalyticsController method getCountJson.

// -------------------------------------------------------------------------
// Count / rectangle
// -------------------------------------------------------------------------
@RequestMapping(value = RESOURCE_PATH + "/count/{program}", method = RequestMethod.GET, produces = { "application/json", "application/javascript" })
// JSON, JSONP
@ResponseBody
public // JSON, JSONP
Rectangle getCountJson(@PathVariable String program, @RequestParam(required = false) String stage, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam Set<String> dimension, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Set<String> asc, @RequestParam(required = false) Set<String> desc, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) boolean skipData, @RequestParam(required = false) boolean completedOnly, @RequestParam(required = false) boolean hierarchyMeta, @RequestParam(required = false) boolean coordinatesOnly, @RequestParam(required = false) EventStatus eventStatus, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) DisplayProperty displayProperty, @RequestParam(required = false) Date relativePeriodDate, @RequestParam(required = false) String userOrgUnit, @RequestParam(required = false) String coordinateField, DhisApiVersion apiVersion, Model model, HttpServletResponse response) throws Exception {
    EventQueryParams params = eventDataQueryService.getFromUrl(program, stage, startDate, endDate, dimension, filter, ouMode, asc, desc, skipMeta, skipData, completedOnly, hierarchyMeta, coordinatesOnly, eventStatus, programStatus, displayProperty, relativePeriodDate, userOrgUnit, coordinateField, page, pageSize, apiVersion);
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING);
    return analyticsService.getRectangle(params);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 32 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class EventAnalyticsController method getQueryHtmlCss.

@PreAuthorize("hasRole('ALL') or hasRole('F_VIEW_EVENT_ANALYTICS')")
@RequestMapping(value = RESOURCE_PATH + "/query/{program}.html+css", method = RequestMethod.GET)
public void getQueryHtmlCss(@PathVariable String program, @RequestParam(required = false) String stage, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam Set<String> dimension, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Set<String> asc, @RequestParam(required = false) Set<String> desc, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) boolean skipData, @RequestParam(required = false) boolean completedOnly, @RequestParam(required = false) boolean hierarchyMeta, @RequestParam(required = false) boolean coordinatesOnly, @RequestParam(required = false) EventStatus eventStatus, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) DisplayProperty displayProperty, @RequestParam(required = false) Date relativePeriodDate, @RequestParam(required = false) String userOrgUnit, @RequestParam(required = false) String coordinateField, DhisApiVersion apiVersion, Model model, HttpServletResponse response) throws Exception {
    EventQueryParams params = eventDataQueryService.getFromUrl(program, stage, startDate, endDate, dimension, filter, ouMode, asc, desc, skipMeta, skipData, completedOnly, hierarchyMeta, coordinatesOnly, eventStatus, programStatus, displayProperty, relativePeriodDate, userOrgUnit, coordinateField, page, pageSize, apiVersion);
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.html", false);
    Grid grid = analyticsService.getEvents(params);
    GridUtils.toHtmlCss(substituteMetaData(grid), response.getWriter());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) Grid(org.hisp.dhis.common.Grid) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class DefaultEventDataQueryService method getFromAnalyticalObject.

@Override
public EventQueryParams getFromAnalyticalObject(EventAnalyticalObject object) {
    Assert.notNull(object, "Event analytical object cannot be null");
    Assert.notNull(object.getProgram(), "Event analytical object must specify a program");
    EventQueryParams.Builder params = new EventQueryParams.Builder();
    I18nFormat format = i18nManager.getI18nFormat();
    IdScheme idScheme = IdScheme.UID;
    Date date = object.getRelativePeriodDate();
    object.populateAnalyticalProperties();
    for (DimensionalObject dimension : ListUtils.union(object.getColumns(), object.getRows())) {
        DimensionalObject dimObj = dataQueryService.getDimension(dimension.getDimension(), getDimensionalItemIds(dimension.getItems()), date, null, format, true, false, idScheme);
        if (dimObj != null) {
            params.addDimension(dimObj);
        } else {
            params.addItem(getQueryItem(dimension.getDimension(), dimension.getFilter(), object.getProgram()));
        }
    }
    for (DimensionalObject filter : object.getFilters()) {
        DimensionalObject dimObj = dataQueryService.getDimension(filter.getDimension(), getDimensionalItemIds(filter.getItems()), date, null, format, true, false, idScheme);
        if (dimObj != null) {
            params.addFilter(dimObj);
        } else {
            params.addItemFilter(getQueryItem(filter.getDimension(), filter.getFilter(), object.getProgram()));
        }
    }
    return params.withProgram(object.getProgram()).withProgramStage(object.getProgramStage()).withStartDate(object.getStartDate()).withEndDate(object.getEndDate()).withValue(object.getValue()).withOutputType(object.getOutputType()).build();
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) I18nFormat(org.hisp.dhis.i18n.I18nFormat) Date(java.util.Date)

Example 34 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetUidNameMapEventQuery.

@Test
public void testGetUidNameMapEventQuery() {
    ProgramStage psA = createProgramStage('A', 0);
    ProgramStage psB = createProgramStage('B', 0);
    Program prA = createProgram('A');
    prA.getProgramStages().add(psA);
    prA.getProgramStages().add(psB);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('A');
    OrganisationUnit ouA = createOrganisationUnit('A');
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).addItem(new QueryItem(deA)).addItem(new QueryItem(deB)).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA))).withDisplayProperty(DisplayProperty.NAME).build();
    Map<String, String> map = AnalyticsUtils.getUidNameMap(params);
    assertEquals(psA.getName(), map.get(psA.getUid()));
    assertEquals(psB.getName(), map.get(psB.getUid()));
    assertEquals(prA.getName(), map.get(prA.getUid()));
    assertEquals(deA.getName(), map.get(deA.getUid()));
    assertEquals(deB.getName(), map.get(deB.getUid()));
    assertEquals(ouA.getName(), map.get(ouA.getUid()));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 35 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class EventAnalyticsServiceTest method testGridAggregation.

@Test
public void testGridAggregation() {
    Grid aggregatedDataValueGrid;
    for (Map.Entry<String, EventQueryParams> entry : eventQueryParams.entrySet()) {
        String key = entry.getKey();
        EventQueryParams params = entry.getValue();
        aggregatedDataValueGrid = eventAnalyticsService.getAggregatedEventData(params);
        AnalyticsTestUtils.assertResultGrid(aggregatedDataValueGrid, results.get(key));
    }
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) Grid(org.hisp.dhis.common.Grid) HashMap(java.util.HashMap) Map(java.util.Map) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Aggregations

EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)42 Test (org.junit.Test)20 DhisSpringTest (org.hisp.dhis.DhisSpringTest)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 Grid (org.hisp.dhis.common.Grid)13 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 DateTime (org.joda.time.DateTime)6 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 Partitions (org.hisp.dhis.analytics.Partitions)4 QueryItem (org.hisp.dhis.common.QueryItem)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 EventChart (org.hisp.dhis.eventchart.EventChart)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 TrackedEntityAttributeDimension (org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 DataElement (org.hisp.dhis.dataelement.DataElement)2