From b811cc516c8167e080a7e499bf293f2d342748a5 Mon Sep 17 00:00:00 2001
From: Ravi Shanigarapu <ravi.shanigarapu@wipro.com>
Date: Wed, 4 Oct 2023 19:34:01 +0530
Subject: [PATCH 1/2] esanjeevani changes

---
 .../repo/esanjeevani/ESanjeevaniRepo.java     |  4 +-
 .../esanjeevani/ESanjeevaniServiceImpl.java   | 55 +++++++++++++++----
 2 files changed, 45 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/iemr/common/repo/esanjeevani/ESanjeevaniRepo.java b/src/main/java/com/iemr/common/repo/esanjeevani/ESanjeevaniRepo.java
index 1e9f826e..48806c41 100644
--- a/src/main/java/com/iemr/common/repo/esanjeevani/ESanjeevaniRepo.java
+++ b/src/main/java/com/iemr/common/repo/esanjeevani/ESanjeevaniRepo.java
@@ -39,8 +39,8 @@ public interface ESanjeevaniRepo extends CrudRepository<V_doortodooruserdetails,
 	@Query(nativeQuery = true, value = "SELECT GovtDistrictID FROM db_iemr.m_district WHERE DistrictID = :districtId ")
 	public Integer getGovDistrictId(@Param("districtId") Integer districtId);
 	
-	@Query(nativeQuery = true, value = "SELECT GovSubDistrictID FROM db_iemr.m_districtbranchmapping WHERE DistrictBranchID = :subDistrictId ")
-	public Integer getGovSubDistrictId(@Param("subDistrictId") Integer subDistrictId);
+	@Query(nativeQuery = true, value = "SELECT GovSubDistrictID,GovVillageID,VillageName FROM db_iemr.m_districtbranchmapping WHERE DistrictBranchID = :subDistrictId ")
+	public List<Object[]> getGovSubDistrictId(@Param("subDistrictId") Integer subDistrictId);
 	
 	@Query(nativeQuery = true, value = "SELECT CountryCode FROM db_iemr.m_country WHERE CountryID = :countryID ")
 	public String getGovCountyId(@Param("countryID") Integer countryID);
diff --git a/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java b/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java
index 62445665..6aea0b5b 100644
--- a/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java
@@ -1,6 +1,7 @@
 package com.iemr.common.service.esanjeevani;
 
 import java.math.BigInteger;
+import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
 import java.time.LocalDate;
