Skip to content

Commit

Permalink
1) Modified beneficiary mapping search.
Browse files Browse the repository at this point in the history
2) Code refactoring.
  • Loading branch information
shreypatidar-beehyv committed Sep 8, 2023
1 parent 1d442c3 commit f087c98
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
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,14 @@ 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(),
response = getErrorResponseString("error in beneficiary search by village Id and last sync date : " + e.getLocalizedMessage(),
5000, "failure", "");
}
return response;
Expand Down
4 changes: 2 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 @@ -26,7 +26,7 @@
@Data
public class SearchSyncDTO {

private Long lastModifDate;
private Integer blockID;
private Long lastModifiedDate;
private Integer villageID;

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ 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 = :villageID and "
+ "(m.mBeneficiaryaddress.lastModDate > :lastModDate or m.mBeneficiarycontact.lastModDate > :lastModDate "
+ "or m.mBeneficiarydetail.lastModDate > :lastModDate ) order by m.benMapId Desc")
List<MBeneficiarymapping> findByBeneficiaryDetailsByVillageIDAndLastModifyDate(@Param("villageID") int 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,25 +507,21 @@ public List<BeneficiariesDTO> searhBeneficiaryByFamilyId(String familyId)
return beneficiaryList;
}

public List<BeneficiariesDTO> searchBeneficiaryByBlockIdAndLastModifyDate(Integer blockID, Timestamp lastModDate) {
public List<BeneficiariesDTO> searchBeneficiaryByVillageIdAndLastModifyDate(Integer villageID, 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(villageID, lastModifiedDate);
if (benMappingsList != null && !benMappingsList.isEmpty()){

for (MBeneficiarymapping benMapOBJ : benMappingsList) {
beneficiaryList.add(this.getBeneficiariesDTO(benMapOBJ));
}
}

} catch (Exception e) {
e.printStackTrace();
logger.error(
"error in beneficiary search for familyId : " + blockID + " error : " + e.getLocalizedMessage());
"error in beneficiary search to sync to CHO App with villageID: " + villageID + " error : " + e.getLocalizedMessage());
}
return beneficiaryList;
}
Expand Down

0 comments on commit f087c98

Please sign in to comment.