From e380492b6ce3bb20489e9881507d2366e7e676af Mon Sep 17 00:00:00 2001
From: Devika <de40034072@wipro.com>
Date: Tue, 12 Sep 2023 14:50:58 +0530
Subject: [PATCH] Multiple beneficiaries sync issue changes for FLW

---
 .../data/rmnch/RMNCHBornBirthDetails.java       |  2 +-
 .../identity/data/rmnch/RMNCHCBACdetails.java   |  2 +-
 .../service/rmnch/RmnchDataSyncServiceImpl.java | 17 +++++++++++------
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHBornBirthDetails.java b/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHBornBirthDetails.java
index 44232d12..468a025a 100644
--- a/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHBornBirthDetails.java
+++ b/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHBornBirthDetails.java
@@ -57,7 +57,7 @@ public class RMNCHBornBirthDetails {
 
 	@Expose
 	@Column(name = "beneficiaryId")
-	private Integer beneficiaryId;
+	private Long benficieryid;
 
 	@Expose
 	@Column(name = "countryid")
diff --git a/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHCBACdetails.java b/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHCBACdetails.java
index 6f9bdf38..806822c8 100644
--- a/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHCBACdetails.java
+++ b/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHCBACdetails.java
@@ -380,7 +380,7 @@ public class RMNCHCBACdetails {
 
 	@Expose
 	@Column(name = "beneficiaryId")
-	private Integer beneficiaryid;
+	private Long benficieryid;
 
 	// new fields, 16-09-2021
 	@Expose
diff --git a/src/main/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImpl.java b/src/main/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImpl.java
index 6f5ed7a3..ff4b24ec 100644
--- a/src/main/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImpl.java
+++ b/src/main/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImpl.java
@@ -141,10 +141,12 @@ public String syncDataToAmrit(String requestOBJ) throws Exception {
 					List<RMNCHBeneficiaryDetailsRmnch> benDetailsExtraList = Arrays.asList(objArr);
 
 					if (benDetailsExtraList != null && benDetailsExtraList.size() > 0) {
-						benRegID = rMNCHMBenRegIdMapRepo.getRegID(benDetailsExtraList.get(0).getBenficieryid());
-
-						if (benRegID != null) {
+//						benRegID = rMNCHMBenRegIdMapRepo.getRegID(benDetailsExtraList.get(0).getBenficieryid());
+//
+//						if (benRegID != null) {
+						
 							for (RMNCHBeneficiaryDetailsRmnch obj : benDetailsExtraList) {
+								benRegID = rMNCHMBenRegIdMapRepo.getRegID(obj.getBenficieryid());
 								obj.setBenRegId(benRegID);
 								RMNCHBeneficiaryDetailsRmnch temp = rMNCHBeneficiaryDetailsRmnchRepo
 										.getByRegID(benRegID);
@@ -164,6 +166,7 @@ public String syncDataToAmrit(String requestOBJ) throws Exception {
 									}
 									obj.setRelatedBeneficiaryIdsDB(sb.toString());
 								}
+							
 
 							}
 
@@ -171,15 +174,16 @@ public String syncDataToAmrit(String requestOBJ) throws Exception {
 									.save(benDetailsExtraList);
 
 							benDetailsExtraList.forEach((n) -> beneficiaryDetailsIds.add(n.getId()));
-						} else
-							throw new Exception("invalid/empty beneficiary request data.");
+//						} else
+//							throw new Exception("invalid/empty beneficiary request data.");
 
 						// born birth details
-						if (jsnOBJ != null && jsnOBJ.has("bornBirthDeatils") && benRegID != null) {
+						if (jsnOBJ != null && jsnOBJ.has("bornBirthDeatils")) {
 							RMNCHBornBirthDetails[] objArr1 = InputMapper.gson()
 									.fromJson(jsnOBJ.get("bornBirthDeatils"), RMNCHBornBirthDetails[].class);
 							List<RMNCHBornBirthDetails> bornBirthList = Arrays.asList(objArr1);
 							for (RMNCHBornBirthDetails obj : bornBirthList) {
+								benRegID = rMNCHMBenRegIdMapRepo.getRegID(obj.getBenficieryid());
 								obj.setBenRegId(benRegID);
 								RMNCHBornBirthDetails temp = rMNCHBornBirthDetailsRepo.getByRegID(benRegID);
 								if (temp != null)
@@ -197,6 +201,7 @@ public String syncDataToAmrit(String requestOBJ) throws Exception {
 							List<RMNCHCBACdetails> cbacList = Arrays.asList(objArr2);
 
 							for (RMNCHCBACdetails obj : cbacList) {
+								benRegID = rMNCHMBenRegIdMapRepo.getRegID(obj.getBenficieryid());
 								obj.setBenRegId(benRegID);
 								obj.setConfirmed_hrp("Not checked");
 								obj.setConfirmed_ncd("Not checked");
