Skip to content
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
16dca5c
fix(bug): isNewAbha null issue
May 20, 2025
2159bb0
fix: coderabbit suggestions
May 20, 2025
0d974fc
Merge branch 'PSMRI:develop' into develop
helenKaryamsetty May 23, 2025
ad4cb57
fix: updated ci properties for prod
May 23, 2025
ee53b5a
fix: updated ci properties for abdm
May 23, 2025
c4eeec1
Merge branch 'develop' into develop
helenKaryamsetty May 23, 2025
d4f90d1
Merge branch 'PSMRI:develop' into develop
helenKaryamsetty May 23, 2025
d169521
Merge branch 'PSMRI:develop' into develop
helenKaryamsetty May 30, 2025
97df66f
fix: updated fasterxml jackson dependency to fix scheduler issue
May 30, 2025
d9e9a7d
fix: updated jackson version
May 30, 2025
029baf2
fix: removed versioning for jackson
May 30, 2025
200d8cf
Merge branch 'develop' into develop
helenKaryamsetty May 30, 2025
dd01b9d
fix: Update pom.xml
helenKaryamsetty May 30, 2025
11164d0
fix: modified jackson version for java 8 times
May 30, 2025
67faf11
Merge branch 'PSMRI:develop' into develop
helenKaryamsetty May 30, 2025
d97c69a
Merge branch 'develop' of https://github.com/helenKaryamsetty/FHIR-AP…
May 30, 2025
93ca69e
fix: jackson dependency version removal
May 30, 2025
bcf12d3
Merge branch 'develop' of https://github.com/helenKaryamsetty/FHIR-API
May 30, 2025
c2bb8ff
fix: updated jackson properties
Jun 3, 2025
ede401d
Merge branch 'develop' of https://github.com/helenKaryamsetty/FHIR-AP…
Jun 3, 2025
1e54fa6
fix: update properties
Jun 3, 2025
382de2e
fix: removed jackson dependency completely
Jun 4, 2025
433f837
fix: added hapi base and modified hapi fhir dependency
Jun 4, 2025
f2c9733
Merge branch 'develop' of https://github.com/helenKaryamsetty/FHIR-AP…
Jun 4, 2025
1111177
fix: added all null checks to fhir bundle
Jun 4, 2025
f90f001
Merge branch 'develop' of https://github.com/helenKaryamsetty/FHIR-AP…
Jun 4, 2025
f27d531
fix: missed null checks
Jun 4, 2025
12bc6c2
fix: adding jackson properties
Jun 5, 2025
f0c9d13
Merge branch 'PSMRI:develop' into develop
helenKaryamsetty Jun 5, 2025
bbd8733
fix: jackson versions modification
Jun 6, 2025
6f21692
Merge branch 'develop' of https://github.com/helenKaryamsetty/FHIR-AP…
Jun 6, 2025
203fe09
Merge branch 'PSMRI:develop' into develop
helenKaryamsetty Jun 6, 2025
2c823aa
Merge branch 'develop' of https://github.com/helenKaryamsetty/FHIR-API
Jun 6, 2025
bbe3ec8
fix(bug): added check to verify if ben is mapped to any healthid
Jun 18, 2025
3fd09d8
Merge branch 'develop' of https://github.com/helenKaryamsetty/FHIR-AP…
Jun 18, 2025
d807595
fix: coderabbitai suggestions
Jun 18, 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 @@ -61,55 +61,68 @@ public class HealthIDServiceImpl implements HealthIDService {
@Autowired
HealthIDRepo healthIDRepo;

@Override
public String mapHealthIDToBeneficiary(String request) throws FHIRException {
BenHealthIDMapping health = InputMapper.gson().fromJson(request, BenHealthIDMapping.class);
health = InputMapper.gson().fromJson(request, BenHealthIDMapping.class);
String[] beneficiaryIdsList = null;
try {
if (health.getBeneficiaryRegID() == null && health.getBeneficiaryID() == null)
throw new FHIRException("Error in mapping request");
if (health.getBeneficiaryRegID() != null)
health = benHealthIDMappingRepo.save(health);
else {
if (health.getBeneficiaryID() != null) {
Long check1 = benHealthIDMappingRepo.getBenRegID(health.getBeneficiaryID());
health.setBeneficiaryRegID(check1);
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();
if (health.getHealthIdNumber() != null) {
beneficiaryIdsList = benHealthIDMappingRepo.getBenIdForHealthId(health.getHealthIdNumber());

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);
if (beneficiaryIdsList != null && beneficiaryIdsList.length > 0) {
return "HealthId is already linked to other beneficiary ID";
} else {
Comment on lines +72 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

Race condition: β€œcheck-then-save” is not atomic.

Between fetching the existing beneficiary IDs (line 74) and persisting the new mapping (later), another thread could insert a row, bypassing this safeguard and again linking the same healthId to a different beneficiary.
Use a database-level unique constraint on health_id_number (preferred) or wrap the block in a @Transactional method with ISOLATION.SERIALIZABLE / PESSIMISTIC_WRITE locking to guarantee consistency.

πŸ€– Prompt for AI Agents
In src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java around
lines 73 to 78, the current check-then-save logic for verifying if a
healthIdNumber is already linked is not atomic, causing a race condition. To fix
this, add a unique constraint on the health_id_number column at the database
level to prevent duplicates. Alternatively, annotate the method with
@Transactional and use an isolation level of SERIALIZABLE or apply
PESSIMISTIC_WRITE locking to ensure the check and save operations are atomic and
consistent.

if (health.getBeneficiaryRegID() != null)
health = benHealthIDMappingRepo.save(health);
else {
if (health.getBeneficiaryID() != null) {
Long benRegId = benHealthIDMappingRepo.getBenRegID(health.getBeneficiaryID());
health.setBeneficiaryRegID(benRegId);
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 Down
Loading