This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
forked from SEL-Columbia/dristhi
/
CampListener.java
111 lines (92 loc) · 3.55 KB
/
CampListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package org.opensrp.web.listener;
import java.util.List;
import org.json.JSONException;
import org.opensrp.camp.dao.CampDate;
import org.opensrp.camp.service.CampDateService;
import org.opensrp.register.mcare.domain.HouseHold;
import org.opensrp.register.mcare.domain.Members;
import org.opensrp.register.mcare.repository.AllHouseHolds;
import org.opensrp.register.mcare.repository.AllMembers;
import org.opensrp.scheduler.Action;
import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.service.MessageFactory;
import org.opensrp.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Service;
@Service
@EnableScheduling
public class CampListener {
private CampDateService campDateService;
private AllActions allActions;
private AllMembers allMembers;
private AllHouseHolds allHouseHolds;
private MessageService messageService;
@Autowired
public void setMessageService(MessageService messageService) {
this.messageService = messageService;
}
@Autowired
public void setAllMembers(AllMembers allMembers) {
this.allMembers = allMembers;
}
@Autowired
public void setAllHouseHolds(AllHouseHolds allHouseHolds) {
this.allHouseHolds = allHouseHolds;
}
@Autowired
public void setAllActions(AllActions allActions) {
this.allActions = allActions;
}
@Autowired
public void setCampDateService(CampDateService campDateService) {
this.campDateService = campDateService;
}
public void campAnnouncementListener(String HA) {
MessageFactory messageFactory = null;
messageFactory = MessageFactory.getMessageFactory("Ann");
try{
List<CampDate> campDates =campDateService.findCampByToday(HA);
sentMessageToClient(messageFactory,campDates);
}catch(Exception e){
e.printStackTrace();
}
}
public void campRemainderListener() throws JSONException {
MessageFactory messageFactory = null;
messageFactory = MessageFactory.getMessageFactory("Rem");
try{
List<CampDate> campDates =campDateService.findByTimeStamp();
sentMessageToClient(messageFactory,campDates);
}catch(Exception e){
e.printStackTrace();
}
}
private void sentMessageToClient(MessageFactory messageFactory,List<CampDate> campDates) throws JSONException{
String message;
System.err.println("messageFactory:"+messageFactory);
if(campDates != null){
for (CampDate campDate : campDates) {
List<Action> actions = allActions.listOfEligibleClientForVaccine(campDate.getHealth_assistant(),campDate.getSession_name());
for (Action action : actions) {
Members member = allMembers.findByCaseId(action.caseId());
HouseHold houseHold = allHouseHolds.findByCaseId(member.relationalid());
if(member.Is_child().equalsIgnoreCase("1")){
message = messageFactory.getMessageType("Child").message(member, campDate);
messageService.sentMessage(message, member.Member_Fname(), houseHold.HoH_Mobile_No(),campDate.getSession_location());
}else if(member.Is_woman().equalsIgnoreCase("1")) {
message = messageFactory.getMessageType("Woman").message(member, campDate);
messageService.sentMessage(message, member.Member_Fname(), houseHold.HoH_Mobile_No(),campDate.getSession_location());
}
else{
}
}
campDate.setDeleted(false);
campDate.setId(campDate.getId());
campDate.setRevision(campDate.getRevision());
campDateService.edit(campDate);
}
}else{
}
}
}