diff --git a/src/main/environment/common_ci.properties b/src/main/environment/common_ci.properties index ee2462d..f3137e0 100644 --- a/src/main/environment/common_ci.properties +++ b/src/main/environment/common_ci.properties @@ -85,17 +85,21 @@ 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 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 1005361..6210f9e 100644 --- a/src/main/environment/common_dev.properties +++ b/src/main/environment/common_dev.properties @@ -85,16 +85,20 @@ 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 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 +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 1d24970..0679bed 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -88,14 +88,19 @@ 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 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 1005361..44e1523 100644 --- a/src/main/environment/common_test.properties +++ b/src/main/environment/common_test.properties @@ -85,16 +85,21 @@ 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 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/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..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(); + 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,13 +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 - EnrollByAadhaar enrollByAadhar = new EnrollByAadhaar(); LoginMethod loginData = InputMapper.gson().fromJson(request, LoginMethod.class); - publicKeyString = certificateKeyService.getCertPublicKey(); + publicKeyString = certificateKeyService.getCertPublicKey(abhaAuthToken); if (loginData.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginData.getLoginId(), publicKeyString); } @@ -212,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) { @@ -248,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"); @@ -259,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(); + publicKeyString = certificateKeyService.getCertPublicKey(abhaAuthToken); if (loginMethod.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginMethod.getLoginId(), publicKeyString); } @@ -392,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"); @@ -403,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 0d70ae7..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 @@ -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(); + 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.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()) ) { + } else if ("aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) + && "aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) { 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,17 +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(); + publicKeyString = certificateKeyService.getCertPublicKey(abhaAuthToken); if (loginData.getLoginId() != null) { encryptedLoginId = encryption.encrypt(loginData.getLoginId(), publicKeyString); } - + OtpRequest otp = new OtpRequest(); otp.setTxnId(loginData.getTxnId()); @@ -199,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); @@ -234,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()) { @@ -251,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 { @@ -264,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; + + } + }