Search in sources :

Example 96 with DateTimeUnit

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

the class NepaliCalendar method toDayIsoInterval.

private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int length) {
    DateTimeUnit from = new DateTimeUnit(dateTimeUnit);
    if (offset > 0) {
        from = plusDays(from, offset);
    } else if (offset < 0) {
        from = minusDays(from, -offset);
    }
    DateTimeUnit to = new DateTimeUnit(from);
    to = plusDays(to, length);
    from = toIso(from);
    to = toIso(to);
    return new DateInterval(from, to, DateIntervalType.ISO8601_DAY);
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DateInterval(org.hisp.dhis.calendar.DateInterval)

Example 97 with DateTimeUnit

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

the class AnalyticsUtils method getDimensionItemNameMap.

/**
 * Returns a mapping between identifiers and names for the given query.
 *
 * @param params the data query parameters.
 * @return a mapping between identifiers and names.
 */
public static Map<String, String> getDimensionItemNameMap(DataQueryParams params) {
    List<DimensionalObject> dimensions = params.getDimensionsAndFilters();
    Map<String, String> map = new HashMap<>();
    Calendar calendar = PeriodType.getCalendar();
    for (DimensionalObject dimension : dimensions) {
        for (DimensionalItemObject item : dimension.getItems()) {
            if (DimensionType.PERIOD.equals(dimension.getDimensionType()) && !calendar.isIso8601()) {
                Period period = (Period) item;
                DateTimeUnit dateTimeUnit = calendar.fromIso(period.getStartDate());
                map.put(period.getPeriodType().getIsoDate(dateTimeUnit), period.getDisplayName());
            } else {
                map.put(item.getDimensionItem(), item.getDisplayProperty(params.getDisplayProperty()));
            }
            if (DimensionType.ORGANISATION_UNIT.equals(dimension.getDimensionType()) && params.isHierarchyMeta()) {
                OrganisationUnit unit = (OrganisationUnit) item;
                map.putAll(NameableObjectUtils.getUidDisplayPropertyMap(unit.getAncestors(), params.getDisplayProperty()));
            }
        }
        map.put(dimension.getDimension(), dimension.getDisplayProperty(params.getDisplayProperty()));
    }
    return map;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataDimensionalItemObject(org.hisp.dhis.common.DataDimensionalItemObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Period(org.hisp.dhis.period.Period) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 98 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit 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();
    boolean includeMetadataDetails = params.isIncludeMetadataDetails();
    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());
                String isoDate = period.getPeriodType().getIsoDate(dateTimeUnit);
                map.put(isoDate, new MetadataItem(period.getDisplayName(), includeMetadataDetails ? period : null));
            } else {
                map.put(item.getDimensionItem(), new MetadataItem(item.getDisplayProperty(params.getDisplayProperty()), includeMetadataDetails ? item : null));
            }
            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()), includeMetadataDetails ? ancestor : null));
                }
            }
            if (DimensionItemType.DATA_ELEMENT == item.getDimensionItemType()) {
                DataElement dataElement = (DataElement) item;
                for (CategoryOptionCombo coc : dataElement.getCategoryOptionCombos()) {
                    map.put(coc.getUid(), new MetadataItem(coc.getDisplayProperty(params.getDisplayProperty()), includeMetadataDetails ? coc : null));
                }
            }
        }
        map.put(dimension.getDimension(), new MetadataItem(dimension.getDisplayProperty(params.getDisplayProperty()), includeMetadataDetails ? dimension : null));
        if (dimension.getDimensionItemKeywords() != null) {
            dimension.getDimensionItemKeywords().getKeywords().forEach(b -> map.put(b.getKey(), b.getMetadataItem()));
        }
    }
    Program program = params.getProgram();
    ProgramStage stage = params.getProgramStage();
    if (ObjectUtils.allNotNull(program)) {
        map.put(program.getUid(), new MetadataItem(program.getDisplayProperty(params.getDisplayProperty()), includeMetadataDetails ? program : null));
        if (stage != null) {
            map.put(stage.getUid(), new MetadataItem(stage.getDisplayName(), includeMetadataDetails ? stage : null));
        } else {
            for (ProgramStage ps : program.getProgramStages()) {
                map.put(ps.getUid(), new MetadataItem(ps.getDisplayName(), includeMetadataDetails ? ps : null));
            }
        }
    }
    return map;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) HashMap(java.util.HashMap) Calendar(org.hisp.dhis.calendar.Calendar) Period(org.hisp.dhis.period.Period) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) DimensionalObject(org.hisp.dhis.common.DimensionalObject) DataElement(org.hisp.dhis.dataelement.DataElement) DataDimensionalItemObject(org.hisp.dhis.common.DataDimensionalItemObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) ProgramStage(org.hisp.dhis.program.ProgramStage) MetadataItem(org.hisp.dhis.common.MetadataItem) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)98 Calendar (org.hisp.dhis.calendar.Calendar)23 Test (org.junit.jupiter.api.Test)17 Date (java.util.Date)15 DateInterval (org.hisp.dhis.calendar.DateInterval)10 Period (org.hisp.dhis.period.Period)6 DateTime (org.joda.time.DateTime)5 LocalDate (java.time.LocalDate)4 DimensionalObject (org.hisp.dhis.common.DimensionalObject)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 ArrayList (java.util.ArrayList)3 WeekFields (java.time.temporal.WeekFields)2 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 InvalidCalendarParametersException (org.hisp.dhis.calendar.exception.InvalidCalendarParametersException)2 DataDimensionalItemObject (org.hisp.dhis.common.DataDimensionalItemObject)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)2 DateUtils.getMediumDateString (org.hisp.dhis.util.DateUtils.getMediumDateString)2