Search in sources :

Example 1 with YearlyPeriodType

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

the class FacilityReportingServiceImpl method getMobileDataSetsForUnit.

// -------------------------------------------------------------------------
// Service methods
// -------------------------------------------------------------------------
@Override
public List<DataSet> getMobileDataSetsForUnit(OrganisationUnit unit, String localeString) {
    List<DataSet> datasets = new ArrayList<>();
    Locale locale = LocaleUtil.getLocale(localeString);
    if (DEBUG)
        log.debug("Getting data sets for unit " + unit.getName());
    for (org.hisp.dhis.dataset.DataSet dataSet : dataSetService.getDataSetsForMobile(unit)) {
        PeriodType periodType = dataSet.getPeriodType();
        if (periodType instanceof DailyPeriodType || periodType instanceof WeeklyPeriodType || periodType instanceof MonthlyPeriodType || periodType instanceof YearlyPeriodType || periodType instanceof QuarterlyPeriodType) {
            if (DEBUG)
                log.debug("Found data set " + dataSet.getName());
            datasets.add(getDataSetForLocale(dataSet.getId(), locale));
        } else {
            log.warn("Dataset '" + dataSet.getName() + "' set to be reported from mobile, but not of a supported period type: " + periodType.getName());
        }
    }
    return datasets;
}
Also used : Locale(java.util.Locale) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.api.mobile.model.DataSet) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) ArrayList(java.util.ArrayList) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType)

Example 2 with YearlyPeriodType

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

the class AnalyticsManagerTest method testWeightedAverage.

@ParameterizedTest
@MethodSource("data")
public void testWeightedAverage(String financialYear, Double weightedAverage) {
    analyticsManager = new JdbcAnalyticsManager(queryPlanner, jdbcTemplate, executionPlanStore);
    AnalyticsAggregationType aggregationType = new AnalyticsAggregationType(AggregationType.SUM, AggregationType.AVERAGE, DataType.NUMERIC, true);
    Period y2017 = createPeriod("2017");
    Period y2018 = createPeriod("2018");
    Period finYear2017 = createPeriod(financialYear);
    Map<String, Object> dataValueMap = new HashMap<>();
    dataValueMap.put(BASE_UID + "-2018", 1.0);
    dataValueMap.put(BASE_UID + "-2017", 154.0);
    ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap = new ListMap<>();
    dataPeriodAggregationPeriodMap.putValue(y2017, finYear2017);
    dataPeriodAggregationPeriodMap.putValue(y2018, finYear2017);
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(createDataElement('A'), createDataElement('B'))).withPeriods(getList(y2017, y2018)).withDataPeriodType(new YearlyPeriodType()).withAggregationType(aggregationType).build();
    analyticsManager.replaceDataPeriodsWithAggregationPeriods(dataValueMap, params, dataPeriodAggregationPeriodMap);
    assertEquals(1, dataValueMap.size());
    assertThat(dataValueMap.get(BASE_UID + "-" + finYear2017.getIsoDate()), is(weightedAverage));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) Period(org.hisp.dhis.period.Period) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) ListMap(org.hisp.dhis.common.ListMap) AnalyticsAggregationType(org.hisp.dhis.analytics.AnalyticsAggregationType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with YearlyPeriodType

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

the class AnalyticsTableTest method testGetTablePartitionName.

@Test
void testGetTablePartitionName() {
    Program program = new Program("ProgramA", "DescriptionA");
    program.setUid("UIDA");
    Period periodA = new YearlyPeriodType().createPeriod(new DateTime(2014, 1, 1, 0, 0).toDate());
    Period periodB = new YearlyPeriodType().createPeriod(new DateTime(2015, 1, 1, 0, 0).toDate());
    AnalyticsTable tableA = new AnalyticsTable(AnalyticsTableType.EVENT, Lists.newArrayList(), Lists.newArrayList(), program);
    tableA.addPartitionTable(2014, periodA.getStartDate(), periodA.getEndDate());
    tableA.addPartitionTable(2015, periodB.getStartDate(), periodB.getEndDate());
    AnalyticsTablePartition partitionA = tableA.getTablePartitions().get(0);
    AnalyticsTablePartition partitionB = tableA.getTablePartitions().get(1);
    assertNotNull(partitionA);
    assertNotNull(partitionB);
    assertEquals("analytics_event_uida_2014", partitionA.getTableName());
    assertEquals("analytics_event_uida_2015", partitionB.getTableName());
    assertEquals("analytics_event_temp_uida_2014", partitionA.getTempTableName());
    assertEquals("analytics_event_temp_uida_2015", partitionB.getTempTableName());
}
Also used : Program(org.hisp.dhis.program.Program) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) Period(org.hisp.dhis.period.Period) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) AnalyticsTablePartition(org.hisp.dhis.analytics.AnalyticsTablePartition) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 4 with YearlyPeriodType

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

