Search in sources :

Example 11 with MonthlyPeriodType

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

the class IdentifiableObjectUtilsTest method testGetPeriodByPeriodType.

@Test
public 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("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("2017ThuW9"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201702"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SatW7"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201703"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SatW8"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201702"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SunW7"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201703"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SunW8"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201702"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SunW7"), monthly, calendar));
    assertEquals(PeriodType.getPeriodFromIsoString("201703"), IdentifiableObjectUtils.getPeriodByPeriodType(PeriodType.getPeriodFromIsoString("2017SunW8"), 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));
}
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.Test)

Example 12 with MonthlyPeriodType

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

the class ChartServiceTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    // ---------------------------------------------------------------------
    // Indicator
    // ---------------------------------------------------------------------
    IndicatorType indicatorType = createIndicatorType('A');
    indicatorA = createIndicator('A', indicatorType);
    indicatorB = createIndicator('B', indicatorType);
    indicatorC = createIndicator('C', indicatorType);
    indicatorService.addIndicatorType(indicatorType);
    indicatorService.addIndicator(indicatorA);
    indicatorService.addIndicator(indicatorB);
    indicatorService.addIndicator(indicatorC);
    List<Indicator> indicators = new ArrayList<>();
    indicators.add(indicatorA);
    indicators.add(indicatorB);
    indicators.add(indicatorC);
    // ---------------------------------------------------------------------
    // Period
    // ---------------------------------------------------------------------
    PeriodType periodType = new MonthlyPeriodType();
    periodA = createPeriod(periodType, getDate(2000, 1, 1), getDate(2000, 1, 2));
    periodB = createPeriod(periodType, getDate(2000, 1, 3), getDate(2000, 1, 4));
    periodC = createPeriod(periodType, getDate(2000, 1, 5), getDate(2000, 1, 6));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    periodService.addPeriod(periodC);
    List<Period> periods = new ArrayList<>();
    periods.add(periodA);
    periods.add(periodB);
    periods.add(periodC);
    // ---------------------------------------------------------------------
    // OrganisationUnit
    // ---------------------------------------------------------------------
    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B');
    organisationUnitService.addOrganisationUnit(unitA);
    organisationUnitService.addOrganisationUnit(unitB);
    List<OrganisationUnit> units = new ArrayList<>();
    units.add(unitA);
    units.add(unitB);
    chartA = createChart('A', indicators, periods, units);
    chartA.setType(ChartType.BAR);
    chartB = createChart('B', indicators, periods, units);
    chartB.setType(ChartType.BAR);
    chartC = createChart('C', indicators, periods, units);
    chartC.setType(ChartType.BAR);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) IndicatorType(org.hisp.dhis.indicator.IndicatorType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Indicator(org.hisp.dhis.indicator.Indicator)

Example 13 with MonthlyPeriodType

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

the class ValidationRuleServiceTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    periodTypeWeekly = new WeeklyPeriodType();
    periodTypeMonthly = new MonthlyPeriodType();
    periodTypeYearly = new YearlyPeriodType();
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementC = createDataElement('C');
    dataElementD = createDataElement('D');
    dataElementE = createDataElement('E');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    dataElementService.addDataElement(dataElementE);
    optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    String suffix = SEPARATOR + optionCombo.getUid();
    optionCombos = new HashSet<>();
    optionCombos.add(optionCombo);
    expressionA = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA");
    expressionB = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB");
    expressionC = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC");
    expressionService.addExpression(expressionA);
    expressionService.addExpression(expressionB);
    expressionService.addExpression(expressionC);
    dataSetWeekly = createDataSet('W', periodTypeWeekly);
    dataSetMonthly = createDataSet('M', periodTypeMonthly);
    dataSetYearly = createDataSet('Y', periodTypeYearly);
    sourceA = createOrganisationUnit('A');
    sourceB = createOrganisationUnit('B');
    sourceC = createOrganisationUnit('C', sourceB);
    sourceD = createOrganisationUnit('D', sourceB);
    sourceE = createOrganisationUnit('E', sourceD);
    sourceF = createOrganisationUnit('F', sourceD);
    sourceG = createOrganisationUnit('G');
    sourcesA.add(sourceA);
    sourcesA.add(sourceB);
    allSources.add(sourceA);
    allSources.add(sourceB);
    allSources.add(sourceC);
    allSources.add(sourceD);
    allSources.add(sourceE);
    allSources.add(sourceF);
    allSources.add(sourceG);
    dataSetMonthly.addOrganisationUnit(sourceA);
    dataSetMonthly.addOrganisationUnit(sourceB);
    dataSetMonthly.addOrganisationUnit(sourceC);
    dataSetMonthly.addOrganisationUnit(sourceD);
    dataSetMonthly.addOrganisationUnit(sourceE);
    dataSetMonthly.addOrganisationUnit(sourceF);
    dataSetWeekly.addOrganisationUnit(sourceB);
    dataSetWeekly.addOrganisationUnit(sourceC);
    dataSetWeekly.addOrganisationUnit(sourceD);
    dataSetWeekly.addOrganisationUnit(sourceE);
    dataSetWeekly.addOrganisationUnit(sourceF);
    dataSetWeekly.addOrganisationUnit(sourceG);
    dataSetYearly.addOrganisationUnit(sourceB);
    dataSetYearly.addOrganisationUnit(sourceC);
    dataSetYearly.addOrganisationUnit(sourceD);
    dataSetYearly.addOrganisationUnit(sourceE);
    dataSetYearly.addOrganisationUnit(sourceF);
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    organisationUnitService.addOrganisationUnit(sourceC);
    organisationUnitService.addOrganisationUnit(sourceD);
    organisationUnitService.addOrganisationUnit(sourceE);
    organisationUnitService.addOrganisationUnit(sourceF);
    organisationUnitService.addOrganisationUnit(sourceG);
    dataSetMonthly.addDataSetElement(dataElementA);
    dataSetMonthly.addDataSetElement(dataElementB);
    dataSetMonthly.addDataSetElement(dataElementC);
    dataSetMonthly.addDataSetElement(dataElementD);
    dataSetWeekly.addDataSetElement(dataElementE);
    dataSetYearly.addDataSetElement(dataElementE);
    dataSetService.addDataSet(dataSetWeekly);
    dataSetService.addDataSet(dataSetMonthly);
    dataSetService.addDataSet(dataSetYearly);
    dataElementService.updateDataElement(dataElementA);
    dataElementService.updateDataElement(dataElementB);
    dataElementService.updateDataElement(dataElementC);
    dataElementService.updateDataElement(dataElementD);
    dataElementService.updateDataElement(dataElementE);
    // deA + deB = deC - deD
    validationRuleA = createValidationRule("A", equal_to, expressionA, expressionB, periodTypeMonthly);
    // deC - deD > deB * 2
    validationRuleB = createValidationRule("B", greater_than, expressionB, expressionC, periodTypeMonthly);
}
Also used : WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Expression(org.hisp.dhis.expression.Expression) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType)

