Skip to content
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3814860
Abdm Facility fetch services changes
Sep 19, 2024
a2224b4
facility save after carecontext and patientcarecontextx update
Sep 26, 2024
1a28c2b
FacilityId save in mongo db and Variable declaration correction
Oct 8, 2024
fea418b
Mongo carecontext save query logic changes
Oct 8, 2024
9d30d46
ABHA Creation M1 V3 API changes
Oct 18, 2024
583594a
Abha V3 changes
Dec 9, 2024
8d206ef
resolved merge conflicts
Dec 9, 2024
4c76193
removed unused code
helenKaryamsetty Dec 9, 2024
c07d839
v3- verify auth by abdm API changes
Dec 12, 2024
d26eeda
Merge branch 'PSMRI:develop' into abdmV3
helenKaryamsetty Dec 12, 2024
5e93901
resolved merge conflicts
Dec 12, 2024
e669df1
fix pulled latest develop
helenKaryamsetty Oct 6, 2025
7a5c0d4
feat: Abdm M2 V3 changes
helenKaryamsetty Oct 6, 2025
43683a2
feat: mongo query change fetch for linktoken
helenKaryamsetty Oct 13, 2025
8ead599
Merge branch 'abdmV3' into abdmV3
helenKaryamsetty Oct 13, 2025
c1c5d38
fix: link carecontext authorization error
helenKaryamsetty Oct 14, 2025
497b3ff
Merge branch 'PSMRI:abdmV3' into abdmV3
helenKaryamsetty Oct 14, 2025
d748156
Merge branch 'abdmV3' of https://github.com/helenKaryamsetty/FHIR-API…
helenKaryamsetty Oct 14, 2025
811aef7
Merge branch 'PSMRI:abdmV3' into abdmV3
helenKaryamsetty Oct 31, 2025
945d874
feat: hiTypes addition
helenKaryamsetty Oct 31, 2025
c1c96f4
feat: version change for testing
helenKaryamsetty Oct 31, 2025
d267c17
fix: minor change for empty response
helenKaryamsetty Nov 4, 2025
49c97fa
fix: resolved merge conflicts
helenKaryamsetty Nov 4, 2025
6d5298f
Simplify queries in CareContextRepo interface
helenKaryamsetty Nov 4, 2025
23b4a20
fix: corrected response format
helenKaryamsetty Nov 6, 2025
db670fc
Merge branch 'abdmV3' of https://github.com/helenKaryamsetty/FHIR-API…
helenKaryamsetty Nov 6, 2025
5d6dd44
fix: minor logic change for care context linking
helenKaryamsetty Nov 19, 2025
1d9835a
Merge branch 'abdmV3' of https://github.com/helenKaryamsetty/FHIR-API…
helenKaryamsetty Nov 19, 2025
765d260
small correction in hiType and error message modification
helenKaryamsetty Dec 15, 2025
71c995d
Merge branch 'abdmV3' of https://github.com/helenKaryamsetty/FHIR-API…
helenKaryamsetty Dec 15, 2025
513a135
Fix display setting for patient care context
helenKaryamsetty Dec 15, 2025
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 @@ -189,7 +189,8 @@ public String generateTokenForCareContext(String request) throws FHIRException {
}

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

