use of org.hisp.dhis.period.YearlyPeriodType 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));
}
use of org.hisp.dhis.period.YearlyPeriodType 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);
}
use of org.hisp.dhis.period.YearlyPeriodType in project dhis2-core by dhis2.
the class DataSetApprovalFrequencyComparatorTest method testA.
@Test
public void testA() {
DataSet dsA = new DataSet("DataSetA", new YearlyPeriodType());
DataSet dsB = new DataSet("DataSetB", new YearlyPeriodType());
DataSet dsC = new DataSet("DataSetC", new MonthlyPeriodType());
DataSet dsD = new DataSet("DataSetD", new QuarterlyPeriodType());
DataApprovalWorkflow workflow = new DataApprovalWorkflow("Workflow A", new QuarterlyPeriodType(), null);
dsA.setWorkflow(workflow);
dsD.setWorkflow(workflow);
List<DataSet> list = Lists.newArrayList(dsA, dsC, dsB, dsD);
Collections.sort(list, DataSetApprovalFrequencyComparator.INSTANCE);
assertEquals(dsD, list.get(0));
assertEquals(dsA, list.get(1));
assertEquals(dsC, list.get(2));
assertEquals(dsB, list.get(3));
}
use of org.hisp.dhis.period.YearlyPeriodType in project dhis2-core by dhis2.
the class DataSetFrequencyComparatorTest method testA.
@Test
public void testA() {
DataSet dsA = new DataSet("DataSetA", new QuarterlyPeriodType());
DataSet dsB = new DataSet("DataSetB", new YearlyPeriodType());
DataSet dsC = new DataSet("DataSetC", new MonthlyPeriodType());
DataSet dsD = new DataSet("DataSetD", new QuarterlyPeriodType());
List<DataSet> list = Lists.newArrayList(dsA, dsC, dsB, dsD);
Collections.sort(list, DataSetFrequencyComparator.INSTANCE);
assertEquals(dsC, list.get(0));
assertEquals(dsA, list.get(1));
assertEquals(dsD, list.get(2));
assertEquals(dsB, list.get(3));
}
use of org.hisp.dhis.period.YearlyPeriodType in project dhis2-core by dhis2.
the class AnalyticsManagerTest method testReplaceDataPeriodsWithAggregationPeriods.
@Test
public void testReplaceDataPeriodsWithAggregationPeriods() {
Period y2012 = createPeriod("2012");
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(createDataElement('A'), createDataElement('B'))).withPeriods(getList(y2012)).withOrganisationUnits(getList(createOrganisationUnit('A'))).withDataPeriodType(new YearlyPeriodType()).withAggregationType(AggregationType.AVERAGE_SUM_INT_DISAGGREGATION).build();
Map<String, Object> dataValueMap = new HashMap<>();
dataValueMap.put(BASE_UID + "A-2012-" + BASE_UID + "A", 1d);
dataValueMap.put(BASE_UID + "B-2012-" + BASE_UID + "A", 1d);
ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap = new ListMap<>();
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q1"));
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q2"));
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q3"));
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q4"));
analyticsManager.replaceDataPeriodsWithAggregationPeriods(dataValueMap, params, dataPeriodAggregationPeriodMap);
assertEquals(8, dataValueMap.size());
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q1-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q2-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q3-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q4-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q1-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q2-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q3-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q4-" + BASE_UID + "A"));
}
Aggregations