Skip to content
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why you changed searchByDistrictId endpoint to searchByVillageIdAndLastModifiedDate
because of searchByDistrictId already we are using in WHC API.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is an API that returns the list of beneficiaries based on a list of village IDs and the last sync date time. It is used to sync beneficiaries for the CHO Android mobile application. Since this and the upstream APIs (In HWC-API) using this endpoint were created by our team and required some changes i.e. why did the modifications as well as the name change .
As for the HWC-API, this endpoint has also been updated there in the properties files.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -328,14 +328,40 @@ public class IdentityController {
JsonElement json = new JsonParser().parse(object);

SearchSyncDTO search = InputMapper.getInstance().gson().fromJson(json, SearchSyncDTO.class);
List<BeneficiariesDTO> list = svc.searchBeneficiaryByBlockIdAndLastModifyDate(search.getBlockID(), new Timestamp(search.getLastModifDate()));
List<BeneficiariesDTO> 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;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> villageID;

}
14 changes: 9 additions & 5 deletions src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,14 @@ public List<Object[]> getBenMappingByBenDetailsIds(@Param("benDetailsIds") List<
public List<Object[]> 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<MBeneficiarymapping> 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<MBeneficiarymapping> findByBeneficiaryDetailsByVillageIDAndLastModifyDate(@Param("villageIDs") List<Integer> 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<Integer> villageID, @Param("lastModDate") Timestamp lastModifiedDate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -508,28 +507,39 @@ public List<BeneficiariesDTO> searhBeneficiaryByFamilyId(String familyId)
return beneficiaryList;
}

public List<BeneficiariesDTO> searchBeneficiaryByBlockIdAndLastModifyDate(Integer blockID, Timestamp lastModDate) {
public List<BeneficiariesDTO> searchBeneficiaryByVillageIdAndLastModifyDate(List<Integer> villageIDs, Timestamp lastModifiedDate) {

List<BeneficiariesDTO> beneficiaryList = new ArrayList<BeneficiariesDTO>();
try {
// find benmap ids
List<MBeneficiarymapping> benMappingsList = mappingRepo.findByBeneficiaryDetailsByBlockIDAndLastModifyDate(blockID, lastModDate);
if (benMappingsList == null || benMappingsList.size() == 0){
return beneficiaryList;
}
else {
List<MBeneficiarymapping> 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<Integer> 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<BeneficiariesDTO> searhBeneficiaryByGovIdentity(String identity)
throws NoResultException, QueryTimeoutException, Exception {
List<BeneficiariesDTO> beneficiaryList = new ArrayList<BeneficiariesDTO>();
Expand Down