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