Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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.http.HttpHeaders;
import org.springframework.http.MediaType;
Expand All @@ -48,6 +50,8 @@ public class Common_NDHMServiceImpl implements Common_NDHMService {
@Autowired
private GenerateTokenAbdmResponsesRepo generateTokenAbdmResponsesRepo;

private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

/***
* @author SH20094090
* @return headers for the NDHM API's
Expand Down Expand Up @@ -158,6 +162,7 @@ NDHMResponse getResponseMongo(String reqID) {
@Override
public GenerateTokenAbdmResponses getLinkToken(String requestId) throws FHIRException {
GenerateTokenAbdmResponses res = generateTokenAbdmResponsesRepo.findByRequestId(requestId);
logger.info("Mongo response returned " + res);
if(res != null) {
return res;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ public String generateTokenForCareContext(String request) throws FHIRException {
if (linkTokenElement != null && !linkTokenElement.isJsonNull()) {
linkToken = linkTokenElement.getAsString();
responseMap.put("X-LINK-TOKEN", linkToken);
logger.info("Mongo has link token");
} else {
if (jsonObject.has("Error") && !jsonObject.get("Error").isJsonNull()) {
JsonObject errorObject = jsonObject.getAsJsonObject("Error");
responseMap.put("Error", errorObject.toString());
logger.info("Mongo has no link token other message - " + errorObject.toString());
responseMap.put("error", errorObject.toString());
} else {
responseMap.put("Error", "Unknown error");
responseMap.put("error", "Unknown error");
}
}
} catch (Exception e) {
Expand All @@ -179,9 +181,7 @@ public String generateTokenForCareContext(String request) throws FHIRException {
}

@Override
public String linkCareContext(String request) throws FHIRException {
String res = null;
String linkToken = null;
public String linkCareContext(String request) throws FHIRException { String linkToken = null;
Map<String, String> responseMap = new HashMap<>();
RestTemplate restTemplate = new RestTemplate();

Expand Down Expand Up @@ -210,9 +210,9 @@ public String linkCareContext(String request) throws FHIRException {
} else {
if (jsonObject.has("Error") && !jsonObject.get("Error").isJsonNull()) {
JsonObject errorObject = jsonObject.getAsJsonObject("Error");
responseMap.put("Error", errorObject.toString());
responseMap.put("error", errorObject.toString());
} else {
responseMap.put("Error", "Unknown error");
responseMap.put("error", "Unknown error");
}
}
} catch (Exception e) {
Expand All @@ -222,7 +222,7 @@ public String linkCareContext(String request) throws FHIRException {

}

if (linkToken != null) {
if (linkToken != null) {

headers.add("Content-Type", MediaType.APPLICATION_JSON + ";charset=utf-8");
headers.add("REQUEST-ID", UUID.randomUUID().toString());
Expand Down Expand Up @@ -277,7 +277,7 @@ public String linkCareContext(String request) throws FHIRException {
logger.info("ABDM response for generate token link for carecontext : " + responseEntity);
String responseStrLogin = common_NDHMService.getBody(responseEntity);
if (responseEntity.getStatusCode() == HttpStatusCode.valueOf(202)) {
res = "Care Context added successfully";
responseMap.put("message", "Care Context added successfully");

} else {
throw new FHIRException(responseEntity.getBody());
Expand All @@ -287,7 +287,7 @@ public String linkCareContext(String request) throws FHIRException {
throw new FHIRException(e.getMessage());
}

return res;
return responseMap.toString();
}

public String checkRecordExisits(String abhaAddress) {
Expand Down
Loading