Search in sources :

Example 1 with CalendarPeriodType

use of org.hisp.dhis.period.CalendarPeriodType 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 2 with CalendarPeriodType

use of org.hisp.dhis.period.CalendarPeriodType 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 3 with CalendarPeriodType

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

the class DefaultPdfDataEntryFormService method getProgramStagePeriodList.

private List<Period> getProgramStagePeriodList() throws ParseException {
    PeriodType periodType = PeriodType.getPeriodTypeByName(MonthlyPeriodType.NAME);
    Period period = setPeriodDateRange(periodType);
    return ((CalendarPeriodType) periodType).generatePeriods(period.getStartDate(), period.getEndDate());
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType)

Example 4 with CalendarPeriodType

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

the class FormUtilsImpl method getPeriodsForDataSet.

@Override
public List<Period> getPeriodsForDataSet(Integer dataSetId, int first, int max) {
    Validate.notNull(dataSetId);
    DataSet dataSet = dataSetService.getDataSet(dataSetId);
    CalendarPeriodType periodType;
    if (dataSet.getPeriodType().getName().equalsIgnoreCase("Yearly")) {
        periodType = new YearlyPeriodType();
    } else {
        periodType = (CalendarPeriodType) dataSet.getPeriodType();
    }
    if (dataSet.getOpenFuturePeriods() > 0) {
        List<Period> periods = periodType.generatePeriods(new Date());
        Collections.reverse(periods);
        return periods;
    } else {
        List<Period> periods = periodType.generateLast5Years(new Date());
        FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
        Collections.reverse(periods);
        if (periods.size() > (first + max)) {
            periods = periods.subList(first, max);
        }
        return periods;
    }
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter)

Example 5 with CalendarPeriodType

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

the class GetLockExceptionFormAction method getPeriodsForDataSet.

private List<Period> getPeriodsForDataSet(int id) {
    DataSet dataSet = dataSetService.getDataSet(id);
    if (dataSet == null) {
        return new ArrayList<>();
    }
    CalendarPeriodType periodType = (CalendarPeriodType) dataSet.getPeriodType();
    List<Period> periods = periodType.generateLast5Years(new Date());
    FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
    Collections.reverse(periods);
    if (periods.size() > 10) {
        periods = periods.subList(0, 10);
    }
    return periods;
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter) Date(java.util.Date)

Aggregations

CalendarPeriodType (org.hisp.dhis.period.CalendarPeriodType)5 Period (org.hisp.dhis.period.Period)5 PastAndCurrentPeriodFilter (org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter)4 Date (java.util.Date)3 DataSet (org.hisp.dhis.dataset.DataSet)2 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)2 ReportTable (org.hisp.dhis.reporttable.ReportTable)2 ArrayList (java.util.ArrayList)1 Calendar (org.hisp.dhis.calendar.Calendar)1 DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1 FinancialAprilPeriodType (org.hisp.dhis.period.FinancialAprilPeriodType)1 FinancialJulyPeriodType (org.hisp.dhis.period.FinancialJulyPeriodType)1 FinancialOctoberPeriodType (org.hisp.dhis.period.FinancialOctoberPeriodType)1 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)1 PeriodType (org.hisp.dhis.period.PeriodType)1 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)1 RelativePeriods (org.hisp.dhis.period.RelativePeriods)1 SixMonthlyAprilPeriodType (org.hisp.dhis.period.SixMonthlyAprilPeriodType)1 SixMonthlyPeriodType (org.hisp.dhis.period.SixMonthlyPeriodType)1