Search in sources :

Example 11 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getIndicatorsViolatingExclusiveGroupSets.

/**
 * Gets all indicators units which are members of more than one group which
 * enter into an exclusive group set.
 */
List<DataIntegrityIssue> getIndicatorsViolatingExclusiveGroupSets() {
    Collection<IndicatorGroupSet> groupSets = indicatorService.getAllIndicatorGroupSets();
    List<DataIntegrityIssue> issues = new ArrayList<>();
    for (IndicatorGroupSet groupSet : groupSets) {
        Collection<Indicator> duplicates = getDuplicates(new ArrayList<>(groupSet.getIndicators()));
        for (Indicator duplicate : duplicates) {
            issues.add(DataIntegrityIssue.toIssue(duplicate, duplicate.getGroups()));
        }
    }
    return issues;
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) ArrayList(java.util.ArrayList) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator)

Example 12 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getInvalidProgramIndicators.

private List<DataIntegrityIssue> getInvalidProgramIndicators(Function<ProgramIndicator, String> property, Predicate<ProgramIndicator> filter) {
    List<ProgramIndicator> programIndicators = programIndicatorService.getAllProgramIndicators().stream().filter(filter).collect(toList());
    List<DataIntegrityIssue> issues = new ArrayList<>();
    for (ProgramIndicator programIndicator : programIndicators) {
        String description = getInvalidExpressionDescription(property.apply(programIndicator));
        if (description != null) {
            issues.add(toIssue(programIndicator, description));
        }
    }
    return issues;
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ArrayList(java.util.ArrayList) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 13 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getDataElementsViolatingExclusiveGroupSets.

/**
 * Gets all data elements units which are members of more than one group
 * which enter into an exclusive group set.
 */
List<DataIntegrityIssue> getDataElementsViolatingExclusiveGroupSets() {
    Collection<DataElementGroupSet> groupSets = dataElementService.getAllDataElementGroupSets();
    List<DataIntegrityIssue> issues = new ArrayList<>();
    for (DataElementGroupSet groupSet : groupSets) {
        Set<DataElement> duplicates = getDuplicates(groupSet.getDataElements());
        for (DataElement duplicate : duplicates) {
            issues.add(DataIntegrityIssue.toIssue(duplicate, duplicate.getGroups()));
        }
    }
    return issues;
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList)

Example 14 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DataIntegrityYamlReaderTest method testReadDataIntegrityYaml.

@Test
void testReadDataIntegrityYaml() {
    List<DataIntegrityCheck> checks = new ArrayList<>();
    readDataIntegrityYaml("data-integrity-checks.yaml", checks::add, sql -> check -> new DataIntegritySummary(check, new Date(), null, 1, 100d), sql -> check -> new DataIntegrityDetails(check, new Date(), null, List.of(new DataIntegrityIssue("id", "name", sql, List.of()))));
    assertEquals(6, checks.size());
    DataIntegrityCheck check = checks.get(0);
    assertEquals("categories_no_options", check.getName());
    assertEquals("Categories with no category options", check.getDescription());
    assertEquals("Categories", check.getSection());
    assertEquals(DataIntegritySeverity.WARNING, check.getSeverity());
    assertEquals("Categories should always have at least a single category options.", check.getIntroduction());
    assertEquals("Any categories without category options should either be removed from the" + " system if they are not in use. Otherwise, appropriate category options" + " should be added to the category.", check.getRecommendation());
    assertTrue(check.getRunDetailsCheck().apply(check).getIssues().get(0).getComment().startsWith("SELECT uid,name from dataelementcategory"));
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 15 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DataIntegrityServiceTest method testInvalidProgramIndicatorFilter.

@Test
void testInvalidProgramIndicatorFilter() {
    ProgramIndicator programIndicator = new ProgramIndicator();
    programIndicator.setName("Test-PI");
    programIndicator.setFilter("A{someuid} + 1");
    when(programIndicatorService.filterIsValid(anyString())).thenReturn(false);
    when(programIndicatorService.getAllProgramIndicators()).thenReturn(List.of(programIndicator));
    when(expressionService.getExpressionDescription(anyString(), any())).thenThrow(new ParserException(INVALID_EXPRESSION));
    List<DataIntegrityIssue> issues = subject.getInvalidProgramIndicatorFilters();
    assertEquals(1, issues.size(), 1);
    DataIntegrityIssue issue = issues.get(0);
    assertEquals(issueName(programIndicator), issue.getName());
    assertEquals(INVALID_EXPRESSION, issue.getComment());
}
Also used : ParserException(org.hisp.dhis.antlr.ParserException) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.jupiter.api.Test)

Aggregations

DataIntegrityIssue (org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue)18 ArrayList (java.util.ArrayList)11 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)9 Test (org.junit.jupiter.api.Test)8 DataElement (org.hisp.dhis.dataelement.DataElement)7 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 ParserException (org.hisp.dhis.antlr.ParserException)5 ExpressionValidationOutcome (org.hisp.dhis.expression.ExpressionValidationOutcome)5 I18n (org.hisp.dhis.i18n.I18n)5 Indicator (org.hisp.dhis.indicator.Indicator)5 Date (java.util.Date)4 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)4 IndicatorGroupSet (org.hisp.dhis.indicator.IndicatorGroupSet)4 ValidationRule (org.hisp.dhis.validation.ValidationRule)4 System.currentTimeMillis (java.lang.System.currentTimeMillis)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Collections.unmodifiableCollection (java.util.Collections.unmodifiableCollection)3 Collections.unmodifiableSet (java.util.Collections.unmodifiableSet)3