Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.iemr.common-API</groupId>
<artifactId>common-api</artifactId>
<version>3.8.1</version>
<version>3.9.0</version>
<packaging>war</packaging>

<name>Common-API</name>
Expand Down
7 changes: 4 additions & 3 deletions src/main/environment/common_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ cron-scheduler-ctidatasync=0 30 01 * * ? *

##-------------------------------###cti data check with call detail report Scheduler------------------------------------------------------

#Runs at everyday 12:10AM
#Runs at everyday 3:00AM - after the NHM data pull and CTI data sync complete
start-ctidatacheck-scheduler=false
cron-scheduler-ctidatacheck=0 00 02 * * *
cron-scheduler-ctidatacheck=0 00 03 * * *

##---------------------------------#### Registration schedular for Avni------------------------------------------------------------------------------

Expand All @@ -93,7 +93,8 @@ cron-scheduler-everwelldatasync=0 0/5 * * * ? *
##-----------------------------------------------#NHM data dashboard schedular----------------------------------------------------------------
# run at everyday 12:01AM
start-nhmdashboard-scheduler=true
cron-scheduler-nhmdashboard=0 1 * * * ? *
cron-scheduler-nhmdashboard=0 1 0 * * ? *
nhm-detailedcallreport-backfill-days=7
##----------------------------------------------------#grievance data sync-----------------------------------------------------------

start-grievancedatasync-scheduler=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,23 @@
@Value("${start-ctidatacheck-scheduler}")
private boolean startCtiDataCheckFlag;

/**
* Number of days (ending yesterday) checked against t_bencall. Kept in sync with
* the detailed call report backfill window, so that days pulled late from CTI are
* also reconciled. The reconciliation itself is idempotent.
*/
@Value("${nhm-detailedcallreport-backfill-days:7}")
private int lookBackDays;

