Search in sources :

Example 1 with CategoryOption

use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.

the class AnalyticsServiceTest method setUpTest.

// Database (value, data element, period)
// --------------------------------------------------------------------
// 
// A: 2, deA, peJan - 4, deB, peFeb - 6, deC, peMar - 8, deD, peApril
// 100, deB, peJan - 2, deD, peFeb
// 
// B: 1, deA, peJan - 3, deB, peFeb - 5, deC, peMar - 7, deD, peApril
// 
// C: 5, deA, peJan - 10, deB, peFeb - 15, deC, peMar - 20, deD, peApril
// 4, deD, peJan - 23, deC, peFeb
// 
// D: 66, deA, peJan - 233, deA, peFeb - 399, deB, peFeb
// 
// E: 1, deA, peJan - 1, deB, peFeb - 1, deC, peMar - 1, deD, peApril
// 32, deD, peJan
// 
// --------------------------------------------------------------------
@Override
public void setUpTest() throws IOException, InterruptedException {
    // Set up meta data for data values
    ReportingRate reportingRateA;
    ReportingRate reportingRateB;
    ocDef = categoryService.getDefaultCategoryOptionCombo();
    ocDef.setUid("o1234578def");
    categoryService.updateCategoryOptionCombo(ocDef);
    catDef = categoryService.getDefaultCategory();
    catDef.setUid("cat12345def");
    categoryService.updateCategory(catDef);
    Period peJan = createPeriod("2017-01");
    Period peFeb = createPeriod("2017-02");
    Period peMar = createPeriod("2017-03");
    Period peApril = createPeriod("2017-04");
    Period peMay = createPeriod("2017-05");
    Period peJune = createPeriod("2017-06");
    Period peJuly = createPeriod("2017-07");
    Period quarter = createPeriod("2017Q1");
    periodService.addPeriod(peJan);
    periodService.addPeriod(peFeb);
    periodService.addPeriod(peMar);
    periodService.addPeriod(peApril);
    periodService.addPeriod(peMay);
    periodService.addPeriod(peJune);
    periodService.addPeriod(peJuly);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    DataElement deC = createDataElement('C');
    DataElement deD = createDataElement('D');
    DataElement deE = createDataElement('E');
    deE.setValueType(ValueType.INTEGER);
    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    dataElementService.addDataElement(deC);
    dataElementService.addDataElement(deD);
    dataElementService.addDataElement(deE);
    OrganisationUnit ouA = createOrganisationUnit('A');
    OrganisationUnit ouB = createOrganisationUnit('B');
    OrganisationUnit ouC = createOrganisationUnit('C');
    ouC.setOpeningDate(getDate(2016, 4, 10));
    ouC.setClosedDate(null);
    OrganisationUnit ouD = createOrganisationUnit('D');
    ouD.setOpeningDate(getDate(2016, 12, 10));
    ouD.setClosedDate(null);
    OrganisationUnit ouE = createOrganisationUnit('E');
    AnalyticsTestUtils.configureHierarchy(ouA, ouB, ouC, ouD, ouE);
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    organisationUnitService.addOrganisationUnit(ouD);
    organisationUnitService.addOrganisationUnit(ouE);
    OrganisationUnitGroup organisationUnitGroupA = createOrganisationUnitGroup('A');
    organisationUnitGroupA.setUid("a2345groupA");
    organisationUnitGroupA.addOrganisationUnit(ouA);
    organisationUnitGroupA.addOrganisationUnit(ouB);
    OrganisationUnitGroup organisationUnitGroupB = createOrganisationUnitGroup('B');
    organisationUnitGroupB.setUid("a2345groupB");
    organisationUnitGroupB.addOrganisationUnit(ouC);
    organisationUnitGroupB.addOrganisationUnit(ouD);
    organisationUnitGroupB.addOrganisationUnit(ouE);
    OrganisationUnitGroup organisationUnitGroupC = createOrganisationUnitGroup('C');
    organisationUnitGroupC.setUid("a2345groupC");
    organisationUnitGroupC.addOrganisationUnit(ouA);
    organisationUnitGroupC.addOrganisationUnit(ouB);
    organisationUnitGroupC.addOrganisationUnit(ouC);
    OrganisationUnitGroup organisationUnitGroupD = createOrganisationUnitGroup('D');
    organisationUnitGroupD.setUid("a2345groupD");
    organisationUnitGroupD.addOrganisationUnit(ouD);
    organisationUnitGroupD.addOrganisationUnit(ouE);
    organisationUnitGroupService.addOrganisationUnitGroup(organisationUnitGroupA);
    organisationUnitGroupService.addOrganisationUnitGroup(organisationUnitGroupB);
    organisationUnitGroupService.addOrganisationUnitGroup(organisationUnitGroupC);
    organisationUnitGroupService.addOrganisationUnitGroup(organisationUnitGroupD);
    OrganisationUnitGroupSet organisationUnitGroupSetA = createOrganisationUnitGroupSet('A');
    organisationUnitGroupSetA.setUid("a234567setA");
    OrganisationUnitGroupSet organisationUnitGroupSetB = createOrganisationUnitGroupSet('B');
    organisationUnitGroupSetB.setUid("a234567setB");
    organisationUnitGroupSetA.getOrganisationUnitGroups().add(organisationUnitGroupA);
    organisationUnitGroupSetA.getOrganisationUnitGroups().add(organisationUnitGroupB);
    organisationUnitGroupSetB.getOrganisationUnitGroups().add(organisationUnitGroupC);
    organisationUnitGroupSetB.getOrganisationUnitGroups().add(organisationUnitGroupD);
    organisationUnitGroupService.addOrganisationUnitGroupSet(organisationUnitGroupSetA);
    organisationUnitGroupService.addOrganisationUnitGroupSet(organisationUnitGroupSetB);
    DataSet dataSetA = createDataSet('A');
    dataSetA.setUid("a23dataSetA");
    dataSetA.addOrganisationUnit(ouD);
    dataSetA.addOrganisationUnit(ouC);
    DataSet dataSetB = createDataSet('B');
    dataSetB.setUid("a23dataSetB");
    dataSetB.addOrganisationUnit(ouD);
    dataSetService.addDataSet(dataSetA);
    dataSetService.addDataSet(dataSetB);
    // Read data values from CSV files
    List<String[]> dataValueLines = CsvUtils.readCsvAsListFromClasspath("csv/dataValues.csv", true);
    parseDataValues(dataValueLines);
    List<String[]> dataSetRegistrationLines = CsvUtils.readCsvAsListFromClasspath("csv/dataSetRegistrations.csv", true);
    parseDataSetRegistrations(dataSetRegistrationLines);
    // Make indicators
    IndicatorType indicatorType_1 = createIndicatorType('A');
    indicatorType_1.setFactor(1);
    indicatorService.addIndicatorType(indicatorType_1);
    // deA
    Indicator indicatorA = createIndicator('A', indicatorType_1);
    String expressionA = "#{" + deA.getUid() + "." + ocDef.getUid() + "}";
    indicatorA.setNumerator(expressionA);
    indicatorA.setDenominator("1");
    // deB + deC
    Indicator indicatorB = createIndicator('B', indicatorType_1);
    String expressionB = "#{" + deB.getUid() + "." + ocDef.getUid() + "}" + "+#{" + deC.getUid() + "." + ocDef.getUid() + "}";
    indicatorB.setNumerator(expressionB);
    indicatorB.setDenominator("1");
    // (deB * deC) / 100
    Indicator indicatorC = createIndicator('C', indicatorType_1);
    String expressionC = "#{" + deB.getUid() + "." + ocDef.getUid() + "}" + "*#{" + deC.getUid() + "." + ocDef.getUid() + "}";
    indicatorC.setNumerator(expressionC);
    indicatorC.setDenominator("100");
    // (deA * deC) / deB
    Indicator indicatorD = createIndicator('D', indicatorType_1);
    String expressionD = "#{" + deA.getUid() + "." + ocDef.getUid() + "}" + "*#{" + deC.getUid() + "." + ocDef.getUid() + "}";
    indicatorD.setNumerator(expressionD);
    indicatorD.setDenominator("#{" + deB.getUid() + "." + ocDef.getUid() + "}");
    // deA * reporting rate B
    Indicator indicatorE = createIndicator('E', indicatorType_1);
    reportingRateA = new ReportingRate(dataSetA);
    reportingRateB = new ReportingRate(dataSetB);
    String expressionE = "#{" + deA.getUid() + "." + ocDef.getUid() + "}" + "*(R{" + reportingRateB.getUid() + ".REPORTING_RATE} / 100)";
    indicatorE.setNumerator(expressionE);
    indicatorE.setDenominator("1");
    // deA * reporting rate A
    Indicator indicatorF = createIndicator('F', indicatorType_1);
    String expressionF = "#{" + deA.getUid() + "." + ocDef.getUid() + "}" + "*(R{" + reportingRateA.getUid() + ".REPORTING_RATE} / 100)";
    indicatorF.setNumerator(expressionF);
    indicatorF.setDenominator("1");
    // deE.periodOffset(-1) + deE.periodOffset(-2)
    Indicator indicatorG = createIndicator('G', indicatorType_1);
    String expressionG = "#{" + deE.getUid() + "}.periodOffset(-1) + #{" + deE.getUid() + "}.periodOffset(-2)";
    indicatorG.setNumerator(expressionG);
    indicatorG.setDenominator("1");
    indicatorService.addIndicator(indicatorA);
    indicatorService.addIndicator(indicatorB);
    indicatorService.addIndicator(indicatorC);
    indicatorService.addIndicator(indicatorD);
    indicatorService.addIndicator(indicatorE);
    indicatorService.addIndicator(indicatorF);
    indicatorService.addIndicator(indicatorG);
    // Validation results
    CategoryOption optionA = new CategoryOption("CategoryOptionA");
    CategoryOption optionB = new CategoryOption("CategoryOptionB");
    categoryService.addCategoryOption(optionA);
    categoryService.addCategoryOption(optionB);
    Category categoryA = createCategory('A', optionA, optionB);
    categoryA.setDataDimensionType(DataDimensionType.ATTRIBUTE);
    categoryA.setUid("categoryabA");
    categoryService.addCategory(categoryA);
    CategoryCombo categoryComboA = createCategoryCombo('A', categoryA);
    categoryService.addCategoryCombo(categoryComboA);
    CategoryOptionCombo optionComboA = createCategoryOptionCombo(categoryComboA, optionA);
    CategoryOptionCombo optionComboB = createCategoryOptionCombo(categoryComboA, optionB);
    CategoryOptionCombo optionComboC = createCategoryOptionCombo(categoryComboA, optionA, optionB);
    categoryService.addCategoryOptionCombo(optionComboA);
    categoryService.addCategoryOptionCombo(optionComboB);
    categoryService.addCategoryOptionCombo(optionComboC);
    CategoryOptionGroup optionGroupA = createCategoryOptionGroup('A', optionA);
    CategoryOptionGroup optionGroupB = createCategoryOptionGroup('B', optionB);
    categoryService.saveCategoryOptionGroup(optionGroupA);
    categoryService.saveCategoryOptionGroup(optionGroupB);
    CategoryOptionGroupSet optionGroupSetB = new CategoryOptionGroupSet("OptionGroupSetB");
    categoryService.saveCategoryOptionGroupSet(optionGroupSetB);
    optionGroupSetB.addCategoryOptionGroup(optionGroupA);
    optionGroupSetB.addCategoryOptionGroup(optionGroupB);
    optionGroupA.getGroupSets().add(optionGroupSetB);
    optionGroupB.getGroupSets().add(optionGroupSetB);
    Expression expressionVRA = new Expression("expressionA", "descriptionA");
    Expression expressionVRB = new Expression("expressionB", "descriptionB");
    Expression expressionVRC = new Expression("expressionC", "descriptionC");
    Expression expressionVRD = new Expression("expressionD", "descriptionD");
    expressionService.addExpression(expressionVRA);
    expressionService.addExpression(expressionVRB);
    expressionService.addExpression(expressionVRC);
    expressionService.addExpression(expressionVRD);
    PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
    ValidationRule validationRuleA = createValidationRule('A', equal_to, expressionVRA, expressionVRB, periodType);
    validationRuleA.setUid("a234567vruA");
    ValidationRule validationRuleB = createValidationRule('B', equal_to, expressionVRC, expressionVRD, periodType);
    validationRuleB.setUid("a234567vruB");
    validationRuleService.saveValidationRule(validationRuleA);
    validationRuleService.saveValidationRule(validationRuleB);
    Date today = new Date();
    ValidationResult validationResultBA = new ValidationResult(validationRuleA, peJan, ouB, optionComboA, 1.0, 2.0, 3);
    validationResultBA.setCreated(today);
    ValidationResult validationResultBB = new ValidationResult(validationRuleA, peJan, ouB, optionComboB, 1.0, 2.0, 3);
    validationResultBB.setCreated(today);
    ValidationResult validationResultAA = new ValidationResult(validationRuleA, peJan, ouA, optionComboA, 1.0, 2.0, 3);
    validationResultAA.setCreated(today);
    ValidationResult validationResultAB = new ValidationResult(validationRuleA, peJan, ouA, optionComboB, 1.0, 2.0, 3);
    validationResultAB.setCreated(today);
    ValidationResult validationResultBAB = new ValidationResult(validationRuleB, peJan, ouA, optionComboB, 1.0, 2.0, 3);
    validationResultBAB.setCreated(today);
    ValidationResult validationResultBBB = new ValidationResult(validationRuleB, peFeb, ouB, optionComboB, 1.0, 2.0, 3);
    validationResultBBB.setCreated(today);
    ValidationResult validationResultBBA = new ValidationResult(validationRuleB, peFeb, ouB, optionComboA, 1.0, 2.0, 3);
    validationResultService.saveValidationResults(Lists.newArrayList(validationResultAA, validationResultAB, validationResultBB, validationResultBA, validationResultBAB, validationResultBBB, validationResultBBA));
    // to ensure that Hibernate has flushed validation
    Thread.sleep(1000);
    // results before generating tables.
    // Generate analytics tables
    analyticsTableGenerator.generateTables(AnalyticsTableUpdateParams.newBuilder().build(), NoopJobProgress.INSTANCE);
    // Set parameters
    List<Indicator> param_indicators = new ArrayList<>();
    List<ReportingRate> param_reportingRates = new ArrayList<>();
    Period y2017 = createPeriod("2017");
    // all data elements - mar 2017
    Period y2017_mar = createPeriod("2017-03");
    DataQueryParams de_avg_2017_03_params = DataQueryParams.newBuilder().withDataElements(dataElementService.getAllDataElements()).withAggregationType(AnalyticsAggregationType.AVERAGE).withSkipRounding(true).withPeriod(y2017_mar).withOutputFormat(OutputFormat.ANALYTICS).build();
    // org unit B - data element C - mar 2017
    List<DataElement> dataElements1 = new ArrayList<>();
    dataElements1.add(deC);
    DataQueryParams deC_ouB_2017_03_params = DataQueryParams.newBuilder().withOrganisationUnit(ouB).withDataElements(dataElements1).withAggregationType(AnalyticsAggregationType.SUM).withPeriod(y2017_mar).withOutputFormat(OutputFormat.ANALYTICS).build();
    AnalyticalObject deC_ouB_2017_03_analytical = new Visualization("deC_ouB_2017_03", dataElements1, param_indicators, param_reportingRates, Lists.newArrayList(y2017_mar), Lists.newArrayList(ouB), false, true, true);
    // org unit A - data element A - Q1 2017
    List<DataElement> dataElements2 = new ArrayList<>();
    dataElements2.add(deA);
    DataQueryParams deA_ouA_2017_Q01_params = DataQueryParams.newBuilder().withOrganisationUnit(ouA).withDataElements(dataElements2).withAggregationType(AnalyticsAggregationType.SUM).withPeriod(quarter).withOutputFormat(OutputFormat.ANALYTICS).build();
    AnalyticalObject deA_ouA_2017_Q01_analytical = new Visualization("deA_ouA_2017_Q01", dataElements2, param_indicators, param_reportingRates, Lists.newArrayList(quarter), Lists.newArrayList(ouA), false, true, true);
    // indicator A - 2017
    DataQueryParams inA_2017_params = DataQueryParams.newBuilder().withIndicators(Lists.newArrayList(indicatorA)).withAggregationType(AnalyticsAggregationType.SUM).withPeriod(y2017).withOutputFormat(OutputFormat.ANALYTICS).build();
    // indicator B (deB + deC) - 2017 Q1
    DataQueryParams inB_deB_deC_2017_Q01_params = DataQueryParams.newBuilder().withIndicators(Lists.newArrayList(indicatorB)).withAggregationType(AnalyticsAggregationType.SUM).withPeriod(quarter).withOutputFormat(OutputFormat.ANALYTICS).build();
    // indicator C (deB * deC) in hundreds - 2017 Q1
    List<Indicator> param_indicators3 = new ArrayList<>();
    param_indicators3.add(indicatorC);
    DataQueryParams inC_deB_deC_2017_Q01_params = DataQueryParams.newBuilder().withIndicators(param_indicators3).withAggregationType(AnalyticsAggregationType.SUM).withPeriod(quarter).withOutputFormat(OutputFormat.ANALYTICS).build();
    AnalyticalObject inC_deB_deC_2017_Q01_analytical = new Visualization("deA_ouA_2017_Q01", Lists.newArrayList(), param_indicators3, param_reportingRates, Lists.newArrayList(quarter), Lists.newArrayList(ouA), true, true, true);
    // indicator D (deA * deC)/deB - 2017 Q1
    DataQueryParams inD_deA_deB_deC_2017_Q01_params = DataQueryParams.newBuilder().withIndicators(Lists.newArrayList(indicatorD)).withAggregationType(AnalyticsAggregationType.SUM).withPeriod(quarter).withOutputFormat(OutputFormat.ANALYTICS).build();
    // indicator E (deA * reporting rate B) / 100 - 2017 Q1
    DataQueryParams inE_deA_reRateA_2017_Q01_params = DataQueryParams.newBuilder().withOrganisationUnit(ouD).withIndicators(Lists.newArrayList(indicatorE)).withAggregationType(AnalyticsAggregationType.SUM).withPeriod(quarter).withOutputFormat(OutputFormat.ANALYTICS).build();
    // indicator F (deA * reporting rate A) / 100 - 2017 Q1
    DataQueryParams inF_deA_reRateB_2017_Q01_params = DataQueryParams.newBuilder().withOrganisationUnit(ouD).withIndicators(Lists.newArrayList(indicatorF)).withAggregationType(AnalyticsAggregationType.SUM).withPeriod(quarter).withOutputFormat(OutputFormat.ANALYTICS).build();
    // indicator G (deE.periodOffset(-1) + deE.periodOffset(-2)) 2017-07
    DataQueryParams inG_deE_periodOffsets_2017_07_params = DataQueryParams.newBuilder().withOrganisationUnit(ouA).withIndicators(Lists.newArrayList(indicatorG)).withAggregationType(AnalyticsAggregationType.SUM).withPeriod(peJuly).withOutputFormat(OutputFormat.ANALYTICS).build();
    // Max value - org unit B and C - data element A - 2017 Feb
    DataQueryParams deA_ouB_ouC_2017_02_params = DataQueryParams.newBuilder().withFilterOrganisationUnits(Lists.newArrayList(ouB, ouC)).withDataElements(Lists.newArrayList(deA)).withAggregationType(new AnalyticsAggregationType(AggregationType.MAX, AggregationType.MAX)).withPeriod(peFeb).withOutputFormat(OutputFormat.ANALYTICS).build();
    // Average value - org unit C and E - data element A, B and D - 2017
    // April
    DataQueryParams deA_deB_deD_ouC_ouE_2017_04_params = DataQueryParams.newBuilder().withFilterOrganisationUnits(Lists.newArrayList(ouC, ouE)).withDataElements(Lists.newArrayList(deA, deB, deD)).withAggregationType(AnalyticsAggregationType.AVERAGE).withOutputFormat(OutputFormat.ANALYTICS).withPeriod(peApril).withOutputFormat(OutputFormat.ANALYTICS).build();
    // Sum org unit B - 2017-01-01 -> 2017-02-20
    DataQueryParams ouB_2017_01_01_2017_02_20_params = DataQueryParams.newBuilder().withDataElements(Lists.newArrayList(deA, deB)).withOrganisationUnit(ouB).withStartDate(getDate(2017, 1, 1)).withEndDate(getDate(2017, 2, 20)).withAggregationType(AnalyticsAggregationType.SUM).withOutputFormat(OutputFormat.ANALYTICS).build();
    // Reportingrate for dataSet A - Q1 2017
    DataQueryParams reRate_2017_Q01_ouC_params = DataQueryParams.newBuilder().withOrganisationUnit(ouC).withReportingRates(Lists.newArrayList(reportingRateA)).withPeriod(quarter).withAggregationType(AnalyticsAggregationType.SUM).withOutputFormat(OutputFormat.ANALYTICS).build();
    // Reportingrate for dataSet B - Q1 2017
    DataQueryParams reRate_2017_Q01_ouD_params = DataQueryParams.newBuilder().withOrganisationUnit(ouD).withReportingRates(Lists.newArrayList(reportingRateB)).withPeriod(quarter).withAggregationType(AnalyticsAggregationType.SUM).withOutputFormat(OutputFormat.ANALYTICS).build();
    // Validation result queries
    DataQueryParams ou_2017_validationruleA_params = DataQueryParams.newBuilder().withValidationRules(Lists.newArrayList(validationRuleA)).withOrganisationUnits(organisationUnitService.getAllOrganisationUnits()).withAggregationType(AnalyticsAggregationType.COUNT).withPeriod(y2017).withOutputFormat(OutputFormat.ANALYTICS).build();
    DataQueryParams ou_2017_validationruleB_params = DataQueryParams.newBuilder().withValidationRules(Lists.newArrayList(validationRuleB)).withOrganisationUnits(organisationUnitService.getAllOrganisationUnits()).withAggregationType(AnalyticsAggregationType.COUNT).withPeriod(y2017).withOutputFormat(OutputFormat.ANALYTICS).build();
    DataQueryParams ou_2017_validationruleAB_params = DataQueryParams.newBuilder().withValidationRules(Lists.newArrayList(validationRuleA, validationRuleB)).withOrganisationUnits(organisationUnitService.getAllOrganisationUnits()).withAggregationType(AnalyticsAggregationType.COUNT).withPeriod(y2017).withOutputFormat(OutputFormat.ANALYTICS).build();
    dataQueryParams.put("de_avg_2017_03", de_avg_2017_03_params);
    dataQueryParams.put("deC_ouB_2017_03", deC_ouB_2017_03_params);
    dataQueryParams.put("deA_ouA_2017_Q01", deA_ouA_2017_Q01_params);
    dataQueryParams.put("inA_2017", inA_2017_params);
    dataQueryParams.put("inB_deB_deC_2017_Q01", inB_deB_deC_2017_Q01_params);
    dataQueryParams.put("inC_deB_deC_2017_Q01", inC_deB_deC_2017_Q01_params);
    dataQueryParams.put("inD_deA_deB_deC_2017_Q01", inD_deA_deB_deC_2017_Q01_params);
    dataQueryParams.put("inE_deA_reRateA_2017_Q01", inE_deA_reRateA_2017_Q01_params);
    dataQueryParams.put("inF_deA_reRateB_2017_Q01", inF_deA_reRateB_2017_Q01_params);
    dataQueryParams.put("inG_deE_periodOffsets_2017_07", inG_deE_periodOffsets_2017_07_params);
    dataQueryParams.put("deA_ouB_ouC_2017_02", deA_ouB_ouC_2017_02_params);
    dataQueryParams.put("deA_deB_deD_ouC_ouE_2017_04", deA_deB_deD_ouC_ouE_2017_04_params);
    dataQueryParams.put("ouB_2017_01_01_2017_02_20", ouB_2017_01_01_2017_02_20_params);
    dataQueryParams.put("reRate_2017_Q01_ouC", reRate_2017_Q01_ouC_params);
    dataQueryParams.put("reRate_2017_Q01_ouD", reRate_2017_Q01_ouD_params);
    dataQueryParams.put("ou_2017_validationruleA", ou_2017_validationruleA_params);
    dataQueryParams.put("ou_2017_validationruleB", ou_2017_validationruleB_params);
    dataQueryParams.put("ou_2017_validationruleAB", ou_2017_validationruleAB_params);
    analyticalObjectHashMap.put("deC_ouB_2017_03", deC_ouB_2017_03_analytical);
    analyticalObjectHashMap.put("deA_ouA_2017_Q01", deA_ouA_2017_Q01_analytical);
    analyticalObjectHashMap.put("inC_deB_deC_2017_Q01", inC_deB_deC_2017_Q01_analytical);
    // Set results
    // --------------------------------------------------------------------
    Map<String, Double> de_avg_2017_03_keyValue = new HashMap<>();
    de_avg_2017_03_keyValue.put("deabcdefghC-201703", 6.75);
    Map<String, Double> deC_ouB_2017_03_keyValue = new HashMap<>();
    deC_ouB_2017_03_keyValue.put("deabcdefghC-ouabcdefghB-201703", 6.0);
    deC_ouB_2017_03_keyValue.put("deabcdefghC-201703-ouabcdefghB", 6.0);
    Map<String, Double> deA_ouA_2017_Q01_keyValue = new HashMap<>();
    deA_ouA_2017_Q01_keyValue.put("deabcdefghA-ouabcdefghA-2017Q1", 308.0);
    deA_ouA_2017_Q01_keyValue.put("deabcdefghA-2017Q1-ouabcdefghA", 308.0);
    Map<String, Double> inA_2017_keyValue = new HashMap<>();
    inA_2017_keyValue.put("inabcdefghA-2017", 308.0);
    Map<String, Double> inB_deB_deC_2017_Q01_keyValue = new HashMap<>();
    inB_deB_deC_2017_Q01_keyValue.put("inabcdefghB-2017Q1", 567.0);
    Map<String, Double> inC_deB_deC_2017_Q01_keyValue = new HashMap<>();
    inC_deB_deC_2017_Q01_keyValue.put("inabcdefghC-2017Q1", 258.50);
    inC_deB_deC_2017_Q01_keyValue.put("inabcdefghC-2017Q1-ouabcdefghA", 258.50);
    Map<String, Double> inD_deA_deB_deC_2017_Q01_keyValue = new HashMap<>();
    inD_deA_deB_deC_2017_Q01_keyValue.put("inabcdefghD-2017Q1", 29.8);
    Map<String, Double> inE_deA_reRateA_2017_Q01_keyValue = new HashMap<>();
    inE_deA_reRateA_2017_Q01_keyValue.put("inabcdefghE-ouabcdefghD-2017Q1", 99.6);
    Map<String, Double> inF_deA_reRateB_2017_Q01_keyValue = new HashMap<>();
    inF_deA_reRateB_2017_Q01_keyValue.put("inabcdefghF-ouabcdefghD-2017Q1", 199.4);
    Map<String, Double> inG_deE_periodOffsets_2017_07_keyvalue = new HashMap<>();
    inG_deE_periodOffsets_2017_07_keyvalue.put("inabcdefghG-ouabcdefghA-201707", 3.0);
    Map<String, Double> deA_ouB_ouC_2017_02_keyValue = new HashMap<>();
    deA_ouB_ouC_2017_02_keyValue.put("deabcdefghA-201702", 233.0);
    Map<String, Double> deA_deB_deD_ouC_ouE_2017_04_keyValue = new HashMap<>();
    deA_deB_deD_ouC_ouE_2017_04_keyValue.put("deabcdefghD-201704", 10.5);
    Map<String, Double> deA_deB_2017_Q01_keyValue = new HashMap<>();
    deA_deB_2017_Q01_keyValue.put("2017Q1", 53.3);
    Map<String, Double> ouB_2017_01_01_2017_02_20_keyValue = new HashMap<>();
    ouB_2017_01_01_2017_02_20_keyValue.put("deabcdefghA-ouabcdefghB", 68.0);
    Map<String, Double> reRate_2017_Q01_ouC_keyValue = new HashMap<>();
    reRate_2017_Q01_ouC_keyValue.put("a23dataSetA.REPORTING_RATE-ouabcdefghC-2017Q1", 100.0);
    Map<String, Double> reRate_2017_Q01_ouD_keyValue = new HashMap<>();
    reRate_2017_Q01_ouD_keyValue.put("a23dataSetB.REPORTING_RATE-ouabcdefghD-2017Q1", 33.3);
    Map<String, Double> ou_2017_validationruleA_keyValue = new HashMap<>();
    ou_2017_validationruleA_keyValue.put("a234567vruA-ouabcdefghA-2017", 4.0);
    ou_2017_validationruleA_keyValue.put("a234567vruA-ouabcdefghB-2017", 2.0);
    Map<String, Double> ou_2017_validationruleB_keyValue = new HashMap<>();
    ou_2017_validationruleB_keyValue.put("a234567vruB-ouabcdefghA-2017", 3.0);
    ou_2017_validationruleB_keyValue.put("a234567vruB-ouabcdefghB-2017", 2.0);
    Map<String, Double> ou_2017_validationruleAB_keyValue = new HashMap<>();
    ou_2017_validationruleAB_keyValue.put("a234567vruA-ouabcdefghA-2017", 4.0);
    ou_2017_validationruleAB_keyValue.put("a234567vruA-ouabcdefghB-2017", 2.0);
    ou_2017_validationruleAB_keyValue.put("a234567vruB-ouabcdefghA-2017", 3.0);
    ou_2017_validationruleAB_keyValue.put("a234567vruB-ouabcdefghB-2017", 2.0);
    results.put("de_avg_2017_03", de_avg_2017_03_keyValue);
    results.put("deC_ouB_2017_03", deC_ouB_2017_03_keyValue);
    results.put("deA_ouA_2017_Q01", deA_ouA_2017_Q01_keyValue);
    results.put("inA_2017", inA_2017_keyValue);
    results.put("inB_deB_deC_2017_Q01", inB_deB_deC_2017_Q01_keyValue);
    results.put("inC_deB_deC_2017_Q01", inC_deB_deC_2017_Q01_keyValue);
    results.put("inD_deA_deB_deC_2017_Q01", inD_deA_deB_deC_2017_Q01_keyValue);
    results.put("inE_deA_reRateA_2017_Q01", inE_deA_reRateA_2017_Q01_keyValue);
    results.put("inF_deA_reRateB_2017_Q01", inF_deA_reRateB_2017_Q01_keyValue);
    results.put("inG_deE_periodOffsets_2017_07", inG_deE_periodOffsets_2017_07_keyvalue);
    results.put("deA_ouB_ouC_2017_02", deA_ouB_ouC_2017_02_keyValue);
    results.put("deA_deB_deD_ouC_ouE_2017_04", deA_deB_deD_ouC_ouE_2017_04_keyValue);
    results.put("deA_deB_2017_Q01", deA_deB_2017_Q01_keyValue);
    results.put("ouB_2017_01_01_2017_02_20", ouB_2017_01_01_2017_02_20_keyValue);
    results.put("reRate_2017_Q01_ouC", reRate_2017_Q01_ouC_keyValue);
    results.put("reRate_2017_Q01_ouD", reRate_2017_Q01_ouD_keyValue);
    results.put("ou_2017_validationruleA", ou_2017_validationruleA_keyValue);
    results.put("ou_2017_validationruleB", ou_2017_validationruleB_keyValue);
    results.put("ou_2017_validationruleAB", ou_2017_validationruleAB_keyValue);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Visualization(org.hisp.dhis.visualization.Visualization) Category(org.hisp.dhis.category.Category) DataSet(org.hisp.dhis.dataset.DataSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ValidationResult(org.hisp.dhis.validation.ValidationResult) AnalyticsAggregationType(org.hisp.dhis.analytics.AnalyticsAggregationType) DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) IndicatorType(org.hisp.dhis.indicator.IndicatorType) CategoryOptionGroup(org.hisp.dhis.category.CategoryOptionGroup) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ReportingRate(org.hisp.dhis.common.ReportingRate) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) Period(org.hisp.dhis.period.Period) Indicator(org.hisp.dhis.indicator.Indicator) Date(java.util.Date) ValidationRule(org.hisp.dhis.validation.ValidationRule) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) Expression(org.hisp.dhis.expression.Expression) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 2 with CategoryOption

