use of org.hisp.dhis.api.mobile.model.LWUITmodel.Notification in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method handleLostToFollowUp.
@SuppressWarnings("finally")
@Override
public Notification handleLostToFollowUp(LostEvent lostEvent) throws NotAllowedException {
Notification notification = new Notification();
try {
ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(lostEvent.getId());
programStageInstance.setDueDate(DateUtils.getMediumDate(lostEvent.getDueDate()));
programStageInstance.setStatus(EventStatus.fromInt(lostEvent.getStatus()));
if (lostEvent.getComment() != null) {
List<MessageConversation> conversationList = new ArrayList<>();
MessageConversation conversation = new MessageConversation(lostEvent.getName(), currentUserService.getCurrentUser(), MessageType.PRIVATE);
conversation.addMessage(new Message(lostEvent.getComment(), null, currentUserService.getCurrentUser()));
conversation.setRead(true);
conversationList.add(conversation);
programStageInstance.setMessageConversations(conversationList);
messageService.saveMessageConversation(conversation);
}
programStageInstanceService.updateProgramStageInstance(programStageInstance);
// send SMS
if (programStageInstance.getProgramInstance().getEntityInstance().getTrackedEntityAttributeValues() != null && lostEvent.getSMS() != null) {
List<User> recipientsList = new ArrayList<>();
for (TrackedEntityAttributeValue attrValue : programStageInstance.getProgramInstance().getEntityInstance().getTrackedEntityAttributeValues()) {
if (ValueType.PHONE_NUMBER == attrValue.getAttribute().getValueType()) {
User user = new User();
user.setPhoneNumber(attrValue.getValue());
recipientsList.add(user);
}
}
Set<User> recipients = new HashSet<>();
recipients.addAll(recipientsList);
smsSender.sendMessage(lostEvent.getName(), lostEvent.getSMS(), null, currentUserService.getCurrentUser(), recipients, false);
}
notification.setMessage("Success");
} catch (Exception e) {
e.printStackTrace();
notification.setMessage("Fail");
} finally {
return notification;
}
}
Aggregations