Search in sources :

Example 6 with Calendar

use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.

the class AnalyticsUtils method getDimensionMetadataItemMap.

/**
     * Returns a mapping between identifiers and meta data items for the given query.
     *
     * @param params the data query parameters.
     * @return a mapping between identifiers and meta data items.
     */
public static Map<String, MetadataItem> getDimensionMetadataItemMap(DataQueryParams params) {
    List<DimensionalObject> dimensions = params.getDimensionsAndFilters();
    Map<String, MetadataItem> map = new HashMap<>();
    Calendar calendar = PeriodType.getCalendar();
    for (DimensionalObject dimension : dimensions) {
        for (DimensionalItemObject item : dimension.getItems()) {
            if (DimensionType.PERIOD == dimension.getDimensionType() && !calendar.isIso8601()) {
                Period period = (Period) item;
                DateTimeUnit dateTimeUnit = calendar.fromIso(period.getStartDate());
                map.put(period.getPeriodType().getIsoDate(dateTimeUnit), new MetadataItem(period.getDisplayName()));
            } else {
                String legendSet = item.hasLegendSet() ? item.getLegendSet().getUid() : null;
                map.put(item.getDimensionItem(), new MetadataItem(item.getDisplayProperty(params.getDisplayProperty()), legendSet));
            }
            if (DimensionType.ORGANISATION_UNIT == dimension.getDimensionType() && params.isHierarchyMeta()) {
                OrganisationUnit unit = (OrganisationUnit) item;
                for (OrganisationUnit ancestor : unit.getAncestors()) {
                    map.put(ancestor.getUid(), new MetadataItem(ancestor.getDisplayProperty(params.getDisplayProperty())));
                }
            }
            if (DimensionItemType.DATA_ELEMENT == item.getDimensionItemType()) {
                DataElement dataElement = (DataElement) item;
                for (DataElementCategoryOptionCombo coc : dataElement.getCategoryOptionCombos()) {
                    map.put(coc.getUid(), new MetadataItem(coc.getDisplayProperty(params.getDisplayProperty())));
                }
            }
        }
        map.put(dimension.getDimension(), new MetadataItem(dimension.getDisplayProperty(params.getDisplayProperty())));
    }
    return map;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Calendar(org.hisp.dhis.calendar.Calendar) Period(org.hisp.dhis.period.Period) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) DimensionalObject(org.hisp.dhis.common.DimensionalObject) DataElement(org.hisp.dhis.dataelement.DataElement) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 7 with Calendar

use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.

the class MonthlyPeriodType method generateRollingPeriods.

/**
     * Generates the last 12 months where the last one is the month which the
     * given date is inside.
     */
@Override
public List<Period> generateRollingPeriods(DateTimeUnit dateTimeUnit) {
    Calendar cal = getCalendar();
    dateTimeUnit.setDay(1);
    dateTimeUnit = cal.minusMonths(dateTimeUnit, 11);
    List<Period> periods = Lists.newArrayList();
    for (int i = 0; i < 12; i++) {
        periods.add(createPeriod(dateTimeUnit, cal));
        dateTimeUnit = cal.plusMonths(dateTimeUnit, 1);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar)

Example 8 with Calendar

use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.

the class MonthlyPeriodType method generatePeriods.

/**
     * Generates monthly Periods for the whole year in which the given Period's
     * startDate exists.
     */
@Override
public List<Period> generatePeriods(DateTimeUnit dateTimeUnit) {
    Calendar cal = getCalendar();
    dateTimeUnit.setMonth(1);
    dateTimeUnit.setDay(1);
    List<Period> periods = Lists.newArrayList();
    int year = dateTimeUnit.getYear();
    while (dateTimeUnit.getYear() == year) {
        periods.add(createPeriod(dateTimeUnit, cal));
        dateTimeUnit = cal.plusMonths(dateTimeUnit, 1);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar)

Example 9 with Calendar

use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.

the class SixMonthlyAbstractPeriodType method generatePeriods.

/**
     * Generates six-monthly Periods for the whole year in which the given
     * Period's startDate exists.
     */
@Override
public List<Period> generatePeriods(DateTimeUnit dateTimeUnit) {
    Calendar cal = getCalendar();
    Period period = createPeriod(dateTimeUnit, cal);
    dateTimeUnit = createLocalDateUnitInstance(period.getStartDate(), cal);
    List<Period> periods = Lists.newArrayList();
    if (dateTimeUnit.getMonth() == getBaseMonth()) {
        periods.add(period);
        periods.add(getNextPeriod(period));
    } else {
        periods.add(getPreviousPeriod(period));
        periods.add(period);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar)

Example 10 with Calendar

use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.

the class SixMonthlyAbstractPeriodType method getRewindedDate.

@Override
public Date getRewindedDate(Date date, Integer rewindedPeriods) {
    Calendar cal = getCalendar();
    date = date != null ? date : new Date();
    rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
    DateTimeUnit dateTimeUnit = createLocalDateUnitInstance(date);
    cal.minusMonths(dateTimeUnit, rewindedPeriods * 6);
    return cal.toIso(dateTimeUnit).toJdkDate();
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Date(java.util.Date)

Aggregations

Calendar (org.hisp.dhis.calendar.Calendar)36 DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)14 Date (java.util.Date)10 Period (org.hisp.dhis.period.Period)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 ArrayList (java.util.ArrayList)5 DimensionalObject (org.hisp.dhis.common.DimensionalObject)4 PeriodType (org.hisp.dhis.period.PeriodType)4 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)3 AnalyticsTable (org.hisp.dhis.analytics.AnalyticsTable)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)2 ReportTable (org.hisp.dhis.reporttable.ReportTable)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1