Skip to content

Commit

Permalink
API Changes for FLW created ABHA IDs data sync (#63)
Browse files Browse the repository at this point in the history
* Modified tnxId keyword to txnId

* Abha-address search API changes

* added validation for multiple phraddress

* Abha-address search response changes

* Save facility id variable change chnages

* Added check to avoid multiple save of single care-context

* removed unused variables

* Updated public key certificate API

* Integrated Abha session v3 APIs and Profile login user verify APIs

* committed coderabitai suggested

* Revert "jwt implementation changes (#53)"

This reverts commit 5e16b7d.

* data Sync for FLW API changes

* Reapply "jwt implementation changes (#53)"

This reverts commit c38d099.

* changed variable type default value as false

---------

Co-authored-by: KA40094929 <KA40094929@APL-5CD1394ZJT>
Co-authored-by: Karyamsetty Helen Grace <[email protected]>
Co-authored-by: KA40094929 <[email protected]>
Co-authored-by: KA40094929 <[email protected]>
  • Loading branch information
5 people authored Feb 27, 2025
1 parent b47be0f commit f55149d
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,6 @@ public String verifyOTPAndGenerateHealthID(
return response.toString();
}

/***
*
* @param request
* @param Authorization
* @return BenRegID of beneficiary after mapping
*/
@CrossOrigin
@Operation(summary = "Map ABHA to beneficiary")
@PostMapping(value = { "/mapHealthIDToBeneficiary" })
public String mapHealthIDToBeneficiary(
@Param(value = "{\"beneficiaryRegID\":\"Long\",\"beneficiaryID\":\"Long\",\"healthId\":\"String\",\"healthIdNumber\":\"String\""
+ "providerServiceMapId\":\"Integer\",\"createdBy\":\"String\"}") @RequestBody String request,
@RequestHeader(value = "Authorization") String Authorization) {
logger.info("NDHM_FHIR Map ABHA to beneficiary API request " + request);
OutputResponse response = new OutputResponse();
try {
if (request != null) {
String s = healthIDService.mapHealthIDToBeneficiary(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 Map ABHA to beneficiary API response " + response.toString());
return response.toString();
}

/***
*
* @param comingRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.wipro.fhir.controller.healthID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wipro.fhir.service.healthID.HealthIDService;
import com.wipro.fhir.utils.exception.FHIRException;
import com.wipro.fhir.utils.response.OutputResponse;

import io.swagger.v3.oas.annotations.Operation;

@CrossOrigin
@RestController
@RequestMapping(value = "/healthIDRecord", headers = "Authorization", consumes = "application/json", produces = "application/json")
public class CreateHealthIdRecord {

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

@Autowired
private HealthIDService healthIDService;

/***
*
* @param request
* @param Authorization
* @return BenRegID of beneficiary after mapping
*/
@CrossOrigin
@Operation(summary = "Map ABHA to beneficiary")
@PostMapping(value = { "/mapHealthIDToBeneficiary" })
public String mapHealthIDToBeneficiary(
@RequestBody String request, @RequestHeader(value = "Authorization") String Authorization) {
logger.info("NDHM_FHIR Map ABHA to beneficiary API request " + request);
OutputResponse response = new OutputResponse();
try {
if (request != null) {
String s = healthIDService.mapHealthIDToBeneficiary(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 Map ABHA to beneficiary API response " + response.toString());
return response.toString();
}


@CrossOrigin
@Operation(summary = "Add New health ID record to healthId table")
@PostMapping(value = { "/addHealthIdRecord" })
public String addRecordToHealthIdTable(
@RequestBody String request, @RequestHeader(value = "Authorization") String Authorization) {
logger.info("NDHM_FHIR API to add the new health record coming from FLW request " + request);
OutputResponse response = new OutputResponse();
try {
if (request != null) {
String s = healthIDService.addRecordToHealthIdTable(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 API to add the new health record coming from FLW response " + response.toString());
return response.toString();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
package com.wipro.fhir.data.healthID;

import lombok.Data;

@Data
public class HealthIDRequestAadhar {

String email;
Expand All @@ -35,77 +38,6 @@ public class HealthIDRequestAadhar {
String healthId;
String password;
String profilePhoto;
public Integer getProviderServiceMapID() {
return providerServiceMapID;
}
public void setProviderServiceMapID(Integer providerServiceMapID) {
this.providerServiceMapID = providerServiceMapID;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
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 getOtp() {
return otp;
}
public void setOtp(String otp) {
this.otp = otp;
}
public String getTxnId() {
return txnId;
}
public void setTxnId(String txnId) {
this.txnId = txnId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getHealthId() {
return healthId;
}
public void setHealthId(String healthId) {
this.healthId = healthId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getProfilePhoto() {
return profilePhoto;
}
public void setProfilePhoto(String profilePhoto) {
this.profilePhoto = profilePhoto;
}

boolean isNew;
String dob;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
public interface HealthIDService {
String mapHealthIDToBeneficiary(String request) throws FHIRException;
public String getBenHealthID(Long benRegID);
public String addRecordToHealthIdTable(String request) throws FHIRException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
*/
package com.wipro.fhir.service.healthID;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -32,8 +34,14 @@
import org.springframework.stereotype.Service;

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.BenHealthIDMapping;
import com.wipro.fhir.data.healthID.HealthIDRequestAadhar;
import com.wipro.fhir.data.healthID.HealthIDResponse;
import com.wipro.fhir.repo.healthID.BenHealthIDMappingRepo;
import com.wipro.fhir.repo.healthID.HealthIDRepo;
import com.wipro.fhir.utils.exception.FHIRException;
import com.wipro.fhir.utils.http.HttpUtils;
import com.wipro.fhir.utils.mapper.InputMapper;
Expand All @@ -46,9 +54,12 @@ public class HealthIDServiceImpl implements HealthIDService {

@Autowired
private BenHealthIDMappingRepo benHealthIDMappingRepo;
@Autowired
HealthIDRepo healthIDRepo;

public String mapHealthIDToBeneficiary(String request) throws FHIRException {
BenHealthIDMapping health = InputMapper.gson().fromJson(request, BenHealthIDMapping.class);
health = InputMapper.gson().fromJson(request, BenHealthIDMapping.class);
try {
if (health.getBeneficiaryRegId() == null && health.getBeneficiaryID() == null)
throw new FHIRException("Error in mapping request");
Expand All @@ -61,6 +72,40 @@ public String mapHealthIDToBeneficiary(String request) throws FHIRException {
health = benHealthIDMappingRepo.save(health);
}
}
// Adding the code to check if the received healthId is present in t_healthId table and add if missing
Integer healthIdCount = healthIDRepo.getCountOfHealthIdNumber(health.getHealthIdNumber());
if(healthIdCount < 1) {
JsonObject jsonRequest = JsonParser.parseString(request).getAsJsonObject();
JsonObject abhaProfileJson = jsonRequest.getAsJsonObject("ABHAProfile");
HealthIDResponse healthID = InputMapper.gson().fromJson(abhaProfileJson, HealthIDResponse.class);

healthID.setHealthIdNumber(abhaProfileJson.get("ABHANumber").getAsString());
JsonArray phrAddressArray = abhaProfileJson.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(", ");
}
}
healthID.setHealthId(abhaAddressBuilder.toString());
healthID.setName(
abhaProfileJson.get("firstName").getAsString() + " " + abhaProfileJson.get("middleName").getAsString() + " " + abhaProfileJson.get("lastName").getAsString());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = simpleDateFormat.parse(abhaProfileJson.get("dob").getAsString());
SimpleDateFormat year = new SimpleDateFormat("yyyy");
SimpleDateFormat month = new SimpleDateFormat("MM");
SimpleDateFormat day = new SimpleDateFormat("dd");
healthID.setYearOfBirth(year.format(date));
healthID.setMonthOfBirth(month.format(date));
healthID.setDayOfBirth(day.format(date));
healthID.setCreatedBy(jsonRequest.get("createdBy").getAsString());
healthID.setProviderServiceMapID(jsonRequest.get("providerServiceMapId").getAsInt());
healthID.setIsNewAbha(jsonRequest.get("isNew").getAsBoolean());
healthIDRepo.save(healthID);
}

} catch (Exception e) {
throw new FHIRException("Error in saving data");
}
Expand All @@ -75,4 +120,48 @@ public String getBenHealthID(Long benRegID) {

return resMap.toString();
}

@Override
public String addRecordToHealthIdTable(String request) throws FHIRException {
JsonObject jsonRequest = JsonParser.parseString(request).getAsJsonObject();
JsonObject abhaProfileJson = jsonRequest.getAsJsonObject("ABHAProfile");
HealthIDResponse healthID = InputMapper.gson().fromJson(abhaProfileJson, HealthIDResponse.class);
String res = null;
try {
Integer healthIdCount = healthIDRepo.getCountOfHealthIdNumber(healthID.getHealthIdNumber());
if(healthIdCount < 1) {
healthID.setHealthIdNumber(abhaProfileJson.get("ABHANumber").getAsString());
JsonArray phrAddressArray = abhaProfileJson.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(", ");
}
}
healthID.setHealthId(abhaAddressBuilder.toString());
healthID.setName(
abhaProfileJson.get("firstName").getAsString() + " " + abhaProfileJson.get("middleName").getAsString() + " " + abhaProfileJson.get("lastName").getAsString());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = simpleDateFormat.parse(abhaProfileJson.get("dob").getAsString());
SimpleDateFormat year = new SimpleDateFormat("yyyy");
SimpleDateFormat month = new SimpleDateFormat("MM");
SimpleDateFormat day = new SimpleDateFormat("dd");
healthID.setYearOfBirth(year.format(date));
healthID.setMonthOfBirth(month.format(date));
healthID.setDayOfBirth(day.format(date));
healthID.setCreatedBy(jsonRequest.get("createdBy").getAsString());
healthID.setProviderServiceMapID(jsonRequest.get("providerServiceMapId").getAsInt());
healthID.setIsNewAbha(jsonRequest.get("isNew").getAsBoolean());
healthIDRepo.save(healthID);
res = "Data Saved Successfully";
} else {
res = "Data already exists";
}
} catch (Exception e) {
throw new FHIRException("Error in saving data");
}
return res;
}
}

0 comments on commit f55149d

Please sign in to comment.