Search in sources :

Example 11 with PeriodType

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

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

the class DataQueryParams method getDataSetPeriodTypeMap.

/**
     * Returns a mapping between identifier and period type for all data sets
     * in this query.
     */
public Map<String, PeriodType> getDataSetPeriodTypeMap() {
    Map<String, PeriodType> map = new HashMap<>();
    for (DimensionalItemObject reportingRate : getReportingRates()) {
        ReportingRate rr = (ReportingRate) reportingRate;
        DataSet ds = rr.getDataSet();
        map.put(ds.getUid(), ds.getPeriodType());
    }
    return map;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.dataset.DataSet)

Example 13 with PeriodType

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

the class ResourceTableServiceTest method setUpTest.

@Override
public void setUpTest() {
    PeriodType pt = new MonthlyPeriodType();
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    idObjectManager.save(deA);
    idObjectManager.save(deB);
    DataElementGroup degA = createDataElementGroup('A');
    DataElementGroup degB = createDataElementGroup('B');
    degA.addDataElement(deA);
    degB.addDataElement(deB);
    idObjectManager.save(degA);
    idObjectManager.save(degB);
    DataElementGroupSet degsA = createDataElementGroupSet('A');
    degsA.addDataElementGroup(degA);
    degsA.addDataElementGroup(degB);
    idObjectManager.save(degsA);
    OrganisationUnit ouA = createOrganisationUnit('A');
    OrganisationUnit ouB = createOrganisationUnit('B');
    OrganisationUnit ouC = createOrganisationUnit('C');
    ouB.setParent(ouA);
    ouC.setParent(ouA);
    ouA.getChildren().add(ouB);
    ouA.getChildren().add(ouC);
    idObjectManager.save(ouA);
    idObjectManager.save(ouB);
    idObjectManager.save(ouC);
    DataSet dsA = createDataSet('A', pt);
    DataSet dsB = createDataSet('B', pt);
    dsA.addDataSetElement(deA);
    dsB.addDataSetElement(deA);
    dsA.addOrganisationUnit(ouA);
    dsB.addOrganisationUnit(ouA);
    dataSetService.addDataSet(dsA);
    dataSetService.addDataSet(dsB);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DataSet(org.hisp.dhis.dataset.DataSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup)

Example 14 with PeriodType

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

the class DefaultQueryPlanner method groupByAggregationType.

/**
     * Groups the given query in sub queries based on the aggregation type of its
     * data elements. The aggregation type can be sum, average aggregation or
     * average disaggregation. Sum means that the data elements have sum aggregation
     * operator. Average aggregation means that the data elements have the average
     * aggregation operator and that the period type of the data elements have
     * higher or equal frequency than the aggregation period type. Average disaggregation
     * means that the data elements have the average aggregation operator and
     * that the period type of the data elements have lower frequency than the
     * aggregation period type. Average bool means that the data elements have the
     * average aggregation operator and the bool value type.
     * <p>
     * If no data elements are present, the aggregation type will be determined
     * based on the first data element in the first data element group in the
     * first data element group set in the query.
     * <p>
     * If the aggregation type is already set/overridden in the request, the
     * query will be returned unchanged. If there are no data elements or data
     * element group sets specified the aggregation type will fall back to sum.
     * 
     * @param params the data query parameters.
     * @return a list of {@link DataQueryParams}.
     */
private List<DataQueryParams> groupByAggregationType(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (!params.getDataElements().isEmpty()) {
        ListMap<AggregationType, DimensionalItemObject> aggregationTypeDataElementMap = QueryPlannerUtils.getAggregationTypeDataElementMap(params);
        for (AggregationType aggregationType : aggregationTypeDataElementMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).withDataElements(aggregationTypeDataElementMap.get(aggregationType)).withAggregationType(aggregationType).build();
            queries.add(query);
        }
    } else if (!params.getDataElementGroupSets().isEmpty()) {
        DimensionalObject degs = params.getDataElementGroupSets().get(0);
        DataElementGroup deg = (DataElementGroup) (degs.hasItems() ? degs.getItems().get(0) : null);
        AggregationType aggregationType = ObjectUtils.firstNonNull(params.getAggregationType(), SUM);
        if (deg != null && !deg.getMembers().isEmpty()) {
            PeriodType periodType = PeriodType.getPeriodTypeByName(params.getPeriodType());
            aggregationType = ObjectUtils.firstNonNull(params.getAggregationType(), deg.getAggregationType());
            aggregationType = QueryPlannerUtils.getAggregationType(deg.getValueType(), aggregationType, periodType, deg.getPeriodType());
        }
        DataQueryParams query = DataQueryParams.newBuilder(params).withAggregationType(aggregationType).build();
        queries.add(query);
    } else {
        DataQueryParams query = DataQueryParams.newBuilder(params).withAggregationType(ObjectUtils.firstNonNull(params.getAggregationType(), SUM)).build();
        queries.add(query);
    }
    if (queries.size() > 1) {
        log.debug(String.format("Split on aggregation type: %d", queries.size()));
    }
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) PeriodType(org.hisp.dhis.period.PeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) AggregationType(org.hisp.dhis.analytics.AggregationType) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 15 with PeriodType

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

the class DefaultPredictorService method getSamplePeriodsMap.

/**
     * Creates a map relating each output period to a list of sample periods
     * from which the sample data is to be drawn.
     *
     * @param outputPeriods the output periods
     * @param predictor the predictor
     * @return map from output periods to sample periods
     */
private ListMap<Period, Period> getSamplePeriodsMap(List<Period> outputPeriods, Predictor predictor) {
    int sequentialCount = predictor.getSequentialSampleCount();
    int annualCount = predictor.getAnnualSampleCount();
    int skipCount = firstNonNull(predictor.getSequentialSkipCount(), 0);
    PeriodType periodType = predictor.getPeriodType();
    ListMap<Period, Period> samplePeriodsMap = new ListMap<Period, Period>();
    for (Period outputPeriod : outputPeriods) {
        samplePeriodsMap.put(outputPeriod, new ArrayList<Period>());
        Period p = periodType.getPreviousPeriod(outputPeriod, skipCount);
        for (int i = skipCount; i < sequentialCount; i++) {
            p = periodType.getPreviousPeriod(p);
            addPeriod(samplePeriodsMap, outputPeriod, p);
        }
        for (int year = 1; year <= annualCount; year++) {
            Period pPrev = periodType.getPreviousYearsPeriod(outputPeriod, year);
            Period pNext = pPrev;
            addPeriod(samplePeriodsMap, outputPeriod, pPrev);
            for (int i = 0; i < sequentialCount; i++) {
                pPrev = periodType.getPreviousPeriod(pPrev);
                pNext = periodType.getNextPeriod(pNext);
                addPeriod(samplePeriodsMap, outputPeriod, pPrev);
                addPeriod(samplePeriodsMap, outputPeriod, pNext);
            }
        }
    }
    return samplePeriodsMap;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Period(org.hisp.dhis.period.Period) ListMap(org.hisp.dhis.common.ListMap)

Aggregations

PeriodType (org.hisp.dhis.period.PeriodType)67 Period (org.hisp.dhis.period.Period)21 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)13 ArrayList (java.util.ArrayList)12 DataSet (org.hisp.dhis.dataset.DataSet)12 DataElement (org.hisp.dhis.dataelement.DataElement)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)7 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)6 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)6 ProgramStage (org.hisp.dhis.program.ProgramStage)6 Test (org.junit.Test)6 Date (java.util.Date)5 HashSet (java.util.HashSet)5 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)5 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)4 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)4 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)4 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)4