Skip to content

Commit 0941f26

Browse files
committed
fix: make a resttemplate request to common-api to store in t_outboundcallrequest table
1 parent 3f23334 commit 0941f26

5 files changed

Lines changed: 96 additions & 5 deletions

File tree

src/main/java/com/iemr/helpline104/controller/outbound/OutboundCallActivityController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.iemr.helpline104.utils.mapper.InputMapper;
3636
import com.iemr.helpline104.utils.response.OutputResponse;
3737

38+
import jakarta.servlet.http.HttpServletRequest;
39+
3840
@RestController
3941
@RequestMapping(value = "/outbound")
4042
public class OutboundCallActivityController {
@@ -135,12 +137,13 @@ public String toggleActivityStatus(@RequestBody String request) {
135137

136138
// Save call details on close
137139
@PostMapping(value = "/callDetails/save", headers = "Authorization")
138-
public String saveCallDetails(@RequestBody String request) {
140+
public String saveCallDetails(@RequestBody String request, HttpServletRequest httpRequest) {
139141
OutputResponse output = new OutputResponse();
140142
try {
141143
T_104CoMoOutboundCallDetails callDetails = inputMapper.gson().fromJson(request,
142144
T_104CoMoOutboundCallDetails.class);
143-
T_104CoMoOutboundCallDetails savedObj = activityService.saveCallDetails(callDetails);
145+
String authorization = httpRequest.getHeader("Authorization");
146+
T_104CoMoOutboundCallDetails savedObj = activityService.saveCallDetails(callDetails, authorization);
144147
output.setResponse(new Gson().toJson(savedObj));
145148
} catch (Exception e) {
146149
output.setError(e);

src/main/java/com/iemr/helpline104/data/comoOutbound/T_104CoMoOutboundCallDetails.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package com.iemr.helpline104.data.comoOutbound;
2323

2424
import java.sql.Date;
25+
import java.sql.Timestamp;
2526

2627
import jakarta.persistence.*;
2728
import lombok.Data;
@@ -65,6 +66,36 @@ public class T_104CoMoOutboundCallDetails {
6566
@Column(name = "CallRemarks", length = 500)
6667
private String callRemarks; // specifically for call activity to avoid conflicts with Remarks field
6768

69+
@Column(name = "BeneficiaryRegID")
70+
private Long beneficiaryRegID;
71+
72+
@Column(name = "ProviderServiceMapID")
73+
private Integer providerServiceMapID;
74+
75+
@Column(name = "PrefferedDateTime")
76+
private Timestamp prefferedDateTime;
77+
78+
@Column(name = "BenCallID")
79+
private Long benCallID;
80+
81+
@Column(name = "RequestedFor")
82+
private String requestedFor;
83+
84+
@Column(name = "CallTypeID")
85+
private Integer callTypeID;
86+
87+
@Column(name = "SubServiceID")
88+
private Integer subServiceID;
89+
90+
@Column(name = "AssignedUserID")
91+
private Integer assignedUserID;
92+
93+
@Column(name = "RequestedFeature")
94+
private String requestedFeature;
95+
96+
@Column(name = "IsSelf")
97+
private Boolean isSelf;
98+
6899
public T_104CoMoOutboundCallDetails() {
69100
super();
70101
}

src/main/java/com/iemr/helpline104/service/outbound/OutboundCallActivityService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public interface OutboundCallActivityService {
4343

4444
ArrayList<T_104CoMoOutboundCallDetails> getCallActivityHistory();
4545

46-
T_104CoMoOutboundCallDetails saveCallDetails(T_104CoMoOutboundCallDetails callDetails);
46+
T_104CoMoOutboundCallDetails saveCallDetails(T_104CoMoOutboundCallDetails callDetails, String authorization);
4747

4848
}

src/main/java/com/iemr/helpline104/service/outbound/OutboundCallActivityServiceImpl.java

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,34 @@
2222

2323
package com.iemr.helpline104.service.outbound;
2424

25+
import java.text.SimpleDateFormat;
2526
import java.util.ArrayList;
2627
import java.util.Arrays;
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
2733
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.http.HttpEntity;
35+
import org.springframework.http.HttpMethod;
36+
import org.springframework.http.ResponseEntity;
2837
import org.springframework.stereotype.Service;
38+
import org.springframework.web.client.RestTemplate;
39+
40+
import com.google.gson.Gson;
2941
import com.iemr.helpline104.repository.comoOutbound.OutboundCallActivityRepository;
3042
import com.iemr.helpline104.data.comoOutbound.OutboundCallActivity;
3143
import com.iemr.helpline104.data.comoOutbound.T_104CoMoOutboundCallDetails;
3244
import com.iemr.helpline104.repository.comoOutbound.CoMoOutboundCallRepository;
45+
import com.iemr.helpline104.utils.RestTemplateUtil;
46+
import com.iemr.helpline104.utils.config.ConfigProperties;
3347

3448
@Service
3549
public class OutboundCallActivityServiceImpl implements OutboundCallActivityService {
3650

51+
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());
52+
3753
@Autowired
3854
private OutboundCallActivityRepository activityRepository;
3955

@@ -95,11 +111,51 @@ public ArrayList<T_104CoMoOutboundCallDetails> getCallActivityHistory() {
95111
}
96112

97113
@Override
98-
public T_104CoMoOutboundCallDetails saveCallDetails(T_104CoMoOutboundCallDetails callDetails) {
114+
public T_104CoMoOutboundCallDetails saveCallDetails(T_104CoMoOutboundCallDetails callDetails, String authorization) {
99115
validateCallStatus(callDetails.getCallStatus());
100116
if (callDetails.getDeleted() == null) {
101117
callDetails.setDeleted(false);
102118
}
103-
return outboundCallRepository.save(callDetails);
119+
T_104CoMoOutboundCallDetails savedObj = outboundCallRepository.save(callDetails);
120+
121+
// Push outbound call request to Common-API's t_outboundcallrequest table
122+
try {
123+
pushToCommonAPI(callDetails, authorization);
124+
} catch (Exception e) {
125+
logger.error("Failed to push outbound call request to Common-API: " + e.getMessage(), e);
126+
}
127+
128+
return savedObj;
129+
}
130+
131+
private void pushToCommonAPI(T_104CoMoOutboundCallDetails callDetails, String authorization) {
132+
String commonApiUrl = ConfigProperties.getPropertyByName("common-url")
133+
+ "/" + ConfigProperties.getPropertyByName("create-outbound-call-request-url");
134+
135+
Map<String, Object> outboundCallRequest = new HashMap<>();
136+
outboundCallRequest.put("beneficiaryRegID", callDetails.getBeneficiaryRegID());
137+
outboundCallRequest.put("providerServiceMapID", callDetails.getProviderServiceMapID());
138+
outboundCallRequest.put("requestedFor", callDetails.getRequestedFor() != null
139+
? callDetails.getRequestedFor()
140+
: callDetails.getCallType() + " - " + callDetails.getCallSubType());
141+
if (callDetails.getPrefferedDateTime() != null) {
142+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
143+
outboundCallRequest.put("prefferedDateTime", sdf.format(callDetails.getPrefferedDateTime()));
144+
}
145+
outboundCallRequest.put("benCallID", callDetails.getBenCallID());
146+
outboundCallRequest.put("createdBy", callDetails.getCreatedBy());
147+
outboundCallRequest.put("callTypeID", callDetails.getCallTypeID());
148+
outboundCallRequest.put("requestedServiceID", callDetails.getSubServiceID());
149+
outboundCallRequest.put("assignedUserID", callDetails.getAssignedUserID());
150+
outboundCallRequest.put("requestedFeature", callDetails.getRequestedFeature());
151+
outboundCallRequest.put("isSelf", callDetails.getIsSelf());
152+
153+
String requestBody = new Gson().toJson(outboundCallRequest);
154+
155+
RestTemplate restTemplate = new RestTemplate();
156+
HttpEntity<Object> requestEntity = RestTemplateUtil.createRequestEntity(requestBody, authorization);
157+
ResponseEntity<String> response = restTemplate.exchange(commonApiUrl, HttpMethod.POST, requestEntity, String.class);
158+
159+
logger.info("Common-API createOutboundCallRequest response: " + response.getBody());
104160
}
105161
}

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spring.jackson.serialization.fail-on-empty-beans=false
2626

2727
####Project specific URL Configurations
2828
create-feedback=feedback/createFeedback
29+
create-outbound-call-request-url=call/createOutboundCallRequest
2930

3031
#spring.session.store-type=none
3132

0 commit comments

Comments
 (0)