From 7e2d47d50c8e3abfb0f6845ad7de83f2ab044f42 Mon Sep 17 00:00:00 2001 From: indraniBan Date: Tue, 13 Aug 2024 12:27:39 +0530 Subject: [PATCH] Biometric changes --- src/main/environment/common_ci.properties | 2 + src/main/environment/common_dev.properties | 8 ++-- .../environment/common_example.properties | 8 ++-- src/main/environment/common_test.properties | 8 ++-- .../fhir/data/healthID/VerifyBiometric.java | 33 +++++++++++++++ .../fhir/service/ndhm/Common_NDHMService.java | 1 + .../service/ndhm/Common_NDHMServiceImpl.java | 11 +++++ ...reateHealthID_Aadhaar_NDHMServiceImpl.java | 15 +++++-- .../ndhm/GenerateHealthID_CardService.java | 2 + .../GenerateHealthID_CardServiceImpl.java | 42 +++++++++++++++++++ .../com/wipro/fhir/utils/http/HttpUtils.java | 8 ++++ src/main/resources/application.properties | 4 +- 12 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/wipro/fhir/data/healthID/VerifyBiometric.java diff --git a/src/main/environment/common_ci.properties b/src/main/environment/common_ci.properties index f7b626f..c21241d 100644 --- a/src/main/environment/common_ci.properties +++ b/src/main/environment/common_ci.properties @@ -66,6 +66,7 @@ verifyOTP_ForCard=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/auth/confirmWithMobileOTP verifyOTP_ForCard_Aadhaar=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/auth/confirmWithAadhaarOtp ## print ABHA card - PNG generateHealthCard=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/health/facility/getPngCard +generateHealthIDCard=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/account/getPngCard ## Generate Notify SMS once episode completed generateABDM_NotifySMS=@env.ABDM_BASE_URL@/gateway/v1/patients/sms/notify2 @@ -74,6 +75,7 @@ generateABDM_NotifySMS=@env.ABDM_BASE_URL@/gateway/v1/patients/sms/notify2 abdmVerifyBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/verifyBio abdmGenerateMobileOTP=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/generateMobileOTP abdmConfirmAadhaarBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/auth/confirmWithAadhaarBio +abdmAccountProfile=@env.ABDM_Account_ID_BASE_URL@/api/v1/account/profile abhaMode=sbx diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties index 3ef0550..6eeea6c 100644 --- a/src/main/environment/common_dev.properties +++ b/src/main/environment/common_dev.properties @@ -66,14 +66,16 @@ verifyOTP_ForCard=https://healthidsbx.abdm.gov.in/api/v1/auth/confirmWithMobileO verifyOTP_ForCard_Aadhaar=https://healthidsbx.abdm.gov.in/api/v1/auth/confirmWithAadhaarOtp ## print ABHA card - PNG generateHealthCard=https://healthidsbx.abdm.gov.in/api/v1/health/facility/getPngCard +generateHealthIDCard=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/account/getPngCard ## Generate Notify SMS once episode completed generateABDM_NotifySMS=https://dev.abdm.gov.in/gateway/v1/patients/sms/notify2 ##verifyBio -abdmVerifyBio=https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/verifyBio -abdmGenerateMobileOTP=https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/generateMobileOTP -abdmConfirmAadhaarBio=https://healthidsbx.abdm.gov.in/api/v1/auth/confirmWithAadhaarBio +abdmVerifyBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/verifyBio +abdmGenerateMobileOTP=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/generateMobileOTP +abdmConfirmAadhaarBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/auth/confirmWithAadhaarBio +abdmAccountProfile=@env.ABDM_Account_ID_BASE_URL@/api/v1/account/profile abhaMode=sbx diff --git a/src/main/environment/common_example.properties b/src/main/environment/common_example.properties index 57288db..eb1f02c 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -66,14 +66,16 @@ verifyOTP_ForCard=https://healthidsbx.abdm.gov.in/api/v1/auth/confirmWithMobileO verifyOTP_ForCard_Aadhaar=https://healthidsbx.abdm.gov.in/api/v1/auth/confirmWithAadhaarOtp ## print ABHA card - PNG generateHealthCard=https://healthidsbx.abdm.gov.in/api/v1/health/facility/getPngCard +generateHealthIDCard=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/account/getPngCard ## Generate Notify SMS once episode completed generateABDM_NotifySMS=https://dev.abdm.gov.in/gateway/v1/patients/sms/notify2 ##verifyBio -abdmVerifyBio=https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/verifyBio -abdmGenerateMobileOTP=https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/generateMobileOTP -abdmConfirmAadhaarBio=https://healthidsbx.abdm.gov.in/api/v1/auth/confirmWithAadhaarBio +abdmVerifyBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/verifyBio +abdmGenerateMobileOTP=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/generateMobileOTP +abdmConfirmAadhaarBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/auth/confirmWithAadhaarBio +abdmAccountProfile=@env.ABDM_Account_ID_BASE_URL@/api/v1/account/profile abhaMode=sbx diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties index 3ef0550..6eeea6c 100644 --- a/src/main/environment/common_test.properties +++ b/src/main/environment/common_test.properties @@ -66,14 +66,16 @@ verifyOTP_ForCard=https://healthidsbx.abdm.gov.in/api/v1/auth/confirmWithMobileO verifyOTP_ForCard_Aadhaar=https://healthidsbx.abdm.gov.in/api/v1/auth/confirmWithAadhaarOtp ## print ABHA card - PNG generateHealthCard=https://healthidsbx.abdm.gov.in/api/v1/health/facility/getPngCard +generateHealthIDCard=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/account/getPngCard ## Generate Notify SMS once episode completed generateABDM_NotifySMS=https://dev.abdm.gov.in/gateway/v1/patients/sms/notify2 ##verifyBio -abdmVerifyBio=https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/verifyBio -abdmGenerateMobileOTP=https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/generateMobileOTP -abdmConfirmAadhaarBio=https://healthidsbx.abdm.gov.in/api/v1/auth/confirmWithAadhaarBio +abdmVerifyBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/verifyBio +abdmGenerateMobileOTP=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/generateMobileOTP +abdmConfirmAadhaarBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/auth/confirmWithAadhaarBio +abdmAccountProfile=@env.ABDM_Account_ID_BASE_URL@/api/v1/account/profile abhaMode=sbx diff --git a/src/main/java/com/wipro/fhir/data/healthID/VerifyBiometric.java b/src/main/java/com/wipro/fhir/data/healthID/VerifyBiometric.java new file mode 100644 index 0000000..d8229cc --- /dev/null +++ b/src/main/java/com/wipro/fhir/data/healthID/VerifyBiometric.java @@ -0,0 +1,33 @@ +package com.wipro.fhir.data.healthID; + +public class VerifyBiometric { + + String aadhaar; + String pid; + String bioType; + + public String getAadhaar() { + return this.aadhaar; + } + + public void setAadhaar(String aadhaar) { + this.aadhaar = aadhaar; + } + + public String getPid() { + return this.pid; + } + + public void setPid(String pid) { + this.pid = pid; + } + + public String getBioType() { + return this.bioType; + } + + public void setBioType(String bioType) { + this.bioType = bioType; + } + +} diff --git a/src/main/java/com/wipro/fhir/service/ndhm/Common_NDHMService.java b/src/main/java/com/wipro/fhir/service/ndhm/Common_NDHMService.java index 5cd2113..a20245a 100644 --- a/src/main/java/com/wipro/fhir/service/ndhm/Common_NDHMService.java +++ b/src/main/java/com/wipro/fhir/service/ndhm/Common_NDHMService.java @@ -35,4 +35,5 @@ public interface Common_NDHMService { public String getBody(ResponseEntity res) throws FHIRException; public String getStatusCode(ResponseEntity res) throws FHIRException; public HttpHeaders getHeadersWithXtoken(String ndhmAuthToken,String X_Token); + public HttpHeaders getHeadersWithAadhaarBioXtoken(String ndhmAuthToken, String X_Token); } diff --git a/src/main/java/com/wipro/fhir/service/ndhm/Common_NDHMServiceImpl.java b/src/main/java/com/wipro/fhir/service/ndhm/Common_NDHMServiceImpl.java index b385627..752e9d6 100644 --- a/src/main/java/com/wipro/fhir/service/ndhm/Common_NDHMServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/ndhm/Common_NDHMServiceImpl.java @@ -165,4 +165,15 @@ public String getStatusCode(ResponseEntity res) throws FHIRException { else throw new FHIRException("NDHM_FHIR Null response returned from API"); } + + @Override + public HttpHeaders getHeadersWithAadhaarBioXtoken(String ndhmAuthToken, String X_Token) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + if (ndhmAuthToken != null) + headers.set("Authorization", ndhmAuthToken); + headers.set("X-Token", "Bearer " + X_Token); + return headers; + } + } 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 eaa14bb..5a43aa2 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 @@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; +import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -93,6 +94,9 @@ public class CreateHealthID_Aadhaar_NDHMServiceImpl implements CreateHealthID_Aa private Common_NDHMService common_NDHMService; @Autowired private GenerateSession_NDHMService generateSession_NDHM; + + @Autowired + private GenerateHealthID_CardService generateHealthID_CardService; @Override public String generateOTP(String request) throws FHIRException { @@ -386,8 +390,9 @@ public String confirmWithAadhaarBio(String request) throws FHIRException { String requestOBJ = new Gson().toJson(obj); logger.info("NDHM_FHIR-confirm Aadhaar bio API request Obj " + requestOBJ); HttpHeaders headers = common_NDHMService.getHeaders(ndhmAuthToken); + HttpEntity httpEntity = new HttpEntity<>(requestOBJ, headers); ResponseEntity responseEntity = httpUtils.postWithResponseEntity(abdmConfirmAadhaarBio, - requestOBJ, headers); + httpEntity, String.class); String responseStrLogin = common_NDHMService.getBody(responseEntity); if (responseStrLogin != null) { JsonObject jsnOBJ = new JsonObject(); @@ -396,10 +401,12 @@ public String confirmWithAadhaarBio(String request) throws FHIRException { jsnOBJ = jsnElmnt.getAsJsonObject(); String X_Token = jsnOBJ.get("x-token").getAsString(); //responseMap.put("aadhaar", obj.getAadhaar()); - responseMap.put("x-token", X_Token); - res = new Gson().toJson(responseMap); - } else + if (null != X_Token) + res = this.generateHealthID_CardService.generateHealthCardForBio(requestOBJ, X_Token); + } else { res = "NDHM_FHIR Error while confirm Aadhaar bio";// throw w + } + } /** * @author SH20094090 diff --git a/src/main/java/com/wipro/fhir/service/ndhm/GenerateHealthID_CardService.java b/src/main/java/com/wipro/fhir/service/ndhm/GenerateHealthID_CardService.java index a6a095e..f580597 100644 --- a/src/main/java/com/wipro/fhir/service/ndhm/GenerateHealthID_CardService.java +++ b/src/main/java/com/wipro/fhir/service/ndhm/GenerateHealthID_CardService.java @@ -30,4 +30,6 @@ public interface GenerateHealthID_CardService { public String validateOTP(String request) throws FHIRException; public String generateCard(String requestOBJ, String NDHM_Auth_TOKEN) throws FHIRException; + + public String generateHealthCardForBio(String requestOBJ, String x_Token) throws FHIRException; } diff --git a/src/main/java/com/wipro/fhir/service/ndhm/GenerateHealthID_CardServiceImpl.java b/src/main/java/com/wipro/fhir/service/ndhm/GenerateHealthID_CardServiceImpl.java index 2eab6cd..61780c7 100644 --- a/src/main/java/com/wipro/fhir/service/ndhm/GenerateHealthID_CardServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/ndhm/GenerateHealthID_CardServiceImpl.java @@ -61,6 +61,8 @@ public class GenerateHealthID_CardServiceImpl implements GenerateHealthID_CardSe private String verifyOTP_ForCard_Aadhaar; @Value("${generateHealthCard}") private String generateHealthCard; + @Value("${generateHealthIDCard}") + private String generateHealthIDCard; Logger logger = LoggerFactory.getLogger(this.getClass().getName()); @Autowired HttpUtils httpUtils; @@ -260,5 +262,45 @@ public String generateCard(String req, String NDHM_X_TOKEN) throws FHIRException throw new FHIRException("NDHM_FHIR Error while accessing ABHA card API "); } + + @Override + public String generateHealthCardForBio(String req, String NDHM_X_TOKEN) throws FHIRException { + String res = null; + try { + String ndhmAuthToken = this.generateSession_NDHM.getNDHMAuthToken(); + HttpHeaders headers = this.common_NDHMService.getHeadersWithAadhaarBioXtoken(ndhmAuthToken, NDHM_X_TOKEN); + ResponseEntity responseEntity = this.httpUtils.getWithResponseEntityByte(generateHealthIDCard, headers); + byte[] ar = responseEntity.getBody(); + if (ar != null) { + res = Base64.getEncoder().encodeToString(ar); + } else { + throw new FHIRException("NDHM_FHIR Error while accessing generate card API"); + } + } catch (HttpClientErrorException e) { + String message = null; + if (e.getResponseBodyAsString() != null) { + HealthIDException exception = (HealthIDException)InputMapper.gson().fromJson(e.getResponseBodyAsString(), HealthIDException.class); + if (exception.getDetails() != null && (exception.getDetails()).length > 0) { + Details[] details = exception.getDetails(); + if (details[0] != null && details[0].getAttribute() != null && details[0] + .getAttribute().getKey() != null) { + message = details[0].getMessage() + " :" + details[0].getAttribute().getKey(); + } else if (details[0] != null) { + message = details[0].getMessage(); + } + } else if (exception.getMessage() != null) { + message = exception.getMessage(); + } + } + if (message != null) + throw new FHIRException("NDHM_FHIR Error while generating ABHA card : " + message); + throw new FHIRException("NDHM_FHIR Error while generating ABHA card : " + e.getMessage()); + } catch (Exception e) { + throw new FHIRException("NDHM_FHIR Error while accessing ABHA card API " + e); + } + if (res != null) + return res; + throw new FHIRException("NDHM_FHIR Error while accessing ABHA card API "); + } } diff --git a/src/main/java/com/wipro/fhir/utils/http/HttpUtils.java b/src/main/java/com/wipro/fhir/utils/http/HttpUtils.java index 9657ae1..194f52d 100644 --- a/src/main/java/com/wipro/fhir/utils/http/HttpUtils.java +++ b/src/main/java/com/wipro/fhir/utils/http/HttpUtils.java @@ -181,4 +181,12 @@ public HttpStatus getStatus() { public void setStatus(HttpStatus status) { this.status = status; } + + public ResponseEntity postWithResponseEntity(String abdmConfirmAadhaarBio, HttpEntity httpEntity, Class class1) { + ResponseEntity responseEntity = new ResponseEntity<>(HttpStatus.BAD_REQUEST); + responseEntity = this.rest.exchange(abdmConfirmAadhaarBio, HttpMethod.POST, httpEntity, String.class, new Object[0]); + setStatus((HttpStatus) responseEntity.getStatusCode()); + String body = responseEntity.getBody(); + return responseEntity; + } } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ac88729..625a42d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ spring.datasource.tomcat.initial-size=5 spring.datasource.tomcat.max-active=30 -spring.datasource.tomcat.max-idle=15 -spring.datasource.tomcat.min-idle=5 +spring.datasource.tomcat.max-idle=5 +spring.datasource.tomcat.min-idle=2 spring.datasource.tomcat.min-evictable-idle-time-millis=15000 spring.datasource.tomcat.remove-abandoned=true spring.datasource.tomcat.remove-abandoned-timeout=1800