2222
2323package com .iemr .helpline104 .service .outbound ;
2424
25+ import java .text .SimpleDateFormat ;
2526import java .util .ArrayList ;
2627import java .util .Arrays ;
28+ import java .util .HashMap ;
29+ import java .util .Map ;
30+
31+ import org .slf4j .Logger ;
32+ import org .slf4j .LoggerFactory ;
2733import org .springframework .beans .factory .annotation .Autowired ;
34+ import org .springframework .http .HttpEntity ;
35+ import org .springframework .http .HttpMethod ;
36+ import org .springframework .http .ResponseEntity ;
2837import org .springframework .stereotype .Service ;
38+ import org .springframework .web .client .RestTemplate ;
39+
40+ import com .google .gson .Gson ;
2941import com .iemr .helpline104 .repository .comoOutbound .OutboundCallActivityRepository ;
3042import com .iemr .helpline104 .data .comoOutbound .OutboundCallActivity ;
3143import com .iemr .helpline104 .data .comoOutbound .T_104CoMoOutboundCallDetails ;
3244import com .iemr .helpline104 .repository .comoOutbound .CoMoOutboundCallRepository ;
45+ import com .iemr .helpline104 .utils .RestTemplateUtil ;
46+ import com .iemr .helpline104 .utils .config .ConfigProperties ;
3347
3448@ Service
3549public 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}
0 commit comments