From 41a4bc03cf78e17e6390a6d5c27d26ac06224773 Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Fri, 13 Dec 2024 18:38:00 +0530 Subject: [PATCH 01/10] 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 02/10] 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 03/10] 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 04/10] 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 05/10] 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 06/10] 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 07/10] 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 08/10] 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); } From 114cfff3a27a2968a5293a0634527b398573ab8c Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Mon, 24 Feb 2025 20:58:58 +0530 Subject: [PATCH 09/10] Integrated Abha session v3 APIs and Profile login user verify APIs --- src/main/environment/common_ci.properties | 5 +- src/main/environment/common_dev.properties | 4 + .../environment/common_example.properties | 6 +- src/main/environment/common_test.properties | 4 + .../v3/abha/CreateAbhaV3Controller.java | 1 - .../v3/abha/LoginAbhaV3Controller.java | 19 ++ .../wipro/fhir/data/healthID/Authorize.java | 16 +- .../fhir/data/healthID/HealthIDResponse.java | 192 +---------------- .../v3/abhaCard/VerifyProfileUserLogin.java | 10 + .../v3/abha/CreateAbhaV3ServiceImpl.java | 27 +-- .../v3/abha/GenerateAuthSessionService.java | 11 + .../abha/GenerateAuthSessionServiceImpl.java | 124 +++++++++++ .../service/v3/abha/LoginAbhaV3Service.java | 4 + .../v3/abha/LoginAbhaV3ServiceImpl.java | 201 ++++++++++++++---- 14 files changed, 364 insertions(+), 260 deletions(-) create mode 100644 src/main/java/com/wipro/fhir/data/v3/abhaCard/VerifyProfileUserLogin.java create mode 100644 src/main/java/com/wipro/fhir/service/v3/abha/GenerateAuthSessionService.java create mode 100644 src/main/java/com/wipro/fhir/service/v3/abha/GenerateAuthSessionServiceImpl.java diff --git a/src/main/environment/common_ci.properties b/src/main/environment/common_ci.properties index 737e068..ed70c81 100644 --- a/src/main/environment/common_ci.properties +++ b/src/main/environment/common_ci.properties @@ -92,11 +92,14 @@ abhaEnrollByAadhaar = @env.ABDM_BASE_URL@/abha/api/v3/enrollment/enrol/byAadhaar 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 +abhaProfileLoginVerifyUser = @env.ABDM_BASE_URL@/abha/api/v3/profile/login/verify/user 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 +webLoginAbhaVerify = @env.ABDM_BASE_URL@/abha/api/v3/phr/web/login/abha/verify +webLoginPhrCard = @env.ABDM_BASE_URL@/abha/api/v3/phr/web/login/profile/abha/phr-card - +x-CM-ID= sbx abhaMode=sbx #logging.pattern.level=DEBUG diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties index 0b036ba..db18ad9 100644 --- a/src/main/environment/common_dev.properties +++ b/src/main/environment/common_dev.properties @@ -92,10 +92,14 @@ abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/b printAbhaCard = https://abhasbx.abdm.gov.in/abha/api/v3/profile/account/abha-card 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 +abhaProfileLoginVerifyUser = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/verify/user 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 +webLoginAbhaVerify = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/verify +webLoginPhrCard = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/profile/abha/phr-card +x-CM-ID= sbx abhaMode=sbx #logging.pattern.level=DEBUG diff --git a/src/main/environment/common_example.properties b/src/main/environment/common_example.properties index bd5e556..803d225 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -95,8 +95,12 @@ abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/b printAbhaCard = https://abhasbx.abdm.gov.in/abha/api/v3/profile/account/abha-card 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 +abhaProfileLoginVerifyUser = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/verify/user +requestAuthByAbdm = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/auth/byAbdm +webLoginAbhaVerify = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/verify +webLoginPhrCard = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/profile/abha/phr-card - +x-CM-ID= sbx abhaMode=sbx #logging.pattern.level=DEBUG diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties index 0b036ba..db18ad9 100644 --- a/src/main/environment/common_test.properties +++ b/src/main/environment/common_test.properties @@ -92,10 +92,14 @@ abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/b printAbhaCard = https://abhasbx.abdm.gov.in/abha/api/v3/profile/account/abha-card 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 +abhaProfileLoginVerifyUser = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/verify/user 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 +webLoginAbhaVerify = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/verify +webLoginPhrCard = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/profile/abha/phr-card +x-CM-ID= sbx abhaMode=sbx #logging.pattern.level=DEBUG diff --git a/src/main/java/com/wipro/fhir/controller/v3/abha/CreateAbhaV3Controller.java b/src/main/java/com/wipro/fhir/controller/v3/abha/CreateAbhaV3Controller.java index 49fbfc6..4e277d9 100644 --- a/src/main/java/com/wipro/fhir/controller/v3/abha/CreateAbhaV3Controller.java +++ b/src/main/java/com/wipro/fhir/controller/v3/abha/CreateAbhaV3Controller.java @@ -105,5 +105,4 @@ public String printAbhaCard(@RequestBody String request) { return response.toString(); } - } diff --git a/src/main/java/com/wipro/fhir/controller/v3/abha/LoginAbhaV3Controller.java b/src/main/java/com/wipro/fhir/controller/v3/abha/LoginAbhaV3Controller.java index 24977f2..7d69230 100644 --- a/src/main/java/com/wipro/fhir/controller/v3/abha/LoginAbhaV3Controller.java +++ b/src/main/java/com/wipro/fhir/controller/v3/abha/LoginAbhaV3Controller.java @@ -64,5 +64,24 @@ public String verifyAbhaLogin(@RequestBody String request) { logger.info("NDHM_FHIR Verify abha login API response " + response.toString()); return response.toString(); } + + @CrossOrigin + @Operation(summary = "Print PHR card - abha address web login") + @PostMapping(value = { "/printWebLoginPhrCard" }) + public String printWebLoginPhrCard(@RequestBody String request) { + OutputResponse response = new OutputResponse(); + try { + if (request != null) { + String s = loginAbhaV3Service.getWebLoginPhrCard(request); + response.setResponse(s); + } else + throw new FHIRException("NDHM_FHIR Empty request object"); + } catch (FHIRException e) { + response.setError(5000, e.getMessage()); + logger.error(e.toString()); + } + logger.info("NDHM_FHIR generate OTP for ABHA card API respponse " + response.toString()); + return response.toString(); + } } diff --git a/src/main/java/com/wipro/fhir/data/healthID/Authorize.java b/src/main/java/com/wipro/fhir/data/healthID/Authorize.java index cb2d07d..8ae94ff 100644 --- a/src/main/java/com/wipro/fhir/data/healthID/Authorize.java +++ b/src/main/java/com/wipro/fhir/data/healthID/Authorize.java @@ -21,19 +21,11 @@ */ package com.wipro.fhir.data.healthID; +import lombok.Data; + +@Data public class Authorize { String clientId; String clientSecret; -public String getClientId() { - return clientId; -} -public void setClientId(String clientId) { - this.clientId = clientId; -} -public String getClientSecret() { - return clientSecret; -} -public void setClientSecret(String clientSecret) { - this.clientSecret = clientSecret; -} +String grantType; } diff --git a/src/main/java/com/wipro/fhir/data/healthID/HealthIDResponse.java b/src/main/java/com/wipro/fhir/data/healthID/HealthIDResponse.java index 99935ae..edb9f15 100644 --- a/src/main/java/com/wipro/fhir/data/healthID/HealthIDResponse.java +++ b/src/main/java/com/wipro/fhir/data/healthID/HealthIDResponse.java @@ -31,10 +31,12 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.Transient; +import lombok.Data; import com.google.gson.annotations.Expose; +@Data @Entity @Table(name = "t_healthid") public class HealthIDResponse { @@ -125,194 +127,10 @@ public class HealthIDResponse { private String modifiedBy; @Column(name = "LastModDate", insertable = false, updatable = false) private Timestamp lastModDate; - + @Column(name = "isNewAbha") + private Boolean isNewAbha; @Expose @Column(name = "TxnID") - String txnId; - - public String getHealthId() { - return healthId; - } - public void setHealthId(String healthId) { - this.healthId = healthId; - } - public String getHealthIdNumber() { - return healthIdNumber; - } - public void setHealthIdNumber(String healthIdNumber) { - this.healthIdNumber = healthIdNumber; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getGender() { - return gender; - } - public void setGender(String gender) { - this.gender = gender; - } - public String getYearOfBirth() { - return yearOfBirth; - } - public void setYearOfBirth(String yearOfBirth) { - this.yearOfBirth = yearOfBirth; - } - public String getMonthOfBirth() { - return monthOfBirth; - } - public void setMonthOfBirth(String monthOfBirth) { - this.monthOfBirth = monthOfBirth; - } - public String getDayOfBirth() { - return dayOfBirth; - } - public void setDayOfBirth(String dayOfBirth) { - this.dayOfBirth = dayOfBirth; - } - public String getFirstName() { - return firstName; - } - public void setFirstName(String firstName) { - this.firstName = firstName; - } - public String getLastName() { - return lastName; - } - public void setLastName(String lastName) { - this.lastName = lastName; - } - public String getMiddleName() { - return middleName; - } - public void setMiddleName(String middleName) { - this.middleName = middleName; - } - public String getStateCode() { - return stateCode; - } - public void setStateCode(String stateCode) { - this.stateCode = stateCode; - } - public String getDistrictCode() { - return districtCode; - } - public void setDistrictCode(String districtCode) { - this.districtCode = districtCode; - } - public String getStateName() { - return stateName; - } - public void setStateName(String stateName) { - this.stateName = stateName; - } - public String getDistrictName() { - return districtName; - } - public void setDistrictName(String districtName) { - this.districtName = districtName; - } - public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } - public String getKycPhoto() { - return kycPhoto; - } - public void setKycPhoto(String kycPhoto) { - this.kycPhoto = kycPhoto; - } - public String getMobile() { - return mobile; - } - public void setMobile(String mobile) { - this.mobile = mobile; - } - - public Integer getProviderServiceMapID() { - return providerServiceMapID; - } - public void setProviderServiceMapID(Integer providerServiceMapID) { - this.providerServiceMapID = providerServiceMapID; - } - - public List getAuthMethods() { - return authMethods; - } - public void setAuthMethods(List authMethods) { - this.authMethods = authMethods; - } - public Integer gethID() { - return hID; - } - public void sethID(Integer hID) { - this.hID = hID; - } - public Long getBeneficiaryRegId() { - return beneficiaryRegId; - } - public void setBeneficiaryRegId(Long beneficiaryRegId) { - this.beneficiaryRegId = beneficiaryRegId; - } - public String getAuthMethod() { - return authMethod; - } - public void setAuthMethod(String authMethod) { - this.authMethod = authMethod; - } - public Boolean getDeleted() { - return deleted; - } - public void setDeleted(Boolean deleted) { - this.deleted = deleted; - } - public String getProcessed() { - return processed; - } - public void setProcessed(String processed) { - this.processed = processed; - } - public String getCreatedBy() { - return createdBy; - } - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - public Timestamp getCreatedDate() { - return createdDate; - } - public void setCreatedDate(Timestamp createdDate) { - this.createdDate = createdDate; - } - public String getModifiedBy() { - return modifiedBy; - } - public void setModifiedBy(String modifiedBy) { - this.modifiedBy = modifiedBy; - } - public Timestamp getLastModDate() { - return lastModDate; - } - public void setLastModDate(Timestamp lastModDate) { - this.lastModDate = lastModDate; - } - public String getTxnId() { - return txnId; - } - public void setTxnId(String txnId) { - this.txnId = txnId; - } - public String getAuthenticationMode() { - return authenticationMode; - } - public void setAuthenticationMode(String authenticationMode) { - this.authenticationMode = authenticationMode; - } - - + String txnId; } diff --git a/src/main/java/com/wipro/fhir/data/v3/abhaCard/VerifyProfileUserLogin.java b/src/main/java/com/wipro/fhir/data/v3/abhaCard/VerifyProfileUserLogin.java new file mode 100644 index 0000000..484ea21 --- /dev/null +++ b/src/main/java/com/wipro/fhir/data/v3/abhaCard/VerifyProfileUserLogin.java @@ -0,0 +1,10 @@ +package com.wipro.fhir.data.v3.abhaCard; + +import lombok.Data; + +@Data +public class VerifyProfileUserLogin { + + private String ABHANumber; + private String txnId; +} 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 0fce983..4ddc4e9 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 @@ -49,7 +49,7 @@ public class CreateAbhaV3ServiceImpl implements CreateAbhaV3Service { @Autowired - private GenerateSession_NDHMService generateSession_NDHM; + private GenerateAuthSessionService generateAuthSessionService; @Autowired private Common_NDHMService common_NDHMService; @Autowired @@ -87,7 +87,7 @@ public String getOtpForEnrollment(String request) throws FHIRException { String publicKeyString = null; try { - String ndhmAuthToken = generateSession_NDHM.getNDHMAuthToken(); + String abhaAuthToken = generateAuthSessionService.getAbhaAuthToken(); MultiValueMap headers = new LinkedMultiValueMap<>(); headers.add("Content-Type", MediaType.APPLICATION_JSON + ";charset=utf-8"); @@ -98,12 +98,12 @@ public String getOtpForEnrollment(String request) throws FHIRException { df.setTimeZone(tz); String nowAsISO = df.format(new Date()); headers.add("TIMESTAMP", nowAsISO); - headers.add("Authorization", ndhmAuthToken); + headers.add("Authorization", abhaAuthToken); RequestOTPEnrollment reqOtpEnrollment = new RequestOTPEnrollment(); LoginMethod loginMethod = InputMapper.gson().fromJson(request, LoginMethod.class); - publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); + publicKeyString = certificateKeyService.getCertPublicKey(abhaAuthToken); if (loginMethod.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginMethod.getLoginId(), publicKeyString); } @@ -156,7 +156,7 @@ public String enrollmentByAadhaar(String request) throws FHIRException { String requestObj = null; try { - String ndhmAuthToken = generateSession_NDHM.getNDHMAuthToken(); + String abhaAuthToken = generateAuthSessionService.getAbhaAuthToken(); MultiValueMap headers = new LinkedMultiValueMap<>(); headers.add("Content-Type", MediaType.APPLICATION_JSON.toString()); headers.add("REQUEST-ID", UUID.randomUUID().toString()); @@ -166,12 +166,12 @@ public String enrollmentByAadhaar(String request) throws FHIRException { df.setTimeZone(tz); String nowAsISO = df.format(new Date()); headers.add("TIMESTAMP", nowAsISO); - headers.add("Authorization", ndhmAuthToken); + headers.add("Authorization", abhaAuthToken); // Create the enrollByAadhar object LoginMethod loginData = InputMapper.gson().fromJson(request, LoginMethod.class); - publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); + publicKeyString = certificateKeyService.getCertPublicKey(abhaAuthToken); if (loginData.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginData.getLoginId(), publicKeyString); } @@ -211,6 +211,9 @@ public String enrollmentByAadhaar(String request) throws FHIRException { constructHealthIdResponse(healthIDResp, abhaProfileAsJsonObj); healthIDResp.setProviderServiceMapID(loginData.getProviderServiceMapId()); healthIDResp.setCreatedBy(loginData.getCreatedBy()); + if(jsonResponse.get("isNew") != null && jsonResponse.get("isNew").getAsString() == "true") { + healthIDResp.setIsNewAbha(true); + } Integer healthIdCount = healthIDRepo.getCountOfHealthIdNumber(healthIDResp.getHealthIdNumber()); HealthIDResponse save = healthIDResp; if (healthIdCount < 1) { @@ -247,7 +250,7 @@ public String verifyAuthByAbdm(String request) throws FHIRException { String publicKeyString = null; try { - String ndhmAuthToken = generateSession_NDHM.getNDHMAuthToken(); + String abhaAuthToken = generateAuthSessionService.getAbhaAuthToken(); MultiValueMap headers = new LinkedMultiValueMap<>(); headers.add("Content-Type", MediaType.APPLICATION_JSON + ";charset=utf-8"); @@ -258,11 +261,11 @@ public String verifyAuthByAbdm(String request) throws FHIRException { df.setTimeZone(tz); String nowAsISO = df.format(new Date()); headers.add("TIMESTAMP", nowAsISO); - headers.add("Authorization", ndhmAuthToken); + headers.add("Authorization", abhaAuthToken); LoginMethod loginMethod = InputMapper.gson().fromJson(request, LoginMethod.class); - publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); + publicKeyString = certificateKeyService.getCertPublicKey(abhaAuthToken); if (loginMethod.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginMethod.getLoginId(), publicKeyString); } @@ -391,7 +394,7 @@ public String getAbhaCardPrinted(String reqObj) throws FHIRException { try { - String ndhmAuthToken = generateSession_NDHM.getNDHMAuthToken(); + String abhaAuthToken = generateAuthSessionService.getAbhaAuthToken(); MultiValueMap headers = new LinkedMultiValueMap<>(); headers.add("Content-Type", MediaType.APPLICATION_JSON + ";charset=utf-8"); @@ -402,7 +405,7 @@ public String getAbhaCardPrinted(String reqObj) throws FHIRException { df.setTimeZone(tz); String nowAsISO = df.format(new Date()); headers.add("TIMESTAMP", nowAsISO); - headers.add("Authorization", ndhmAuthToken); + headers.add("Authorization", abhaAuthToken); JsonObject stringReqObj = JsonParser.parseString(reqObj).getAsJsonObject(); if (stringReqObj.has("xToken") && stringReqObj.get("xToken") != null) { diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/GenerateAuthSessionService.java b/src/main/java/com/wipro/fhir/service/v3/abha/GenerateAuthSessionService.java new file mode 100644 index 0000000..6ff58fc --- /dev/null +++ b/src/main/java/com/wipro/fhir/service/v3/abha/GenerateAuthSessionService.java @@ -0,0 +1,11 @@ +package com.wipro.fhir.service.v3.abha; + +import com.wipro.fhir.utils.exception.FHIRException; + +public interface GenerateAuthSessionService { + + String generateAbhaAuthToken() throws FHIRException; + + String getAbhaAuthToken() throws FHIRException; + +} diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/GenerateAuthSessionServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/abha/GenerateAuthSessionServiceImpl.java new file mode 100644 index 0000000..9074fbd --- /dev/null +++ b/src/main/java/com/wipro/fhir/service/v3/abha/GenerateAuthSessionServiceImpl.java @@ -0,0 +1,124 @@ +package com.wipro.fhir.service.v3.abha; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +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.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.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.wipro.fhir.data.healthID.Authorize; +import com.wipro.fhir.service.ndhm.Common_NDHMService; +import com.wipro.fhir.utils.exception.FHIRException; + +@Service +public class GenerateAuthSessionServiceImpl implements GenerateAuthSessionService { + + Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + + private static String ABHA_AUTH_TOKEN; + private static Long ABHA_TOKEN_EXP; + + @Autowired + private Common_NDHMService common_NDHMService; + + @Value("${clientID}") + private String clientID; + + @Value("${clientSecret}") + private String clientSecret; + + @Value("${x-CM-ID}") + private String xCMId; + + @Value("${abdmV3UserAuthenticate}") + private String abdmV3UserAuthenticate; + + @Override + public String generateAbhaAuthToken() throws FHIRException { + + RestTemplate restTemplate = new RestTemplate(); + Authorize obj = new Authorize(); + String res = null; + + try { + obj.setClientId(clientID); + obj.setClientSecret(clientSecret); + obj.setGrantType("client_credentials"); + String requestOBJ = new Gson().toJson(obj); + + 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("X-CM-ID", xCMId); + + HttpEntity httpEntity = new HttpEntity<>(requestOBJ, headers); + ResponseEntity responseEntity = restTemplate.exchange(abdmV3UserAuthenticate, HttpMethod.POST, + httpEntity, String.class); + + String responseStrLogin=common_NDHMService.getBody(responseEntity); + if (responseStrLogin != null) { + JsonObject jsnOBJ = JsonParser.parseString(responseStrLogin).getAsJsonObject(); + ABHA_AUTH_TOKEN = "Bearer" + " " + jsnOBJ.get("accessToken").getAsString(); + Integer expiry = jsnOBJ.get("expiresIn").getAsInt(); + double time = expiry / 60; + Date date = new Date(); + java.sql.Date sqlDate = new java.sql.Date(date.getTime()); + Calendar ndhmCalendar = Calendar.getInstance(); + ndhmCalendar.setTime(sqlDate); + ndhmCalendar.add(Calendar.MINUTE, (int) time); + Date abhaTokenEndTime = ndhmCalendar.getTime(); + ABHA_TOKEN_EXP = abhaTokenEndTime.getTime(); + res = "success"; + } else + throw new FHIRException("NDHM_FHIR Error while accessing authenticate API"); + } catch (Exception e) { + throw new FHIRException("NDHM_FHIR Error while accessing authenticate API " + e); + } + return res; + } + @Override + public String getAbhaAuthToken() throws FHIRException { + try { + if (ABHA_AUTH_TOKEN == null || ABHA_TOKEN_EXP == null + || ABHA_TOKEN_EXP < System.currentTimeMillis()) { + String authenticateMsg = generateAbhaAuthToken(); + + if (authenticateMsg.equalsIgnoreCase("success")) + logger.info("NDHM_FHIR NDHM V3 authentication success at : " + System.currentTimeMillis()); + else { + logger.error("NDHM_FHIR NDHM V3 user authentication failed at : " + System.currentTimeMillis()); + throw new FHIRException("ABHA user authentication failed."); + } + } + + } catch (Exception e) { + throw new FHIRException(e.getMessage()); + } + return ABHA_AUTH_TOKEN; + } + + +} diff --git a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3Service.java b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3Service.java index 0ad41fc..92bc9d1 100644 --- a/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3Service.java +++ b/src/main/java/com/wipro/fhir/service/v3/abha/LoginAbhaV3Service.java @@ -8,4 +8,8 @@ public interface LoginAbhaV3Service { String verifyAbhaLogin(String request) throws FHIRException; + String verifyProfileLoginUser(String tToken, String txnId, String abhaNumber) throws FHIRException; + + String getWebLoginPhrCard(String reqObj) throws FHIRException; + } 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 90e759b..7e8e9ff 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 @@ -31,39 +31,45 @@ import com.wipro.fhir.data.v3.abhaCard.OtpRequest; import com.wipro.fhir.data.v3.abhaCard.RequestOTPEnrollment; import com.wipro.fhir.data.v3.abhaCard.VerifyAbhaLogin; +import com.wipro.fhir.data.v3.abhaCard.VerifyProfileUserLogin; import com.wipro.fhir.service.ndhm.Common_NDHMService; import com.wipro.fhir.service.ndhm.GenerateSession_NDHMService; import com.wipro.fhir.utils.Encryption; import com.wipro.fhir.utils.exception.FHIRException; -import com.wipro.fhir.utils.http.HttpUtils; import com.wipro.fhir.utils.mapper.InputMapper; @Service public class LoginAbhaV3ServiceImpl implements LoginAbhaV3Service { - + @Autowired - private GenerateSession_NDHMService generateSession_NDHM; + private GenerateAuthSessionService generateAuthSessionService; @Autowired private Common_NDHMService common_NDHMService; @Autowired private Encryption encryption; @Autowired private CertificateKeyService certificateKeyService; - + @Value("${abhaLoginRequestOtp}") String abhaLoginRequestOtp; - + @Value("${webLoginAbhaRequestOtp}") String webLoginAbhaRequestOtp; - + @Value("${webLoginAbhaVerify}") String webLoginAbhaVerify; - + @Value("${verifyAbhaLogin}") String verifyAbhaLoginUrl; + + @Value("${abhaProfileLoginVerifyUser}") + String abhaProfileLoginVerifyUser; + @Value("${webLoginPhrCard}") + String abhawebProfileLoginPhrCard; + private final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); - + @Override public String requestOtpForAbhaLogin(String request) throws FHIRException { String res = null; @@ -74,7 +80,7 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException { ResponseEntity responseEntity; try { - String ndhmAuthToken = generateSession_NDHM.getNDHMAuthToken(); + String abhaAuthToken = generateAuthSessionService.getAbhaAuthToken(); MultiValueMap headers = new LinkedMultiValueMap<>(); headers.add("Content-Type", MediaType.APPLICATION_JSON + ";charset=utf-8"); @@ -85,38 +91,44 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException { df.setTimeZone(tz); String nowAsISO = df.format(new Date()); headers.add("TIMESTAMP", nowAsISO); - headers.add("Authorization", ndhmAuthToken); + headers.add("Authorization", abhaAuthToken); RequestOTPEnrollment reqOtpEnrollment = new RequestOTPEnrollment(); LoginAbhaRequest loginAbhaRequest = InputMapper.gson().fromJson(request, LoginAbhaRequest.class); - publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); + publicKeyString = certificateKeyService.getCertPublicKey(abhaAuthToken); if (loginAbhaRequest.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginAbhaRequest.getLoginId(), publicKeyString); reqOtpEnrollment.setLoginId(encryptedLoginId); } - if ("AADHAAR".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "abha-number".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() )) { + } 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() )) { + } 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() )) { + } 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()) ) { + } else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) + && "mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) { reqOtpEnrollment.setScope(new String[] { "abha-login", "mobile-verify" }); reqOtpEnrollment.setLoginHint("mobile"); reqOtpEnrollment.setOtpSystem("abdm"); - } else if ("aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) ) { + } else if ("aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) + && "aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) { reqOtpEnrollment.setScope(new String[] { "abha-login", "aadhaar-verify" }); reqOtpEnrollment.setLoginHint("aadhaar"); reqOtpEnrollment.setOtpSystem("aadhaar"); @@ -128,12 +140,11 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException { logger.info("ABDM reqobj for request otp for Abha login: " + requestOBJ); HttpEntity httpEntity = new HttpEntity<>(requestOBJ, headers); - if("abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) { - responseEntity = restTemplate.exchange(webLoginAbhaRequestOtp, HttpMethod.POST, - httpEntity, String.class); + 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); + responseEntity = restTemplate.exchange(abhaLoginRequestOtp, HttpMethod.POST, httpEntity, String.class); } logger.info("ABDM response for response otp for Abha login: " + responseEntity); @@ -154,8 +165,7 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException { return res; } - - + @Override public String verifyAbhaLogin(String request) throws FHIRException { Map responseMap = new HashMap<>(); @@ -166,7 +176,7 @@ public String verifyAbhaLogin(String request) throws FHIRException { ResponseEntity responseEntity; try { - String ndhmAuthToken = generateSession_NDHM.getNDHMAuthToken(); + String abhaAuthToken = generateAuthSessionService.getAbhaAuthToken(); MultiValueMap headers = new LinkedMultiValueMap<>(); headers.add("Content-Type", MediaType.APPLICATION_JSON.toString()); headers.add("REQUEST-ID", UUID.randomUUID().toString()); @@ -176,16 +186,16 @@ public String verifyAbhaLogin(String request) throws FHIRException { df.setTimeZone(tz); String nowAsISO = df.format(new Date()); headers.add("TIMESTAMP", nowAsISO); - headers.add("Authorization", ndhmAuthToken); + headers.add("Authorization", abhaAuthToken); // Create the enrollByAadhar object VerifyAbhaLogin verifyAbhaLogin = new VerifyAbhaLogin(); LoginMethod loginData = InputMapper.gson().fromJson(request, LoginMethod.class); - publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken); + publicKeyString = certificateKeyService.getCertPublicKey(abhaAuthToken); if (loginData.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginData.getLoginId(), publicKeyString); } - + OtpRequest otp = new OtpRequest(); otp.setTxnId(loginData.getTxnId()); @@ -198,29 +208,28 @@ public String verifyAbhaLogin(String request) throws FHIRException { verifyAbhaLogin.setAuthData(authDataMap); if ("AADHAAR".equalsIgnoreCase(loginData.getLoginMethod())) { - verifyAbhaLogin.setScope(new String[] {"abha-login", "aadhaar-verify" } ); + verifyAbhaLogin.setScope(new String[] { "abha-login", "aadhaar-verify" }); } else if ("MOBILE".equalsIgnoreCase(loginData.getLoginMethod())) { - verifyAbhaLogin.setScope(new String[] {"abha-login", "mobile-verify" } ); + verifyAbhaLogin.setScope(new String[] { "abha-login", "mobile-verify" }); } else if ("abha-mobile".equalsIgnoreCase(loginData.getLoginMethod())) { - verifyAbhaLogin.setScope(new String[] {"abha-address-login", "mobile-verify" } ); - + 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" } ); + 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); - - if("abha-aadhaar".equalsIgnoreCase(loginData.getLoginMethod()) || "abha-mobile".equalsIgnoreCase(loginData.getLoginMethod())) { - responseEntity = restTemplate.exchange(webLoginAbhaVerify, HttpMethod.POST, - httpEntity, String.class); + + 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); + responseEntity = restTemplate.exchange(verifyAbhaLoginUrl, HttpMethod.POST, httpEntity, String.class); } String responseStrLogin = common_NDHMService.getBody(responseEntity); @@ -233,14 +242,21 @@ public String verifyAbhaLogin(String request) throws FHIRException { if (authResult != null && (authResult.equalsIgnoreCase("success"))) { if (jsonResponse.has("accounts")) { - responseMap.put("abhaDetails", jsonResponse.get("accounts").getAsJsonArray().get(0).getAsJsonObject().toString()); + String abhaNumber = jsonResponse.get("accounts").getAsJsonArray().get(0).getAsJsonObject() + .get("ABHANumber").getAsString(); + responseMap.put("abhaDetails", + jsonResponse.get("accounts").getAsJsonArray().get(0).getAsJsonObject().toString()); responseMap.put("txnId", jsonResponse.get("txnId").getAsString()); - if (jsonResponse.has("token")) { + if ("MOBILE".equalsIgnoreCase(loginData.getLoginMethod()) && jsonResponse.has("token")) { + String xtoken = verifyProfileLoginUser(jsonResponse.get("token").getAsString(), + jsonResponse.get("txnId").getAsString(), abhaNumber); + responseMap.put("xToken", xtoken); + } else 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()); + } else if (jsonResponse.has("users")) { + responseMap.put("abhaDetails", + jsonResponse.get("users").getAsJsonArray().get(0).getAsJsonObject().toString()); if (jsonResponse.has("tokens") && jsonResponse.get("tokens").isJsonObject()) { JsonObject tokensObject = jsonResponse.get("tokens").getAsJsonObject(); if (tokensObject.has("token") && !tokensObject.get("token").isJsonNull()) { @@ -250,7 +266,7 @@ public String verifyAbhaLogin(String request) throws FHIRException { } } } else { - String message = jsonResponse.get("message").getAsString(); + String message = jsonResponse.get("message").getAsString(); throw new FHIRException(message); } } else { @@ -263,5 +279,98 @@ public String verifyAbhaLogin(String request) throws FHIRException { return responseMap.toString(); } + @Override + public String verifyProfileLoginUser(String tToken, String txnId, String abhaNumber) throws FHIRException { + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity responseEntity; + String token = null; + + try { + String abhaAuthToken = generateAuthSessionService.getAbhaAuthToken(); + MultiValueMap headers = new LinkedMultiValueMap<>(); + headers.add("Content-Type", MediaType.APPLICATION_JSON.toString()); + 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", abhaAuthToken); + headers.add("T-token", "Bearer " + tToken); + + VerifyProfileUserLogin verifyUser = new VerifyProfileUserLogin(); + verifyUser.setABHANumber(abhaNumber); + verifyUser.setTxnId(txnId); + + String requestObj = new Gson().toJson(verifyUser); + logger.info("ABDM request for verify profile user login: " + requestObj); + HttpEntity httpEntity = new HttpEntity<>(requestObj, headers); + + responseEntity = restTemplate.exchange(abhaProfileLoginVerifyUser, HttpMethod.POST, httpEntity, + String.class); + + logger.info("ABDM response for response otp for Abha login: " + responseEntity); + String responseStrLogin = common_NDHMService.getBody(responseEntity); + if (responseEntity.getStatusCode() == HttpStatusCode.valueOf(200) && responseEntity.hasBody()) { + JsonObject jsnOBJ = JsonParser.parseString(responseStrLogin).getAsJsonObject(); + token = jsnOBJ.get("token").getAsString(); + } + } catch (Exception e) { + throw new FHIRException(e.getMessage()); + } + + return token; + } + + + @Override + public String getWebLoginPhrCard(String reqObj) throws FHIRException { + + String res = null; + Map responseMap = new HashMap<>(); + RestTemplate restTemplate = new RestTemplate(); + + + try { + String abhaAuthToken = generateAuthSessionService.getAbhaAuthToken(); + + 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", abhaAuthToken); + + JsonObject stringReqObj = JsonParser.parseString(reqObj).getAsJsonObject(); + if (stringReqObj.has("xToken") && stringReqObj.get("xToken") != null) { + String xToken = stringReqObj.get("xToken").getAsString(); + headers.add("X-token", "Bearer " + xToken); + } + HttpEntity httpEntity = new HttpEntity<>(headers); + ResponseEntity responseEntity = restTemplate.exchange(abhawebProfileLoginPhrCard, HttpMethod.GET, httpEntity, + String.class); + + logger.info("ABDM response for print Abha card:" + responseEntity); + String responseStrLogin = common_NDHMService.getBody(responseEntity); + if (responseEntity.getStatusCode() == HttpStatusCode.valueOf(202)) { + responseMap.put("png", responseStrLogin); + res = new Gson().toJson(responseMap); + } else { + throw new FHIRException(responseEntity.getBody()); + } + + } catch (Exception e) { + throw new FHIRException(e.getMessage()); + } + return res; + + } + } From cc1b2527bdd3f04d06f6a60942c032ce7e9d583e Mon Sep 17 00:00:00 2001 From: KA40094929 Date: Tue, 25 Feb 2025 10:40:36 +0530 Subject: [PATCH 10/10] committed coderabitai suggested --- src/main/environment/common_dev.properties | 1 - .../wipro/fhir/service/v3/abha/LoginAbhaV3ServiceImpl.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties index db18ad9..3e012e9 100644 --- a/src/main/environment/common_dev.properties +++ b/src/main/environment/common_dev.properties @@ -96,7 +96,6 @@ abhaProfileLoginVerifyUser = https://abhasbx.abdm.gov.in/abha/api/v3/profile/log 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 -webLoginAbhaVerify = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/abha/verify webLoginPhrCard = https://abhasbx.abdm.gov.in/abha/api/v3/phr/web/login/profile/abha/phr-card x-CM-ID= 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 7e8e9ff..7c15d3a 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 @@ -123,12 +123,12 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException { reqOtpEnrollment.setLoginHint(loginAbhaRequest.getLoginHint()); reqOtpEnrollment.setOtpSystem("abdm"); } else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) - && "mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) { + && "mobile".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) { reqOtpEnrollment.setScope(new String[] { "abha-login", "mobile-verify" }); reqOtpEnrollment.setLoginHint("mobile"); reqOtpEnrollment.setOtpSystem("abdm"); } else if ("aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) - && "aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) { + && "aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) { reqOtpEnrollment.setScope(new String[] { "abha-login", "aadhaar-verify" }); reqOtpEnrollment.setLoginHint("aadhaar"); reqOtpEnrollment.setOtpSystem("aadhaar");