Search in sources :

Example 1 with RelativePeriods

use of org.hisp.dhis.period.RelativePeriods 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)

Example 2 with RelativePeriods

use of org.hisp.dhis.period.RelativePeriods in project dhis2-core by dhis2.

the class ReportTableTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    dataElements = new ArrayList<>();
    categoryOptionCombos = new ArrayList<>();
    indicators = new ArrayList<>();
    reportingRates = new ArrayList<>();
    periods = new ArrayList<>();
    units = new ArrayList<>();
    relativeUnits = new ArrayList<>();
    groups = new ArrayList<>();
    montlyPeriodType = PeriodType.getPeriodTypeByName(MonthlyPeriodType.NAME);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementA.setId('A');
    dataElementB.setId('B');
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    deGroupSetA = createDataElementGroupSet('A');
    deGroupA = createDataElementGroup('A');
    deGroupB = createDataElementGroup('B');
    deGroupA.getGroupSets().add(deGroupSetA);
    deGroupB.getGroupSets().add(deGroupSetA);
    deGroupSetA.getMembers().add(deGroupA);
    deGroupSetA.getMembers().add(deGroupB);
    categoryOptionComboA = createCategoryOptionCombo('A', 'A', 'B');
    categoryOptionComboB = createCategoryOptionCombo('B', 'C', 'D');
    categoryOptionComboA.setId('A');
    categoryOptionComboB.setId('B');
    categoryOptionCombos.add(categoryOptionComboA);
    categoryOptionCombos.add(categoryOptionComboB);
    categoryCombo = new DataElementCategoryCombo("CategoryComboA", DataDimensionType.DISAGGREGATION);
    categoryCombo.setId('A');
    categoryCombo.setOptionCombos(new HashSet<>(categoryOptionCombos));
    indicatorType = createIndicatorType('A');
    indicatorA = createIndicator('A', indicatorType);
    indicatorB = createIndicator('B', indicatorType);
    indicatorA.setId('A');
    indicatorB.setId('B');
    indicators.add(indicatorA);
    indicators.add(indicatorB);
    DataSet dataSetA = createDataSet('A', montlyPeriodType);
    DataSet dataSetB = createDataSet('B', montlyPeriodType);
    dataSetA.setId('A');
    dataSetB.setId('B');
    reportingRateA = new ReportingRate(dataSetA);
    reportingRateB = new ReportingRate(dataSetB);
    reportingRates.add(reportingRateA);
    reportingRates.add(reportingRateB);
    periodA = createPeriod(montlyPeriodType, getDate(2008, 1, 1), getDate(2008, 1, 31));
    periodB = createPeriod(montlyPeriodType, getDate(2008, 2, 1), getDate(2008, 2, 28));
    periodA.setId('A');
    periodB.setId('B');
    periods.add(periodA);
    periods.add(periodB);
    relatives = new RelativePeriods();
    relatives.setLastMonth(true);
    relatives.setThisYear(true);
    List<Period> rp = relatives.getRelativePeriods();
    periodC = rp.get(0);
    periodD = rp.get(1);
    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B', unitA);
    unitC = createOrganisationUnit('C', unitA);
    unitA.setId('A');
    unitB.setId('B');
    unitC.setId('C');
    unitA.getChildren().add(unitB);
    unitA.getChildren().add(unitC);
    units.add(unitA);
    units.add(unitB);
    relativeUnits.add(unitA);
    ouGroupSetA = createOrganisationUnitGroupSet('A');
    ouGroupA = createOrganisationUnitGroup('A');
    ouGroupB = createOrganisationUnitGroup('B');
    ouGroupA.getGroupSets().add(ouGroupSetA);
    ouGroupB.getGroupSets().add(ouGroupSetA);
    ouGroupA.setId('A');
    ouGroupB.setId('B');
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupA);
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupB);
    groups.add(ouGroupA);
    groups.add(ouGroupB);
    i18nFormat = new MockI18nFormat();
}
Also used : MockI18nFormat(org.hisp.dhis.mock.MockI18nFormat) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) RelativePeriods(org.hisp.dhis.period.RelativePeriods) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) Period(org.hisp.dhis.period.Period)

Example 3 with RelativePeriods

use of org.hisp.dhis.period.RelativePeriods in project dhis2-core by dhis2.

the class ReportTableStoreTest method setUpTest.

