Search in sources :

Example 1 with TrackerWarningReport

use of org.hisp.dhis.tracker.report.TrackerWarningReport in project dhis2-core by dhis2.

the class ProgramRuleIntegrationTest method testImportEventInProgramStageSuccessWithWarningRaised.

@Test
void testImportEventInProgramStageSuccessWithWarningRaised() throws IOException {
    InputStream inputStream = new ClassPathResource("tracker/tei_enrollment_event.json").getInputStream();
    TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportReport);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    List<TrackerWarningReport> warningReports = trackerImportReport.getValidationReport().getWarnings();
    assertEquals(4, warningReports.size());
    assertEquals(3, warningReports.stream().filter(w -> w.getTrackerType().equals(TrackerType.EVENT)).count());
    assertEquals(1, warningReports.stream().filter(w -> w.getTrackerType().equals(TrackerType.ENROLLMENT)).count());
    inputStream = new ClassPathResource("tracker/event_update_no_datavalue.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    trackerImportReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportReport);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    warningReports = trackerImportReport.getValidationReport().getWarnings();
    assertEquals(3, warningReports.size());
    assertEquals(TrackerErrorCode.E1308, warningReports.get(0).getWarningCode());
    assertEquals("Generated by program rule (`ProgramRule`) - DataElement `DATAEL00001` is being replaced in event `EVENT123456`", warningReports.get(0).getWarningMessage());
    inputStream = new ClassPathResource("tracker/event_update_datavalue.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    trackerImportReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportReport);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    warningReports = trackerImportReport.getValidationReport().getWarnings();
    assertEquals(3, warningReports.size());
    assertEquals(TrackerErrorCode.E1308, warningReports.get(0).getWarningCode());
    assertEquals("Generated by program rule (`ProgramRule`) - DataElement `DATAEL00001` is being replaced in event `EVENT123456`", warningReports.get(0).getWarningMessage());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) InputStream(java.io.InputStream) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport) ClassPathResource(org.springframework.core.io.ClassPathResource) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with TrackerWarningReport

use of org.hisp.dhis.tracker.report.TrackerWarningReport in project dhis2-core by dhis2.

the class ValidationUtils method validateNotes.

protected static List<Note> validateNotes(ValidationErrorReporter reporter, TrackerDto dto, List<Note> notesToCheck) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    final List<Note> notes = new ArrayList<>();
    for (Note note : notesToCheck) {
        if (// Ignore notes with no text
        isNotEmpty(note.getValue())) {
            // warning, ignore the note and continue
            if (isNotEmpty(note.getNote()) && context.getNote(note.getNote()).isPresent()) {
                TrackerWarningReport warning = TrackerWarningReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).warningCode(TrackerErrorCode.E1119).addArg(note.getNote()).build(reporter.getValidationContext().getBundle());
                reporter.addWarning(warning);
            } else {
                notes.add(note);
            }
        }
    }
    return notes;
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) ArrayList(java.util.ArrayList) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport)

Example 3 with TrackerWarningReport

use of org.hisp.dhis.tracker.report.TrackerWarningReport in project dhis2-core by dhis2.

the class ValidationUtils method addIssuesToReporter.

public static void addIssuesToReporter(ValidationErrorReporter reporter, TrackerDto dto, List<ProgramRuleIssue> programRuleIssues) {
    programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(ERROR)).forEach(issue -> {
        List<String> args = Lists.newArrayList(issue.getRuleUid());
        args.addAll(issue.getArgs());
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    });
    programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(WARNING)).forEach(issue -> {
        List<String> args = Lists.newArrayList(issue.getRuleUid());
        args.addAll(issue.getArgs());
        TrackerWarningReport warning = TrackerWarningReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).warningCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
        reporter.addWarning(warning);
    });
}
Also used : WARNING(org.hisp.dhis.tracker.programrule.IssueType.WARNING) DataValue(org.hisp.dhis.tracker.domain.DataValue) ERROR(org.hisp.dhis.tracker.programrule.IssueType.ERROR) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Note(org.hisp.dhis.tracker.domain.Note) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) Collectors(java.util.stream.Collectors) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) List(java.util.List) FeatureType(org.hisp.dhis.organisationunit.FeatureType) TrackerDto(org.hisp.dhis.tracker.domain.TrackerDto) Geometry(org.locationtech.jts.geom.Geometry) GEOMETRY_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.GEOMETRY_CANT_BE_NULL) ValidationStrategy(org.hisp.dhis.program.ValidationStrategy) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Aggregations

TrackerWarningReport (org.hisp.dhis.tracker.report.TrackerWarningReport)3 ArrayList (java.util.ArrayList)2 Note (org.hisp.dhis.tracker.domain.Note)2 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists (com.google.common.collect.Lists)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils.isNotEmpty (org.apache.commons.lang3.StringUtils.isNotEmpty)1 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)1 EventStatus (org.hisp.dhis.event.EventStatus)1 FeatureType (org.hisp.dhis.organisationunit.FeatureType)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1 ValidationStrategy (org.hisp.dhis.program.ValidationStrategy)1 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)1 DataValue (org.hisp.dhis.tracker.domain.DataValue)1 Event (org.hisp.dhis.tracker.domain.Event)1 TrackerDto (org.hisp.dhis.tracker.domain.TrackerDto)1