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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
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);
}
}
Aggregations