use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.

the class DefaultAggregateAccessManager method canRead.

// ---------------------------------------------------------------------
// AggregateAccessManager implementation
// ---------------------------------------------------------------------
@Override
public List<String> canRead(User user, DataValue dataValue) {
    List<String> errors = new ArrayList<>();
    if (user == null || user.isSuper()) {
        return errors;
    }
    Set<CategoryOption> options = new HashSet<>();
    CategoryOptionCombo categoryOptionCombo = dataValue.getCategoryOptionCombo();
    if (categoryOptionCombo != null) {
        options.addAll(categoryOptionCombo.getCategoryOptions());
    }
    CategoryOptionCombo attributeOptionCombo = dataValue.getAttributeOptionCombo();
    if (attributeOptionCombo != null) {
        options.addAll(attributeOptionCombo.getCategoryOptions());
    }
    options.forEach(option -> {
        if (!aclService.canDataRead(user, option)) {
            errors.add("User has no data read access for CategoryOption: " + option.getUid());
        }
    });
    return errors;
}
Also used : ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet)

Example 3 with CategoryOption

use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.

the class AbstractEventService method getEvent.

@Transactional(readOnly = true)
@Override
public Event getEvent(ProgramStageInstance programStageInstance, boolean isSynchronizationQuery, boolean skipOwnershipCheck) {
    if (programStageInstance == null) {
        return null;
    }
    Event event = new Event();
    event.setEvent(programStageInstance.getUid());
    if (programStageInstance.getProgramInstance().getEntityInstance() != null) {
        event.setTrackedEntityInstance(programStageInstance.getProgramInstance().getEntityInstance().getUid());
    }
    event.setFollowup(programStageInstance.getProgramInstance().getFollowup());
    event.setEnrollmentStatus(EnrollmentStatus.fromProgramStatus(programStageInstance.getProgramInstance().getStatus()));
    event.setStatus(programStageInstance.getStatus());
    event.setEventDate(DateUtils.getIso8601NoTz(programStageInstance.getExecutionDate()));
    event.setDueDate(DateUtils.getIso8601NoTz(programStageInstance.getDueDate()));
    event.setStoredBy(programStageInstance.getStoredBy());
    event.setCompletedBy(programStageInstance.getCompletedBy());
    event.setCompletedDate(DateUtils.getIso8601NoTz(programStageInstance.getCompletedDate()));
    event.setCreated(DateUtils.getIso8601NoTz(programStageInstance.getCreated()));
    event.setCreatedByUserInfo(programStageInstance.getCreatedByUserInfo());
    event.setLastUpdatedByUserInfo(programStageInstance.getLastUpdatedByUserInfo());
    event.setCreatedAtClient(DateUtils.getIso8601NoTz(programStageInstance.getCreatedAtClient()));
    event.setLastUpdated(DateUtils.getIso8601NoTz(programStageInstance.getLastUpdated()));
    event.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(programStageInstance.getLastUpdatedAtClient()));
    event.setGeometry(programStageInstance.getGeometry());
    event.setDeleted(programStageInstance.isDeleted());
    if (programStageInstance.getAssignedUser() != null) {
        event.setAssignedUser(programStageInstance.getAssignedUser().getUid());
        event.setAssignedUserUsername(programStageInstance.getAssignedUser().getUsername());
        event.setAssignedUserDisplayName(programStageInstance.getAssignedUser().getName());
    }
    User user = currentUserService.getCurrentUser();
    OrganisationUnit ou = programStageInstance.getOrganisationUnit();
    List<String> errors = trackerAccessManager.canRead(user, programStageInstance, skipOwnershipCheck);
    if (!errors.isEmpty()) {
        throw new IllegalQueryException(errors.toString());
    }
    if (ou != null) {
        event.setOrgUnit(ou.getUid());
        event.setOrgUnitName(ou.getName());
    }
    Program program = programStageInstance.getProgramInstance().getProgram();
    event.setProgram(program.getUid());
    event.setEnrollment(programStageInstance.getProgramInstance().getUid());
    event.setProgramStage(programStageInstance.getProgramStage().getUid());
    CategoryOptionCombo attributeOptionCombo = programStageInstance.getAttributeOptionCombo();
    if (attributeOptionCombo != null) {
        event.setAttributeOptionCombo(attributeOptionCombo.getUid());
        event.setAttributeCategoryOptions(String.join(";", attributeOptionCombo.getCategoryOptions().stream().map(CategoryOption::getUid).collect(Collectors.toList())));
    }
    if (programStageInstance.getProgramInstance().getEntityInstance() != null) {
        event.setTrackedEntityInstance(programStageInstance.getProgramInstance().getEntityInstance().getUid());
    }
    Collection<EventDataValue> dataValues;
    if (!isSynchronizationQuery) {
        dataValues = programStageInstance.getEventDataValues();
    } else {
        Set<String> dataElementsToSync = programStageInstance.getProgramStage().getProgramStageDataElements().stream().filter(psde -> !psde.getSkipSynchronization()).map(psde -> psde.getDataElement().getUid()).collect(Collectors.toSet());
        dataValues = programStageInstance.getEventDataValues().stream().filter(dv -> dataElementsToSync.contains(dv.getDataElement())).collect(Collectors.toSet());
    }
    for (EventDataValue dataValue : dataValues) {
        if (getDataElement(user.getUid(), dataValue.getDataElement())) {
            DataValue value = new DataValue();
            value.setCreated(DateUtils.getIso8601NoTz(dataValue.getCreated()));
            value.setCreatedByUserInfo(dataValue.getCreatedByUserInfo());
            value.setLastUpdated(DateUtils.getIso8601NoTz(dataValue.getLastUpdated()));
            value.setLastUpdatedByUserInfo(dataValue.getLastUpdatedByUserInfo());
            value.setDataElement(dataValue.getDataElement());
            value.setValue(dataValue.getValue());
            value.setProvidedElsewhere(dataValue.getProvidedElsewhere());
            value.setStoredBy(dataValue.getStoredBy());
            event.getDataValues().add(value);
        } else {
            log.info("Can not find a Data Element having UID [" + dataValue.getDataElement() + "]");
        }
    }
    event.getNotes().addAll(NoteHelper.convertNotes(programStageInstance.getComments()));
    event.setRelationships(programStageInstance.getRelationshipItems().stream().filter(Objects::nonNull).map((r) -> relationshipService.getRelationship(r.getRelationship(), RelationshipParams.FALSE, user)).collect(Collectors.toSet()));
    return event;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) Arrays(java.util.Arrays) CategoryService(org.hisp.dhis.category.CategoryService) FIRST_PAGE(org.hisp.dhis.common.SlimPager.FIRST_PAGE) CategoryOption(org.hisp.dhis.category.CategoryOption) ValidationUtils(org.hisp.dhis.system.util.ValidationUtils) EventRow(org.hisp.dhis.dxf2.events.report.EventRow) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) StringUtils(org.apache.commons.lang3.StringUtils) EVENT_CREATED_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_CREATED_ID) EVENT_EXECUTION_DATE_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_EXECUTION_DATE_ID) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EnrollmentStatus(org.hisp.dhis.dxf2.events.enrollment.EnrollmentStatus) EventSyncService(org.hisp.dhis.program.EventSyncService) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) Map(java.util.Map) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) EVENT_STATUS_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_STATUS_ID) OrganisationUnitSelectionMode(org.hisp.dhis.common.OrganisationUnitSelectionMode) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) Set(java.util.Set) SchemaService(org.hisp.dhis.schema.SchemaService) TrackerOwnershipManager(org.hisp.dhis.trackedentity.TrackerOwnershipManager) Slf4j(lombok.extern.slf4j.Slf4j) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) ProgramType(org.hisp.dhis.program.ProgramType) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) TrackedEntityCommentService(org.hisp.dhis.trackedentitycomment.TrackedEntityCommentService) EVENT_STORED_BY_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_STORED_BY_ID) QueryItem(org.hisp.dhis.common.QueryItem) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) EVENT_GEOMETRY(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_GEOMETRY) ArrayList(java.util.ArrayList) RelationshipParams(org.hisp.dhis.dxf2.events.RelationshipParams) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) SlimPager(org.hisp.dhis.common.SlimPager) ImportConflicts(org.hisp.dhis.dxf2.importsummary.ImportConflicts) EventManager(org.hisp.dhis.dxf2.events.importer.EventManager) EVENT_ENROLLMENT_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_ENROLLMENT_ID) IdSchemes(org.hisp.dhis.common.IdSchemes) RelationshipService(org.hisp.dhis.dxf2.events.relationship.RelationshipService) DEFAULT_PAGE_SIZE(org.hisp.dhis.common.Pager.DEFAULT_PAGE_SIZE) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TrackedEntityInstanceService(org.hisp.dhis.trackedentity.TrackedEntityInstanceService) DebugUtils(org.hisp.dhis.commons.util.DebugUtils) ERROR(org.hisp.dhis.system.notification.NotificationLevel.ERROR) CodeGenerator(org.hisp.dhis.common.CodeGenerator) ProgramService(org.hisp.dhis.program.ProgramService) DateUtils(org.hisp.dhis.util.DateUtils) EVENT_PROGRAM_STAGE_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_PROGRAM_STAGE_ID) PAGER_META_KEY(org.hisp.dhis.dxf2.events.event.EventSearchParams.PAGER_META_KEY) Authorities(org.hisp.dhis.security.Authorities) Date(java.util.Date) WorkContextLoader(org.hisp.dhis.dxf2.events.importer.context.WorkContextLoader) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) EVENT_LAST_UPDATED_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_LAST_UPDATED_ID) ProgramStageInstanceService(org.hisp.dhis.program.ProgramStageInstanceService) NoteHelper(org.hisp.dhis.dxf2.events.NoteHelper) EVENT_PROGRAM_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_PROGRAM_ID) EVENT_DUE_DATE_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_DUE_DATE_ID) UserService(org.hisp.dhis.user.UserService) Collection(java.util.Collection) EventStatus(org.hisp.dhis.event.EventStatus) Collectors(java.util.stream.Collectors) QueryService(org.hisp.dhis.query.QueryService) EventRows(org.hisp.dhis.dxf2.events.report.EventRows) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) EventImporter(org.hisp.dhis.dxf2.events.importer.EventImporter) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) Cache(org.hisp.dhis.cache.Cache) EVENT_ORG_UNIT_NAME(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_ORG_UNIT_NAME) EVENT_CREATED_BY_USER_INFO_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_CREATED_BY_USER_INFO_ID) EVENT_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_ID) HashMap(java.util.HashMap) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) Program(org.hisp.dhis.program.Program) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) Notifier(org.hisp.dhis.system.notification.Notifier) DbmsManager(org.hisp.dhis.dbms.DbmsManager) GridHeader(org.hisp.dhis.common.GridHeader) User(org.hisp.dhis.user.User) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) EVENT_ORG_UNIT_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_ORG_UNIT_ID) EVENT_LAST_UPDATED_BY_USER_INFO_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_LAST_UPDATED_BY_USER_INFO_ID) Collections.emptyMap(java.util.Collections.emptyMap) EVENT_DELETED(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_DELETED) Pager(org.hisp.dhis.common.Pager) Grid(org.hisp.dhis.common.Grid) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) EVENT_ATTRIBUTE_OPTION_COMBO_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_ATTRIBUTE_OPTION_COMBO_ID) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CachingMap(org.hisp.dhis.commons.collection.CachingMap) Collections(java.util.Collections) EVENT_COMPLETED_BY_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_COMPLETED_BY_ID) EVENT_COMPLETED_DATE_ID(org.hisp.dhis.dxf2.events.event.EventSearchParams.EVENT_COMPLETED_DATE_ID) Transactional(org.springframework.transaction.annotation.Transactional) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with CategoryOption