Example 14 with MonthlyPeriodType

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

the class UniqueArrayListTest method testAdd.

@Test
public void testAdd() {
    List<Period> list = new UniqueArrayList<>();
    PeriodType periodType = new MonthlyPeriodType();
    Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    // Duplicate
    Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
    list.add(peA);
    list.add(peB);
    list.add(peC);
    assertEquals(2, list.size());
    assertTrue(list.contains(peA));
    assertTrue(list.contains(peB));
    assertTrue(list.contains(peC));
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 15 with MonthlyPeriodType

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

the class UniqueArrayListTest method testAddAll.

@Test
public void testAddAll() {
    List<Period> list = new ArrayList<>();
    PeriodType periodType = new MonthlyPeriodType();
    Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    // Duplicate
    Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
    list.add(peA);
    list.add(peB);
    list.add(peC);
    assertEquals(3, list.size());
    List<Period> uniqueList = new UniqueArrayList<>();
    uniqueList.addAll(list);
    assertEquals(2, uniqueList.size());
    assertTrue(uniqueList.contains(peA));
    assertTrue(uniqueList.contains(peB));
    assertTrue(uniqueList.contains(peC));
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)33 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)12 Test (org.junit.Test)12 Period (org.hisp.dhis.period.Period)11 PeriodType (org.hisp.dhis.period.PeriodType)11 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)10 DataSet (org.hisp.dhis.dataset.DataSet)8 ArrayList (java.util.ArrayList)7 WeeklyPeriodType (org.hisp.dhis.period.WeeklyPeriodType)6 DateTime (org.joda.time.DateTime)5 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)2 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)2 Indicator (org.hisp.dhis.indicator.Indicator)2