From 39f8f157f603d87e7e51fcc452f0cd011db3560e Mon Sep 17 00:00:00 2001
From: Ravi Shanigarapu <ravi.shanigarapu@wipro.com>
Date: Fri, 27 Sep 2024 19:28:49 +0530
Subject: [PATCH 1/3] download reports

---
 .../repository/callreport/CallReportSecondaryRepo.java | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/iemr/common/secondary/repository/callreport/CallReportSecondaryRepo.java b/src/main/java/com/iemr/common/secondary/repository/callreport/CallReportSecondaryRepo.java
index 7df776f6..0a5dee7f 100644
--- a/src/main/java/com/iemr/common/secondary/repository/callreport/CallReportSecondaryRepo.java
+++ b/src/main/java/com/iemr/common/secondary/repository/callreport/CallReportSecondaryRepo.java
@@ -101,7 +101,7 @@ public List<Object[]> getDistrictWiseCallReport(@Param("startDateTime") Timestam
 	public List<Object[]> getUnblockedUserReport(@Param("startDateTime") Timestamp startDateTime,
 	@Param("endDateTime") Timestamp endDateTime,@Param("providerServiceMapID") Integer providerServiceMapID);
 	
-	@Query(value="call db_iemr.Pr_1097Sexualorientation(:startDateTime,:endDateTime,:state,:district,:sexualOrientation,:providerServiceMapID)", nativeQuery=true)
+	@Query(value="call Pr_1097Sexualorientation(:startDateTime,:endDateTime,:state,:district,:sexualOrientation,:providerServiceMapID)", nativeQuery=true)
 	public List<Object[]> getAllBySexualOrientationReport(@Param("startDateTime") Timestamp startTimestamp,
 	@Param("endDateTime") Timestamp endTimestamp,@Param("state") String state,
 	@Param("district") String district,@Param("sexualOrientation") String sexual_Orientation,
@@ -132,25 +132,25 @@ public List<Object[]> getLocationWiseReport(@Param("startDateTime") Timestamp st
 	@Param("endDateTime") Timestamp endDateTime,@Param("locationID") Long locationID,
 	@Param("providerServiceMapID") Integer providerServiceMapID);
 
-	@Query(value="call db_iemr.Pr_1097LanguageDistribution(:startDateTime,:endDateTime,:state,:district,:beneficiaryPreferredLanguage,:providerServiceMapID)", nativeQuery=true)
+	@Query(value="call Pr_1097LanguageDistribution(:startDateTime,:endDateTime,:state,:district,:beneficiaryPreferredLanguage,:providerServiceMapID)", nativeQuery=true)
 	public List<Object[]> getLanguageDistributionReport(@Param("startDateTime") Timestamp startDateTime,
 	@Param("endDateTime") Timestamp endDateTime,@Param("state") String state,
 	@Param("district") String district,@Param("beneficiaryPreferredLanguage") String beneficiaryPreferredLanguage,
 	@Param("providerServiceMapID") Integer providerServiceMapID);
 
 
-	@Query(value="call db_iemr.Pr_1097AgegroupDistribution(:startDateTime,:endDateTime,:state,:district,:minAge,:maxAge,:providerServiceMapID)", nativeQuery=true)
+	@Query(value="call Pr_1097AgegroupDistribution(:startDateTime,:endDateTime,:state,:district,:minAge,:maxAge,:providerServiceMapID)", nativeQuery=true)
 	public List<Object[]> getAllByAgeGroup(@Param("startDateTime") Timestamp startTimestamp,
 	@Param("endDateTime") Timestamp endTimestamp, @Param("state") String state, @Param("district") String district, 
 	@Param("minAge") Integer minAge, @Param("maxAge") Integer maxAge, @Param("providerServiceMapID") Integer providerServiceMapID);
 
-	@Query(value="call Pr_1097calltypeReport(:startDateTime,:endDateTime,:state,:district,:beneficiaryCallType,:beneficiaryCallSubType,:beneficiaryPreferredLanguage,:gender,:beneficiarySexualOrientation,:providerServiceMapID)", nativeQuery=true)
+	@Query(value="call db_reporting.Pr_1097calltypeReport(:startDateTime,:endDateTime,:state,:district,:beneficiaryCallType,:beneficiaryCallSubType,:beneficiaryPreferredLanguage,:gender,:beneficiarySexualOrientation,:providerServiceMapID)", nativeQuery=true)
 	public List<Object[]> getAllReportsByDate(@Param("startDateTime") Timestamp startTimestamp,
 	@Param("endDateTime") Timestamp endTimestamp, @Param("state") String state, @Param("district") String district,
 	@Param("beneficiaryCallType") String beneficiaryCallType,@Param("beneficiaryCallSubType") String beneficiaryCallSubType, @Param("beneficiaryPreferredLanguage") String beneficiaryPreferredLanguage, @Param("gender") String gender,
 	@Param("beneficiarySexualOrientation") String beneficiarySexualOrientation, @Param("providerServiceMapID") Integer providerServiceMapID);
 
-	@Query(value="call db_iemr.Pr_1097GenderDistribution(:startDateTime,:endDateTime,:state,:district,:gender,:providerServiceMapID)", nativeQuery=true)
+	@Query(value="call Pr_1097GenderDistribution(:startDateTime,:endDateTime,:state,:district,:gender,:providerServiceMapID)", nativeQuery=true)
 	public List<Object[]> getAllByGender(@Param("startDateTime") Timestamp startDateTime,
 	@Param("endDateTime") Timestamp endDateTime, @Param("state") String state, @Param("district") String district,
 	@Param("gender") String gender, @Param("providerServiceMapID") Integer providerServiceMapID);

From cdc22b3df83fc5ee9b6da06e252c0518969c8b62 Mon Sep 17 00:00:00 2001
From: Ravi Shanigarapu <ravi.shanigarapu@wipro.com>
Date: Tue, 1 Oct 2024 17:46:10 +0530
Subject: [PATCH 2/3] logic modified save Section-Fields

---
 .../customization/CustomizationServiceImpl.java | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java b/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java
index 2ac45a72..911c64cc 100644
--- a/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java
@@ -176,6 +176,7 @@ public String getSections() {
 	@Override
 	public String saveSectionAndFields(SectionFieldsMappingDTO sectionFieldsMappingDTO, String Authorization)
 			throws Exception {
+		Map<String, Object> responseMap = new HashMap<>();
 		try {
 
 			if (sectionFieldsMappingDTO != null && sectionFieldsMappingDTO.getFields() != null
@@ -209,22 +210,22 @@ public String saveSectionAndFields(SectionFieldsMappingDTO sectionFieldsMappingD
 						if (sb.length() >= 1)
 							sectionAndFieldsMapping.setOption(sb.substring(0, sb.length() - 1));
 					}
-					if (!ObjectUtils.isEmpty(byFieldName) || byFieldName.size() > 0)// Added by Ravi
+					if (ObjectUtils.isEmpty(byFieldName))
 						sectionAndFieldsMappingList.add(sectionAndFieldsMapping);
 
 				}
-				if (!ObjectUtils.isEmpty(sectionAndFieldsMappingList) && sectionAndFieldsMappingList.size() > 0)// Added
-																												// by
-																												// Ravi
+				if (!ObjectUtils.isEmpty(sectionAndFieldsMappingList) && !sectionAndFieldsMappingList.isEmpty()) {
 					sectionAndFieldsMappingRepo.saveAll(sectionAndFieldsMappingList);
+					responseMap.put("response", "section and fields mapping done successfully");
+				}else {
+					throw new IllegalArgumentException("Invalid request: Field name already exists");
+				}
 			} else
-				throw new IllegalArgumentException("Invalid request: please pass valid request");
-			Map<String, Object> responseMap = new HashMap<>();
-			responseMap.put("response", "section and fields mapping done successfully");
-			return new Gson().toJson(responseMap);
+				throw new IllegalArgumentException("Invalid request: Please pass valid request");
 		} catch (Exception e) {
 			throw new Exception(e.getMessage());
 		}
+		return new Gson().toJson(responseMap);
 	}
 
 	@Override

From a654a34edd6eafa45d904d8439b65fdead96ed16 Mon Sep 17 00:00:00 2001
From: Ravi Shanigarapu <ravi.shanigarapu@wipro.com>
Date: Mon, 7 Oct 2024 17:09:13 +0530
Subject: [PATCH 3/3] AMM-1006

---
 .../repo/customization/SectionAndFieldsMappingRepo.java       | 4 ++--
 .../service/customization/CustomizationServiceImpl.java       | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java b/src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java
index 098f51f9..79b770d2 100644
--- a/src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java
+++ b/src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java
@@ -23,7 +23,7 @@ List<SectionAndFieldsMapping> findSectionIdAndSectionNameAndServiceProviderId(
 	@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.id = :id")
 	SectionAndFieldsMapping getById(@Param("id") Integer id);
 
-	@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName")
-	List<SectionAndFieldsMapping> getByFieldName(@Param("fieldName") String fieldName);
+	@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName and sfm.serviceProviderId = :serviceProviderId")
+	List<SectionAndFieldsMapping> getByFieldName(@Param("fieldName") String fieldName,@Param("serviceProviderId") Integer serviceProviderId);
 	
 }
diff --git a/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java b/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java
index 911c64cc..d1b18598 100644
--- a/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java
@@ -185,7 +185,7 @@ public String saveSectionAndFields(SectionFieldsMappingDTO sectionFieldsMappingD
 				List<SectionAndFieldsMapping> sectionAndFieldsMappingList = new ArrayList<>();
 				for (SectionAndFieldsMapping sectionFieldsMapping : sectionFieldsMappingDTO.getFields()) {
 					List<SectionAndFieldsMapping> byFieldName = sectionAndFieldsMappingRepo
-							.getByFieldName(sectionFieldsMapping.getFieldName());
+							.getByFieldName(sectionFieldsMapping.getFieldName(),sectionFieldsMapping.getServiceProviderId());
 					sectionAndFieldsMapping = new SectionAndFieldsMapping();
 					sectionAndFieldsMapping.setSectionId(sectionFieldsMappingDTO.getSectionId());
 					sectionAndFieldsMapping.setCreatedBy(sectionFieldsMappingDTO.getCreatedBy());