use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.

the class AttributeOptionComboLoader method getAttributeOptionCombo.

private CategoryOptionCombo getAttributeOptionCombo(CategoryCombo categoryCombo, Set<String> opts, String attributeOptionCombo, IdScheme idScheme) {
    if (categoryCombo == null) {
        throw new IllegalQueryException("Illegal category combo");
    }
    // ---------------------------------------------------------------------
    // Attribute category options validation
    // ---------------------------------------------------------------------
    CategoryOptionCombo attrOptCombo = null;
    if (opts != null) {
        Set<CategoryOption> categoryOptions = new HashSet<>();
        for (String uid : opts) {
            CategoryOption categoryOption = getCategoryOption(idScheme, uid);
            if (categoryOption == null) {
                throw new IllegalQueryException("Illegal category option identifier: " + uid);
            }
            categoryOptions.add(categoryOption);
        }
        final String id = resolveCategoryComboId(categoryCombo, idScheme);
        attrOptCombo = getAttributeOptionCombo(idScheme, id, categoryOptions);
        if (attrOptCombo == null) {
            throw new IllegalQueryException("Attribute option combo does not exist for given category combo and category options");
        }
    } else if (attributeOptionCombo != null) {
        attrOptCombo = getCategoryOptionCombo(idScheme, attributeOptionCombo);
    }
    if (attrOptCombo == null) {
        attrOptCombo = getDefault();
    }
    if (attrOptCombo == null) {
        throw new IllegalQueryException("Default attribute option combo does not exist");
    }
    return attrOptCombo;
}
Also used : CategoryOption(org.hisp.dhis.category.CategoryOption) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet)

