From 68bb0805100885199faf0e1cb3613591d0910367 Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Wed, 20 Dec 2023 18:03:58 +0530
Subject: [PATCH 01/12] Added limit condition while fetching Item stock entry
 details in eaushadha API

---
 .../iemr/common/repository/eausadha/ItemStockEntryRepo.java    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/java/com/iemr/common/repository/eausadha/ItemStockEntryRepo.java b/src/main/java/com/iemr/common/repository/eausadha/ItemStockEntryRepo.java
index eae06706..1403681d 100644
--- a/src/main/java/com/iemr/common/repository/eausadha/ItemStockEntryRepo.java
+++ b/src/main/java/com/iemr/common/repository/eausadha/ItemStockEntryRepo.java
@@ -15,7 +15,8 @@
 @RestResource(exported = false)
 public interface ItemStockEntryRepo extends CrudRepository<ItemStockEntry, Integer> {
 	
-	@Query("Select t from ItemStockEntry t Where t.itemID = :itemId And t.batchNo = :batchNo")
+	@Query(nativeQuery = true, value = " SELECT * FROM db_iemr.t_itemstockentry "
+			+ " WHERE ItemID =:itemId and BatchNo =:batchNo LIMIT 1" )
 	ItemStockEntry getItemStocks(@Param("itemId")Integer itemId, @Param("batchNo")String batchNo);
 	
 	@Transactional

From 7afc342b34b640d23bc82c79559d12e644d484bb Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Tue, 30 Jan 2024 13:19:17 +0530
Subject: [PATCH 02/12] Minor modifications in 1097 referral sms template

---
 .../java/com/iemr/common/service/sms/SMSServiceImpl.java    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java b/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java
index 1d63bb45..51e6c49c 100644
--- a/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java
@@ -878,7 +878,7 @@ private String getInstituteData(String className, String methodName, SMSRequest
 		case "address2":
 			String truncatedAdress2 = institute.getAddress() != null ? institute.getAddress() + " " : "";
 			if(!truncatedAdress2.isEmpty()) {
-				variableValue = getSubstringInRange(institute.getAddress(), 30, 59);
+				variableValue = getSubstringInRange(institute.getAddress(), 29, 59);
 			}else {
 				variableValue = "";
 			}
@@ -886,7 +886,7 @@ private String getInstituteData(String className, String methodName, SMSRequest
 		case "address3":
 			String truncatedAdress3 = institute.getAddress() != null ? institute.getAddress() + " " : "";
 			if(!truncatedAdress3.isEmpty()) {
-				variableValue = getSubstringInRange(institute.getAddress(), 60, 89);
+				variableValue = getSubstringInRange(institute.getAddress(), 59, 89);
 			}else {
 				variableValue = "";
 			}
@@ -920,7 +920,7 @@ private String getInstituteData(String className, String methodName, SMSRequest
 		default:
 			break;
 		}
-		return variableValue.trim();
+		return variableValue;
 	}
 	
 	private static String getSubstringInRange(String input, int startIndex, int endIndex) {

From 593728d02ae4c7dbb2663e19848151876b061ce3 Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Wed, 31 Jan 2024 15:29:09 +0530
Subject: [PATCH 03/12] Added institute name along with referral SMS

---
 .../common/service/sms/SMSServiceImpl.java     | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java b/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java
index 51e6c49c..0de15785 100644
--- a/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java
@@ -868,25 +868,31 @@ private String getInstituteData(String className, String methodName, SMSRequest
 			variableValue = address;
 			break;
 		case "address1":
-			String truncatedAdress1 = institute.getAddress() != null ? institute.getAddress() + " " : "";
+			String hospitalName1 = institute.getInstitutionName() != null ? institute.getInstitutionName() + " " : "";
+			String addressValue1 = institute.getAddress() != null ? institute.getAddress() + " " : "";
+			String truncatedAdress1 = hospitalName1.concat(" ").concat(addressValue1);
 			if(!truncatedAdress1.isEmpty()) {
-				variableValue = getSubstringInRange(institute.getAddress(), 0, 29);
+				variableValue = getSubstringInRange(truncatedAdress1, 0, 29);
 			}else {
 				variableValue = "";
 			}
 			break;
 		case "address2":
-			String truncatedAdress2 = institute.getAddress() != null ? institute.getAddress() + " " : "";
+			String hospitalName2 = institute.getInstitutionName() != null ? institute.getInstitutionName() + " " : "";
+			String addressValue2 = institute.getAddress() != null ? institute.getAddress() + " " : "";
+			String truncatedAdress2 = hospitalName2.concat(" ").concat(addressValue2);
 			if(!truncatedAdress2.isEmpty()) {
-				variableValue = getSubstringInRange(institute.getAddress(), 29, 59);
+				variableValue = getSubstringInRange(truncatedAdress2, 29, 59);
 			}else {
 				variableValue = "";
 			}
 			break;
 		case "address3":
-			String truncatedAdress3 = institute.getAddress() != null ? institute.getAddress() + " " : "";
+			String hospitalName3 = institute.getInstitutionName() != null ? institute.getInstitutionName() + " " : "";
+			String addressValue3= institute.getAddress() != null ? institute.getAddress() + " " : "";
+			String truncatedAdress3 = hospitalName3.concat(" ").concat(addressValue3);
 			if(!truncatedAdress3.isEmpty()) {
-				variableValue = getSubstringInRange(institute.getAddress(), 59, 89);
+				variableValue = getSubstringInRange(truncatedAdress3, 59, 89);
 			}else {
 				variableValue = "";
 			}

From 0ad1dd7afef4d66a3f32fcb94dfbbb83c7528279 Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Fri, 16 Feb 2024 18:28:54 +0530
Subject: [PATCH 04/12] Removed myapp propeties and minor change in
 interceptor.

---
 .../config/BlockingHttpMethodInterceptor.java | 36 -------------------
 .../iemr/common/config/InterceptorConfig.java | 17 +++------
 .../CareStreamCreateOrderController.java      |  1 -
 3 files changed, 5 insertions(+), 49 deletions(-)
 delete mode 100644 src/main/java/com/iemr/common/config/BlockingHttpMethodInterceptor.java

diff --git a/src/main/java/com/iemr/common/config/BlockingHttpMethodInterceptor.java b/src/main/java/com/iemr/common/config/BlockingHttpMethodInterceptor.java
deleted file mode 100644
index 447e3aaa..00000000
--- a/src/main/java/com/iemr/common/config/BlockingHttpMethodInterceptor.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.iemr.common.config;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.servlet.HandlerInterceptor;
-import org.springframework.web.servlet.ModelAndView;
-
-public class BlockingHttpMethodInterceptor implements HandlerInterceptor {
-	@Override
-    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
-        String method = request.getMethod();
-        if (!("GET".equals(method) || "POST".equals(method))) {
-            response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
-            return false;
-        }
-        return true;
-}
-
-	@Override
-	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
-			ModelAndView modelAndView) throws Exception {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
-			throws Exception {
-		// TODO Auto-generated method stub
-		
-	}
-}
\ No newline at end of file
diff --git a/src/main/java/com/iemr/common/config/InterceptorConfig.java b/src/main/java/com/iemr/common/config/InterceptorConfig.java
index 37817edf..2beb8de9 100644
--- a/src/main/java/com/iemr/common/config/InterceptorConfig.java
+++ b/src/main/java/com/iemr/common/config/InterceptorConfig.java
@@ -29,21 +29,14 @@
 import com.iemr.common.utils.http.HTTPRequestInterceptor;
 
 @Configuration
-public class InterceptorConfig extends WebMvcConfigurerAdapter
-{
+public class InterceptorConfig extends WebMvcConfigurerAdapter {
 
 	@Autowired
 	HTTPRequestInterceptor requestInterceptor;
 
-//	@Override
-//	public void addInterceptors(InterceptorRegistry registry)
-//	{
-//		registry.addInterceptor(requestInterceptor);
-//	}
-	
 	@Override
-    public void addInterceptors(InterceptorRegistry registry) {
-        registry.addInterceptor(new BlockingHttpMethodInterceptor())
-                .addPathPatterns("/**"); 
-    }
+	public void addInterceptors(InterceptorRegistry registry) {
+		registry.addInterceptor(requestInterceptor);
+	}
+
 }
\ No newline at end of file
diff --git a/src/main/java/com/iemr/common/controller/carestream/CareStreamCreateOrderController.java b/src/main/java/com/iemr/common/controller/carestream/CareStreamCreateOrderController.java
index 529c759c..4a4f2a05 100644
--- a/src/main/java/com/iemr/common/controller/carestream/CareStreamCreateOrderController.java
+++ b/src/main/java/com/iemr/common/controller/carestream/CareStreamCreateOrderController.java
@@ -44,7 +44,6 @@
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 
-@PropertySource("classpath:myapp.properties")
 @RestController
 @RequestMapping(value = "/carestream")
 public class CareStreamCreateOrderController {

From 6cfbb83c1b61002af1229c37198b37eb060b5faa Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Thu, 21 Mar 2024 10:11:08 +0530
Subject: [PATCH 05/12] Change in Phone No comparison while fetching call audit
 details

---
 .../callhandling/BeneficiaryCallServiceImpl.java | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/iemr/common/service/callhandling/BeneficiaryCallServiceImpl.java b/src/main/java/com/iemr/common/service/callhandling/BeneficiaryCallServiceImpl.java
index c554ee8d..55f6b09c 100644
--- a/src/main/java/com/iemr/common/service/callhandling/BeneficiaryCallServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/callhandling/BeneficiaryCallServiceImpl.java
@@ -1070,8 +1070,12 @@ private Long getTotalCallCount(CriteriaBuilder criteriaBuilder, BeneficiaryCall
 			predicates.add(criteriaBuilder.equal(entityRoot.get("callTypeID"), callRequest.getCallTypeID()));
 		}
 
-		predicates.add(criteriaBuilder.like(entityRoot.get("phoneNo"),
-				(callRequest.getPhoneNo() == null) ? "%%" : callRequest.getPhoneNo()));
+//		predicates.add(criteriaBuilder.like(entityRoot.get("phoneNo"),
+//				(callRequest.getPhoneNo() == null) ? "%%" : callRequest.getPhoneNo()));
+		
+		if (callRequest.getPhoneNo() != null) {
+			predicates.add(criteriaBuilder.equal(entityRoot.get("phoneNo"), callRequest.getPhoneNo()));
+		}
 
 		if (callRequest.getInboundOutbound() != null) {
 			callRequest.setIsOutbound(callRequest.getInboundOutbound().equalsIgnoreCase("outbound") ? true : false);
@@ -1211,8 +1215,12 @@ public String filterCallList(String request, String auth) throws IEMRException {
 			predicates.add(criteriaBuilder.equal(root.get("callTypeID"), callRequest.getCallTypeID()));
 		}
 
-		predicates.add(criteriaBuilder.like(root.get("phoneNo"),
-				(callRequest.getPhoneNo() == null) ? "%%" : callRequest.getPhoneNo()));
+//		predicates.add(criteriaBuilder.like(root.get("phoneNo"),
+//				(callRequest.getPhoneNo() == null) ? "%%" : callRequest.getPhoneNo()));
+		
+		if (callRequest.getPhoneNo() != null) {
+			predicates.add(criteriaBuilder.equal(root.get("phoneNo"), callRequest.getPhoneNo()));
+		}
 
 		if (callRequest.getInboundOutbound() != null) {
 			callRequest.setIsOutbound(callRequest.getInboundOutbound().equalsIgnoreCase("outbound") ? true : false);

From 9a499da8be29ec701fec1caf6c4a91d380f70f6b Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Mon, 8 Apr 2024 18:24:08 +0530
Subject: [PATCH 06/12] Corrected empty array response in JsonObject -
 editBenCommunity

---
 .../beneficiary/BeneficiaryRegistrationController.java       | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java b/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java
index 598a78d4..4225d695 100644
--- a/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java
+++ b/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java
@@ -452,7 +452,10 @@ public String updateBenefciaryCommunityorEducation(
 								.toJson(iemrSearchUserService.userExitsCheckWithId(
 										benificiaryDetails.getBeneficiaryRegID(), auth,
 										benificiaryDetails.getIs1097())));
-				JSONObject responseObj = new JSONObject(updatedUserData.getJSONObject(0).toString());
+				JSONObject responseObj = new JSONObject();
+				if(updatedUserData != null && updatedUserData.length()>0) {
+					updatedUserData.getJSONObject(0).toString();
+					}
 				responseObj.put("updateCount", updateCount);
 				response.setResponse(responseObj.toString());
 			}

From 2dac92fa68e2b4f5a731b76d9f6cb94869d49f36 Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Tue, 9 Apr 2024 14:41:35 +0530
Subject: [PATCH 07/12] Reverted - update community education changes

---
 .../beneficiary/BeneficiaryRegistrationController.java       | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java b/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java
index 4225d695..598a78d4 100644
--- a/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java
+++ b/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java
@@ -452,10 +452,7 @@ public String updateBenefciaryCommunityorEducation(
 								.toJson(iemrSearchUserService.userExitsCheckWithId(
 										benificiaryDetails.getBeneficiaryRegID(), auth,
 										benificiaryDetails.getIs1097())));
-				JSONObject responseObj = new JSONObject();
-				if(updatedUserData != null && updatedUserData.length()>0) {
-					updatedUserData.getJSONObject(0).toString();
-					}
+				JSONObject responseObj = new JSONObject(updatedUserData.getJSONObject(0).toString());
 				responseObj.put("updateCount", updateCount);
 				response.setResponse(responseObj.toString());
 			}

From 7224a045efd525ad02da5a5957698a47ecef11de Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Mon, 15 Apr 2024 15:54:18 +0530
Subject: [PATCH 08/12] Added cti data sync scheduler execution time change and
 start date and end date change for last two days

---
 src/main/environment/common_dev.properties    |  2 +-
 src/main/environment/common_test.properties   |  3 +-
 .../ctiCall/CallCentreDataSyncImpl.java       | 42 +++++++++++++------
 3 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties
index 7b8521f1..dbef254e 100644
--- a/src/main/environment/common_dev.properties
+++ b/src/main/environment/common_dev.properties
@@ -64,7 +64,7 @@ cron-scheduler-email=0 0/1 * * * ? *
 
 ###cti data sync Scheduler configurations
 start-ctidatasync-scheduler=false
-cron-scheduler-ctidatasync=0 00 01 * * ? *
+cron-scheduler-ctidatasync=0 0 2 */2 * ?
 
 ###cti data check with call detail report Scheduler
 #Runs at everyday 12:10AM 
diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties
index 1e51a0c3..5d39b23a 100644
--- a/src/main/environment/common_test.properties
+++ b/src/main/environment/common_test.properties
@@ -59,7 +59,8 @@ cron-scheduler-email=0 0/1 * * * ? *
 ##-------------------------------###cti data sync Scheduler configurations------------------------------------------------------
 
 start-ctidatasync-scheduler=false
-cron-scheduler-ctidatasync=0 00 01 * * ? *
+cron-scheduler-ctidatasync=0 0 2 */2 * ?
+
 
 ##-------------------------------###cti data check with call detail report Scheduler------------------------------------------------------
 
diff --git a/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java b/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java
index 14cf3d48..9f966f30 100644
--- a/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java
+++ b/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java
@@ -22,6 +22,8 @@
 package com.iemr.common.service.ctiCall;
 
 import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -86,20 +88,34 @@ public String callUrl(String urlRequest) {
 	@Override
 	public void ctiDataSync() {
 		List<Objects[]> resultSet = null;
-		Date date = new Date();
-		java.sql.Date sqlDate = new java.sql.Date(date.getTime());
-		String text = sqlDate.toString();
-		Timestamp endDate = new Timestamp(sqlDate.getTime());
-		Calendar calendar = Calendar.getInstance();
-		calendar.setTime(sqlDate);
-		logger.info("CZduration: " + CZduration);
-		calendar.add(Calendar.DATE, -(Integer.parseInt(CZduration)));
-		Date beforeDate = calendar.getTime();
-		Timestamp startDate = new Timestamp(beforeDate.getTime());
+//		Date date = new Date();
+//		java.sql.Date sqlDate = new java.sql.Date(date.getTime());
+//		String text = sqlDate.toString();
+//		Timestamp endDate = new Timestamp(sqlDate.getTime());
+//		Calendar calendar = Calendar.getInstance();
+//		calendar.setTime(sqlDate);
+//		logger.info("CZduration: " + CZduration);
+//		calendar.add(Calendar.DATE, -(Integer.parseInt(CZduration)));
+//		Date beforeDate = calendar.getTime();
+//		Timestamp startDate = new Timestamp(beforeDate.getTime());
+		
+		 // Get the current date
+	       LocalDate currentDate = LocalDate.now();
+	       // Calculate two days before the current date
+	       LocalDate startDate = currentDate.minusDays(3);
+	       // Calculate yesterday's date
+	       LocalDate endDate = currentDate.minusDays(2);
+	       // 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);
+	       // Convert LocalDateTime to Timestamp
+	       Timestamp startTimeStamp = Timestamp.valueOf(startDateTime);
+	       Timestamp endTimeStamp = Timestamp.valueOf(endDateTime);
+		
 		// application properties will have a config date variable.
-		logger.info("startDate: " + startDate);
-		logger.info("endDate: " + endDate);
-		List<BeneficiaryCall> list = callReportRepo.getAllBenCallIDetails(startDate, endDate);
+		logger.info("startDate: " + startTimeStamp);
+		logger.info("endDate: " + endTimeStamp);
+		List<BeneficiaryCall> list = callReportRepo.getAllBenCallIDetails(startTimeStamp, endTimeStamp);
 
 		if (!list.isEmpty()) {
 			

From b213107e06e8b63e03f2250608d68f92f7fa1226 Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Mon, 15 Apr 2024 16:49:00 +0530
Subject: [PATCH 09/12] Added cti data sync scheduler execution time change and
 start date and end date change for last two days

---
 src/main/environment/common_dev.properties                    | 1 +
 .../iemr/common/service/ctiCall/CallCentreDataSyncImpl.java   | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties
index dbef254e..db4bebfa 100644
--- a/src/main/environment/common_dev.properties
+++ b/src/main/environment/common_dev.properties
@@ -63,6 +63,7 @@ start-email-scheduler=false
 cron-scheduler-email=0 0/1 * * * ? *
 
 ###cti data sync Scheduler configurations
+#Runs at every two days at 2AM
 start-ctidatasync-scheduler=false
 cron-scheduler-ctidatasync=0 0 2 */2 * ?
 
diff --git a/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java b/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java
index 9f966f30..b8988312 100644
--- a/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java
+++ b/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java
@@ -101,9 +101,9 @@ public void ctiDataSync() {
 		
 		 // Get the current date
 	       LocalDate currentDate = LocalDate.now();
-	       // Calculate two days before the current date
+	       // Calculate three days before the current date
 	       LocalDate startDate = currentDate.minusDays(3);
-	       // Calculate yesterday's date
+	       // Calculate two days before the current date
 	       LocalDate endDate = currentDate.minusDays(2);
 	       // Convert LocalDate to LocalDateTime to set time as 00:00:00
 	       LocalDateTime startDateTime = startDate.atTime(0, 0, 0);

From b1a34dabd2160a552e27da925683252669172e99 Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Tue, 16 Apr 2024 09:31:35 +0530
Subject: [PATCH 10/12] Added cti data sync scheduler execution time

---
 src/main/environment/common_dev.properties  | 2 +-
 src/main/environment/common_test.properties | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties
index db4bebfa..2bd12f14 100644
--- a/src/main/environment/common_dev.properties
+++ b/src/main/environment/common_dev.properties
@@ -63,7 +63,7 @@ start-email-scheduler=false
 cron-scheduler-email=0 0/1 * * * ? *
 
 ###cti data sync Scheduler configurations
-#Runs at every two days at 2AM
+#Runs at every alternative days at 2AM
 start-ctidatasync-scheduler=false
 cron-scheduler-ctidatasync=0 0 2 */2 * ?
 
diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties
index 5d39b23a..6f25e1a3 100644
--- a/src/main/environment/common_test.properties
+++ b/src/main/environment/common_test.properties
@@ -58,6 +58,7 @@ start-email-scheduler=false
 cron-scheduler-email=0 0/1 * * * ? *
 ##-------------------------------###cti data sync Scheduler configurations------------------------------------------------------
 
+#Runs at every alternative days at 2AM
 start-ctidatasync-scheduler=false
 cron-scheduler-ctidatasync=0 0 2 */2 * ?
 

From 32fcecca2e853b1e21211268dec9f07ae232bc33 Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Thu, 18 Apr 2024 10:22:44 +0530
Subject: [PATCH 11/12] Removed commented code

---
 .../ctiCall/CallCentreDataSyncImpl.java       | 25 +++----------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java b/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java
index b8988312..55f2273b 100644
--- a/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java
+++ b/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java
@@ -88,16 +88,7 @@ public String callUrl(String urlRequest) {
 	@Override
 	public void ctiDataSync() {
 		List<Objects[]> resultSet = null;
-//		Date date = new Date();
-//		java.sql.Date sqlDate = new java.sql.Date(date.getTime());
-//		String text = sqlDate.toString();
-//		Timestamp endDate = new Timestamp(sqlDate.getTime());
-//		Calendar calendar = Calendar.getInstance();
-//		calendar.setTime(sqlDate);
-//		logger.info("CZduration: " + CZduration);
-//		calendar.add(Calendar.DATE, -(Integer.parseInt(CZduration)));
-//		Date beforeDate = calendar.getTime();
-//		Timestamp startDate = new Timestamp(beforeDate.getTime());
+
 		
 		 // Get the current date
 	       LocalDate currentDate = LocalDate.now();
@@ -119,7 +110,7 @@ public void ctiDataSync() {
 
 		if (!list.isEmpty()) {
 			
-			// List<Long> benList = new ArrayList<>();
+		
 			String callDuartion = null;
 			String filePath = null;
 			String URL = null;
@@ -135,22 +126,14 @@ public void ctiDataSync() {
 						JSONObject requestFile = new JSONObject();
 						requestFile.put("agent_id", call.getAgentID());
 						requestFile.put("session_id", call.getCallID());
-//						OutputResponse response1 = ctiService.getVoiceFile(requestFile.toString(), "extra parameter");
-//						if (response1.getStatusCode() == OutputResponse.SUCCESS) {
-//							CTIVoiceFile getVoiceFile = InputMapper.gson().fromJson(response1.getData(),
-//									CTIVoiceFile.class);
-//							String recordingFilePath = getVoiceFile.getPath() + "/" + getVoiceFile.getFilename();
-////						beneficiaryCallRepository.updateVoiceFilePathNew(benificiaryCall.getAgentID(),
-////								benificiaryCall.getCallID(), recordingFilePath, null);
-//							recordingPath = ctiLoggerURL + "/" + recordingFilePath;
+
 						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();
-//							beneficiaryCallRepository.updateVoiceFilePathNew(call.getAgentID(),
-//									call.getCallID(), recordingFilePath.substring(20), null);
+
 							if(recordingFilePath.length() > 20)
 								recordingPath = recordingFilePath.substring(20);
 							logger.info("recordingPath: " + recordingPath);

From 9042df0e4edf94500ef9e3a832ed1e560811bcec Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Thu, 30 May 2024 16:58:43 +0530
Subject: [PATCH 12/12] cti-datacheck changes - calltype Id updation if it's
 null

---
 src/main/environment/common_test.properties   |  1 +
 .../NHMDetailCallReportScheduler.java         | 89 +++++++++++++++++--
 .../repository/report/CallReportRepo.java     |  9 +-
 3 files changed, 88 insertions(+), 11 deletions(-)

diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties
index 5c5514bb..2fae65eb 100644
--- a/src/main/environment/common_test.properties
+++ b/src/main/environment/common_test.properties
@@ -13,6 +13,7 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 secondary.datasource.username=<Enter your DB_REPORTING username>
 secondary.datasource.password=<Enter your DB_REPORTING password>
 secondary.datasource.url=<Enter DB_REPORTING URL here>
+secondary.datasource.driver-class-name=com.mysql.jdbc.Drive
 
 encDbUserName=zFlYsp9Z0s+lRvLM15A3g/Ba0w8VGs/1usuW7EsGF3k=
 encDbPass=JGGAGn5wTlrbTLUHY+5BzfBa0w8VGs/1usuW7EsGF3k=
diff --git a/src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java b/src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java
index 8a9d4aed..3451d56f 100644
--- a/src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java
+++ b/src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java
@@ -4,9 +4,13 @@
 import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Objects;
+import java.util.Set;
 
 import org.apache.xml.security.stax.config.ConfigurationProperties;
+import org.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -17,6 +21,7 @@
 
 import com.iemr.common.data.callhandling.BeneficiaryCall;
 import com.iemr.common.data.nhm_dashboard.DetailedCallReport;
+import com.iemr.common.repository.callhandling.IEMRCalltypeRepositoryImplCustom;
 import com.iemr.common.repository.nhm_dashboard.DetailedCallReportRepo;
 import com.iemr.common.repository.report.CallReportRepo;
 import com.iemr.common.utils.config.ConfigProperties;
@@ -31,12 +36,14 @@ public class NHMDetailCallReportScheduler {
 	@Autowired
 	private CallReportRepo callReportRepo;
 
+	@Autowired
+	private IEMRCalltypeRepositoryImplCustom iEMRCalltypeRepositoryImplCustom;
+
 	Logger logger = LoggerFactory.getLogger(this.getClass().getName());
 
 	@Value("${start-ctidatacheck-scheduler}")
 	private boolean startCtiDataCheckFlag;
 
-
 	@Scheduled(cron = "${cron-scheduler-ctidatacheck}")
 	public void detailedCallReport() {
 		if (startCtiDataCheckFlag) {
@@ -48,7 +55,7 @@ public void detailedCallReport() {
 				String[] dateArr = date.toString().split("T");
 				endDate = dateArr[0].concat(" 23:59:59");
 				fromDate = dateArr[0].concat(" 00:00:01");
-
+                
 				Timestamp fromTime = Timestamp.valueOf(fromDate);
 				Timestamp endTime = Timestamp.valueOf(endDate);
 				logger.info("Call detailed report check request - FromTime -" + fromTime + "Endtime - " + endTime);
@@ -57,19 +64,52 @@ public void detailedCallReport() {
 				for (DetailedCallReport detailedCallReport : findByCallStartTimeBetween) {
 					String phoneNo = detailedCallReport.getPHONE();
 					String sessionID = detailedCallReport.getSession_ID();
-					int existRecord = callReportRepo.getBenCallDetailsBySessionIDAndPhone(sessionID, phoneNo);
-					if (existRecord != 0) {
+					BeneficiaryCall existRecord = callReportRepo.getBenCallDetailsBySessionIDAndPhone(sessionID,phoneNo);
+					if (existRecord != null) {
 						logger.info("Record already present in t_bencall table with sessionID : " + sessionID
 								+ " phoneNo : " + phoneNo);
+						logger.info("Existing record from t_bencall: " + existRecord);
 						if (null != detailedCallReport.getOrientation_Type()
 								&& detailedCallReport.getOrientation_Type().equalsIgnoreCase("OUTBOUND")) {
-							callReportRepo.updateIsOutboundForCall(true, sessionID, phoneNo );
+							
+							if(existRecord.getCallTypeID() == null) {
+								logger.info("Called Service Id: " + existRecord.getCalledServiceID());
+							// Fetching callTypeId
+							Integer callTypeId = getCallTypeId(true, existRecord.getCalledServiceID(),
+									detailedCallReport);
+							
+							logger.info("CallTypeId after comparison: " + callTypeId);
+							if (callTypeId != null) {
+								callReportRepo.updateIsOutboundForCallWithCallType(true, sessionID, phoneNo,callTypeId);
+							} else {
+								callReportRepo.updateIsOutboundForCall(true, sessionID, phoneNo);
+							}
+							}
+							else {
+								callReportRepo.updateIsOutboundForCall(true, sessionID, phoneNo);
+							}
 						} else {
-							callReportRepo.updateIsOutboundForCall(false, sessionID, phoneNo );
+							if(existRecord.getCallTypeID() == null) {
+								
+								logger.info("Called Service Id: " + existRecord.getCalledServiceID());
+							// Fetching callTypeId
+							Integer callTypeId = getCallTypeId(false, existRecord.getCalledServiceID(),
+									detailedCallReport);
+
+							logger.info("CallTypeId after comparison: " + callTypeId);
+							if (callTypeId != null) {
+								callReportRepo.updateIsOutboundForCallWithCallType(false, sessionID, phoneNo, callTypeId);
+							} else {
+								callReportRepo.updateIsOutboundForCall(false, sessionID, phoneNo);
+							}
+							
+						}
+							else {
+								callReportRepo.updateIsOutboundForCall(false, sessionID, phoneNo);
+							}
 						}
 					} else {
-						logger.info("Record missed in t_bencall table with sessionID : " + sessionID + " phoneNo : "
-								+ phoneNo);
+						logger.info("Record missed in t_bencall table with sessionID : " + sessionID + " phoneNo : " + phoneNo);
 						BeneficiaryCall callDetail = getCallDetail(detailedCallReport);
 						callReportRepo.save(callDetail);
 					}
@@ -82,6 +122,36 @@ public void detailedCallReport() {
 
 	}
 
+	private Integer getCallTypeId(Boolean isOutbound, Integer calledServiceId, DetailedCallReport detailedCallReport) {
+		Set<Objects[]> callTypesArray = new HashSet<Objects[]>();
+
+		if (detailedCallReport.getAgent_Disposition_Category() != null
+				&& detailedCallReport.getAgent_Disposition() != null) {
+			if (isOutbound == true) {
+				callTypesArray = iEMRCalltypeRepositoryImplCustom.getOutboundCallTypes(calledServiceId, true);
+			} else {
+				callTypesArray = iEMRCalltypeRepositoryImplCustom.getInboundCallTypes(calledServiceId, true);
+			}
+
+			for (Object[] object : callTypesArray) {
+				String callGroupType = (String) object[3];
+				String callType = (String) object[0];
+				String detailedCallGroupType = detailedCallReport.getAgent_Disposition_Category().replace("_", " ");
+				String detailedCallType = detailedCallReport.getAgent_Disposition().replace("_", " ");
+				logger.info("Detailed Call - CallGroupType: " + detailedCallGroupType);
+				logger.info("Detailed Call - CallType: " + detailedCallType);
+				
+				if (callGroupType.equalsIgnoreCase(detailedCallGroupType)
+						&& callType.equalsIgnoreCase(detailedCallType)) {
+					return (Integer) object[1];
+				}
+			}
+		}
+
+		return null;
+
+	}
+
 	private BeneficiaryCall getCallDetail(DetailedCallReport detailedCallReport) {
 		BeneficiaryCall beneficiaryCall = new BeneficiaryCall();
 		beneficiaryCall.setCallID(detailedCallReport.getSession_ID());
@@ -104,7 +174,8 @@ private BeneficiaryCall getCallDetail(DetailedCallReport detailedCallReport) {
 		beneficiaryCall.setCreatedBy("Admin");
 
 		beneficiaryCall.setCallDuration(String.valueOf(detailedCallReport.getCall_Duration()));
-
+		
+		
 		return beneficiaryCall;
 
 	}
diff --git a/src/main/java/com/iemr/common/repository/report/CallReportRepo.java b/src/main/java/com/iemr/common/repository/report/CallReportRepo.java
index 3104427e..2e1e4dba 100644
--- a/src/main/java/com/iemr/common/repository/report/CallReportRepo.java
+++ b/src/main/java/com/iemr/common/repository/report/CallReportRepo.java
@@ -44,13 +44,18 @@ public interface CallReportRepo extends CrudRepository<BeneficiaryCall, Integer>
 			+ "and report.createdDate >= :startDate and report.createdDate <= :endDate ")
 	public List<BeneficiaryCall> getAllBenCallIDetails(@Param("startDate") Timestamp startDate, @Param("endDate") Timestamp endDate);//start date and end date as param for x days.
 
-	@Query("SELECT COUNT(*) FROM BeneficiaryCall call WHERE call.callID = :sessionID and call.phoneNo = :phoneNo")
-	public int getBenCallDetailsBySessionIDAndPhone(@Param("sessionID") String sessionID,@Param("phoneNo") String phoneNo);
+	@Query("SELECT call FROM BeneficiaryCall call WHERE call.callID = :sessionID and call.phoneNo = :phoneNo")
+	public BeneficiaryCall getBenCallDetailsBySessionIDAndPhone(@Param("sessionID") String sessionID,@Param("phoneNo") String phoneNo);
 	
 	@Transactional
 	@Modifying
 	@Query("update BeneficiaryCall set isOutbound= :isOutbound where callID = :callID and phoneNo= :phoneNo")
 	public int updateIsOutboundForCall(@Param("isOutbound") boolean isOutbound, @Param("callID") String callID, @Param("phoneNo") String phoneNo );
+	
+	@Transactional
+	@Modifying
+	@Query("update BeneficiaryCall set isOutbound= :isOutbound, callTypeID= :callTypeID where callID = :callID and phoneNo= :phoneNo")
+	public int updateIsOutboundForCallWithCallType(@Param("isOutbound") boolean isOutbound, @Param("callID") String callID, @Param("phoneNo") String phoneNo, @Param("callTypeID") Integer callTypeID );
 }
 
 
