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;
}
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();
}
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);
}
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;
}
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);
}
Aggregations