Search in sources :

Example 1 with ReportTable

use of org.hisp.dhis.reporttable.ReportTable in project dhis2-core by dhis2.

the class DimensionServiceTest method testMergeAnalyticalObject.

@Test
public void testMergeAnalyticalObject() {
    ReportTable reportTable = new ReportTable();
    reportTable.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
    reportTable.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA, ouB, ouC, ouD, ouE)));
    reportTable.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA, peB)));
    dimensionService.mergeAnalyticalObject(reportTable);
    assertEquals(2, reportTable.getDataDimensionItems().size());
    assertEquals(2, reportTable.getPeriods().size());
    assertEquals(5, reportTable.getOrganisationUnits().size());
}
Also used : ReportTable(org.hisp.dhis.reporttable.ReportTable) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 2 with ReportTable

use of org.hisp.dhis.reporttable.ReportTable in project dhis2-core by dhis2.

the class InterpretationController method writeReportTableInterpretation.

// -------------------------------------------------------------------------
// Intepretation create
// -------------------------------------------------------------------------
@RequestMapping(value = "/reportTable/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeReportTableInterpretation(@PathVariable("uid") String reportTableUid, @RequestParam(value = "pe", required = false) String isoPeriod, @RequestParam(value = "ou", required = false) String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    ReportTable reportTable = idObjectManager.get(ReportTable.class, reportTableUid);
    if (reportTable == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Report table does not exist or is not accessible: " + reportTableUid));
    }
    Period period = PeriodType.getPeriodFromIsoString(isoPeriod);
    OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, reportTable, currentUserService.getCurrentUser());
    createIntepretation(new Interpretation(reportTable, period, orgUnit, text), request, response);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ReportTable(org.hisp.dhis.reporttable.ReportTable) Period(org.hisp.dhis.period.Period) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ReportTable

use of org.hisp.dhis.reporttable.ReportTable in project dhis2-core by dhis2.

the class GetReportParamsAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    User user = currentUserService.getCurrentUser();
    selectionTreeManager.setSelectedOrganisationUnit(user.getOrganisationUnit());
    if (uid != null) {
        ReportTable reportTable = reportTableService.getReportTable(uid, ReportTableService.MODE_REPORT_TABLE);
        if (reportTable != null) {
            reportParams = reportTable.getReportParams();
            if (reportParams.isParamReportingMonth() && reportTable.getRelatives() != null) {
                CalendarPeriodType periodType = (CalendarPeriodType) reportTable.getRelatives().getPeriodType();
                periods = periodType.generateLast5Years(new Date());
                Collections.reverse(periods);
                FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
                for (Period period : periods) {
                    period.setName(format.formatPeriod(period));
                }
            }
        }
    }
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) ReportTable(org.hisp.dhis.reporttable.ReportTable) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter) Date(java.util.Date)

Example 4 with ReportTable

use of org.hisp.dhis.reporttable.ReportTable in project dhis2-core by dhis2.

the class DefaultReportTableService method getReportTableGridByUser.

@Override
public Grid getReportTableGridByUser(String uid, Date reportingPeriod, String organisationUnitUid, User user) {
    I18nFormat format = i18nManager.getI18nFormat();
    ReportTable reportTable = getReportTable(uid);
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitUid);
    List<OrganisationUnit> atLevels = new ArrayList<>();
    List<OrganisationUnit> inGroups = new ArrayList<>();
    if (reportTable.hasOrganisationUnitLevels()) {
        atLevels.addAll(organisationUnitService.getOrganisationUnitsAtLevels(reportTable.getOrganisationUnitLevels(), reportTable.getOrganisationUnits()));
    }
    if (reportTable.hasItemOrganisationUnitGroups()) {
        inGroups.addAll(organisationUnitService.getOrganisationUnits(reportTable.getItemOrganisationUnitGroups(), reportTable.getOrganisationUnits()));
    }
    reportTable.init(user, reportingPeriod, organisationUnit, atLevels, inGroups, format);
    Map<String, Object> valueMap = analyticsService.getAggregatedDataValueMapping(reportTable);
    Grid reportTableGrid = reportTable.getGrid(new ListGrid(), valueMap, DisplayProperty.SHORTNAME, true);
    reportTable.clearTransientState();
    return reportTableGrid;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) ArrayList(java.util.ArrayList) ReportTable(org.hisp.dhis.reporttable.ReportTable) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 5 with ReportTable

use of org.hisp.dhis.reporttable.ReportTable in project dhis2-core by dhis2.

the class GetReportParamsAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    if (mode == null || uid == null) {
        return SUCCESS;
    }
    RelativePeriods relatives = null;
    if (MODE_REPORT_TABLE.equals(mode)) {
        ReportTable reportTable = reportTableService.getReportTable(uid);
        if (reportTable != null) {
            reportParams = reportTable.getReportParams();
            relatives = reportTable.getRelatives();
        }
    } else if (MODE_REPORT.equals(mode)) {
        Report report = reportService.getReport(uid);
        if (report != null && report.isTypeReportTable()) {
            reportParams = report.getReportTable().getReportParams();
            relatives = report.getReportTable().getRelatives();
        } else if (report != null && (report.isTypeJdbc() || report.isTypeHtml())) {
            reportParams = report.getReportParams();
            relatives = report.getRelatives();
        }
        if (type == null && report != null) {
            // Set type based on report
            type = report.getType();
        }
    }
    if (reportParams != null && reportParams.isParamReportingMonth() && relatives != null) {
        CalendarPeriodType periodType = (CalendarPeriodType) relatives.getPeriodType();
        List<Period> periods = periodType.generateLast5Years(new Date());
        Collections.reverse(periods);
        FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
        Calendar calendar = PeriodType.getCalendar();
        for (Period period_ : periods) {
            BaseIdentifiableObject period = new BaseIdentifiableObject();
            if (calendar.isIso8601()) {
                period.setUid(period_.getIsoDate());
                period.setDisplayName(format.formatPeriod(period_));
            } else {
                DateTimeUnit dateTimeUnit = calendar.fromIso(period_.getStartDate());
                period.setUid(period_.getPeriodType().getIsoDate(dateTimeUnit));
                period.setDisplayName(format.formatPeriod(period_));
            }
            this.periods.add(period);
        }
    }
    return SUCCESS;
}
Also used : RelativePeriods(org.hisp.dhis.period.RelativePeriods) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) Report(org.hisp.dhis.report.Report) Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) ReportTable(org.hisp.dhis.reporttable.ReportTable) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter) Date(java.util.Date)

Aggregations

ReportTable (org.hisp.dhis.reporttable.ReportTable)13 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 Test (org.junit.Test)4 Date (java.util.Date)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Period (org.hisp.dhis.period.Period)3 User (org.hisp.dhis.user.User)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CalendarPeriodType (org.hisp.dhis.period.CalendarPeriodType)2 Report (org.hisp.dhis.report.Report)2 PastAndCurrentPeriodFilter (org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter)2 BiConsumer (java.util.function.BiConsumer)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Calendar (org.hisp.dhis.calendar.Calendar)1 DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)1 Chart (org.hisp.dhis.chart.Chart)1 AnalyticalObject (org.hisp.dhis.common.AnalyticalObject)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1