@Scheduled(cron = "${cron-scheduler-ctidatacheck}")
public void detailedCallReport() {
if (startCtiDataCheckFlag) {
try {
String endDate = null;
String fromDate = null;
LocalDateTime date = null;
date = LocalDateTime.now().minusDays(1);
String[] dateArr = date.toString().split("T");
endDate = dateArr[0].concat(" 23:59:59");
fromDate = dateArr[0].concat(" 00:00:01");
int days = lookBackDays > 0 ? lookBackDays : 1;
LocalDateTime endDay = LocalDateTime.now().minusDays(1);

Check warning on line 57 in src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly specify the time zone by passing a ZoneId or a Clock to the .now() method.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ_L7yNtDI9jzO8qw2-_&open=AZ_L7yNtDI9jzO8qw2-_&pullRequest=445
LocalDateTime startDay = endDay.minusDays(days - 1L);
String endDate = endDay.toString().split("T")[0].concat(" 23:59:59");
String fromDate = startDay.toString().split("T")[0].concat(" 00:00:00");

Timestamp fromTime = Timestamp.valueOf(fromDate);
Timestamp endTime = Timestamp.valueOf(endDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.sql.Timestamp;

import org.springframework.beans.factory.annotation.Value;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.gson.annotations.Expose;
import com.iemr.common.data.beneficiary.Beneficiary;
Expand Down Expand Up @@ -234,6 +236,9 @@
@Column(name = "InsName")
private String instName;

@Value("${cti-logger_base_url}")
private String loggerBaseURL;

@Transient
@Expose
private String[] instNames;
Expand Down Expand Up @@ -280,7 +285,7 @@

public BeneficiaryCall(Long benCallID, Timestamp createdDate, String agentID, String callID, String recordingPath,
String archivePath) {
String loggerBaseURL = ConfigProperties.getPropertyByName("cti-logger_base_url");
// String loggerBaseURL = ConfigProperties.getPropertyByName("cti-logger_base_url");

Check warning on line 288 in src/main/java/com/iemr/common/data/callhandling/BeneficiaryCall.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This block of commented-out lines of code should be removed.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ_L9heYednYktmpi-Vz&open=AZ_L9heYednYktmpi-Vz&pullRequest=445
this.benCallID = benCallID;
this.createdDate = createdDate;
this.agentID = agentID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,27 @@
*/
package com.iemr.common.repository.nhm_dashboard;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.iemr.common.data.nhm_dashboard.DetailedCallReport;

@Repository
public interface DetailedCallReportRepo extends CrudRepository<DetailedCallReport, Long> {
List<DetailedCallReport> findByCallStartTimeBetween(Timestamp startDate, Timestamp endDate);

/**
* Call dates for which data has already been pulled from CTI. Used to detect
* the days that were missed by earlier scheduler runs, so that they can be
* pulled again instead of staying permanently empty.
*/
@Query(value = "select distinct date(Call_Start_Time) from t_DetailedCallReport "
+ "where Call_Start_Time between :startDate and :endDate", nativeQuery = true)
List<Date> findExistingCallDates(@Param("startDate") Timestamp startDate, @Param("endDate") Timestamp endDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@

private Logger logger = LoggerFactory.getLogger(BeneficiaryCallServiceImpl.class);

private static String ctiLoggerURL = ConfigProperties.getPropertyByName("cti-logger_base_url");
// private static String ctiLoggerURL = ConfigProperties.getPropertyByName("cti-logger_base_url");

Check warning on line 148 in src/main/java/com/iemr/common/service/callhandling/BeneficiaryCallServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This block of commented-out lines of code should be removed.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ_L9hb0ednYktmpi-Vx&open=AZ_L9hb0ednYktmpi-Vx&pullRequest=445

@Value("${cti-logger_base_url}")
private String ctiLoggerURL;

@Autowired
private IdentityBeneficiaryService identityBeneficiaryService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
private static HttpUtils httpUtils;
@Autowired
private CTIService ctiService;
private static String ctiLoggerURL = ConfigProperties.getPropertyByName("cti-logger_base_url");
// private static String ctiLoggerURL = ConfigProperties.getPropertyByName("cti-logger_base_url");

Check warning on line 66 in src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This block of commented-out lines of code should be removed.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ_L9hduednYktmpi-Vy&open=AZ_L9hduednYktmpi-Vy&pullRequest=445
@Value("${cti-logger_base_url}")
private String ctiLoggerURL;

public CallCentreDataSyncImpl() {
if (httpUtils == null) {
Expand All @@ -81,10 +83,10 @@
@Override
public void ctiDataSync() {
LocalDate currentDate = LocalDate.now();
// Calculate three days before the current date
LocalDate startDate = currentDate.minusDays(3);
// Calculate two days before the current date
LocalDate endDate = currentDate.minusDays(2);
// Look back 7 days to retry records that failed in previous runs
LocalDate startDate = currentDate.minusDays(7);
// Up to yesterday
LocalDate endDate = currentDate.minusDays(1);
// Convert LocalDate to LocalDateTime to set time as 00:00:00
LocalDateTime startDateTime = startDate.atTime(0, 0, 0);
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
Expand All @@ -96,64 +98,78 @@
List<BeneficiaryCall> list = callReportRepo.getAllBenCallIDetails(startTimeStamp, endTimeStamp);

if (!list.isEmpty()) {

// List<Long> benList = new ArrayList<>();
String callDuartion = null;
String filePath = null;
String URL = null;
String callinfoapiURL = null;
String ctiResponse = null;
String callEndTime = null;
String callStartTime = null;
String recordingPath = "";
logger.info("Total records to process for CTI data sync: " + list.size());
for (BeneficiaryCall call : list) {
if (call.getCallID() != null) {
recordingPath = null;
try {
JSONObject requestFile = new JSONObject();
requestFile.put("agent_id", call.getAgentID());
requestFile.put("session_id", call.getCallID());

OutputResponse response1 = ctiService.getVoiceFileNew(requestFile.toString(), "extra parameter");
if(response1 != null && response1.getStatusCode() == 200) {

CTIResponse ctiResponsePath = InputMapper.gson().fromJson(response1.getData(),
CTIResponse.class);
String recordingFilePath = ctiResponsePath.getResponse().toString();
if(recordingFilePath.length() > 20)
recordingPath = recordingFilePath.substring(20);
logger.info("recordingPath: " + recordingPath);
}

callDuartion = null;
callinfoapiURL = this.callinfoapiURL;
URL = callinfoapiURL.replace("CTI_SERVER", ctiServerIP).replace("AGENT_ID", call.getAgentID())
.replace("SESSION_ID", call.getCallID()).replace("PHONE_NO", call.getPhoneNo());

logger.info("calling CTI API url: " + URL);
ctiResponse = this.callUrl(URL);
logger.info("calling CTI_CDR_CALL_INFO API returned " + ctiResponse);

CTIData data = InputMapper.gson().fromJson(ctiResponse, CTIData.class);
CTIResponse model = data.getResponse();

if (model.getResponse_code().equals("1")) {
callDuartion = model.getCall_duration();
callEndTime = model.getCall_end_date_time();
callStartTime = model.getCall_start_date_time();
}
if (callDuartion != null)
call.setCZcallDuration(Integer.parseInt(callDuartion));
call.setRecordingPath(recordingPath);
if (call.getCallID() == null) {
logger.warn("Skipping record with null callID, benCallID: " + call.getBenCallID());
continue;
}
String recordingPath = null;
String callDuartion = null;
String callEndTime = null;
String callStartTime = null;
try {
JSONObject requestFile = new JSONObject();
requestFile.put("agent_id", call.getAgentID());
requestFile.put("session_id", call.getCallID());

OutputResponse response1 = ctiService.getVoiceFileNew(requestFile.toString(), "extra parameter");
if(response1 != null && response1.getStatusCode() == 200) {

CTIResponse ctiResponsePath = InputMapper.gson().fromJson(response1.getData(),
CTIResponse.class);
String recordingFilePath = ctiResponsePath.getResponse().toString();
if(recordingFilePath.length() > 20)
recordingPath = recordingFilePath.substring(20);
else if (!recordingFilePath.isEmpty())
recordingPath = recordingFilePath;
logger.info("recordingPath: " + recordingPath);
}

String callInfoURL = this.callinfoapiURL;
String URL = callInfoURL.replace("CTI_SERVER", ctiServerIP).replace("AGENT_ID", call.getAgentID())

Check warning on line 130 in src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ_L7yKbDI9jzO8qw2-7&open=AZ_L7yKbDI9jzO8qw2-7&pullRequest=445
.replace("SESSION_ID", call.getCallID()).replace("PHONE_NO", call.getPhoneNo());

logger.info("calling CTI API url: " + URL);
String ctiResponse = this.callUrl(URL);
logger.info("calling CTI_CDR_CALL_INFO API returned " + ctiResponse);

CTIData data = InputMapper.gson().fromJson(ctiResponse, CTIData.class);
CTIResponse model = data.getResponse();

if (model != null && "1".equals(model.getResponse_code())) {
callDuartion = model.getCall_duration();
callEndTime = model.getCall_end_date_time();
callStartTime = model.getCall_start_date_time();
} else {
logger.warn("CTI API returned non-success for sessionID: " + call.getCallID()
+ ", response_code: " + (model != null ? model.getResponse_code() : "null"));
}

// Only save if we got at least the call duration from CTI
if (callDuartion != null) {
call.setCZcallDuration(Integer.parseInt(callDuartion));
call.setCZcallEndTime(callEndTime);
call.setCZcallStartTime(callStartTime);
call.setRecordingPath(recordingPath);
callReportRepo.save(call);
logger.info("CTI data sync saved for benCallID: " + call.getBenCallID());
} else if (recordingPath != null) {
// Duration not available yet, but recording path is β€” save path only
call.setRecordingPath(recordingPath);
callReportRepo.save(call);
logger.info("calling CTI_CDR_CALL_INFO after API call save response " + call);
} catch (Exception e) {
logger.error("VoiceFile failed with error " + e.getMessage(), e);
logger.info("Only recordingPath saved (duration pending) for benCallID: " + call.getBenCallID());
} else {
logger.warn("No CTI data available yet for sessionID: " + call.getCallID()
+ ", benCallID: " + call.getBenCallID() + " - will retry next run");
}
} catch (Exception e) {
logger.error("CTI data sync failed for benCallID: " + call.getBenCallID()
+ ", sessionID: " + call.getCallID() + " - " + e.getMessage(), e);
}
}
} else {
logger.info("No pending records found for CTI data sync");
}
}
}
Loading
Loading