@@ -74,13 +75,17 @@ public String getProviderLogin() throws Exception {
 		String token = null;
 
 		try {
-			String encryptedPassword = DigestUtils.sha512Hex(eSanjeevaniPassword).toLowerCase()
-					+ DigestUtils.sha512Hex(eSanjeevaniSalt).toLowerCase();
-			String encryptedPaasword = DigestUtils.sha512Hex(encryptedPassword);
+			String encryptedPaasword = encryptSHA512(encryptSHA512(eSanjeevaniPassword)+encryptSHA512(eSanjeevaniSalt));
+			/*
+			 * String encryptedPassword =
+			 * DigestUtils.sha512Hex(eSanjeevaniPassword).toLowerCase() +
+			 * DigestUtils.sha512Hex(eSanjeevaniSalt).toLowerCase(); String
+			 * encryptedPaasword = DigestUtils.sha512Hex(encryptedPassword);
+			 */
 
 			ESanjeevaniProviderAuth reqObj = new ESanjeevaniProviderAuth();
 			reqObj.setUserName(eSanjeevaniUserName);
-			reqObj.setPassword(eSanjeevaniPassword);
+			reqObj.setPassword(encryptedPaasword);
 			reqObj.setSalt(eSanjeevaniSalt);
 			reqObj.setSource(eSanjeevaniSource);
 
@@ -102,6 +107,25 @@ public String getProviderLogin() throws Exception {
 		return token;
 
 	}
+	private String encryptSHA512(String string) {
+		try {
+			MessageDigest digest = MessageDigest.getInstance("SHA-512");
+			byte[] hashbytes = digest.digest(string.getBytes());
+			StringBuilder hexString = new StringBuilder();
+			for (byte b : hashbytes) {
+				String hex = Integer.toHexString(0xff & b);
+				if(hex.length()==1) {
+					hexString.append('0');
+				}
+				hexString.append(hex);
+			}
+			return hexString.toString();
+		}catch (Exception e) {
+			return null;
+		}
+		
+	}
+
 
 	@Override
 	public String registerPatient(Long benRegId) throws Exception {
@@ -146,6 +170,7 @@ public String registerPatient(Long benRegId) throws Exception {
 			}
 
 			String accessToken = getProviderLogin();
+			logger.info("getProviderLogin response - " + accessToken);
 			if (accessToken != null && !StringUtils.isEmpty(accessToken)) {
 				MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
 				String registryReqObj = new Gson().toJson(reqObj);
@@ -262,16 +287,23 @@ private void setBeneficiaryAddressDetails(BigInteger benAddressId,
 					addressObj.setAddressLine1(addressDetails[8].toString());
 				if (addressDetails[9] != null)
 					addressObj.setPostalCode(addressDetails[9].toString());
-				addressObj.setAddressType("Physical");
-				addressObj.setPostalCode("123456");
-				addressObj.setCityCode(233);
-				addressObj.setCityDisplay("kareemnagar");
-
+				//addressObj.setAddressType("Physical");
+				//addressObj.setPostalCode("123456");
+				
 				String govCountryCode = eSanjeevaniRepo.getGovCountyId(countryId);
 				Integer govtStateCode = eSanjeevaniRepo.getGovStateId(stateId);
 				Integer govtDistrictCode = eSanjeevaniRepo.getGovDistrictId(districtId);
-				Integer govBlockCode = eSanjeevaniRepo.getGovSubDistrictId(blockId);
-
+				List<Object[]> govBlockCodeObj = eSanjeevaniRepo.getGovSubDistrictId(blockId);
+				
+				Object[] objects = govBlockCodeObj.get(0);
+				Integer govBlockCode = (Integer)objects[0];
+				Integer govVillageID = (Integer)objects[1];
+				String govVillageName = objects[2].toString();
+				
+				if (govVillageID != null)
+					addressObj.setCityCode(govVillageID);
+				if (govVillageName != null)
+					addressObj.setCityDisplay(govVillageName);
 				if (null != govCountryCode)
 					addressObj.setCountryCode(govCountryCode);
 				if (null != govtStateCode)
@@ -298,7 +330,6 @@ private void setBeneficiaryContactDetails(BigInteger benContactId,
 				contactObj.setContactPointStatus(true);
 				contactObj.setContactPointType("phone");
 				contactObj.setContactPointValue(beneficiaryContactDetails);
-
 				contactObjList.add(contactObj);
 			}
 		}

From 78211a2f4e6addcc503964abc024f5aaba710052 Mon Sep 17 00:00:00 2001
From: Ravi Shanigarapu <ravi.shanigarapu@wipro.com>
Date: Thu, 5 Oct 2023 09:55:03 +0530
Subject: [PATCH 2/2] commented code removed

---
 .../esanjeevani/ESanjeevaniServiceImpl.java       | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java b/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java
index 6aea0b5b..5c52fdf5 100644
--- a/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java
@@ -76,13 +76,7 @@ public String getProviderLogin() throws Exception {
 
 		try {
 			String encryptedPaasword = encryptSHA512(encryptSHA512(eSanjeevaniPassword)+encryptSHA512(eSanjeevaniSalt));
-			/*
-			 * String encryptedPassword =
-			 * DigestUtils.sha512Hex(eSanjeevaniPassword).toLowerCase() +
-			 * DigestUtils.sha512Hex(eSanjeevaniSalt).toLowerCase(); String
-			 * encryptedPaasword = DigestUtils.sha512Hex(encryptedPassword);
-			 */
-
+	
 			ESanjeevaniProviderAuth reqObj = new ESanjeevaniProviderAuth();
 			reqObj.setUserName(eSanjeevaniUserName);
 			reqObj.setPassword(encryptedPaasword);
@@ -130,7 +124,6 @@ private String encryptSHA512(String string) {
 	@Override
 	public String registerPatient(Long benRegId) throws Exception {
 		try {
-			// String accessToken = getProviderLogin();
 			ESanjeevaniPatientRegistration reqObj = new ESanjeevaniPatientRegistration();
 			ArrayList<ESanjeevaniPatientAddress> addressObj = new ArrayList<>();
 			ArrayList<ESanjeevaniPatientContactDetail> contactObj = new ArrayList<>();
@@ -262,7 +255,6 @@ private void setBeneficiaryAddressDetails(BigInteger benAddressId,
 				Integer blockId = 0;
 				Object[] addressDetails = beneficiaryAddDetails.get(0);
 				logger.info("address details fetch for beneficiary - " + addressDetails);
-//				JSONObject addressDetails = new JSONObject(beneficiaryAddDetails);
 				if (addressDetails[0] != null)
 					countryId = (int) addressDetails[0];
 				else 
@@ -287,9 +279,6 @@ private void setBeneficiaryAddressDetails(BigInteger benAddressId,
 					addressObj.setAddressLine1(addressDetails[8].toString());
 				if (addressDetails[9] != null)
 					addressObj.setPostalCode(addressDetails[9].toString());
-				//addressObj.setAddressType("Physical");
-				//addressObj.setPostalCode("123456");
-				
 				String govCountryCode = eSanjeevaniRepo.getGovCountyId(countryId);
 				Integer govtStateCode = eSanjeevaniRepo.getGovStateId(stateId);
 				Integer govtDistrictCode = eSanjeevaniRepo.getGovDistrictId(districtId);
@@ -325,8 +314,6 @@ private void setBeneficiaryContactDetails(BigInteger benContactId,
 			String beneficiaryContactDetails = eSanjeevaniRepo.getBeneficiaryContactDetails(benContactId);
 			logger.info("contact details fetch for beneficiary - " + beneficiaryContactDetails);
 			if (null != beneficiaryContactDetails) {
-//				JSONObject contactDetails = new JSONObject(beneficiaryContactDetails);
-//				Object[] contactDetails = beneficiaryContactDetails.get(0);
 				contactObj.setContactPointStatus(true);
 				contactObj.setContactPointType("phone");
 				contactObj.setContactPointValue(beneficiaryContactDetails);
