Skip to content

Commit

Permalink
Merge pull request #2 from beehyv/develop_babs
Browse files Browse the repository at this point in the history
Implementing Basic reverse sync operation
  • Loading branch information
roopesh-beehyv authored Aug 17, 2023
2 parents 26f807b + c3611d9 commit 1cd247c
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.lang.reflect.Type;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -31,6 +32,7 @@
import javax.persistence.NoResultException;
import javax.persistence.QueryTimeoutException;

import com.iemr.common.identity.dto.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -52,14 +54,6 @@
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.iemr.common.identity.domain.MBeneficiarymapping;
import com.iemr.common.identity.dto.BenIdImportDTO;
import com.iemr.common.identity.dto.BeneficiariesDTO;
import com.iemr.common.identity.dto.BeneficiariesPartialDTO;
import com.iemr.common.identity.dto.BeneficiaryCreateResp;
import com.iemr.common.identity.dto.IdentityDTO;
import com.iemr.common.identity.dto.IdentityEditDTO;
import com.iemr.common.identity.dto.IdentitySearchDTO;
import com.iemr.common.identity.dto.ReserveIdentityDTO;
import com.iemr.common.identity.exception.MissingMandatoryFieldsException;
import com.iemr.common.identity.mapper.IdentityMapper;
import com.iemr.common.identity.mapper.InputMapper;
Expand Down Expand Up @@ -309,6 +303,32 @@ public class IdentityController {
return response;
}

// search beneficiary by lastModDate and districtID
@CrossOrigin(origins = { "*commonapi*" })
// @PostMapping(path = "/searchByDistrictId", headers = "Authorization")
@PostMapping(path = "/searchByDistrictId")
public @ResponseBody String searchBeneficiaryByBlockIdAndLastModDate(
@ApiParam(value = "\"String\"") @RequestBody String object) {
logger.info("IdentityController.getBeneficiary - start. search object = " + object);
String response;
try {

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()));

response = getSuccessResponseString(list, 200, "success", "getIdentityByAgent");

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(),
5000, "failure", "");
}
return response;
}

// search beneficiary by gov identity - aadhar, pan, voter id etc
@CrossOrigin(origins = { "*commonapi*" })
@PostMapping(path = "/searhByGovIdentity", headers = "Authorization")
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.dto;

import lombok.Data;

@Data
public class SearchSyncDTO {

private Long lastModifDate;
private Integer blockID;

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package com.iemr.common.identity.repo;

import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
Expand Down Expand Up @@ -125,4 +126,10 @@ 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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,29 @@ public List<BeneficiariesDTO> searhBeneficiaryByFamilyId(String familyId)
return beneficiaryList;
}

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

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 {
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());
}
return beneficiaryList;
}

public List<BeneficiariesDTO> searhBeneficiaryByGovIdentity(String identity)
throws NoResultException, QueryTimeoutException, Exception {
List<BeneficiariesDTO> beneficiaryList = new ArrayList<BeneficiariesDTO>();
Expand Down

0 comments on commit 1cd247c

Please sign in to comment.