From 6a80e17b080274834c7ff827a6314220cee3dc35 Mon Sep 17 00:00:00 2001 From: khal <32254816+kalyan-chokkam@users.noreply.github.com> Date: Tue, 16 Jan 2024 15:04:22 +0530 Subject: [PATCH 1/3] updating syncDataToAmrit api to include RMNCHMBeneficiarydetail entity (#44) --- .../rmnch/RMNCHMobileAppController.java | 12 +++++++++++- .../repo/rmnch/RMNCHBenDetailsRepo.java | 4 ++++ .../rmnch/RmnchDataSyncServiceImpl.java | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iemr/common/identity/controller/rmnch/RMNCHMobileAppController.java b/src/main/java/com/iemr/common/identity/controller/rmnch/RMNCHMobileAppController.java index 33fbc9c..a68aacf 100644 --- a/src/main/java/com/iemr/common/identity/controller/rmnch/RMNCHMobileAppController.java +++ b/src/main/java/com/iemr/common/identity/controller/rmnch/RMNCHMobileAppController.java @@ -87,7 +87,17 @@ public String syncDataToAmrit(@ApiParam(value = "{\r\n" + " \"beneficiaryDetail + " \"nishchayPregnancyStatusPosition\": \"Integer\",\r\n" + " \"nishchayDeliveryStatus\": \"String\",\r\n" + " \"nishchayDeliveryStatusPosition\": \"Integer\",\r\n" + " \"relatedBeneficiaryIds\": [\r\n" - + " \"Long\"\r\n" + " ]\r\n" + " }\r\n" + " ],\r\n" + " \"bornBirthDeatils\": [\r\n" + + " \"Long\"\r\n" + " ],\r\n" + + " \"beneficiaryRegID\":\"Long\",\"firstName\":\"String\",\"lastName\":\"String\",\"\n" + + " \"dob\":\"Timestamp\",\"fatherName\":\"String\",\"spouseName\":\"String\",\"\n" + + " \"govtIdentityNo\":\"String\",\"govtIdentityTypeID\":\"Integer\",\"emergencyRegistration\":\"Boolean\",\"\n" + + " \"maritalstatusId\":\"Short\",\"maritalstatus\":\"String\",\"gender\":\"String\",\"genderId\":\"Integer\",\"i_bendemographics\":{\"educationID\":\"Long\",\"\n" + + " \"beneficiaryRegID\":\"Long\",\"occupationID\":\"Integer\",\"healthCareWorkerID\":\"Short\",\"incomeStatusID\":\"Integer\",\"\n" + + " \"communityID\":\"Integer\",\"preferredLangID\":\"Integer\",\"districtID\":\"Integer\",\"stateID\":\"Integer\",\"\n" + + " \"pinCode\":\"String\",\"blockID\":\"Integer\",\"districtBranchID\":\"Integer\",\"createdBy\":\"String\",\"addressLine1\":\"String\"},\"\n" + + " \"benPhoneMaps\":{\"parentBenRegID\":\"Long\",\"phoneNo\":\"String\",\"phoneTypeID\":\"Integer\",\"benRelationshipID\":\"Integer\",\"\n" + + " \"deleted\":\"Boolean\",\"createdBy\":\"String\"},\"\n" + + " }\r\n" + " ],\r\n" + " \"bornBirthDeatils\": [\r\n" + " {\r\n" + " \"BenRegId\": \"Long\",\r\n" + " \"Countyid\": \"Integer\",\r\n" + " \"Processed\": \"String\",\r\n" + " \"ProviderServiceMapID\": \"Integer\",\r\n" + " \"VanID\": \"Integer\",\r\n" + " \"bcdBatchNo\": \"String\",\r\n" diff --git a/src/main/java/com/iemr/common/identity/repo/rmnch/RMNCHBenDetailsRepo.java b/src/main/java/com/iemr/common/identity/repo/rmnch/RMNCHBenDetailsRepo.java index 028e781..b2bcb29 100644 --- a/src/main/java/com/iemr/common/identity/repo/rmnch/RMNCHBenDetailsRepo.java +++ b/src/main/java/com/iemr/common/identity/repo/rmnch/RMNCHBenDetailsRepo.java @@ -35,4 +35,8 @@ public interface RMNCHBenDetailsRepo extends CrudRepository benDetailsExtraList = Arrays.asList(objArr); + List benDetailsList = new ArrayList<>(); if (benDetailsExtraList != null && benDetailsExtraList.size() > 0) { // benRegID = rMNCHMBenRegIdMapRepo.getRegID(benDetailsExtraList.get(0).getBenficieryid()); @@ -166,14 +167,30 @@ public String syncDataToAmrit(String requestOBJ) throws Exception { } obj.setRelatedBeneficiaryIdsDB(sb.toString()); } - + RMNCHMBeneficiarydetail rmnchmBeneficiarydetail = + rMNCHBenDetailsRepo.getByBenRegID(BigInteger.valueOf(obj.getBenRegId())); + if (rmnchmBeneficiarydetail != null) { + rmnchmBeneficiarydetail.setFirstName(obj.getFirstName()); + rmnchmBeneficiarydetail.setLastName(obj.getLastName()); + rmnchmBeneficiarydetail.setFatherName(obj.getFatherName()); + rmnchmBeneficiarydetail.setMotherName(obj.getMotherName()); + rmnchmBeneficiarydetail.setDob(obj.getDob()); + rmnchmBeneficiarydetail.setSpousename(obj.getSpousename()); + rmnchmBeneficiarydetail.setGender(obj.getGender()); + rmnchmBeneficiarydetail.setGenderId(obj.getGenderId()); + rmnchmBeneficiarydetail.setMaritalstatus(obj.getMaritalstatus()); + rmnchmBeneficiarydetail.setMaritalstatusId(obj.getMaritalstatusId()); + benDetailsList.add(rmnchmBeneficiarydetail); + } } benDetailsExtraList = (ArrayList) rMNCHBeneficiaryDetailsRmnchRepo .save(benDetailsExtraList); benDetailsExtraList.forEach((n) -> beneficiaryDetailsIds.add(n.getId())); + // update beneficiary data in i_beneficiarydetails table + rMNCHBenDetailsRepo.save(benDetailsList); // } else // throw new Exception("invalid/empty beneficiary request data."); From 6d206fb02afb5629bb5c69da2882f42b122b5c3b Mon Sep 17 00:00:00 2001 From: shreypatidar-beehyv Date: Thu, 18 Jan 2024 11:34:21 +0530 Subject: [PATCH 2/3] APIs to get unsynced beneficiaries and count of unsynced beneficiaries - For CHO mobile application (#45) * 1) Modified beneficiary mapping search. 2) Code refactoring. * API modification to fetch beneficiaries based on villageId list instead of single Id. (#5) * Modified API to sync beneficiaries based on villageId list instead of a single villageId. * 1) Added API to get count of Beneficiaries to be synced from server to App so that progress bar can be implemented. (#7) --------- Co-authored-by: roopesh-beehyv <118873622+roopesh-beehyv@users.noreply.github.com> --- .../controller/IdentityController.java | 40 +++++++++++++++---- .../common/identity/dto/SearchSyncDTO.java | 5 ++- .../common/identity/repo/BenMappingRepo.java | 14 ++++--- .../identity/service/IdentityService.java | 28 ++++++++----- 4 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/iemr/common/identity/controller/IdentityController.java b/src/main/java/com/iemr/common/identity/controller/IdentityController.java index e256fd1..e9a4376 100644 --- a/src/main/java/com/iemr/common/identity/controller/IdentityController.java +++ b/src/main/java/com/iemr/common/identity/controller/IdentityController.java @@ -317,9 +317,9 @@ public class IdentityController { // search beneficiary by lastModDate and districtID @CrossOrigin(origins = { "*commonapi*" }) - @ApiOperation(value ="Search beneficiary by blockId and last modified date") - @PostMapping(path = "/searchByDistrictId") - public @ResponseBody String searchBeneficiaryByBlockIdAndLastModDate( + @ApiOperation(value ="Search beneficiary by villageId and last modified date-time") + @PostMapping(path = "/searchByVillageIdAndLastModifiedDate") + public @ResponseBody String searchBeneficiaryByVillageIdAndLastModDate( @ApiParam(value = "\"String\"") @RequestBody String object) { logger.info("IdentityController.getBeneficiary - start. search object = " + object); String response; @@ -328,14 +328,40 @@ public class IdentityController { JsonElement json = new JsonParser().parse(object); SearchSyncDTO search = InputMapper.getInstance().gson().fromJson(json, SearchSyncDTO.class); - List list = svc.searchBeneficiaryByBlockIdAndLastModifyDate(search.getBlockID(), new Timestamp(search.getLastModifDate())); + List list = svc.searchBeneficiaryByVillageIdAndLastModifyDate(search.getVillageID(), new Timestamp(search.getLastModifiedDate())); - response = getSuccessResponseString(list, 200, "success", "getIdentityByAgent"); + response = getSuccessResponseString(list, 200, "success", "getIdentityByVillageAndLastSyncTime"); logger.info("IdentityController.getBeneficiary - end"); } catch (Exception e) { - logger.error("error in beneficiary search by Family Id : " + e.getLocalizedMessage()); - response = getErrorResponseString("error in beneficiary search by block Id : " + e.getLocalizedMessage(), + logger.error("error in beneficiary search by village Ids and last sync date : " + e.getLocalizedMessage()); + response = getErrorResponseString("error in beneficiary search by village Ids and last sync date : " + e.getLocalizedMessage(), + 5000, "failure", ""); + } + return response; + } + + // search beneficiary by lastModDate and districtID + @CrossOrigin(origins = { "*commonapi*" }) + @ApiOperation(value ="Get count of beneficiary by villageId and last modified date-time") + @PostMapping(path = "/countBenByVillageIdAndLastModifiedDate") + public @ResponseBody String countBeneficiaryByVillageIdAndLastModDate( + @ApiParam(value = "\"String\"") @RequestBody String object) { + logger.info("IdentityController.getBeneficiaryCount- start. search object = " + object); + String response; + try { + + JsonElement json = new JsonParser().parse(object); + + SearchSyncDTO search = InputMapper.getInstance().gson().fromJson(json, SearchSyncDTO.class); + Long beneficiaryCount = svc.countBeneficiaryByVillageIdAndLastModifyDate(search.getVillageID(), new Timestamp(search.getLastModifiedDate())); + + response = getSuccessResponseString(String.valueOf(beneficiaryCount), 200, "success", "getIdentityCountByVillageAndLastSyncTime"); + + logger.info("IdentityController.getBeneficiaryCount - end"); + } catch (Exception e) { + logger.error("error in getting beneficiary count by village Ids and last sync date : " + e.getLocalizedMessage()); + response = getErrorResponseString("error in getting beneficiary count by village Ids and last sync date : " + e.getLocalizedMessage(), 5000, "failure", ""); } return response; diff --git a/src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java b/src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java index b224159..45bf61c 100644 --- a/src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java +++ b/src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java @@ -22,11 +22,12 @@ package com.iemr.common.identity.dto; import lombok.Data; +import java.util.List; @Data public class SearchSyncDTO { - private Long lastModifDate; - private Integer blockID; + private Long lastModifiedDate; + private List villageID; } diff --git a/src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java b/src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java index 3154b69..253c73c 100644 --- a/src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java +++ b/src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java @@ -126,10 +126,14 @@ public List getBenMappingByBenDetailsIds(@Param("benDetailsIds") List< public List getBenMappingByVanSerialNo(@Param("benMapIds") BigInteger benMapIds, @Param("vanID") Integer vanID); - @Query(value = "select m from MBeneficiarymapping m where m.mBeneficiaryaddress.permVillageId = :blockID and (m.mBeneficiaryAccount.lastModDate > :lastModDate " - + "or m.mBeneficiaryaddress.lastModDate > :lastModDate or m.mBeneficiaryconsent.lastModDate > :lastModDate " - + "or m.mBeneficiarycontact.lastModDate > :lastModDate or m.mBeneficiarydetail.lastModDate > :lastModDate ) " - + "order by m.benMapId Desc") - List findByBeneficiaryDetailsByBlockIDAndLastModifyDate(@Param("blockID") int blockID, @Param("lastModDate") Timestamp lastModDate); + @Query(value = "select m from MBeneficiarymapping m where m.mBeneficiaryaddress.permVillageId IN :villageIDs and " + + "(m.mBeneficiaryaddress.lastModDate > :lastModDate or m.mBeneficiarycontact.lastModDate > :lastModDate " + + "or m.mBeneficiarydetail.lastModDate > :lastModDate ) order by m.benMapId Desc") + List findByBeneficiaryDetailsByVillageIDAndLastModifyDate(@Param("villageIDs") List villageID, @Param("lastModDate") Timestamp lastModifiedDate); + + @Query(value = "select COUNT(m) from MBeneficiarymapping m where m.mBeneficiaryaddress.permVillageId IN :villageIDs and " + + "(m.mBeneficiaryaddress.lastModDate > :lastModDate or m.mBeneficiarycontact.lastModDate > :lastModDate " + + "or m.mBeneficiarydetail.lastModDate > :lastModDate ) order by m.benMapId Desc") + Long getBeneficiaryCountsByVillageIDAndLastModifyDate(@Param("villageIDs") List villageID, @Param("lastModDate") Timestamp lastModifiedDate); } diff --git a/src/main/java/com/iemr/common/identity/service/IdentityService.java b/src/main/java/com/iemr/common/identity/service/IdentityService.java index dce6bd2..d1315a3 100644 --- a/src/main/java/com/iemr/common/identity/service/IdentityService.java +++ b/src/main/java/com/iemr/common/identity/service/IdentityService.java @@ -24,7 +24,6 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Timestamp; -import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayDeque; import java.util.ArrayList; @@ -508,28 +507,39 @@ public List searhBeneficiaryByFamilyId(String familyId) return beneficiaryList; } - public List searchBeneficiaryByBlockIdAndLastModifyDate(Integer blockID, Timestamp lastModDate) { + public List searchBeneficiaryByVillageIdAndLastModifyDate(List villageIDs, Timestamp lastModifiedDate) { List beneficiaryList = new ArrayList(); try { // find benmap ids - List benMappingsList = mappingRepo.findByBeneficiaryDetailsByBlockIDAndLastModifyDate(blockID, lastModDate); - if (benMappingsList == null || benMappingsList.size() == 0){ - return beneficiaryList; - } - else { + List benMappingsList = mappingRepo.findByBeneficiaryDetailsByVillageIDAndLastModifyDate(villageIDs, lastModifiedDate); + if (benMappingsList != null && !benMappingsList.isEmpty()){ + for (MBeneficiarymapping benMapOBJ : benMappingsList) { beneficiaryList.add(this.getBeneficiariesDTO(benMapOBJ)); } } - } catch (Exception e) { logger.error( - "error in beneficiary search for familyId : " + blockID + " error : " + e.getLocalizedMessage()); + "error in beneficiary search to sync to CHO App with villageIDs: " + villageIDs + " error : " + e.getLocalizedMessage()); } return beneficiaryList; } + public Long countBeneficiaryByVillageIdAndLastModifyDate(List villageIDs, Timestamp lastModifiedDate) { + + Long beneficiaryCount= 0L; + try { + // find benmap ids + beneficiaryCount = mappingRepo.getBeneficiaryCountsByVillageIDAndLastModifyDate(villageIDs, lastModifiedDate); + + } catch (Exception e) { + logger.error( + "error in getting beneficiary count to sync to CHO App with villageIDs: " + villageIDs + " error : " + e.getLocalizedMessage()); + } + return beneficiaryCount; + } + public List searhBeneficiaryByGovIdentity(String identity) throws NoResultException, QueryTimeoutException, Exception { List beneficiaryList = new ArrayList(); From fe8c560e43b0aaa707fd2a8748576868854b32a5 Mon Sep 17 00:00:00 2001 From: indraniBan <133205641+indraniBan@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:34:58 +0530 Subject: [PATCH 3/3] some code logic modified (#55) Co-authored-by: IN40068837 --- .../identity/mapper/IdentityMapper.java | 40 +++++++++---------- .../identity/service/IdentityService.java | 2 - 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/iemr/common/identity/mapper/IdentityMapper.java b/src/main/java/com/iemr/common/identity/mapper/IdentityMapper.java index e3f8f87..7ca320d 100644 --- a/src/main/java/com/iemr/common/identity/mapper/IdentityMapper.java +++ b/src/main/java/com/iemr/common/identity/mapper/IdentityMapper.java @@ -397,28 +397,22 @@ MBeneficiaryfamilymapping identityDTOToMBeneficiaryfamilymapping(BenFamilyDTO be @Mapping(target = "beneficiaryDetails.healthCareWorkerId", source = "map.MBeneficiarydetail.healthCareWorkerId"), @Mapping(target = "beneficiaryDetails.healthCareWorker", source = "map.MBeneficiarydetail.healthCareWorker"), @Mapping(target = "beneficiaryDetails.preferredLanguage", source = "map.MBeneficiarydetail.preferredLanguage"), - // @Mapping(target="beneficiaryDetails.", - // source="map.MBeneficiarydetail.processed"), @Mapping(target = "beneficiaryDetails.religion", source = "map.MBeneficiarydetail.religion"), @Mapping(target = "beneficiaryDetails.remarks", source = "map.MBeneficiarydetail.remarks"), - // @Mapping(target="beneficiaryDetails.", - // source="map.MBeneficiarydetail.reserved"), - // @Mapping(target="beneficiaryDetails.", - // source="map.MBeneficiarydetail.reservedById"), - // @Mapping(target="beneficiaryDetails.", - // source="map.MBeneficiarydetail.reservedFor"), - // @Mapping(target="beneficiaryDetails.", - // source="map.MBeneficiarydetail.reservedOn"), @Mapping(target = "beneficiaryDetails.servicePointId", source = "map.MBeneficiarydetail.servicePointId"), @Mapping(target = "beneficiaryDetails.sourceOfInfo", source = "map.MBeneficiarydetail.sourceOfInfo"), @Mapping(target = "beneficiaryDetails.spouseName", source = "map.MBeneficiarydetail.spouseName"), @Mapping(target = "beneficiaryDetails.status", source = "map.MBeneficiarydetail.status"), @Mapping(target = "beneficiaryDetails.title", source = "map.MBeneficiarydetail.title"), @Mapping(target = "beneficiaryDetails.zoneId", source = "map.MBeneficiarydetail.zoneId"), - @Mapping(target = "contacts", expression = "java( Phone.createContactList(map.getMBeneficiarycontact(), " - + "benRegId.toString(), map.getMBeneficiarydetail().getFirstName() + \" \" + " - + "map.getMBeneficiarydetail().getMiddleName() + \" \" + " - + "map.getMBeneficiarydetail().getLastName()))"), + @Mapping(target = "contacts", expression = "java( map != null && map.getMBeneficiarycontact() != null && " + + "map.getMBeneficiarydetail() != null ? " + + "Phone.createContactList(map.getMBeneficiarycontact(), " + + "(benRegId != null ? benRegId.toString() : null), " + + "(map.getMBeneficiarydetail().getFirstName() != null ? map.getMBeneficiarydetail().getFirstName() : \"\") + \" \" + " + + "(map.getMBeneficiarydetail().getMiddleName() != null ? map.getMBeneficiarydetail().getMiddleName() : \"\") + \" \" + " + + "(map.getMBeneficiarydetail().getLastName() != null ? map.getMBeneficiarydetail().getLastName() : \"\") " + + ") : null)"), /* * New columns added for MMU integration 09-04-2018 @@ -452,12 +446,14 @@ MBeneficiaryfamilymapping identityDTOToMBeneficiaryfamilymapping(BenFamilyDTO be @Mapping(target = "ifscCode", source = "map.MBeneficiaryAccount.ifscCode"), @Mapping(target = "accountNo", source = "map.MBeneficiaryAccount.accountNo"), @Mapping(target = "benAccountID", source = "map.benAccountID"), - @Mapping(target = "ageAtMarriage", expression = "java(MBeneficiarydetail.getAgeAtMarriageCalc(" - + "map.getMBeneficiarydetail().getDob(), map.getMBeneficiarydetail().getMarriageDate(), " - + "map.getMBeneficiarydetail().getAgeAtMarriage()))"), - @Mapping(target = "marriageDate", expression = "java(MBeneficiarydetail.getMarriageDateCalc(" - + "map.getMBeneficiarydetail().getDob(), map.getMBeneficiarydetail().getMarriageDate(), " - + "map.getMBeneficiarydetail().getAgeAtMarriage()))"), + @Mapping(target = "ageAtMarriage", expression = "java(map != null && map.getMBeneficiarydetail() != null ? " + + "MBeneficiarydetail.getAgeAtMarriageCalc(map.getMBeneficiarydetail().getDob(), " + + "map.getMBeneficiarydetail().getMarriageDate(), " + + "map.getMBeneficiarydetail().getAgeAtMarriage()) : null)"), + @Mapping(target = "marriageDate", expression = "java(map != null && map.getMBeneficiarydetail() != null ? " + + "MBeneficiarydetail.getMarriageDateCalc(map.getMBeneficiarydetail().getDob(), " + + "map.getMBeneficiarydetail().getMarriageDate(), " + + "map.getMBeneficiarydetail().getAgeAtMarriage()) : null)"), @Mapping(target = "literacyStatus", source = "map.MBeneficiarydetail.literacyStatus"), @Mapping(target = "motherName", source = "map.MBeneficiarydetail.motherName"), @@ -483,8 +479,8 @@ MBeneficiaryfamilymapping identityDTOToMBeneficiaryfamilymapping(BenFamilyDTO be @Mapping(target = "beneficiaryDetails.headOfFamily_Relation", source = "map.MBeneficiarydetail.headOfFamily_Relation"), // Start 1097 - @Mapping(expression = "java(MBeneficiarydetail.calculateAge(map.getMBeneficiarydetail().getDob()))", target = "beneficiaryAge"), - // End 1097 + @Mapping(expression = "java(map != null && map.getMBeneficiarydetail() != null ? MBeneficiarydetail.calculateAge(map.getMBeneficiarydetail().getDob()) : null)", target = "beneficiaryAge")// End 1097 + }) BeneficiariesDTO mBeneficiarymappingToBeneficiariesDTO(MBeneficiarymapping map); diff --git a/src/main/java/com/iemr/common/identity/service/IdentityService.java b/src/main/java/com/iemr/common/identity/service/IdentityService.java index d1315a3..dff5c16 100644 --- a/src/main/java/com/iemr/common/identity/service/IdentityService.java +++ b/src/main/java/com/iemr/common/identity/service/IdentityService.java @@ -1424,7 +1424,6 @@ public void editIdentityEducationOrCommunity(IdentityEditDTO identity) throws Mi identity.getEducationId()); } } - } public int importBenIdToLocalServer(List benIdImportDTOList) { @@ -1457,7 +1456,6 @@ public int importBenIdToLocalServer(List benIdImportDTOList) { return i.length; } else return 0; - } public Long checkBenIDAvailabilityLocal() {