the class DataApprovalWorkflowTest method testGetWorkflowSqlCoEnddateExtension.

/**
 * Note that as part of the following test, we are checking to be sure that
 * the longest extension to the category option end date is returned from
 * data sets that are successively added to the workflow. The total
 * extension length (period length times number of periods) is always
 * increasing as we add data sets to the workflow. The most recently-added
 * data set always has the longest total extension so far.
 */
@Test
void testGetWorkflowSqlCoEnddateExtension() {
    DataSet noPeriodsAfterCoEndDate = createDataSet("noPeriodsAfterCoEndDate", new MonthlyPeriodType(), 0);
    DataSet dailyDs = createDataSet("dailyDs", new DailyPeriodType(), 3);
    DataSet weeklyDs = createDataSet("weeklyDs", new WeeklyPeriodType(), 3);
    DataSet weeklyWedDs = createDataSet("weeklyWedDs", new WeeklyWednesdayPeriodType(), 4);
    DataSet weeklyThuDs = createDataSet("weeklyThuDs", new WeeklyThursdayPeriodType(), 5);
    DataSet weeklySatDs = createDataSet("weeklySatDs", new WeeklySaturdayPeriodType(), 6);
    DataSet weeklySunDs = createDataSet("weeklySunDs", new WeeklySundayPeriodType(), 7);
    DataSet biWeeklyDs = createDataSet("biWeeklyDs", new BiWeeklyPeriodType(), 4);
    DataSet monthlyDs = createDataSet("monthlyDs", new MonthlyPeriodType(), 3);
    DataSet biMonthlyDs = createDataSet("biMonthlyDs", new BiMonthlyPeriodType(), 3);
    DataSet querterlyDs = createDataSet("querterlyDs", new QuarterlyPeriodType(), 3);
    DataSet sixMonthlyDs = createDataSet("sixMonthlyDs", new SixMonthlyPeriodType(), 3);
    DataSet sixMonthlyAprDs = createDataSet("sixMonthlyAprDs", new SixMonthlyAprilPeriodType(), 4);
    DataSet sixMonthlyNovDs = createDataSet("sixMonthlyNovDs", new SixMonthlyNovemberPeriodType(), 5);
    DataSet yearlyDs = createDataSet("yearlyDs", new YearlyPeriodType(), 3);
    DataSet financialAprDs = createDataSet("financialAprDs", new FinancialAprilPeriodType(), 4);
    DataSet financialJulDs = createDataSet("financialJulDs", new FinancialJulyPeriodType(), 5);
    DataSet financialOctDs = createDataSet("financialOctDs", new FinancialOctoberPeriodType(), 6);
    DataSet financialNovDs = createDataSet("financialNovDs", new FinancialNovemberPeriodType(), 7);
    DataSet twoYearlyDs = createDataSet("twoYearlyDs", new TwoYearlyPeriodType(), 4);
    DataApprovalWorkflow workflow = new DataApprovalWorkflow("test workflow", new DailyPeriodType(), newHashSet());
    assertEquals("", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(noPeriodsAfterCoEndDate);
    assertEquals("", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(dailyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 day'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklyWedDs);
    assertEquals(" + 4 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklyThuDs);
    assertEquals(" + 5 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklySatDs);
    assertEquals(" + 6 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklySunDs);
    assertEquals(" + 7 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(biWeeklyDs);
    assertEquals(" + 4 * INTERVAL '+ 2 weeks'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(monthlyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 month'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(biMonthlyDs);
    assertEquals(" + 3 * INTERVAL '+ 2 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(querterlyDs);
    assertEquals(" + 3 * INTERVAL '+ 3 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(sixMonthlyDs);
    assertEquals(" + 3 * INTERVAL '+ 6 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(sixMonthlyAprDs);
    assertEquals(" + 4 * INTERVAL '+ 6 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(sixMonthlyNovDs);
    assertEquals(" + 5 * INTERVAL '+ 6 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(yearlyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialAprDs);
    assertEquals(" + 4 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialJulDs);
    assertEquals(" + 5 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialOctDs);
    assertEquals(" + 6 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialNovDs);
    assertEquals(" + 7 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(twoYearlyDs);
    assertEquals(" + 4 * INTERVAL '+ 2 years'", workflow.getSqlCoEndDateExtension());
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) WeeklySaturdayPeriodType(org.hisp.dhis.period.WeeklySaturdayPeriodType) SixMonthlyNovemberPeriodType(org.hisp.dhis.period.SixMonthlyNovemberPeriodType) DataSet(org.hisp.dhis.dataset.DataSet) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) TwoYearlyPeriodType(org.hisp.dhis.period.TwoYearlyPeriodType) WeeklySundayPeriodType(org.hisp.dhis.period.WeeklySundayPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) FinancialNovemberPeriodType(org.hisp.dhis.period.FinancialNovemberPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) WeeklyWednesdayPeriodType(org.hisp.dhis.period.WeeklyWednesdayPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType) TwoYearlyPeriodType(org.hisp.dhis.period.TwoYearlyPeriodType) WeeklyThursdayPeriodType(org.hisp.dhis.period.WeeklyThursdayPeriodType) Test(org.junit.jupiter.api.Test)

Example 5 with YearlyPeriodType

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

the class IdentifiableObjectUtilsTest method testGetPeriodByPeriodType.

@Test
void testGetPeriodByPeriodType() {
    Calendar calendar = Iso8601Calendar.getInstance();
    WeeklyPeriodType weekly = new WeeklyPeriodType();
    MonthlyPeriodType monthly = new MonthlyPeriodType();
    QuarterlyPeriodType quarterly = new QuarterlyPeriodType();
    YearlyPeriodType yearly = new YearlyPeriodType();
    assertEquals(PeriodType.getPeriodFromIsoString("2017W10"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("20170308"), weekly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("2017W9"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("20170301"), weekly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201702"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017W8"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201703"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017W9"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201705"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017W21"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201706"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017W22"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201708"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017W35"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201702"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017WedW8"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201703"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017WedW9"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201702"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017ThuW8"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201703"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017ThuW10"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201702"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SatW7"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201703"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SatW10"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201702"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SunW7"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201703"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SunW9"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201702"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SunW7"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201703"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SunW9"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("2017Q1"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("201703"), quarterly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("2017Q2"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("201704"), quarterly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("2016"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2016Q4"), yearly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("2017"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017Q1"), yearly, calendar));
    assertNull(PeriodType.getPeriodFromIsoString("u3847847"));
}
Also used : WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) Iso8601Calendar(org.hisp.dhis.calendar.impl.Iso8601Calendar) Calendar(org.hisp.dhis.calendar.Calendar) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Test(org.junit.jupiter.api.Test)

Aggregations

YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)18 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)11 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)10 Test (org.junit.jupiter.api.Test)9 WeeklyPeriodType (org.hisp.dhis.period.WeeklyPeriodType)8 Period (org.hisp.dhis.period.Period)6 DataSet (org.hisp.dhis.dataset.DataSet)5 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)5 Calendar (java.util.Calendar)4 AnalyticsAggregationType (org.hisp.dhis.analytics.AnalyticsAggregationType)3 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)3 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)2 ListMap (org.hisp.dhis.common.ListMap)2 Expression (org.hisp.dhis.expression.Expression)2 BiMonthlyPeriodType (org.hisp.dhis.period.BiMonthlyPeriodType)2 BiWeeklyPeriodType (org.hisp.dhis.period.BiWeeklyPeriodType)2