From 41a4bc03cf78e17e6390a6d5c27d26ac06224773 Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Fri, 13 Dec 2024 18:38:00 +0530 Subject: [PATCH 1/8] Modified tnxId keyword to txnId --- .../java/com/wipro/fhir/data/v3/abhaCard/LoginMethod.java | 2 +- .../wipro/fhir/data/v3/abhaCard/RequestOTPEnrollment.java | 2 +- .../ndhm/CreateHealthID_Aadhaar_NDHMServiceImpl.java | 8 ++++---- .../fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java | 8 ++++---- .../fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/wipro/fhir/data/v3/abhaCard/LoginMethod.java b/src/main/java/com/wipro/fhir/data/v3/abhaCard/LoginMethod.java index 2536f29..bde1e58 100644 --- a/src/main/java/com/wipro/fhir/data/v3/abhaCard/LoginMethod.java +++ b/src/main/java/com/wipro/fhir/data/v3/abhaCard/LoginMethod.java @@ -8,7 +8,7 @@ public class LoginMethod { private String loginId; private String loginMethod; private String pId; - private String tnxId; + private String txnId; private String mobileNumber; private String createdBy; private int providerServiceMapId; diff --git a/src/main/java/com/wipro/fhir/data/v3/abhaCard/RequestOTPEnrollment.java b/src/main/java/com/wipro/fhir/data/v3/abhaCard/RequestOTPEnrollment.java index 8eefe19..b49cd0a 100644 --- a/src/main/java/com/wipro/fhir/data/v3/abhaCard/RequestOTPEnrollment.java +++ b/src/main/java/com/wipro/fhir/data/v3/abhaCard/RequestOTPEnrollment.java @@ -5,7 +5,7 @@ @Data public class RequestOTPEnrollment { - String tnxId; + String txnId; String[] scope; String loginHint; String loginId; diff --git a/src/main/java/com/wipro/fhir/service/ndhm/CreateHealthID_Aadhaar_NDHMServiceImpl.java b/src/main/java/com/wipro/fhir/service/ndhm/CreateHealthID_Aadhaar_NDHMServiceImpl.java index 5a43aa2..0a676d7 100644 --- a/src/main/java/com/wipro/fhir/service/ndhm/CreateHealthID_Aadhaar_NDHMServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/ndhm/CreateHealthID_Aadhaar_NDHMServiceImpl.java @@ -177,7 +177,7 @@ public String verifyOTP(String request) throws FHIRException { JsonParser jsnParser = new JsonParser(); JsonElement jsnElmnt = jsnParser.parse(responseStrLogin); jsnOBJ = jsnElmnt.getAsJsonObject(); - resMap.put("tnxId", jsnOBJ.get("txnId").getAsString()); + resMap.put("txnId", jsnOBJ.get("txnId").getAsString()); res = new Gson().toJson(resMap); } else throw new FHIRException("NDHM_FHIR Error while verifying the OTP"); @@ -210,7 +210,7 @@ public String checkAndGenerateMobileOTP(String request) throws FHIRException { jsnOBJ = jsnElmnt.getAsJsonObject(); //String mobileLinked = jsnOBJ.get("mobileLinked").getAsString(); resMap.put("mobileLinked", jsnOBJ.get("mobileLinked").getAsString()); - resMap.put("tnxId", jsnOBJ.get("txnId").getAsString()); + resMap.put("txnId", jsnOBJ.get("txnId").getAsString()); res = new Gson().toJson(resMap); } else @@ -242,7 +242,7 @@ public String verifyMobileOTP(String request) throws FHIRException { JsonParser jsnParser = new JsonParser(); JsonElement jsnElmnt = jsnParser.parse(responseStrLogin); jsnOBJ = jsnElmnt.getAsJsonObject(); - resMap.put("tnxId", jsnOBJ.get("txnId").getAsString()); + resMap.put("txnId", jsnOBJ.get("txnId").getAsString()); res = new Gson().toJson(resMap); } else throw new FHIRException("NDHM_FHIR Error while verifiying mobile OTP"); @@ -367,7 +367,7 @@ public String generateMobileOTP(String request) throws FHIRException { jsnOBJ = jsnElmnt.getAsJsonObject(); // String mobileLinked = jsnOBJ.get("mobileLinked").getAsString(); // resMap.put("mobileLinked", jsnOBJ.get("mobileLinked").getAsString()); - resMap.put("tnxId", jsnOBJ.get("txnId").getAsString()); + resMap.put("txnId", jsnOBJ.get("txnId").getAsString()); res = new Gson().toJson(resMap); } else diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java index 40cdb4e..727231b 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java @@ -114,7 +114,7 @@ public String getOtpForEnrollment(String request) throws FHIRException { reqOtpEnrollment.setScope(new String[] { "abha-enrol" }); } else if ("MOBILE".equalsIgnoreCase(loginMethod.getLoginMethod())) { reqOtpEnrollment.setLoginId(encryptedLoginId); - reqOtpEnrollment.setTnxId(loginMethod.getTnxId()); + reqOtpEnrollment.setTxnId(loginMethod.getTxnId()); reqOtpEnrollment.setOtpSystem("abdm"); reqOtpEnrollment.setLoginHint("mobile"); reqOtpEnrollment.setScope(new String[] { "abha-enrol", "mobile-verify" }); @@ -276,7 +276,7 @@ public String verifyAuthByAbdm(String request) throws FHIRException { String formattedTimestamp = now.format(formatter); otp.setTimestamp(formattedTimestamp); - otp.setTxnId(loginMethod.getTnxId()); + otp.setTxnId(loginMethod.getTxnId()); otp.setOtpValue(encryptedLoginId); String[] scope; @@ -327,7 +327,7 @@ public String formAadharEnrollReqObjByAadhar(LoginMethod loginData, String encry String formattedTimestamp = now.format(formatter); otp.setTimestamp(formattedTimestamp); - otp.setTxnId(loginData.getTnxId()); + otp.setTxnId(loginData.getTxnId()); otp.setOtpValue(encryptedLoginId); otp.setMobile(loginData.getMobileNumber()); @@ -359,7 +359,7 @@ public String formAadharEnrollReqObjByBiometric(LoginMethod loginData, String en String formattedTimestamp = now.format(formatter); bio.setTimestamp(formattedTimestamp); - bio.setTxnId(loginData.getTnxId()); + bio.setTxnId(loginData.getTxnId()); bio.setAadhaar(encryptedLoginId); bio.setFingerPrintAuthPid(loginData.getPId()); diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java index e33fc6a..3263912 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java @@ -170,7 +170,7 @@ public String verifyAbhaLogin(String request) throws FHIRException { OtpRequest otp = new OtpRequest(); - otp.setTxnId(loginData.getTnxId()); + otp.setTxnId(loginData.getTxnId()); otp.setOtpValue(encryptedLoginId); Map authDataMap = new HashMap<>(); From 55e48816ef62241dc109117399e7c91800a0bc63 Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Fri, 13 Dec 2024 23:12:19 +0530 Subject: [PATCH 2/8] Abha-address search API changes --- src/main/environment/common_ci.properties | 2 + src/main/environment/common_dev.properties | 2 + .../environment/common_example.properties | 2 + src/main/environment/common_test.properties | 2 + .../v3/abha/LoginAbhaV3ServiceImpl.java | 42 ++++++++++++++++--- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/main/environment/common_ci.properties b/src/main/environment/common_ci.properties index f99d537..abbb76c 100644 --- a/src/main/environment/common_ci.properties +++ b/src/main/environment/common_ci.properties @@ -92,6 +92,8 @@ printAbhaCard = @env.ABDM_BASE_URL@/abha/api/v3/profile/account/abha-card abhaLoginRequestOtp = @env.ABDM_BASE_URL@/abha/api/v3/profile/login/request/otp verifyAbhaLogin = @env.ABDM_BASE_URL@/abha/api/v3/profile/login/verify requestAuthByAbdm = @env.ABDM_BASE_URL@/abha/api/v3/enrollment/auth/byAbdm +webLoginAbhaRequestOtp = @env.ABDM_BASE_URL@/abha/api/v3/phr/web/login/abha/request/otp +webLoginAbhaVerify = @env.ABDM_BASE_URL@/abha/api/v3/phr/web/login/abha/verify abhaMode=sbx diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties index aca47c2..e6ea966 100644 --- a/src/main/environment/common_dev.properties +++ b/src/main/environment/common_dev.properties @@ -92,6 +92,8 @@ printAbhaCard = https://abhasbx.abdm.gov.in/abha/api/v3/profile/account/abha-car abhaLoginRequestOtp = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/request/otp verifyAbhaLogin = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/verify requestAuthByAbdm = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/auth/byAbdm +webLoginAbhaRequestOtp = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/request/otp +webLoginAbhaVerify = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/verify abhaMode=sbx diff --git a/src/main/environment/common_example.properties b/src/main/environment/common_example.properties index fc9a950..f0a48a6 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -55,6 +55,8 @@ abdmCheckAndGenerateMobileOTP= https://healthidsbx.abdm.gov.in/api/v2/registrati abdmVerifyMobileOTP= https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/verifyMobileOTP abdmcreateHealthIdWithPreVerified= https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/createHealthIdWithPreVerified requestAuthByAbdm = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/auth/byAbdm +webLoginAbhaRequestOtp = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/request/otp +webLoginAbhaVerify = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/verify ##CareContext Creation API generateOTPForCareContext=https://dev.abdm.gov.in/gateway/v0.5/users/auth/init diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties index aca47c2..e6ea966 100644 --- a/src/main/environment/common_test.properties +++ b/src/main/environment/common_test.properties @@ -92,6 +92,8 @@ printAbhaCard = https://abhasbx.abdm.gov.in/abha/api/v3/profile/account/abha-car abhaLoginRequestOtp = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/request/otp verifyAbhaLogin = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/verify requestAuthByAbdm = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/auth/byAbdm +webLoginAbhaRequestOtp = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/request/otp +webLoginAbhaVerify = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/verify abhaMode=sbx diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java index 3263912..138b8c1 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java @@ -53,6 +53,12 @@ public class LoginAbhaV3ServiceImpl implements LoginAbhaV3Service { @Value("${abhaLoginRequestOtp}") String abhaLoginRequestOtp; + @Value("${webLoginAbhaRequestOtp}") + String webLoginAbhaRequestOtp; + + @Value("${webLoginAbhaVerify}") + String webLoginAbhaVerify; + @Value("${verifyAbhaLogin}") String verifyAbhaLoginUrl; @@ -65,6 +71,7 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException { RestTemplate restTemplate = new RestTemplate(); String encryptedLoginId = null; String publicKeyString = null; + ResponseEntity responseEntity; try { String ndhmAuthToken = generateSession_NDHM.getNDHMAuthToken(); @@ -89,16 +96,22 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException { reqOtpEnrollment.setLoginId(encryptedLoginId); } - if ("AADHAAR".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && - ("abha-number".equalsIgnoreCase(loginAbhaRequest.getLoginHint()) || "abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint()) )) { + if ("AADHAAR".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "abha-number".equalsIgnoreCase(loginAbhaRequest.getLoginHint() )) { reqOtpEnrollment.setScope(new String[] { "abha-login", "aadhaar-verify" }); reqOtpEnrollment.setLoginHint(loginAbhaRequest.getLoginHint()); reqOtpEnrollment.setOtpSystem("aadhaar"); - } else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) - && ("abha-number".equalsIgnoreCase(loginAbhaRequest.getLoginHint()) || "abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint()) )) { + } else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "abha-number".equalsIgnoreCase(loginAbhaRequest.getLoginHint() )) { reqOtpEnrollment.setScope(new String[] { "abha-login", "mobile-verify" }); reqOtpEnrollment.setLoginHint(loginAbhaRequest.getLoginHint()); reqOtpEnrollment.setOtpSystem("abdm"); + } else if ("aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint() )) { + reqOtpEnrollment.setScope(new String[] { "abha-address-login", "aadhaar-verify" }); + reqOtpEnrollment.setLoginHint(loginAbhaRequest.getLoginHint()); + reqOtpEnrollment.setOtpSystem("aadhaar"); + } else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint() )) { + reqOtpEnrollment.setScope(new String[] { "abha-address-login", "mobile-verify" }); + reqOtpEnrollment.setLoginHint(loginAbhaRequest.getLoginHint()); + reqOtpEnrollment.setOtpSystem("abdm"); } else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) ) { reqOtpEnrollment.setScope(new String[] { "abha-login", "mobile-verify" }); reqOtpEnrollment.setLoginHint("mobile"); @@ -115,8 +128,13 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException { logger.info("ABDM reqobj for request otp for Abha login: " + requestOBJ); HttpEntity httpEntity = new HttpEntity<>(requestOBJ, headers); - ResponseEntity responseEntity = restTemplate.exchange(abhaLoginRequestOtp, HttpMethod.POST, + if("abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) { + responseEntity = restTemplate.exchange(webLoginAbhaRequestOtp, HttpMethod.POST, + httpEntity, String.class); + } else { + responseEntity = restTemplate.exchange(abhaLoginRequestOtp, HttpMethod.POST, httpEntity, String.class); + } logger.info("ABDM response for response otp for Abha login: " + responseEntity); String responseStrLogin = common_NDHMService.getBody(responseEntity); @@ -145,6 +163,7 @@ public String verifyAbhaLogin(String request) throws FHIRException { String encryptedLoginId = null; String publicKeyString = null; HealthIDResponse health = new HealthIDResponse(); + ResponseEntity responseEntity; try { String ndhmAuthToken = generateSession_NDHM.getNDHMAuthToken(); @@ -185,14 +204,25 @@ public String verifyAbhaLogin(String request) throws FHIRException { } else if ("MOBILE".equalsIgnoreCase(loginData.getLoginMethod())) { verifyAbhaLogin.setScope(new String[] {"abha-login", "mobile-verify" } ); + } else if ("abha-mobile".equalsIgnoreCase(loginData.getLoginMethod())) { + verifyAbhaLogin.setScope(new String[] {"abha-address-login", "mobile-verify" } ); + + } else if ("abha-aadhaar".equalsIgnoreCase(loginData.getLoginMethod())) { + verifyAbhaLogin.setScope(new String[] {"abha-address-login", "aadhaar-verify" } ); } String requestObj = new Gson().toJson(verifyAbhaLogin); logger.info("ABDM request for verify abha login: " + requestObj); HttpEntity httpEntity = new HttpEntity<>(requestObj, headers); - ResponseEntity responseEntity = restTemplate.exchange(verifyAbhaLoginUrl, HttpMethod.POST, + + if("abha-aadhaar".equalsIgnoreCase(loginData.getLoginMethod()) || "abha-mobile".equalsIgnoreCase(loginData.getLoginMethod())) { + responseEntity = restTemplate.exchange(webLoginAbhaVerify, HttpMethod.POST, + httpEntity, String.class); + } else { + responseEntity = restTemplate.exchange(verifyAbhaLoginUrl, HttpMethod.POST, httpEntity, String.class); + } logger.info("ABDM response for verify abha login: " + httpEntity); String responseStrLogin = common_NDHMService.getBody(responseEntity); From f3445cb750c84d64836dbe96a3c0306a7aeafc82 Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Mon, 16 Dec 2024 14:17:33 +0530 Subject: [PATCH 3/8] added validation for multiple phraddress --- .../service/v3/abha/CreateAbhaV3ServiceImpl.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java index 727231b..c233694 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java @@ -26,6 +26,7 @@ import org.springframework.web.client.RestTemplate; import com.google.gson.Gson; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.wipro.fhir.data.healthID.HealthIDResponse; @@ -431,8 +432,16 @@ public String getAbhaCardPrinted(String reqObj) throws FHIRException { private void constructHealthIdResponse(HealthIDResponse healthIDResp, JsonObject profile) throws ParseException { healthIDResp.setHealthIdNumber(profile.get("ABHANumber").getAsString()); - String abhaAddress = profile.get("phrAddress").getAsString().replace("[", "").replace("]", ""); - healthIDResp.setHealthId(abhaAddress); + JsonArray phrAddressArray = profile.getAsJsonArray("phrAddress"); + StringBuilder abhaAddressBuilder = new StringBuilder(); + + for (int i = 0; i < phrAddressArray.size(); i++) { + abhaAddressBuilder.append(phrAddressArray.get(i).getAsString()); + if (i < phrAddressArray.size() - 1) { + abhaAddressBuilder.append(", "); + } + } + healthIDResp.setHealthId(abhaAddressBuilder.toString()); healthIDResp.setName( healthIDResp.getFirstName() + " " + healthIDResp.getMiddleName() + " " + healthIDResp.getLastName()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy"); @@ -444,5 +453,5 @@ private void constructHealthIdResponse(HealthIDResponse healthIDResp, JsonObject healthIDResp.setMonthOfBirth(month.format(date)); healthIDResp.setDayOfBirth(day.format(date)); } - + } From f967118995245bff94596c8df4cfa26f32a55703 Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Tue, 17 Dec 2024 22:18:05 +0530 Subject: [PATCH 4/8] Abha-address search response changes --- .../fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java index 138b8c1..0d70ae7 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java @@ -224,8 +224,8 @@ public String verifyAbhaLogin(String request) throws FHIRException { httpEntity, String.class); } - logger.info("ABDM response for verify abha login: " + httpEntity); String responseStrLogin = common_NDHMService.getBody(responseEntity); + logger.info("ABDM response for verify abha login: " + responseEntity); if (responseEntity.getStatusCode() == HttpStatusCode.valueOf(200) && responseEntity.hasBody()) { JsonObject jsonResponse = JsonParser.parseString(responseStrLogin).getAsJsonObject(); @@ -239,6 +239,16 @@ public String verifyAbhaLogin(String request) throws FHIRException { if (jsonResponse.has("token")) { responseMap.put("xToken", jsonResponse.get("token").getAsString()); } + } else if(jsonResponse.has("users")) { + responseMap.put("abhaDetails", jsonResponse.get("users").getAsJsonArray().get(0).getAsJsonObject().toString()); + responseMap.put("txnId", jsonResponse.get("txnId").getAsString()); + if (jsonResponse.has("tokens") && jsonResponse.get("tokens").isJsonObject()) { + JsonObject tokensObject = jsonResponse.get("tokens").getAsJsonObject(); + if (tokensObject.has("token") && !tokensObject.get("token").isJsonNull()) { + String token = tokensObject.get("token").getAsString(); + responseMap.put("xToken", token); + } + } } } else { String message = jsonResponse.get("message").getAsString(); From 8430a37def65c225439f7e9a4af8e9b608b064a5 Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Tue, 7 Jan 2025 15:22:01 +0530 Subject: [PATCH 5/8] Save facility id variable change chnages --- .../data/mongo/care_context/SaveFacilityIdForVisit.java | 2 +- .../com/wipro/fhir/service/common/CommonServiceImpl.java | 1 + .../wipro/fhir/service/facility/FacilityServiceImpl.java | 8 +++----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/wipro/fhir/data/mongo/care_context/SaveFacilityIdForVisit.java b/src/main/java/com/wipro/fhir/data/mongo/care_context/SaveFacilityIdForVisit.java index 0a3c9f3..ea5358a 100644 --- a/src/main/java/com/wipro/fhir/data/mongo/care_context/SaveFacilityIdForVisit.java +++ b/src/main/java/com/wipro/fhir/data/mongo/care_context/SaveFacilityIdForVisit.java @@ -7,7 +7,7 @@ @Data public class SaveFacilityIdForVisit { - String facilityId; + String abdmFacilityId; BigInteger visitCode; } diff --git a/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java b/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java index 5d676d3..1d2fbb1 100644 --- a/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java @@ -212,6 +212,7 @@ public String processResourceOperation() throws FHIRException { int j = diagnosticReportRecordBundle.processDiagnosticReportRecordBundle(resourceRequestHandler, p); // 3. prescription Bundle int k = prescriptionBundle.processPrescriptionRecordBundle(resourceRequestHandler, p); + logger.info("The value of i: " +i + " The value of j: " + j + " The value of k: " + k ); if (i > 0 && j > 0 && k > 0) { diff --git a/src/main/java/com/wipro/fhir/service/facility/FacilityServiceImpl.java b/src/main/java/com/wipro/fhir/service/facility/FacilityServiceImpl.java index 117a3c1..bcb6925 100644 --- a/src/main/java/com/wipro/fhir/service/facility/FacilityServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/facility/FacilityServiceImpl.java @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -16,7 +15,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.wipro.fhir.data.mongo.care_context.AddCareContextRequest; import com.wipro.fhir.data.mongo.care_context.SaveFacilityIdForVisit; import com.wipro.fhir.repo.healthID.BenHealthIDMappingRepo; import com.wipro.fhir.service.ndhm.Common_NDHMService; @@ -88,10 +86,10 @@ public String saveAbdmFacilityId(String reqObj) throws FHIRException { String res = null; try { SaveFacilityIdForVisit requestObj = InputMapper.gson().fromJson(reqObj, SaveFacilityIdForVisit.class); - if(requestObj.getFacilityId() == null || requestObj.getFacilityId() == "") { - requestObj.setFacilityId(abdmFacilityId); + if(requestObj.getAbdmFacilityId() == null || requestObj.getAbdmFacilityId() == "") { + requestObj.setAbdmFacilityId(abdmFacilityId); } - Integer response = benHealthIDMappingRepo.updateFacilityIdForVisit(requestObj.getVisitCode(), requestObj.getFacilityId()); + Integer response = benHealthIDMappingRepo.updateFacilityIdForVisit(requestObj.getVisitCode(), requestObj.getAbdmFacilityId()); if(response > 0 ) { res = "ABDM Facility ID updated successfully"; } else From 68a81b3a9f13b4c45351ee95900912dcb21ea9c2 Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Thu, 9 Jan 2025 17:28:45 +0530 Subject: [PATCH 6/8] Added check to avoid multiple save of single care-context --- .../service/common/CommonServiceImpl.java | 122 +++++++----------- 1 file changed, 50 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java b/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java index 1d2fbb1..7cc60ff 100644 --- a/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java @@ -40,7 +40,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Update; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -59,7 +58,6 @@ import com.wipro.fhir.data.mongo.care_context.NDHMResponse; import com.wipro.fhir.data.mongo.care_context.Notification; import com.wipro.fhir.data.mongo.care_context.PatientCareContexts; -import com.wipro.fhir.data.mongo.care_context.PatientCareContextsStringOBJ; import com.wipro.fhir.data.mongo.care_context.SMSNotify; import com.wipro.fhir.data.patient.PatientDemographic; import com.wipro.fhir.data.patient_data_handler.PatientDemographicModel_NDHM_Patient_Profile; @@ -96,17 +94,13 @@ public class CommonServiceImpl implements CommonService { @Value("${patient-search-page-size}") private String patient_search_page_size; - + @Value("${abhaMode}") private String abhaMode; private static String authKey; private UUID uuid; - //public static String NDHM_AUTH_TOKEN; - //public static Long NDHM_TOKEN_EXP; - //public static String NDHM_OTP_TOKEN; - @Value("${clientID}") private String clientID; @@ -127,7 +121,6 @@ public class CommonServiceImpl implements CommonService { private APIChannel aPIChannel; @Autowired private AMRIT_ResourceMongoRepo aMRIT_ResourceMongoRepo; - @Autowired private PatientCareContextsMongoRepo patientCareContextsMongoRepo; @@ -148,7 +141,7 @@ public class CommonServiceImpl implements CommonService { @Autowired private PatientDataGatewayService patientDataGatewayService; - + @Autowired private MongoTemplate mongoTemplate; @@ -159,7 +152,7 @@ public class CommonServiceImpl implements CommonService { private PatientDemographic patientDemographic; @Autowired private Common_NDHMService common_NDHMService; - + @Autowired private BenHealthIDMappingRepo benHealthIDMappingRepo; @@ -168,7 +161,8 @@ public String processResourceOperation() throws FHIRException { String response = null; // list of patient eligible for resource creation List pList = getPatientListForResourceEligible(); - logger.info("No of records available to create FHIR in last 2 dagetPatientListForResourceEligibleys : " + pList.size()); + logger.info("No of records available to create FHIR in last 2 dagetPatientListForResourceEligibleys : " + + pList.size()); ResourceRequestHandler resourceRequestHandler; for (PatientEligibleForResourceCreation p : pList) { @@ -196,10 +190,11 @@ public String processResourceOperation() throws FHIRException { if (patientDemographicOBJ.getPreferredPhoneNo() != null) sendAbdmAdvSMS(patientDemographicOBJ.getPreferredPhoneNo()); else - throw new FHIRException("Advertisement sms could not be sent as beneficiary phone no not found"); - } - else - throw new FHIRException("Beneficiary not found, benRegId = " +resourceRequestHandler.getBeneficiaryRegID()); + throw new FHIRException( + "Advertisement sms could not be sent as beneficiary phone no not found"); + } else + throw new FHIRException( + "Beneficiary not found, benRegId = " + resourceRequestHandler.getBeneficiaryRegID()); } catch (Exception e) { logger.error(e.getMessage()); @@ -212,7 +207,7 @@ public String processResourceOperation() throws FHIRException { int j = diagnosticReportRecordBundle.processDiagnosticReportRecordBundle(resourceRequestHandler, p); // 3. prescription Bundle int k = prescriptionBundle.processPrescriptionRecordBundle(resourceRequestHandler, p); - logger.info("The value of i: " +i + " The value of j: " + j + " The value of k: " + k ); + logger.info("The value of i: " + i + " The value of j: " + j + " The value of k: " + k); if (i > 0 && j > 0 && k > 0) { @@ -290,47 +285,16 @@ public String getUUID() { // 31-03-2021 // @Override - public int addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForResourceCreation pVisit) + public void addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForResourceCreation pVisit) throws FHIRException { - int response = 0; if (pDemo != null && pVisit != null) { -// JsonObject jsnOBJ = new JsonObject(); -// JsonParser jsnParser = new JsonParser(); -// JsonElement jsnElmnt = jsnParser.parse(requestObj); -// jsnOBJ = jsnElmnt.getAsJsonObject(); - - PatientCareContextsStringOBJ patientCareContextsStringOBJ = new PatientCareContextsStringOBJ(); - - // wrong variable name in request obj for benregid, need to correct in main - // request obj first -// Long benID = null; -// Long benRegID = null; -// Long visitCode = null; -// -// if (jsnOBJ.has("beneficiaryID") && jsnOBJ.get("beneficiaryID") != null) -// benRegID = jsnOBJ.get("beneficiaryID").getAsLong(); -// if (jsnOBJ.has("visitCode") && jsnOBJ.get("visitCode") != null) -// visitCode = jsnOBJ.get("visitCode").getAsLong(); -// String healthID = jsnOBJ.get("healthID").getAsString(); -// String healthIDNumber = jsnOBJ.get("healthIdNumber").getAsString(); -// String visitCategory = jsnOBJ.get("visitCategory").getAsString(); -// String phoneNo; -// String gender; -// String yearOfBirth; -// String name; -// String email; - - // get benid -// if (benRegID != null) -// benID = benHealthIDMappingRepo.getBenID(benRegID); - - // fetch abdm facility id - logger.info("********t_benvisistData fetch request pvisit data :" , pVisit); + // fetch abdm facility id + logger.info("********t_benvisistData fetch request pvisit data :", pVisit); List res = benHealthIDMappingRepo.getAbdmFacilityAndlinkedDate(pVisit.getVisitCode()); - + // check care context record in mongo against beneficiaryID ArrayList ccList = new ArrayList<>(); @@ -338,28 +302,46 @@ public int addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForRes logger.info("********t_benvisistData fetch response : {}", res); cc.setReferenceNumber(pVisit.getVisitCode() != null ? pVisit.getVisitCode().toString() : null); - cc.setDisplay(pVisit.getVisitCategory() != null ? pVisit.getVisitCategory().toString() : null); + cc.setDisplay(pVisit.getVisitCategory() != null ? pVisit.getVisitCategory().toString() : null); Object[] resData = null; if (res.get(0) != null) { resData = res.get(0); - cc.setAbdmFacilityId(resData[0] != null ? resData[0].toString() : null ); - cc.setCareContextLinkedDate(resData[1] != null ? resData[1].toString() : null); + cc.setAbdmFacilityId(resData[0] != null ? resData[0].toString() : null); + cc.setCareContextLinkedDate(resData[1] != null ? resData[1].toString() : null); } - - logger.info("********data to be saved in mongo :" , cc); + + logger.info("********data to be saved in mongo :", cc); PatientCareContexts pcc; PatientCareContexts resultSet = null; - if (pDemo.getBeneficiaryID() != null) { pcc = patientCareContextsMongoRepo.findByIdentifier(pDemo.getBeneficiaryID().toString()); if (pcc != null && pcc.getIdentifier() != null) { - ccList = pcc.getCareContextsList(); - ccList.add(cc); - pcc.setCareContextsList(ccList); - resultSet = patientCareContextsMongoRepo.save(pcc); - + // Get the existing careContextsList + if (pcc.getCareContextsList() != null && pcc.getCareContextsList().size() > 0) { + ccList = pcc.getCareContextsList(); + + // Check if the visitCode is already in the careContextsList + boolean visitCodeExists = false; + for (CareContexts existingContext : ccList) { + if (existingContext.getReferenceNumber() != null + && existingContext.getReferenceNumber().equals(pVisit.getVisitCode().toString())) { + visitCodeExists = true; + return; + } + } + ccList.add(cc); + pcc.setCareContextsList(ccList); + resultSet = patientCareContextsMongoRepo.save(pcc); + } +// } +// if (pcc != null && pcc.getIdentifier() != null) { +// ccList = pcc.getCareContextsList(); +// ccList.add(cc); +// pcc.setCareContextsList(ccList); +// resultSet = patientCareContextsMongoRepo.save(pcc); +// } else { pcc = new PatientCareContexts(); pcc.setCaseReferenceNumber(pDemo.getBeneficiaryID().toString()); @@ -396,13 +378,9 @@ public int addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForRes // save carecontext back to mongo resultSet = patientCareContextsMongoRepo.save(pcc); } - - if (resultSet != null && resultSet.get_id() != null) - response = 1; } } - return response; } @Deprecated @@ -424,7 +402,7 @@ public String ndhmUserAuthenticate() throws FHIRException { JsonParser jsnParser = new JsonParser(); JsonElement jsnElmnt = jsnParser.parse(responseStrLogin); jsnOBJ = jsnElmnt.getAsJsonObject(); - //NDHM_AUTH_TOKEN = "Bearer" + " " + jsnOBJ.get("accessToken").getAsString(); + // NDHM_AUTH_TOKEN = "Bearer" + " " + jsnOBJ.get("accessToken").getAsString(); Integer expiry = jsnOBJ.get("expiresIn").getAsInt(); double time = expiry / 60; Date date = new Date(); @@ -432,7 +410,7 @@ public String ndhmUserAuthenticate() throws FHIRException { Calendar ndhmCalendar = Calendar.getInstance(); ndhmCalendar.setTime(sqlDate); ndhmCalendar.add(Calendar.MINUTE, (int) time); - + res = "success"; } else res = "Error while accessing authenticate API"; @@ -478,7 +456,7 @@ public List fetchTempResourceFromMongo(ResourceRequestHandler re * @author SH20094090 * @return * - * get the UUID and isoTimestamp for NDMH API's + * get the UUID and isoTimestamp for NDMH API's */ @Deprecated @Override @@ -542,7 +520,7 @@ public String getMongoNDHMResponse(String requestID) throws FHIRException { * @param reqID * @return * - * hitting MongoDB + * hitting MongoDB */ @Deprecated NDHMResponse getResponseMongo(String reqID) { @@ -629,8 +607,8 @@ public void sendAbdmAdvSMS(String phone) throws FHIRException { SMSNotify smsNotify = new SMSNotify(obj.getRequestId(), obj.getTimestamp(), notification); String requestOBJ = new Gson().toJson(smsNotify); logger.info("NDHM_FHIR Generate Notify SMS request Obj: " + requestOBJ); - if(abhaMode !=null && !(abhaMode.equalsIgnoreCase("abdm") || abhaMode.equalsIgnoreCase("sbx"))) - abhaMode="sbx"; + if (abhaMode != null && !(abhaMode.equalsIgnoreCase("abdm") || abhaMode.equalsIgnoreCase("sbx"))) + abhaMode = "sbx"; HttpHeaders headers = common_NDHMService.getHeaders(ndhmAuthToken, abhaMode); ResponseEntity responseEntity = httpUtils.postWithResponseEntity(generateABDM_NotifySMS, requestOBJ, headers); From 44df923ddc4c80f97b8ccd584c1a06e7aaf1165a Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Thu, 9 Jan 2025 18:20:40 +0530 Subject: [PATCH 7/8] removed unused variables --- .../wipro/fhir/service/common/CommonServiceImpl.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java b/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java index 7cc60ff..85c6973 100644 --- a/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java @@ -161,8 +161,7 @@ public String processResourceOperation() throws FHIRException { String response = null; // list of patient eligible for resource creation List pList = getPatientListForResourceEligible(); - logger.info("No of records available to create FHIR in last 2 dagetPatientListForResourceEligibleys : " - + pList.size()); + logger.info("No of records available to create FHIR in last 2 dagetPatientListForResourceEligibleys : " + pList.size()); ResourceRequestHandler resourceRequestHandler; for (PatientEligibleForResourceCreation p : pList) { @@ -312,7 +311,6 @@ public void addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForRe logger.info("********data to be saved in mongo :", cc); PatientCareContexts pcc; - PatientCareContexts resultSet = null; if (pDemo.getBeneficiaryID() != null) { pcc = patientCareContextsMongoRepo.findByIdentifier(pDemo.getBeneficiaryID().toString()); @@ -323,17 +321,16 @@ public void addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForRe ccList = pcc.getCareContextsList(); // Check if the visitCode is already in the careContextsList - boolean visitCodeExists = false; for (CareContexts existingContext : ccList) { if (existingContext.getReferenceNumber() != null && existingContext.getReferenceNumber().equals(pVisit.getVisitCode().toString())) { - visitCodeExists = true; + logger.info("Visit code already Exisit in Mongo for benId:" + pDemo.getBeneficiaryID().toString() + "and visit code : " + pVisit.getVisitCode() ); return; } } ccList.add(cc); pcc.setCareContextsList(ccList); - resultSet = patientCareContextsMongoRepo.save(pcc); + patientCareContextsMongoRepo.save(pcc); } // } // if (pcc != null && pcc.getIdentifier() != null) { @@ -376,7 +373,7 @@ public void addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForRe ccList.add(cc); pcc.setCareContextsList(ccList); // save carecontext back to mongo - resultSet = patientCareContextsMongoRepo.save(pcc); + patientCareContextsMongoRepo.save(pcc); } } From 9c3b51f63d4eb7cbfb84680bed55eb06dd58a07d Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Thu, 30 Jan 2025 14:13:40 +0530 Subject: [PATCH 8/8] Updated public key certificate API --- src/main/environment/common_ci.properties | 1 + src/main/environment/common_dev.properties | 1 + .../environment/common_example.properties | 1 + src/main/environment/common_test.properties | 1 + .../v3/abha/CertificateKeyService.java | 2 +- .../v3/abha/CertificateKeyServiceImpl.java | 58 ++++++++++++++----- .../v3/abha/CreateAbhaV3ServiceImpl.java | 7 +-- .../v3/abha/LoginAbhaV3ServiceImpl.java | 5 +- 8 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/main/environment/common_ci.properties b/src/main/environment/common_ci.properties index abbb76c..737e068 100644 --- a/src/main/environment/common_ci.properties +++ b/src/main/environment/common_ci.properties @@ -85,6 +85,7 @@ abdmAccountProfile=@env.ABDM_Account_ID_BASE_URL@/api/v1/account/profile getAbdmFacilityServicies= @env.ABDM_BASE_URL@/devservice/v1/bridges/getServices ##ABDM V3 APIs +abdmV3UserAuthenticate = @env.ABDM_BASE_URL@/api/hiecm/gateway/v3/sessions getAuthCertPublicKey = @env.ABDM_HEALTH_ID_BASE_URL@/api/v1/auth/cert requestOtpForEnrollment = @env.ABDM_BASE_URL@/abha/api/v3/enrollment/request/otp abhaEnrollByAadhaar = @env.ABDM_BASE_URL@/abha/api/v3/enrollment/enrol/byAadhaar diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties index e6ea966..0b036ba 100644 --- a/src/main/environment/common_dev.properties +++ b/src/main/environment/common_dev.properties @@ -85,6 +85,7 @@ abdmAccountProfile=@env.ABDM_Account_ID_BASE_URL@/api/v1/account/profile getAbdmFacilityServicies= https://dev.abdm.gov.in/devservice/v1/bridges/getServices ##ABDM V3 APIs +abdmV3UserAuthenticate = https://dev.abdm.gov.in/api/hiecm/gateway/v3/sessions getAuthCertPublicKey = https://healthidsbx.abdm.gov.in/api/v1/auth/cert requestOtpForEnrollment = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/request/otp abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/byAadhaar diff --git a/src/main/environment/common_example.properties b/src/main/environment/common_example.properties index f0a48a6..ce69dea 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -87,6 +87,7 @@ abdmAccountProfile=@env.ABDM_Account_ID_BASE_URL@/api/v1/account/profile getAbdmFacilityServicies= https://dev.abdm.gov.in/devservice/v1/bridges/getServices ##ABDM V3 APIs +abdmV3UserAuthenticate = https://dev.abdm.gov.in/api/hiecm/gateway/v3/sessions getAuthCertPublicKey = https://healthidsbx.abdm.gov.in/api/v1/auth/cert requestOtpForEnrollment = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/request/otp abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/byAadhaar diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties index e6ea966..0b036ba 100644 --- a/src/main/environment/common_test.properties +++ b/src/main/environment/common_test.properties @@ -85,6 +85,7 @@ abdmAccountProfile=@env.ABDM_Account_ID_BASE_URL@/api/v1/account/profile getAbdmFacilityServicies= https://dev.abdm.gov.in/devservice/v1/bridges/getServices ##ABDM V3 APIs +abdmV3UserAuthenticate = https://dev.abdm.gov.in/api/hiecm/gateway/v3/sessions getAuthCertPublicKey = https://healthidsbx.abdm.gov.in/api/v1/auth/cert requestOtpForEnrollment = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/request/otp abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/byAadhaar diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/CertificateKeyService.java b/src/main/java/com/wipro/fhir/service/v3/abha/CertificateKeyService.java index 63bf1e8..594c137 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/CertificateKeyService.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/CertificateKeyService.java @@ -4,6 +4,6 @@ public interface CertificateKeyService { - public String getCertPublicKey() throws FHIRException; + public String getCertPublicKey(String ndhmAuthToken) throws FHIRException; } diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/CertificateKeyServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/abha/CertificateKeyServiceImpl.java index 71e5845..cbf9f0f 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/CertificateKeyServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/CertificateKeyServiceImpl.java @@ -1,41 +1,73 @@ package com.wipro.fhir.service.v3.abha; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; +import java.util.UUID; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.wipro.fhir.service.ndhm.Common_NDHMService; import com.wipro.fhir.utils.exception.FHIRException; @Service -public class CertificateKeyServiceImpl implements CertificateKeyService{ - +public class CertificateKeyServiceImpl implements CertificateKeyService { + + @Autowired + private Common_NDHMService common_NDHMService; + @Value("${getAuthCertPublicKey}") String getAuthCertPublicKey; - + private final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); - + @Override - public String getCertPublicKey() throws FHIRException { + public String getCertPublicKey(String ndhmAuthToken) throws FHIRException { RestTemplate restTemplate = new RestTemplate(); - HttpEntity requestEntity = new HttpEntity<>(null); + String publicKey = null; - ResponseEntity certResp = restTemplate.exchange(getAuthCertPublicKey, HttpMethod.GET, requestEntity, - String.class); - String body = certResp.getBody(); + MultiValueMap headers = new LinkedMultiValueMap<>(); + headers.add("Content-Type", MediaType.APPLICATION_JSON + ";charset=utf-8"); + headers.add("REQUEST-ID", UUID.randomUUID().toString()); + + TimeZone tz = TimeZone.getTimeZone("UTC"); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + df.setTimeZone(tz); + String nowAsISO = df.format(new Date()); + headers.add("TIMESTAMP", nowAsISO); + headers.add("Authorization", ndhmAuthToken); - String publicKeyString = body.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "") - .replaceAll("\\s+", ""); + HttpEntity httpEntity = new HttpEntity<>(null, headers); + + ResponseEntity certResp = restTemplate.exchange(getAuthCertPublicKey, HttpMethod.GET, httpEntity, + String.class); + String responseStrLogin = common_NDHMService.getBody(certResp); + if (certResp.getStatusCode() == HttpStatusCode.valueOf(200) && certResp.hasBody()) { + JsonObject jsnOBJ = JsonParser.parseString(responseStrLogin).getAsJsonObject(); + publicKey = jsnOBJ.get("publicKey").getAsString(); - logger.info("publicKeyString : " + publicKeyString); + logger.info("publicKeyString : " + publicKey); - return publicKeyString; + return publicKey; + } + return publicKey; } } diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java index c233694..0fce983 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/CreateAbhaV3ServiceImpl.java @@ -103,7 +103,7 @@ public String getOtpForEnrollment(String request) throws FHIRException { RequestOTPEnrollment reqOtpEnrollment = new RequestOTPEnrollment(); LoginMethod loginMethod = InputMapper.gson().fromJson(request, LoginMethod.class); - publicKeyString = certificateKeyService.getCertPublicKey(); + publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); if (loginMethod.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginMethod.getLoginId(), publicKeyString); } @@ -169,10 +169,9 @@ public String enrollmentByAadhaar(String request) throws FHIRException { headers.add("Authorization", ndhmAuthToken); // Create the enrollByAadhar object - EnrollByAadhaar enrollByAadhar = new EnrollByAadhaar(); LoginMethod loginData = InputMapper.gson().fromJson(request, LoginMethod.class); - publicKeyString = certificateKeyService.getCertPublicKey(); + publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); if (loginData.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginData.getLoginId(), publicKeyString); } @@ -263,7 +262,7 @@ public String verifyAuthByAbdm(String request) throws FHIRException { LoginMethod loginMethod = InputMapper.gson().fromJson(request, LoginMethod.class); - publicKeyString = certificateKeyService.getCertPublicKey(); + publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); if (loginMethod.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginMethod.getLoginId(), publicKeyString); } diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java index 0d70ae7..90e759b 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java @@ -90,7 +90,7 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException { RequestOTPEnrollment reqOtpEnrollment = new RequestOTPEnrollment(); LoginAbhaRequest loginAbhaRequest = InputMapper.gson().fromJson(request, LoginAbhaRequest.class); - publicKeyString = certificateKeyService.getCertPublicKey(); + publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); if (loginAbhaRequest.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginAbhaRequest.getLoginId(), publicKeyString); reqOtpEnrollment.setLoginId(encryptedLoginId); @@ -181,8 +181,7 @@ public String verifyAbhaLogin(String request) throws FHIRException { // Create the enrollByAadhar object VerifyAbhaLogin verifyAbhaLogin = new VerifyAbhaLogin(); LoginMethod loginData = InputMapper.gson().fromJson(request, LoginMethod.class); - - publicKeyString = certificateKeyService.getCertPublicKey(); + publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); if (loginData.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginData.getLoginId(), publicKeyString); }