Search in sources :

Example 1 with Note

use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.

the class NotesConverterService method to.

@Override
public Note to(TrackedEntityComment trackedEntityComment) {
    Note note = new Note();
    note.setNote(trackedEntityComment.getUid());
    note.setValue(trackedEntityComment.getCommentText());
    note.setStoredAt(DateUtils.instantFromDate(trackedEntityComment.getCreated()));
    note.setStoredBy(trackedEntityComment.getCreator());
    return note;
}
Also used : Note(org.hisp.dhis.tracker.domain.Note)

Example 2 with Note

use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.

the class EnrollmentNoteValidationHookTest method testNoteWithExistingUidWarnings.

@Test
void testNoteWithExistingUidWarnings() {
    // Given
    final Note note = rnd.nextObject(Note.class);
    TrackerBundle trackerBundle = mock(TrackerBundle.class);
    TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
    TrackerPreheat preheat = mock(TrackerPreheat.class);
    when(ctx.getBundle()).thenReturn(trackerBundle);
    when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
    when(trackerBundle.getPreheat()).thenReturn(preheat);
    when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    enrollment.setNotes(Collections.singletonList(note));
    // When
    this.hook.validateEnrollment(reporter, enrollment);
    // Then
    assertTrue(reporter.hasWarnings());
    assertTrue(reporter.hasWarningReport(warn -> E1119.equals(warn.getWarningCode()) && ENROLLMENT.equals(warn.getTrackerType()) && enrollment.getUid().equals(warn.getUid())));
    assertThat(enrollment.getNotes(), hasSize(0));
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) E1119(org.hisp.dhis.tracker.report.TrackerErrorCode.E1119) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Note(org.hisp.dhis.tracker.domain.Note) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ENROLLMENT(org.hisp.dhis.tracker.TrackerType.ENROLLMENT) Mockito.when(org.mockito.Mockito.when) ValidationMode(org.hisp.dhis.tracker.ValidationMode) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Collections(java.util.Collections) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Mockito.mock(org.mockito.Mockito.mock) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 3 with Note

use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.

the class EnrollmentNoteValidationHookTest method testNotesAreValidWhenUidDoesNotExist.

@Test
void testNotesAreValidWhenUidDoesNotExist() {
    // Given
    final List<Note> notes = rnd.objects(Note.class, 5).collect(Collectors.toList());
    TrackerBundle trackerBundle = mock(TrackerBundle.class);
    TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
    when(ctx.getBundle()).thenReturn(trackerBundle);
    when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    enrollment.setNotes(notes);
    // When
    this.hook.validateEnrollment(reporter, enrollment);
    // Then
    assertFalse(reporter.hasErrors());
    assertThat(enrollment.getNotes(), hasSize(5));
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 4 with Note

use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.

the class NotesConverterServiceTest method verifyConvertCommentsToNotes.

@Test
void verifyConvertCommentsToNotes() {
    List<Note> notes = rnd.objects(Note.class, 10).collect(Collectors.toList());
    final List<TrackedEntityComment> comments = notesConverterService.from(preheat, notes);
    assertThat(comments, hasSize(10));
    for (Note note : notes) {
        assertNoteValues(comments.stream().filter(c -> c.getUid().equals(note.getNote())).findFirst().get(), note);
    }
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) Collectors(java.util.stream.Collectors) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) List(java.util.List) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Note(org.hisp.dhis.tracker.domain.Note) Matchers.hasSize(org.hamcrest.Matchers.hasSize) User(org.hisp.dhis.user.User) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) DateUtils(org.hisp.dhis.util.DateUtils) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) Note(org.hisp.dhis.tracker.domain.Note) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 5 with Note

use of org.hisp.dhis.tracker.domain.Note 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)

Aggregations

Note (org.hisp.dhis.tracker.domain.Note)18 Test (org.junit.jupiter.api.Test)15 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)10 TrackedEntityComment (org.hisp.dhis.trackedentitycomment.TrackedEntityComment)9 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)7 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)5 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers.hasSize (org.hamcrest.Matchers.hasSize)4 BeanRandomizer (org.hisp.dhis.random.BeanRandomizer)4 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)4 Event (org.hisp.dhis.tracker.domain.Event)4 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2