-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathOutboundCallActivityController.java
More file actions
185 lines (163 loc) · 7.52 KB
/
OutboundCallActivityController.java
File metadata and controls
185 lines (163 loc) · 7.52 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.helpline104.controller.outbound;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.iemr.helpline104.data.comoOutbound.OutboundCallActivity;
import com.iemr.helpline104.data.comoOutbound.T_104CoMoOutboundCallDetails;
import com.iemr.helpline104.service.outbound.OutboundCallActivityService;
import com.iemr.helpline104.utils.CookieUtil;
import com.iemr.helpline104.utils.JwtUtil;
import com.iemr.helpline104.utils.mapper.InputMapper;
import com.iemr.helpline104.utils.response.OutputResponse;
import jakarta.servlet.http.HttpServletRequest;
@RestController
@RequestMapping(value = "/outbound")
public class OutboundCallActivityController {
@Autowired
private OutboundCallActivityService activityService;
@Autowired
private InputMapper inputMapper;
@Autowired
private JwtUtil jwtUtil;
@Autowired
private CookieUtil cookieUtil;
// Get activities by providerServiceMapID
@PostMapping(value = "/activities", headers = "Authorization")
public String getActiveActivities(@RequestBody String request) {
OutputResponse output = new OutputResponse();
try {
JsonObject obj = new JsonParser().parse(request).getAsJsonObject();
ArrayList<OutboundCallActivity> activities;
if (obj.has("providerServiceMapID") && obj.get("providerServiceMapID") != null
&& !obj.get("providerServiceMapID").isJsonNull()) {
Integer providerServiceMapID = obj.get("providerServiceMapID").getAsInt();
activities = activityService.getActiveActivitiesByProvider(providerServiceMapID);
} else {
// Return all active activities if providerServiceMapID not provided
activities = activityService.getActiveActivitiesByProvider(null);
}
output.setResponse(new Gson().toJson(activities));
} catch (Exception e) {
output.setError(e);
}
return output.toString();
}
// Get ALL active activities (for admin/supervisor)
@GetMapping(value = "/activities/all", headers = "Authorization")
public String getAllActiveActivities() {
OutputResponse output = new OutputResponse();
try {
ArrayList<OutboundCallActivity> activities = activityService.getAllActivities();
output.setResponse(new Gson().toJson(activities));
} catch (Exception e) {
output.setError(e);
}
return output.toString();
}
// Save/Create activity
@PostMapping(value = "/activity", headers = "Authorization")
public String saveActivity(@RequestBody String request) {
OutputResponse output = new OutputResponse();
try {
OutboundCallActivity activity = inputMapper.gson().fromJson(request, OutboundCallActivity.class);
OutboundCallActivity savedObj = activityService.saveActivity(activity);
output.setResponse("Activity saved successfully with ID: " + savedObj.getActivityID());
} catch (Exception e) {
output.setError(e);
}
return output.toString();
}
// Update activity name
@PutMapping(value = "/activity/name", headers = "Authorization")
public String updateActivityName(@RequestBody String request) {
OutputResponse output = new OutputResponse();
try {
JsonObject obj = new JsonParser().parse(request).getAsJsonObject();
Long activityID = obj.get("activityID").getAsLong();
String activityName = obj.get("activityName").getAsString();
String modifiedBy = obj.get("modifiedBy").getAsString();
Integer updated = activityService.updateActivityName(activityID, activityName, modifiedBy);
output.setResponse("Activity name updated successfully. Rows affected: " + updated);
} catch (Exception e) {
output.setError(e);
}
return output.toString();
}
// Toggle activity status (enable/disable)
@PutMapping(value = "/activity/status", headers = "Authorization")
public String toggleActivityStatus(@RequestBody String request) {
OutputResponse output = new OutputResponse();
try {
JsonObject obj = new JsonParser().parse(request).getAsJsonObject();
Long activityID = obj.get("activityID").getAsLong();
Boolean deleted = obj.get("deleted").getAsBoolean();
String modifiedBy = obj.get("modifiedBy").getAsString();
Integer updated = activityService.toggleActivityStatus(activityID, deleted, modifiedBy);
output.setResponse("Activity status updated successfully. Rows affected: " + updated);
} catch (Exception e) {
output.setError(e);
}
return output.toString();
}
// Save call details on close
@PostMapping(value = "/callDetails/save", headers = "Authorization")
public String saveCallDetails(@RequestBody String request) {
OutputResponse output = new OutputResponse();
try {
T_104CoMoOutboundCallDetails callDetails = inputMapper.gson().fromJson(request,
T_104CoMoOutboundCallDetails.class);
T_104CoMoOutboundCallDetails savedObj = activityService.saveCallDetails(callDetails);
output.setResponse(new Gson().toJson(savedObj));
} catch (Exception e) {
output.setError(e);
}
return output.toString();
}
// Get active call details for the logged-in user
@GetMapping(value = "/callDetails/get", headers = "Authorization")
public String getActiveCallDetails(HttpServletRequest httpRequest) {
OutputResponse output = new OutputResponse();
try {
String jwtToken = cookieUtil.getCookieValue(httpRequest, "Jwttoken").orElse(null);
if (jwtToken == null) {
jwtToken = httpRequest.getHeader("JwtToken");
}
if (jwtToken == null) {
throw new IllegalArgumentException("Authentication token not found");
}
String userName = jwtUtil.extractUsername(jwtToken);
if (userName == null || userName.isEmpty()) {
throw new IllegalArgumentException("Unable to extract user from token");
}
ArrayList<T_104CoMoOutboundCallDetails> callDetails = activityService.getActiveCallDetailsByUser(userName);
output.setResponse(new Gson().toJson(callDetails));
} catch (Exception e) {
output.setError(e);
}
return output.toString();
}
}