@Override
public void setUpTest() throws Exception {
    dataElements = new ArrayList<>();
    indicators = new ArrayList<>();
    reportingRates = new ArrayList<>();
    periods = new ArrayList<>();
    units = new ArrayList<>();
    indicatorType = createIndicatorType('A');
    indicatorService.addIndicatorType(indicatorType);
    periodType = PeriodType.getPeriodTypeByName(MonthlyPeriodType.NAME);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    indicatorA = createIndicator('A', indicatorType);
    indicatorB = createIndicator('B', indicatorType);
    indicatorService.addIndicator(indicatorA);
    indicatorService.addIndicator(indicatorB);
    indicators.add(indicatorA);
    indicators.add(indicatorB);
    DataSet dataSetA = createDataSet('A', periodType);
    DataSet dataSetB = createDataSet('B', periodType);
    dataSetService.addDataSet(dataSetA);
    dataSetService.addDataSet(dataSetB);
    reportingRateA = new ReportingRate(dataSetA);
    reportingRateB = new ReportingRate(dataSetB);
    reportingRates.add(reportingRateA);
    reportingRates.add(reportingRateB);
    periodA = createPeriod(periodType, getDate(2000, 1, 1), getDate(2000, 1, 31));
    periodB = createPeriod(periodType, getDate(2000, 2, 1), getDate(2000, 2, 28));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    periods.add(periodA);
    periods.add(periodB);
    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B');
    organisationUnitService.addOrganisationUnit(unitA);
    organisationUnitService.addOrganisationUnit(unitB);
    units.add(unitA);
    units.add(unitB);
    relativesA = new RelativePeriods();
    relativesA.setLastMonth(true);
    relativesA.setThisYear(true);
    relativesB = new RelativePeriods();
    relativesB.setLastMonth(true);
    relativesB.setThisYear(true);
    relativesC = new RelativePeriods();
    relativesC.setLastMonth(true);
    relativesC.setThisYear(true);
}
Also used : RelativePeriods(org.hisp.dhis.period.RelativePeriods) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate)

Example 4 with RelativePeriods

use of org.hisp.dhis.period.RelativePeriods in project dhis2-core by dhis2.

the class DefaultMappingService method getIndicatorLastYearMapView.

@Override
public MapView getIndicatorLastYearMapView(String indicatorUid, String organisationUnitUid, int level) {
    MapView mapView = new MapView();
    Period period = periodService.reloadPeriod(new RelativePeriods().setThisYear(true).getRelativePeriods().iterator().next());
    Indicator indicator = indicatorService.getIndicator(indicatorUid);
    OrganisationUnit unit = organisationUnitService.getOrganisationUnit(organisationUnitUid);
    mapView.addDataDimensionItem(indicator);
    mapView.getPeriods().add(period);
    mapView.getOrganisationUnits().add(unit);
    mapView.getOrganisationUnitLevels().add(level);
    mapView.setName(indicator.getName());
    return mapView;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RelativePeriods(org.hisp.dhis.period.RelativePeriods) Period(org.hisp.dhis.period.Period) Indicator(org.hisp.dhis.indicator.Indicator)

Example 5 with RelativePeriods

use of org.hisp.dhis.period.RelativePeriods in project dhis2-core by dhis2.

the class DefaultChartService method getJFreePeriodChart.

// -------------------------------------------------------------------------
// Specific chart methods
// -------------------------------------------------------------------------
@Override
public JFreeChart getJFreePeriodChart(Indicator indicator, OrganisationUnit unit, boolean title, I18nFormat format) {
    List<Period> periods = periodService.reloadPeriods(new RelativePeriods().setLast12Months(true).getRelativePeriods(format, true));
    Chart chart = new Chart();
    if (title) {
        chart.setName(indicator.getName());
    }
    chart.setType(ChartType.LINE);
    chart.setDimensions(DimensionalObject.DATA_X_DIM_ID, DimensionalObject.PERIOD_DIM_ID, DimensionalObject.ORGUNIT_DIM_ID);
    chart.setHideLegend(true);
    chart.addDataDimensionItem(indicator);
    chart.setPeriods(periods);
    chart.getOrganisationUnits().add(unit);
    chart.setHideSubtitle(title);
    chart.setFormat(format);
    return getJFreeChart(chart);
}
Also used : RelativePeriods(org.hisp.dhis.period.RelativePeriods) Period(org.hisp.dhis.period.Period) Chart(org.hisp.dhis.chart.Chart) BaseChart(org.hisp.dhis.chart.BaseChart) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

RelativePeriods (org.hisp.dhis.period.RelativePeriods)7 Period (org.hisp.dhis.period.Period)6 BaseChart (org.hisp.dhis.chart.BaseChart)2 Chart (org.hisp.dhis.chart.Chart)2 ReportingRate (org.hisp.dhis.common.ReportingRate)2 DataSet (org.hisp.dhis.dataset.DataSet)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 JFreeChart (org.jfree.chart.JFreeChart)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Calendar (org.hisp.dhis.calendar.Calendar)1 DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)1 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1 DataDimensionItem (org.hisp.dhis.common.DataDimensionItem)1 DimensionType (org.hisp.dhis.common.DimensionType)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)1