-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathBeneficiaryServiceImpl.java
More file actions
590 lines (493 loc) · 27.5 KB
/
BeneficiaryServiceImpl.java
File metadata and controls
590 lines (493 loc) · 27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
package com.iemr.flw.service.impl;
import java.math.BigInteger;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.iemr.flw.domain.iemr.EyeCheckupVisit;
import com.iemr.flw.domain.iemr.IncentiveActivity;
import com.iemr.flw.dto.iemr.EyeCheckupListDTO;
import com.iemr.flw.dto.iemr.EyeCheckupRequestDTO;
import com.iemr.flw.masterEnum.GroupName;
import com.iemr.flw.repo.iemr.*;
import com.iemr.flw.utils.JwtUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer;
import com.iemr.flw.domain.identity.BenHealthIDDetails;
import com.iemr.flw.domain.identity.RMNCHBeneficiaryDetailsRmnch;
import com.iemr.flw.domain.identity.RMNCHBornBirthDetails;
import com.iemr.flw.domain.identity.RMNCHHouseHoldDetails;
import com.iemr.flw.domain.identity.RMNCHMBeneficiaryAccount;
import com.iemr.flw.domain.identity.RMNCHMBeneficiaryImage;
import com.iemr.flw.domain.identity.RMNCHMBeneficiaryaddress;
import com.iemr.flw.domain.identity.RMNCHMBeneficiarycontact;
import com.iemr.flw.domain.identity.RMNCHMBeneficiarydetail;
import com.iemr.flw.domain.identity.RMNCHMBeneficiarymapping;
import com.iemr.flw.dto.identity.GetBenRequestHandler;
import com.iemr.flw.mapper.InputMapper;
import com.iemr.flw.repo.identity.BeneficiaryRepo;
import com.iemr.flw.repo.identity.HouseHoldRepo;
import com.iemr.flw.service.BeneficiaryService;
import com.iemr.flw.utils.config.ConfigProperties;
import com.iemr.flw.utils.http.HttpUtils;
@Service
@Qualifier("rmnchServiceImpl")
public class BeneficiaryServiceImpl implements BeneficiaryService {
private final Logger logger = LoggerFactory.getLogger(BeneficiaryServiceImpl.class);
@Value("${door-to-door-page-size}")
private String door_to_door_page_size;
@Value("${fhir-url}")
private String fhirUrl;
@Value("${getHealthID}")
private String getHealthID;
@Autowired
private BeneficiaryRepo beneficiaryRepo;
@Autowired
private HouseHoldRepo houseHoldRepo;
@Autowired
private GeneralOpdRepo generalOpdRepo;
@Autowired
IncentivesRepo incentivesRepo;
@Autowired
IncentiveRecordRepo recordRepo;
@Autowired
private EyeCheckUpVisitRepo eyeCheckUpVisitRepo;
@Autowired
private JwtUtil jwtUtil;
@Autowired
private UserServiceRoleRepo userRepo;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd-MM-yyyy");
@Override
public String getBenData(GetBenRequestHandler request, String authorisation) throws Exception {
String outputResponse = null;
int totalPage = 0;
try {
if (request != null && request.getAshaId() != null) {
List<RMNCHMBeneficiaryaddress> resultSet;
Integer pageSize = Integer.valueOf(door_to_door_page_size);
if (request.getPageNo() != null) {
String userName = beneficiaryRepo.getUserName(request.getAshaId());
if (userName == null || userName.isEmpty())
throw new Exception("Asha details not found, please contact administrator");
request.setUserName(userName);
PageRequest pr = PageRequest.of(request.getPageNo(), pageSize);
if (request.getFromDate() != null && request.getToDate() != null) {
Page<RMNCHMBeneficiaryaddress> p = beneficiaryRepo.getBenDataWithinDates(
request.getUserName(), request.getFromDate(), request.getToDate(), pr);
resultSet = p.getContent();
totalPage = p.getTotalPages();
} else {
Page<RMNCHMBeneficiaryaddress> p = beneficiaryRepo.getBenDataByUser(request.getUserName(),
pr);
resultSet = p.getContent();
totalPage = p.getTotalPages();
}
if (resultSet != null && resultSet.size() > 0) {
outputResponse = getMappingsForAddressIDs(resultSet, totalPage, authorisation);
}
} else {
// page no not invalid
throw new Exception("Invalid page no");
}
} else
throw new Exception("Invalid/missing village details");
} catch (Exception e) {
throw new Exception(e.getMessage());
}
return outputResponse;
}
private String getMappingsForAddressIDs(List<RMNCHMBeneficiaryaddress> addressList, int totalPage,
String authorisation) {
RMNCHHouseHoldDetails benHouseHoldRMNCH_ROBJ;
RMNCHBeneficiaryDetailsRmnch benDetailsRMNCH_OBJ;
RMNCHBornBirthDetails benBotnBirthRMNCH_ROBJ;
RMNCHMBeneficiarydetail benDetailsOBJ;
RMNCHMBeneficiaryAccount benAccountOBJ;
RMNCHMBeneficiaryImage benImageOBJ;
RMNCHMBeneficiaryaddress benAddressOBJ;
RMNCHMBeneficiarycontact benContactOBJ;
Map<String, Object> resultMap;
ArrayList<Map<String, Object>> resultList = new ArrayList<>();
for (RMNCHMBeneficiaryaddress a : addressList) {
// exception by-passing
try {
RMNCHMBeneficiarymapping m = beneficiaryRepo.getByAddressID(a.getId());
if (m != null) {
benHouseHoldRMNCH_ROBJ = new RMNCHHouseHoldDetails();
benDetailsRMNCH_OBJ = new RMNCHBeneficiaryDetailsRmnch();
benBotnBirthRMNCH_ROBJ = new RMNCHBornBirthDetails();
benDetailsOBJ = new RMNCHMBeneficiarydetail();
benAccountOBJ = new RMNCHMBeneficiaryAccount();
benImageOBJ = new RMNCHMBeneficiaryImage();
benAddressOBJ = new RMNCHMBeneficiaryaddress();
benContactOBJ = new RMNCHMBeneficiarycontact();
Map<String, Object> healthDetails = getBenHealthDetails(m.getBenRegId());
if (m.getBenDetailsId() != null) {
benDetailsOBJ = beneficiaryRepo.getDetailsById(m.getBenDetailsId());
}
if (m.getBenAccountID() != null) {
benAccountOBJ = beneficiaryRepo.getAccountById(m.getBenAccountID());
}
if (m.getBenImageId() != null) {
benImageOBJ = beneficiaryRepo.getImageById(m.getBenImageId().longValue());
}
if (m.getBenAddressId() != null) {
benAddressOBJ = beneficiaryRepo.getAddressById(m.getBenAddressId());
}
if (m.getBenContactsId() != null) {
benContactOBJ = beneficiaryRepo.getContactById(m.getBenContactsId());
}
BigInteger benID = null;
if (m.getBenRegId() != null)
benID = beneficiaryRepo.getBenIdFromRegID(m.getBenRegId().longValue());
if (m.getBenRegId() != null) {
benDetailsRMNCH_OBJ = beneficiaryRepo
.getDetailsByRegID((m.getBenRegId()).longValue());
benBotnBirthRMNCH_ROBJ = beneficiaryRepo.getBornBirthByRegID((m.getBenRegId()).longValue());
if (benDetailsRMNCH_OBJ != null && benDetailsRMNCH_OBJ.getHouseoldId() != null)
benHouseHoldRMNCH_ROBJ = houseHoldRepo
.getByHouseHoldID(benDetailsRMNCH_OBJ.getHouseoldId());
}
if (benDetailsRMNCH_OBJ == null)
benDetailsRMNCH_OBJ = new RMNCHBeneficiaryDetailsRmnch();
// new mapping 30-06-2021
if (benDetailsOBJ.getMotherName() != null)
benDetailsRMNCH_OBJ.setMotherName(benDetailsOBJ.getMotherName());
if (benDetailsOBJ.getLiteracyStatus() != null)
benDetailsRMNCH_OBJ.setLiteracyStatus(benDetailsOBJ.getLiteracyStatus());
// bank
if (benAccountOBJ.getNameOfBank() != null)
benDetailsRMNCH_OBJ.setNameOfBank(benAccountOBJ.getNameOfBank());
if (benAccountOBJ.getBranchName() != null)
benDetailsRMNCH_OBJ.setBranchName(benAccountOBJ.getBranchName());
if (benAccountOBJ.getIfscCode() != null)
benDetailsRMNCH_OBJ.setIfscCode(benAccountOBJ.getIfscCode());
if (benAccountOBJ.getBankAccount() != null)
benDetailsRMNCH_OBJ.setBankAccount(benAccountOBJ.getBankAccount());
// location
if (benAddressOBJ.getCountyid() != null)
benDetailsRMNCH_OBJ.setCountryId(benAddressOBJ.getCountyid());
if (benAddressOBJ.getPermCountry() != null)
benDetailsRMNCH_OBJ.setCountryName(benAddressOBJ.getPermCountry());
if (benAddressOBJ.getStatePerm() != null)
benDetailsRMNCH_OBJ.setStateId(benAddressOBJ.getStatePerm());
if (benAddressOBJ.getPermState() != null)
benDetailsRMNCH_OBJ.setStateName(benAddressOBJ.getPermState());
if (benAddressOBJ.getDistrictidPerm() != null) {
benDetailsRMNCH_OBJ.setDistrictid(benAddressOBJ.getDistrictidPerm());
}
if (benAddressOBJ.getDistrictnamePerm() != null) {
benDetailsRMNCH_OBJ.setDistrictname(benAddressOBJ.getDistrictnamePerm());
}
if (benAddressOBJ.getPermSubDistrictId() != null)
benDetailsRMNCH_OBJ.setBlockId(benAddressOBJ.getPermSubDistrictId());
if (benAddressOBJ.getPermSubDistrict() != null)
benDetailsRMNCH_OBJ.setBlockName(benAddressOBJ.getPermSubDistrict());
if (benAddressOBJ.getVillageidPerm() != null)
benDetailsRMNCH_OBJ.setVillageId(benAddressOBJ.getVillageidPerm());
if (benAddressOBJ.getVillagenamePerm() != null)
benDetailsRMNCH_OBJ.setVillageName(benAddressOBJ.getVillagenamePerm());
if (benAddressOBJ.getPermServicePointId() != null)
benDetailsRMNCH_OBJ.setServicePointID(benAddressOBJ.getPermServicePointId());
if (benAddressOBJ.getPermServicePoint() != null)
benDetailsRMNCH_OBJ.setServicePointName(benAddressOBJ.getPermServicePoint());
if (benAddressOBJ.getPermZoneID() != null)
benDetailsRMNCH_OBJ.setZoneID(benAddressOBJ.getPermZoneID());
if (benAddressOBJ.getPermZone() != null)
benDetailsRMNCH_OBJ.setZoneName(benAddressOBJ.getPermZone());
if (benAddressOBJ.getPermAddrLine1() != null)
benDetailsRMNCH_OBJ.setAddressLine1(benAddressOBJ.getPermAddrLine1());
if (benAddressOBJ.getPermAddrLine2() != null)
benDetailsRMNCH_OBJ.setAddressLine2(benAddressOBJ.getPermAddrLine2());
if (benAddressOBJ.getPermAddrLine3() != null)
benDetailsRMNCH_OBJ.setAddressLine3(benAddressOBJ.getPermAddrLine3());
// -----------------------------------------------------------------------------
// related benids
if (benDetailsRMNCH_OBJ.getRelatedBeneficiaryIdsDB() != null) {
String[] relatedBenIDsString = benDetailsRMNCH_OBJ.getRelatedBeneficiaryIdsDB().split(",");
Long[] relatedBenIDs = new Long[relatedBenIDsString.length];
int pointer = 0;
for (String s : relatedBenIDsString) {
relatedBenIDs[pointer] = Long.valueOf(s);
pointer++;
}
benDetailsRMNCH_OBJ.setRelatedBeneficiaryIds(relatedBenIDs);
}
// ------------------------------------------------------------------------------
if (benDetailsOBJ.getCommunity() != null)
benDetailsRMNCH_OBJ.setCommunity(benDetailsOBJ.getCommunity());
if (benDetailsOBJ.getCommunityId() != null)
benDetailsRMNCH_OBJ.setCommunityId(benDetailsOBJ.getCommunityId());
if (benContactOBJ.getPreferredPhoneNum() != null)
benDetailsRMNCH_OBJ.setContact_number(benContactOBJ.getPreferredPhoneNum());
if (benDetailsOBJ.getDob() != null)
benDetailsRMNCH_OBJ.setDob(benDetailsOBJ.getDob());
if (benDetailsOBJ.getFatherName() != null)
benDetailsRMNCH_OBJ.setFatherName(benDetailsOBJ.getFatherName());
if (benDetailsOBJ.getFirstName() != null)
benDetailsRMNCH_OBJ.setFirstName(benDetailsOBJ.getFirstName());
if (benDetailsOBJ.getGender() != null)
benDetailsRMNCH_OBJ.setGender(benDetailsOBJ.getGender());
if (benDetailsOBJ.getGenderId() != null)
benDetailsRMNCH_OBJ.setGenderId(benDetailsOBJ.getGenderId());
if (benDetailsOBJ.getMaritalstatus() != null)
benDetailsRMNCH_OBJ.setMaritalstatus(benDetailsOBJ.getMaritalstatus());
if (benDetailsOBJ.getMaritalstatusId() != null)
benDetailsRMNCH_OBJ.setMaritalstatusId(benDetailsOBJ.getMaritalstatusId());
if (benDetailsOBJ.getMarriageDate() != null)
benDetailsRMNCH_OBJ.setMarriageDate(benDetailsOBJ.getMarriageDate());
if (benDetailsOBJ.getReligion() != null)
benDetailsRMNCH_OBJ.setReligion(benDetailsOBJ.getReligion());
if (benDetailsOBJ.getReligionID() != null)
benDetailsRMNCH_OBJ.setReligionID(benDetailsOBJ.getReligionID());
if (benDetailsOBJ.getSpousename() != null)
benDetailsRMNCH_OBJ.setSpousename(benDetailsOBJ.getSpousename());
if (benImageOBJ != null && benImageOBJ.getUser_image() != null)
benDetailsRMNCH_OBJ.setUser_image(benImageOBJ.getUser_image());
// new fields
// benDetailsRMNCH_OBJ.setRegistrationDate(benDetailsOBJ.getCreatedDate());
if (benID != null)
benDetailsRMNCH_OBJ.setBenficieryid(benID.longValue());
if (benDetailsOBJ.getLastName() != null)
benDetailsRMNCH_OBJ.setLastName(benDetailsOBJ.getLastName());
if (benDetailsRMNCH_OBJ.getCreatedBy() == null)
if (benDetailsOBJ.getCreatedBy() != null)
benDetailsRMNCH_OBJ.setCreatedBy(benDetailsOBJ.getCreatedBy());
// age calculation
String ageDetails = "";
int age_val = 0;
String ageUnit = null;
if (benDetailsOBJ.getDob() != null) {
Date date = new Date(benDetailsOBJ.getDob().getTime());
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
java.time.LocalDate todayDate = java.time.LocalDate.now();
java.time.LocalDate birthdate = java.time.LocalDate.of(year, month, day);
Period p = Period.between(birthdate, todayDate);
int d = p.getDays();
int mo = p.getMonths();
int y = p.getYears();
if (y > 0) {
ageDetails = y + " years - " + mo + " months";
age_val = y;
ageUnit = (age_val > 1) ? "Years" : "Year";
} else {
if (mo > 0) {
ageDetails = mo + " months - " + d + " days";
age_val = mo;
ageUnit = (age_val > 1) ? "Months" : "Month";
} else {
ageDetails = d + " days";
age_val = d;
ageUnit = (age_val > 1) ? "Days" : "Day";
}
}
}
benDetailsRMNCH_OBJ.setAgeFull(ageDetails);
benDetailsRMNCH_OBJ.setAge(age_val);
if (ageUnit != null)
benDetailsRMNCH_OBJ.setAge_unit(ageUnit);
resultMap = new HashMap<>();
if (benHouseHoldRMNCH_ROBJ != null)
resultMap.put("householdDetails", benHouseHoldRMNCH_ROBJ);
else
resultMap.put("householdDetails", new HashMap<String, Object>());
if (benBotnBirthRMNCH_ROBJ != null)
resultMap.put("bornbirthDeatils", benBotnBirthRMNCH_ROBJ);
else
resultMap.put("bornbirthDeatils", new HashMap<String, Object>());
resultMap.put("beneficiaryDetails", benDetailsRMNCH_OBJ);
resultMap.put("abhaHealthDetails", healthDetails);
resultMap.put("houseoldId", benDetailsRMNCH_OBJ.getHouseoldId());
resultMap.put("benficieryid", benDetailsRMNCH_OBJ.getBenficieryid());
resultMap.put("isDeath", benDetailsRMNCH_OBJ.getIsDeath());
resultMap.put("isDeathValue", benDetailsRMNCH_OBJ.getIsDeathValue());
resultMap.put("dateOfDeath",benDetailsRMNCH_OBJ.getDateOfDeath());
resultMap.put("timeOfDeath", benDetailsRMNCH_OBJ.getTimeOfDeath());
resultMap.put("reasonOfDeath", benDetailsRMNCH_OBJ.getReasonOfDeath());
resultMap.put("reasonOfDeathId", benDetailsRMNCH_OBJ.getReasonOfDeathId());
resultMap.put("placeOfDeath", benDetailsRMNCH_OBJ.getPlaceOfDeath());
resultMap.put("placeOfDeathId", benDetailsRMNCH_OBJ.getPlaceOfDeathId());
resultMap.put("isSpouseAdded", benDetailsRMNCH_OBJ.getIsSpouseAdded());
resultMap.put("isChildrenAdded", benDetailsRMNCH_OBJ.getIsChildrenAdded());
resultMap.put("noOfchildren", benDetailsRMNCH_OBJ.getNoOfchildren());
resultMap.put("isMarried", benDetailsRMNCH_OBJ.getIsMarried());
resultMap.put("doYouHavechildren", benDetailsRMNCH_OBJ.getDoYouHavechildren());
resultMap.put("noofAlivechildren ",benDetailsRMNCH_OBJ.getNoofAlivechildren());
resultMap.put("BenRegId", m.getBenRegId());
// adding asha id / created by - user id
if (benAddressOBJ.getCreatedBy() != null) {
Integer userID = beneficiaryRepo.getUserIDByUserName(benAddressOBJ.getCreatedBy());
if (userID != null && userID > 0)
resultMap.put("ashaId", userID);
}
// get HealthID of ben
if (m.getBenRegId() != null) {
fetchHealthIdByBenRegID(m.getBenRegId().longValue(), authorisation, resultMap);
}
resultList.add(resultMap);
} else {
// mapping not available
}
} catch (Exception e) {
logger.error("error for addressID :"+e.getMessage() + a.getId() + " and vanID : " + a.getVanID());
}
}
Map<String, Object> response = new HashMap<>();
response.put("data", resultList);
response.put("pageSize", Integer.parseInt(door_to_door_page_size));
response.put("totalPage", totalPage);
Gson gson = new GsonBuilder().setDateFormat("MMM dd, yyyy h:mm:ss a").create();
return gson.toJson(response);
}
private Map<String, Object> getBenHealthDetails(BigInteger benRegId) {
Map<String, Object> healthDetails = new HashMap<>();
if (null != benRegId) {
Object[] benHealthIdNumber = beneficiaryRepo.getBenHealthIdNumber(benRegId);
if (benHealthIdNumber != null && benHealthIdNumber.length > 0) {
Object[] healthData = (Object[]) benHealthIdNumber[0];
String healthIdNumber = healthData[0] != null ? healthData[0].toString() : null;
String healthId = healthData[1] != null ? healthData[1].toString() : null;
if (null != healthIdNumber) {
List<Object[]> health = beneficiaryRepo.getBenHealthDetails(healthIdNumber);
if (health != null && !health.isEmpty()) {
for (Object[] objects : health) {
healthDetails.put("HealthID", objects[0]);
healthDetails.put("HealthIdNumber", objects[1]);
healthDetails.put("isNewAbha", objects[2]);
}
} else {
healthDetails.put("HealthIdNumber", healthIdNumber);
healthDetails.put("HealthID", healthId);
healthDetails.put("isNewAbha", null);
}
}
}
}
return healthDetails;
}
private Map<String, Object> getBenBenVisitDetails(BigInteger benRegId) {
Map<String, Object> healthDetails = new HashMap<>();
if (null != benRegId) {
String benHealthIdNumber = String.valueOf(beneficiaryRepo.getBenHealthIdNumber(benRegId));
if (null != benHealthIdNumber) {
ArrayList<Object[]> health = beneficiaryRepo.getBenHealthDetails(benHealthIdNumber);
for (Object[] objects : health) {
healthDetails.put("HealthID", objects[0]);
healthDetails.put("HealthIdNumber", objects[1]);
healthDetails.put("isNewAbha", objects[2]);
}
}
}
return healthDetails;
}
public void fetchHealthIdByBenRegID(Long benRegID, String authorization, Map<String, Object> resultMap) {
Map<String, Long> requestMap = new HashMap<String, Long>();
requestMap.put("beneficiaryRegID", benRegID);
requestMap.put("beneficiaryID", null);
JsonParser jsnParser = new JsonParser();
HttpUtils utils = new HttpUtils();
List<String> result = null;
try {
HashMap<String, Object> header = new HashMap<String, Object>();
header.put("Authorization", authorization);
String responseStr = utils.post(fhirUrl + "/"
+ getHealthID, new Gson().toJson(requestMap), header);
JsonElement jsnElmnt = jsnParser.parse(responseStr);
JsonObject jsnOBJ = new JsonObject();
jsnOBJ = jsnElmnt.getAsJsonObject();
if (jsnOBJ.get("data") != null && jsnOBJ.get("data").getAsJsonObject().get("BenHealthDetails") != null) {
result = new ArrayList<String>();
BenHealthIDDetails[] ben = InputMapper.gson().fromJson(
new Gson().toJson(jsnOBJ.get("data").getAsJsonObject().get("BenHealthDetails")),
BenHealthIDDetails[].class);
for (BenHealthIDDetails value : ben) {
if (value.getHealthId() != null)
resultMap.put("healthId", value.getHealthId());
if (value.getHealthIdNumber() != null)
resultMap.put("healthIdNumber", value.getHealthIdNumber());
}
}
} catch (Exception e) {
logger.info("Error while fetching ABHA" + e.getMessage());
// return null;
}
// return result;
}
@Override
public String saveEyeCheckupVsit(List<EyeCheckupRequestDTO> eyeCheckupRequestDTOS,String token) {
try {
for (EyeCheckupRequestDTO dto : eyeCheckupRequestDTOS) {
EyeCheckupVisit visit = new EyeCheckupVisit();
visit.setBeneficiaryId(dto.getBeneficiaryId());
visit.setHouseholdId(dto.getHouseHoldId());
visit.setUserId(jwtUtil.extractUserId(token));
visit.setCreatedBy(dto.getUserName());
StringBuilder sb = new StringBuilder();
// fields mapping
EyeCheckupListDTO f = dto.getFields();
sb.append(f.getDischarge_summary_upload());
String longText = sb.toString();
visit.setVisitDate(LocalDate.parse(f.getVisit_date(), FORMATTER));
visit.setSymptomsObserved(f.getSymptoms_observed());
visit.setEyeAffected(f.getEye_affected());
visit.setReferredTo(f.getReferred_to());
visit.setDischargeSummaryUpload(longText);
visit.setFollowUpStatus(f.getFollow_up_status());
visit.setDateOfSurgery(f.getDate_of_surgery());
// save/update
eyeCheckUpVisitRepo.save(visit);
}
return "Eye checkup data saved successfully.";
} catch (Exception e) {
e.printStackTrace();
}
return null ;
}
@Override
public List<EyeCheckupRequestDTO> getEyeCheckUpVisit(GetBenRequestHandler request) {
List<EyeCheckupVisit> visits = eyeCheckUpVisitRepo.findByUserId(request.getAshaId());
return visits.stream().map(v -> {
EyeCheckupRequestDTO dto = new EyeCheckupRequestDTO();
dto.setId(v.getId());
dto.setBeneficiaryId(v.getBeneficiaryId());
dto.setHouseHoldId(v.getHouseholdId());
dto.setUserName(v.getCreatedBy());
dto.setVisitDate(v.getVisitDate().format(FORMATTER));
EyeCheckupListDTO fields = new EyeCheckupListDTO();
fields.setVisit_date(v.getVisitDate().format(FORMATTER));
fields.setSymptoms_observed(v.getSymptomsObserved());
fields.setEye_affected(v.getEyeAffected());
fields.setReferred_to(v.getReferredTo());
fields.setFollow_up_status(v.getFollowUpStatus());
fields.setDate_of_surgery(v.getDateOfSurgery());
fields.setDischarge_summary_upload(v.getDischargeSummaryUpload());
dto.setFields(fields);
return dto;
}).collect(Collectors.toList());
}
}