Search in sources :

Example 11 with TrackedEntityComment

use of org.hisp.dhis.trackedentitycomment.TrackedEntityComment in project dhis2-core by dhis2.

the class AbstractEventService method saveTrackedEntityComment.

private void saveTrackedEntityComment(ProgramStageInstance programStageInstance, Event event, String storedBy) {
    for (Note note : event.getNotes()) {
        TrackedEntityComment comment = new TrackedEntityComment();
        comment.setCreator(storedBy);
        comment.setCreatedDate(new Date());
        comment.setCommentText(note.getValue());
        commentService.addTrackedEntityComment(comment);
        programStageInstance.getComments().add(comment);
        programStageInstanceService.updateProgramStageInstance(programStageInstance);
    }
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Date(java.util.Date)

Example 12 with TrackedEntityComment

use of org.hisp.dhis.trackedentitycomment.TrackedEntityComment in project dhis2-core by dhis2.

the class AbstractEnrollmentService method saveTrackedEntityComment.

private void saveTrackedEntityComment(ProgramInstance programInstance, Enrollment enrollment, User user) {
    for (Note note : enrollment.getNotes()) {
        String noteUid = CodeGenerator.isValidUid(note.getNote()) ? note.getNote() : CodeGenerator.generateUid();
        if (!commentService.trackedEntityCommentExists(noteUid) && !StringUtils.isEmpty(note.getValue())) {
            TrackedEntityComment comment = new TrackedEntityComment();
            comment.setUid(noteUid);
            comment.setCommentText(note.getValue());
            comment.setCreator(StringUtils.isEmpty(note.getStoredBy()) ? user.getUsername() : note.getStoredBy());
            Date created = DateUtils.parseDate(note.getStoredDate());
            if (created == null) {
                created = new Date();
            }
            comment.setCreated(created);
            comment.setLastUpdatedBy(user);
            comment.setLastUpdated(new Date());
            commentService.addTrackedEntityComment(comment);
            programInstance.getComments().add(comment);
            programInstanceService.updateProgramInstance(programInstance, user);
            teiService.updateTrackedEntityInstance(programInstance.getEntityInstance(), user);
        }
    }
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Note(org.hisp.dhis.dxf2.events.event.Note) Date(java.util.Date)

Example 13 with TrackedEntityComment

use of org.hisp.dhis.trackedentitycomment.TrackedEntityComment in project dhis2-core by dhis2.

the class AbstractEventService method saveTrackedEntityComment.

private void saveTrackedEntityComment(ProgramStageInstance programStageInstance, Event event, User user, String storedBy) {
    for (Note note : event.getNotes()) {
        String noteUid = CodeGenerator.isValidUid(note.getNote()) ? note.getNote() : CodeGenerator.generateUid();
        if (!commentService.trackedEntityCommentExists(noteUid) && !StringUtils.isEmpty(note.getValue())) {
            TrackedEntityComment comment = new TrackedEntityComment();
            comment.setUid(noteUid);
            comment.setCommentText(note.getValue());
            comment.setCreator(getValidUsername(note.getStoredBy(), null, storedBy));
            Date created = DateUtils.parseDate(note.getStoredDate());
            comment.setCreated(created);
            comment.setLastUpdatedBy(user);
            comment.setLastUpdated(new Date());
            commentService.addTrackedEntityComment(comment);
            programStageInstance.getComments().add(comment);
        }
    }
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) Date(java.util.Date)

Example 14 with TrackedEntityComment

use of org.hisp.dhis.trackedentitycomment.TrackedEntityComment in project dhis2-core by dhis2.

the class NotesConverterServiceTest method verifyConvertNoteToComment.

@Test
void verifyConvertNoteToComment() {
    TrackedEntityComment comment = rnd.nextObject(TrackedEntityComment.class);
    final Note note = notesConverterService.to(comment);
    assertCommentValues(note, comment);
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Note(org.hisp.dhis.tracker.domain.Note) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 15 with TrackedEntityComment

use of org.hisp.dhis.trackedentitycomment.TrackedEntityComment in project dhis2-core by dhis2.

the class NotesConverterServiceTest method verifyConvertNotesToComments.

@Test
void verifyConvertNotesToComments() {
    List<TrackedEntityComment> comments = rnd.objects(TrackedEntityComment.class, 10).collect(Collectors.toList());
    final List<Note> notes = notesConverterService.to(comments);
    for (TrackedEntityComment comment : comments) {
        assertCommentValues(notes.stream().filter(n -> n.getNote().equals(comment.getUid())).findFirst().get(), comment);
    }
}
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)

Aggregations

TrackedEntityComment (org.hisp.dhis.trackedentitycomment.TrackedEntityComment)20 Test (org.junit.jupiter.api.Test)11 Note (org.hisp.dhis.tracker.domain.Note)9 Date (java.util.Date)8 List (java.util.List)6 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)5 Collectors (java.util.stream.Collectors)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers.hasSize (org.hamcrest.Matchers.hasSize)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 BeanRandomizer (org.hisp.dhis.random.BeanRandomizer)4 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)4 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)4 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)4 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Note (org.hisp.dhis.dxf2.events.event.Note)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2