Example 5 with CategoryOption

use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.

the class AttributeOptionComboLoader method loadCategoryOption.

private CategoryOption loadCategoryOption(IdScheme idScheme, String id) {
    String key = "categoryoptionid";
    final String sql = "select " + key + ", uid, code, name, startdate, enddate, sharing from dataelementcategoryoption " + "where " + resolveId(idScheme, key, id);
    try {
        return jdbcTemplate.queryForObject(sql, (rs, i) -> {
            CategoryOption categoryOption = new CategoryOption();
            categoryOption.setId(rs.getLong(key));
            categoryOption.setUid(rs.getString("uid"));
            categoryOption.setCode(rs.getString("code"));
            categoryOption.setName(rs.getString("name"));
            categoryOption.setStartDate(rs.getDate("startdate"));
            categoryOption.setEndDate(rs.getDate("enddate"));
            categoryOption.setSharing(getSharing(rs.getString("sharing")));
            return categoryOption;
        });
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
Also used : CategoryOption(org.hisp.dhis.category.CategoryOption) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Aggregations

CategoryOption (org.hisp.dhis.category.CategoryOption)87 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)47 CategoryCombo (org.hisp.dhis.category.CategoryCombo)38 Category (org.hisp.dhis.category.Category)34 Test (org.junit.jupiter.api.Test)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)26 Program (org.hisp.dhis.program.Program)19 ArrayList (java.util.ArrayList)18 Event (org.hisp.dhis.tracker.domain.Event)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 DataElement (org.hisp.dhis.dataelement.DataElement)13 Collections (java.util.Collections)12 DataSet (org.hisp.dhis.dataset.DataSet)12 CodeGenerator (org.hisp.dhis.common.CodeGenerator)11 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)11 CategoryService (org.hisp.dhis.category.CategoryService)10 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)10