-
Notifications
You must be signed in to change notification settings - Fork 31
Restricting one ben with one healthId #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 35 commits
16dca5c
2159bb0
0d974fc
ad4cb57
ee53b5a
c4eeec1
d4f90d1
d169521
97df66f
d9e9a7d
029baf2
200d8cf
dd01b9d
11164d0
67faf11
d97c69a
93ca69e
bcf12d3
c2bb8ff
ede401d
1e54fa6
382de2e
433f837
f2c9733
1111177
f90f001
f27d531
12bc6c2
f0c9d13
bbd8733
6f21692
203fe09
2c823aa
bbe3ec8
3fd09d8
d807595
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -61,55 +61,69 @@ 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); | ||||||||||||||||||||||||||||||||||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| 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); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Null-safety & naming.
-Long check1 = benHealthIDMappingRepo.getBenRegID(health.getBeneficiaryID());
-health.setBeneficiaryRegID(check1);
+Long beneficiaryRegId = benHealthIDMappingRepo.getBenRegID(health.getBeneficiaryID());
+if (beneficiaryRegId == null) {
+ throw new FHIRException("Invalid beneficiaryID β no matching registration ID found");
+}
+health.setBeneficiaryRegID(beneficiaryRegId);π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| // 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"); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.