Expand All @@ -212,26 +213,26 @@ public String generateTokenForCareContext(String request) throws FHIRException {
JsonObject jsonObject = jsonElement.getAsJsonObject();

try {
JsonElement linkTokenElement = jsonObject.get("LinkToken");
if (linkTokenElement != null && !linkTokenElement.isJsonNull()) {
JsonElement linkTokenElement = jsonObject.get("LinkToken");
if (linkTokenElement != null && !linkTokenElement.isJsonNull()) {
linkToken = linkTokenElement.getAsString();
headers.add("X-LINK-TOKEN", linkToken);
} else {
if (jsonObject.has("Error") && !jsonObject.get("Error").isJsonNull()) {
JsonObject errorObject = jsonObject.getAsJsonObject("Error");
responseMap.put("error", errorObject.toString());
} else {
responseMap.put("error", "Unknown error");
}
}
} else {
if (jsonObject.has("Error") && !jsonObject.get("Error").isJsonNull()) {
JsonObject errorObject = jsonObject.getAsJsonObject("Error");
responseMap.put("error", errorObject.toString());
} else {
responseMap.put("error", "Unknown error");
}
}
} catch (Exception e) {
throw new FHIRException("ABDM_FHIR Error while parsing response: " + e.getMessage());
}
}

}
if (linkToken != null) {

if (linkToken != null) {

headers.add("Content-Type", MediaType.APPLICATION_JSON + ";charset=utf-8");
headers.add("REQUEST-ID", UUID.randomUUID().toString());
Expand All @@ -249,9 +250,10 @@ public String generateTokenForCareContext(String request) throws FHIRException {
} else {
headers.add("X-HIP-ID", abdmFacilityId);
}

String[] hiTypes = findHiTypes(addCareContextRequest.getVisitCode(), addCareContextRequest.getVisitCategory());


String[] hiTypes = findHiTypes(addCareContextRequest.getVisitCode(),
addCareContextRequest.getVisitCategory());

LinkCareContextRequest linkCareContextRequest = new LinkCareContextRequest();
CareContexts careContexts = new CareContexts();
ArrayList<PatientCareContext> pcc = new ArrayList<PatientCareContext>();
Expand All @@ -265,13 +267,13 @@ public String generateTokenForCareContext(String request) throws FHIRException {
cc.add(careContexts);

patient.setReferenceNumber(addCareContextRequest.getVisitCode());
patient.setDisplay(addCareContextRequest.getVisitCategory() + " care context of " + addCareContextRequest.getAbhaNumber());
patient.setDisplay(addCareContextRequest.getVisitCategory() + " - " + hiType + " care context of "
+ addCareContextRequest.getAbhaNumber());
patient.setCount(1);
patient.setCareContexts(cc);
patient.setHiType(hiType);
pcc.add(patient);
}


if (null != addCareContextRequest.getAbhaNumber() && "" != addCareContextRequest.getAbhaNumber()) {
String abha = addCareContextRequest.getAbhaNumber();
Expand All @@ -283,7 +285,7 @@ public String generateTokenForCareContext(String request) throws FHIRException {
linkCareContextRequest.setPatient(pcc);

String requestOBJ = new Gson().toJson(linkCareContextRequest);
logger.info("ABDM reqobj for generate token link for carecontext : " + requestOBJ);
logger.info("ABDM reqobj for link for carecontext : " + requestOBJ);

HttpEntity<String> httpEntity = new HttpEntity<>(requestOBJ, headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(linkCareContext, HttpMethod.POST,
Expand All @@ -296,16 +298,40 @@ public String generateTokenForCareContext(String request) throws FHIRException {

} else {
JsonObject json = JsonParser.parseString(responseEntity.getBody()).getAsJsonObject();
if (json.has("error")) {
JsonObject errorObj = json.getAsJsonObject("error");
String message = errorObj.has("message") ? errorObj.get("message").getAsString() : "Unknown error";
responseMap.put("error", message);
} else {
responseMap.put("error", "Unknown error");
}
if (json.has("error")) {
JsonObject errorObj = json.getAsJsonObject("error");
String message = errorObj.has("message") ? errorObj.get("message").getAsString()
: "Unknown error";
responseMap.put("error", message);
} else {
responseMap.put("error", "Unknown error");
}
}
}
} catch (Exception e) {
String msg = e.getMessage();
String jsonString = null;
int start = msg.indexOf("{");
int end = msg.lastIndexOf("}");

if (start != -1 && end != -1) {
jsonString = msg.substring(start, end + 1);
}

if (jsonString != null) {
try {
JsonObject json = JsonParser.parseString(jsonString).getAsJsonObject();
if (json.has("error")) {
JsonObject errorObj = json.getAsJsonObject("error");
String message = errorObj.has("message") ? errorObj.get("message").getAsString()
: "Unknown error";
throw new FHIRException(message);
}
} catch (Exception ex) {
throw new FHIRException("Error parsing API error response");
}
}

throw new FHIRException(e.getMessage());
}

Expand Down Expand Up @@ -364,7 +390,7 @@ public String[] findHiTypes(String visitCode, String visitCategory) {

int hasLabTests = careContextRepo.hasLabtestsDone(visitCode);
if (hasLabTests > 0) {
hiTypes.add("DiagnoticsReport");
hiTypes.add("DiagnoticReport");
}

int hasVaccineDetails = careContextRepo.hasVaccineDetails(visitCode);
Expand Down
Loading