Skip to content

Commit 737c197

Browse files
helenKaryamsettyKA40094929Karyamsetty Helen GraceKA40094929
authored
Restricting one ben with one healthId (#109)
* fix(bug): isNewAbha null issue * fix: coderabbit suggestions * fix: updated ci properties for prod * fix: updated ci properties for abdm * fix: updated fasterxml jackson dependency to fix scheduler issue * fix: updated jackson version * fix: removed versioning for jackson * fix: Update pom.xml * fix: modified jackson version for java 8 times * fix: jackson dependency version removal * fix: updated jackson properties * fix: update properties * fix: removed jackson dependency completely * fix: added hapi base and modified hapi fhir dependency * fix: added all null checks to fhir bundle * fix: missed null checks * fix: adding jackson properties * fix: jackson versions modification * fix(bug): added check to verify if ben is mapped to any healthid * fix: coderabbitai suggestions --------- Co-authored-by: KA40094929 <KA40094929@APL-5CD1394ZJT> Co-authored-by: Karyamsetty Helen Grace <ka40094929@wipro.com> Co-authored-by: KA40094929 <KA40094929@APL-5CD1394ZJT.wipro.com>
1 parent 6a05670 commit 737c197

1 file changed

Lines changed: 54 additions & 41 deletions

File tree

src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -61,55 +61,68 @@ public class HealthIDServiceImpl implements HealthIDService {
6161
@Autowired
6262
HealthIDRepo healthIDRepo;
6363

64+
@Override
6465
public String mapHealthIDToBeneficiary(String request) throws FHIRException {
6566
BenHealthIDMapping health = InputMapper.gson().fromJson(request, BenHealthIDMapping.class);
66-
health = InputMapper.gson().fromJson(request, BenHealthIDMapping.class);
67+
String[] beneficiaryIdsList = null;
6768
try {
6869
if (health.getBeneficiaryRegID() == null && health.getBeneficiaryID() == null)
6970
throw new FHIRException("Error in mapping request");
70-
if (health.getBeneficiaryRegID() != null)
71-
health = benHealthIDMappingRepo.save(health);
7271
else {
73-
if (health.getBeneficiaryID() != null) {
74-
Long check1 = benHealthIDMappingRepo.getBenRegID(health.getBeneficiaryID());
75-
health.setBeneficiaryRegID(check1);
76-
health = benHealthIDMappingRepo.save(health);
77-
}
78-
}
79-
// Adding the code to check if the received healthId is present in t_healthId table and add if missing
80-
Integer healthIdCount = healthIDRepo.getCountOfHealthIdNumber(health.getHealthIdNumber());
81-
if(healthIdCount < 1) {
82-
JsonObject jsonRequest = JsonParser.parseString(request).getAsJsonObject();
83-
JsonObject abhaProfileJson = jsonRequest.getAsJsonObject("ABHAProfile");
84-
HealthIDResponse healthID = InputMapper.gson().fromJson(abhaProfileJson, HealthIDResponse.class);
85-
86-
healthID.setHealthIdNumber(abhaProfileJson.get("ABHANumber").getAsString());
87-
JsonArray phrAddressArray = abhaProfileJson.getAsJsonArray("phrAddress");
88-
StringBuilder abhaAddressBuilder = new StringBuilder();
72+
if (health.getHealthIdNumber() != null) {
73+
beneficiaryIdsList = benHealthIDMappingRepo.getBenIdForHealthId(health.getHealthIdNumber());
8974

90-
for (int i = 0; i < phrAddressArray.size(); i++) {
91-
abhaAddressBuilder.append(phrAddressArray.get(i).getAsString());
92-
if (i < phrAddressArray.size() - 1) {
93-
abhaAddressBuilder.append(", ");
94-
}
95-
}
96-
healthID.setHealthId(abhaAddressBuilder.toString());
97-
healthID.setName(
98-
abhaProfileJson.get("firstName").getAsString() + " " + abhaProfileJson.get("middleName").getAsString() + " " + abhaProfileJson.get("lastName").getAsString());
99-
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
100-
Date date = simpleDateFormat.parse(abhaProfileJson.get("dob").getAsString());
101-
SimpleDateFormat year = new SimpleDateFormat("yyyy");
102-
SimpleDateFormat month = new SimpleDateFormat("MM");
103-
SimpleDateFormat day = new SimpleDateFormat("dd");
104-
healthID.setYearOfBirth(year.format(date));
105-
healthID.setMonthOfBirth(month.format(date));
106-
healthID.setDayOfBirth(day.format(date));
107-
healthID.setCreatedBy(jsonRequest.get("createdBy").getAsString());
108-
healthID.setProviderServiceMapID(jsonRequest.get("providerServiceMapId").getAsInt());
109-
healthID.setIsNewAbha(jsonRequest.get("isNew").getAsBoolean());
110-
healthIDRepo.save(healthID);
75+
if (beneficiaryIdsList != null && beneficiaryIdsList.length > 0) {
76+
return "HealthId is already linked to other beneficiary ID";
77+
} else {
78+
if (health.getBeneficiaryRegID() != null)
79+
health = benHealthIDMappingRepo.save(health);
80+
else {
81+
if (health.getBeneficiaryID() != null) {
82+
Long benRegId = benHealthIDMappingRepo.getBenRegID(health.getBeneficiaryID());
83+
health.setBeneficiaryRegID(benRegId);
84+
health = benHealthIDMappingRepo.save(health);
85+
}
86+
}
87+
// Adding the code to check if the received healthId is present in t_healthId
88+
// table and add if missing
89+
Integer healthIdCount = healthIDRepo.getCountOfHealthIdNumber(health.getHealthIdNumber());
90+
if (healthIdCount < 1) {
91+
JsonObject jsonRequest = JsonParser.parseString(request).getAsJsonObject();
92+
JsonObject abhaProfileJson = jsonRequest.getAsJsonObject("ABHAProfile");
93+
HealthIDResponse healthID = InputMapper.gson().fromJson(abhaProfileJson,
94+
HealthIDResponse.class);
95+
96+
healthID.setHealthIdNumber(abhaProfileJson.get("ABHANumber").getAsString());
97+
JsonArray phrAddressArray = abhaProfileJson.getAsJsonArray("phrAddress");
98+
StringBuilder abhaAddressBuilder = new StringBuilder();
99+
100+
for (int i = 0; i < phrAddressArray.size(); i++) {
101+
abhaAddressBuilder.append(phrAddressArray.get(i).getAsString());
102+
if (i < phrAddressArray.size() - 1) {
103+
abhaAddressBuilder.append(", ");
104+
}
105+
}
106+
healthID.setHealthId(abhaAddressBuilder.toString());
107+
healthID.setName(abhaProfileJson.get("firstName").getAsString() + " "
108+
+ abhaProfileJson.get("middleName").getAsString() + " "
109+
+ abhaProfileJson.get("lastName").getAsString());
110+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
111+
Date date = simpleDateFormat.parse(abhaProfileJson.get("dob").getAsString());
112+
SimpleDateFormat year = new SimpleDateFormat("yyyy");
113+
SimpleDateFormat month = new SimpleDateFormat("MM");
114+
SimpleDateFormat day = new SimpleDateFormat("dd");
115+
healthID.setYearOfBirth(year.format(date));
116+
healthID.setMonthOfBirth(month.format(date));
117+
healthID.setDayOfBirth(day.format(date));
118+
healthID.setCreatedBy(jsonRequest.get("createdBy").getAsString());
119+
healthID.setProviderServiceMapID(jsonRequest.get("providerServiceMapId").getAsInt());
120+
healthID.setIsNewAbha(jsonRequest.get("isNew").getAsBoolean());
121+
healthIDRepo.save(healthID);
122+
}
123+
}
124+
}
111125
}
112-
113126
} catch (Exception e) {
114127
throw new FHIRException("Error in saving data");
115128
}

0 commit comments

Comments
 (0)