Search in sources :

Example 16 with YearlyPeriodType

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

the class DataSetFrequencyComparatorTest method testA.

@Test
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));
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Test(org.junit.jupiter.api.Test)

Example 17 with YearlyPeriodType

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

the class DataSetApprovalFrequencyComparatorTest method testA.

@Test
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.assignWorkflow(workflow);
    dsD.assignWorkflow(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));
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Test(org.junit.jupiter.api.Test)

Example 18 with YearlyPeriodType

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

the class ValidationServiceTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    this.userService = injectUserService;
    CurrentUserService currentUserService = new MockCurrentUserService(allSources, null);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, validationService);
    ptWeekly = new WeeklyPeriodType();
    ptMonthly = new MonthlyPeriodType();
    ptYearly = 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);
    CategoryOption optionX = createCategoryOption('X');
    Category categoryX = createCategory('X', optionX);
    categoryComboX = createCategoryCombo('X', categoryX);
    optionComboX = createCategoryOptionCombo(categoryComboX, optionX);
    categoryComboX.getOptionCombos().add(optionComboX);
    categoryService.addCategoryOption(optionX);
    categoryService.addCategory(categoryX);
    categoryService.addCategoryCombo(categoryComboX);
    categoryService.addCategoryOptionCombo(optionComboX);
    optionCombo = categoryService.getDefaultCategoryOptionCombo();
    String suffixX = SEPARATOR + optionComboX.getUid();
    String suffix = SEPARATOR + optionCombo.getUid();
    optionCombos = new HashSet<>();
    optionCombos.add(optionCombo);
    Expression expressionA = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA");
    Expression expressionA2 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA2");
    Expression expressionA3 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA3");
    Expression expressionA4 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA4");
    Expression expressionA5 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA5");
    Expression expressionB = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB");
    Expression expressionB2 = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB2");
    Expression expressionB3 = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB3");
    Expression expressionC = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC");
    Expression expressionC2 = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC2");
    Expression expressionC3 = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC3");
    Expression expressionI = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI");
    Expression expressionI2 = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI2");
    Expression expressionI3 = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI3");
    Expression expressionJ = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionJ");
    Expression expressionJ2 = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionJ2");
    Expression expressionK = new Expression("#{" + dataElementC.getUid() + "}", "expressionK", NEVER_SKIP);
    Expression expressionL = new Expression("#{" + dataElementD.getUid() + "}", "expressionL", NEVER_SKIP);
    Expression expressionP = new Expression(SYMBOL_DAYS, "expressionP", NEVER_SKIP);
    Expression expressionP2 = new Expression(SYMBOL_DAYS, "expressionP2", NEVER_SKIP);
    Expression expressionQ = new Expression("#{" + dataElementE.getUid() + "}", "expressionQ", NEVER_SKIP);
    Expression expressionR = new Expression("#{" + dataElementA.getUid() + "} + #{" + dataElementB.getUid() + "}", "expressionR");
    Expression expressionS = new Expression("#{" + dataElementA.getUid() + suffixX + "} + #{" + dataElementB.getUid() + suffixX + "}", "expressionS");
    Expression expressionT = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffixX + "}", "expressionT");
    Expression expressionU = new Expression("1000", "expressionU");
    Expression expressionU2 = new Expression("1000", "expressionU2");
    Expression expressionU3 = new Expression("1000", "expressionU3");
    Expression expressionU4 = new Expression("1000", "expressionU4");
    periodA = createPeriod(ptMonthly, getDate(2000, 3, 1), getDate(2000, 3, 31));
    periodB = createPeriod(ptMonthly, getDate(2000, 4, 1), getDate(2000, 4, 30));
    periodC = createPeriod(ptMonthly, getDate(2000, 5, 1), getDate(2000, 5, 31));
    periodY = createPeriod(ptYearly, getDate(2000, 1, 1), getDate(2000, 12, 31));
    dayInPeriodA = periodService.getDayInPeriod(periodA, new Date());
    dayInPeriodB = periodService.getDayInPeriod(periodB, new Date());
    dayInPeriodC = periodService.getDayInPeriod(periodC, new Date());
    dayInPeriodY = periodService.getDayInPeriod(periodY, new Date());
    dataSetWeekly = createDataSet('W', ptWeekly);
    dataSetMonthly = createDataSet('M', ptMonthly);
    dataSetYearly = createDataSet('Y', ptYearly);
    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');
    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);
    orgUnitGroupA = createOrganisationUnitGroup('A');
    orgUnitGroupB = createOrganisationUnitGroup('B');
    orgUnitGroupC = createOrganisationUnitGroup('C');
    orgUnitGroupA.addOrganisationUnit(sourceB);
    orgUnitGroupA.addOrganisationUnit(sourceC);
    orgUnitGroupB.addOrganisationUnit(sourceD);
    orgUnitGroupB.addOrganisationUnit(sourceE);
    orgUnitGroupC.addOrganisationUnit(sourceE);
    orgUnitGroupC.addOrganisationUnit(sourceF);
    organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupA);
    organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupB);
    organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupC);
    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
    ruleA = createValidationRule("A", equal_to, expressionA, expressionB, ptMonthly);
    // deC - deD > deB * 2
    ruleB = createValidationRule("B", greater_than, expressionB2, expressionC, ptMonthly);
    // deC - deD <= deA + deB
    ruleC = createValidationRule("C", less_than_or_equal_to, expressionB3, expressionA2, ptMonthly);
    // deA + deB < deB * 2
    ruleD = createValidationRule("D", less_than, expressionA3, expressionC2, ptMonthly);
    // deA [Compulsory pair] deB
    ruleE = createValidationRule("E", compulsory_pair, expressionI, expressionJ, ptMonthly);
    // deA [Exclusive pair] deB
    ruleF = createValidationRule("F", exclusive_pair, expressionI2, expressionJ2, ptMonthly);
    // deC = DeD
    ruleG = createValidationRule("G", equal_to, expressionK, expressionL, ptMonthly);
    // deA = [days]
    ruleP = createValidationRule("P", equal_to, expressionI3, expressionP, ptMonthly);
    // deE = [days]
    ruleQ = createValidationRule("Q", equal_to, expressionQ, expressionP2, ptYearly);
    // deA(sum) + deB(sum) = 1000
    ruleR = createValidationRule("R", equal_to, expressionR, expressionU, ptMonthly);
    // deA.optionComboX + deB.optionComboX = 1000
    ruleS = createValidationRule("S", equal_to, expressionS, expressionU2, ptMonthly);
    // deA.default + deB.optionComboX = 1000
    ruleT = createValidationRule("T", equal_to, expressionT, expressionU3, ptMonthly);
    // deA.default + deB.default = 1000
    ruleU = createValidationRule("U", equal_to, expressionA4, expressionU4, ptMonthly);
    // deA + deB = deB * 2
    ruleX = createValidationRule("X", equal_to, expressionA5, expressionC3, ptMonthly);
    group = createValidationRuleGroup('A');
    defaultCombo = categoryService.getDefaultCategoryOptionCombo();
}
Also used : WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) Category(org.hisp.dhis.category.Category) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Expression(org.hisp.dhis.expression.Expression) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) CategoryOption(org.hisp.dhis.category.CategoryOption) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Date(java.util.Date)

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