Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile app changes #51

Merged
merged 11 commits into from
Jan 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ public String searhBeneficiaryByFamilyId(

// search beneficiary by lastModDate and districtID
@CrossOrigin(origins = { "*commonapi*" })
@Operation(summary ="Search beneficiary by blockId and last modified date")
@PostMapping(path = "/searchByDistrictId")
public String searchBeneficiaryByBlockIdAndLastModDate(
@Operation(summary ="Search beneficiary by villageId and last modified date-time")
@PostMapping(path = "/searchByVillageIdAndLastModifiedDate")
public String searchBeneficiaryByVillageIdAndLastModDate(
@Param(value = "\"String\"") @RequestBody String object) {
logger.info("IdentityController.getBeneficiary - start. search object = " + object);
String response;
Expand All @@ -308,19 +308,39 @@ public String searchBeneficiaryByBlockIdAndLastModDate(
JsonElement json = JsonParser.parseString(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*" })
@Operation(summary ="Get count of beneficiary by villageId and last modified date-time")
@PostMapping(path = "/countBenByVillageIdAndLastModifiedDate")
public String countBeneficiaryByVillageIdAndLastModDate(
@Param(value = "\"String\"") @RequestBody String object) {
String response;
try {

JsonElement json = JsonParser.parseString(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;
}
@CrossOrigin(origins = { "*commonapi*" })
@Operation(summary = "Search beneficiary based on government identity number")
@PostMapping(path = "/searhByGovIdentity", headers = "Authorization")
Expand All @@ -343,7 +363,7 @@ public String searhBeneficiaryByGovIdentity(

logger.info("IdentityController.getBeneficiary - end");
} catch (Exception e) {
logger.error("error in beneficiary search by Gov Identity No : " + e.getLocalizedMessage());
logger.error("error in beneficiary search by Gov Identity No : {} " , e.getLocalizedMessage());
response = getErrorResponseString(
"error in beneficiary search by GovIdentity No : " + e.getLocalizedMessage(), 5000, "failure", "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,77 +56,16 @@ public class RMNCHMobileAppController {

@PostMapping(value = "/syncDataToAmrit", consumes = "application/json", produces = "application/json")
@Operation(summary = "Sync data to AMRIT for already regestered beneficiary with AMRIT beneficiary id ")
public String syncDataToAmrit(@Param(value = "{\r\n" + " \"beneficiaryDetails\": [\r\n" + " {\r\n"
+ " \"BenRegId\": \"Long\",\r\n" + " \"Countyid\": \"Integer\",\r\n"
+ " \"Processed\": \"String\",\r\n" + " \"ProviderServiceMapID\": \"Integer\",\r\n"
+ " \"VanID\": \"Integer\",\r\n" + " \"aadhaNo\": \"String\",\r\n"
+ " \"aadha_noId\": \"Integer\",\r\n" + " \"age\": \"Integer\",\r\n"
+ " \"age_unit\": \"String\",\r\n" + " \"age_unitId\": \"Integer\",\r\n"
+ " \"bankAccount\": \"String\",\r\n" + " \"bank_accountId\": \"Integer\",\r\n"
+ " \"benficieryid\": \"Long\",\r\n" + " \"childRegisteredAWCID\": \"Long\",\r\n"
+ " \"childRegisteredSchoolID\": \"Integer\",\r\n" + " \"createdBy\": \"String\",\r\n"
+ " \"createdDate\": \"Timestamp\",\r\n" + " \"currSubDistrictId\": \"Integer\",\r\n"
+ " \"facilitySectionID\": \"Integer\",\r\n" + " \"familyHeadRelation\": \"String\",\r\n"
+ " \"familyHeadRelationPosition\": \"Integer\",\r\n" + " \"guidelineId\": \"String\",\r\n"
+ " \"houseoldId\": \"Long\",\r\n" + " \"id\": \"Long\",\r\n"
+ " \"ifscCode\": \"String\",\r\n" + " \"lastDeliveryConductedID\": \"Integer\",\r\n"
+ " \"latitude\": \"Decimal\",\r\n" + " \"lengthofMenstrualCycleId\": \"Integer\",\r\n"
+ " \"literacyId\": \"Integer\",\r\n" + " \"longitude\": \"Decimal\",\r\n"
+ " \"marriageDate\": \"Timestamp\",\r\n" + " \"menstrualBFDId\": \"Integer\",\r\n"
+ " \"menstrualProblemId\": \"Integer\",\r\n" + " \"menstrualStatusId\": \"Integer\",\r\n"
+ " \"mobileOthers\": \"String\",\r\n" + " \"mobilenoofRelation\": \"String\",\r\n"
+ " \"mobilenoofRelationId\": \"Integer\",\r\n" + " \"nameOfBank\": \"String\",\r\n"
+ " \"ncd_priority\": \"Integer\",\r\n" + " \"need_opcareId\": \"Integer\",\r\n"
+ " \"previousLiveBirth\": \"String\",\r\n" + " \"rchid\": \"String\",\r\n"
+ " \"registrationDate\": \"Timestamp\",\r\n" + " \"registrationType\": \"String\",\r\n"
+ " \"regularityofMenstrualCycleId\": \"Integer\",\r\n" + " \"religionOthers\": \"String\",\r\n"
+ " \"reproductiveStatus\": \"String\",\r\n" + " \"reproductiveStatusId\": \"Integer\",\r\n"
+ " \"serverUpdatedStatus\": \"Integer\",\r\n" + " \"typeofSchoolID\": \"Integer\",\r\n"
+ " \"villagename\": \"String\",\r\n" + " \"whoConductedDeliveryID\": \"Integer\",\r\n"
+ " \"hrpStatus\": \"Boolean\",\r\n" + " \"immunization\": \"Boolean\",\r\n"
+ " \"nishchayPregnancyStatus\": \"String\",\r\n"
+ " \"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"
+ " {\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"
+ " \"benficieryid\": \"Integer\",\r\n" + " \"birthDefects\": \"String\",\r\n"
+ " \"birthDefectsOthers\": \"String\",\r\n" + " \"birthDefectsid\": \"Integer\",\r\n"
+ " \"birthDosage\": \"String\",\r\n" + " \"birthDosageid\": \"Integer\",\r\n"
+ " \"birthPlace\": \"String\",\r\n" + " \"birthPlaceid\": \"Integer\",\r\n"
+ " \"childName\": \"String\",\r\n" + " \"complecations\": \"String\",\r\n"
+ " \"complecationsOther\": \"String\",\r\n" + " \"complecationsid\": \"Integer\",\r\n"
+ " \"conductedDelivery\": \"String\",\r\n" + " \"conductedDeliveryOther\": \"String\",\r\n"
+ " \"conductedDeliveryid\": \"Integer\",\r\n"
+ " \"corticosteroidGivenMotherid\": \"Integer\",\r\n" + " \"createdBy\": \"String\",\r\n"
+ " \"createdDate\": \"Timestamp\",\r\n" + " \"criedImmediately\": \"String\",\r\n"
+ " \"criedImmediatelyid\": \"Integer\",\r\n" + " \"deliveryType\": \"String\",\r\n"
+ " \"deliveryTypeOther\": \"String\",\r\n" + " \"deliveryTypeid\": \"Integer\",\r\n"
+ " \"districtid\": \"Integer\",\r\n" + " \"districtname\": \"String\",\r\n"
+ " \"facilityOther\": \"String\",\r\n" + " \"facilityid\": \"Integer\",\r\n"
+ " \"feedingStarted\": \"String\",\r\n" + " \"feedingStartedid\": \"Integer\",\r\n"
+ " \"gestationalAgeid\": \"Integer\",\r\n" + " \"heightAtBirth\": \"Integer\",\r\n"
+ " \"hptdBatchNo\": \"String\",\r\n" + " \"id\": \"Integer\",\r\n"
+ " \"motherBenId\": \"Integer\",\r\n" + " \"motherName\": \"String\",\r\n"
+ " \"motherposition\": \"Integer\",\r\n" + " \"opvBatchNo\": \"String\",\r\n"
+ " \"placeName\": \"String\",\r\n" + " \"serverUpdatedStatus\": \"Integer\",\r\n"
+ " \"stateid\": \"Integer\",\r\n" + " \"term\": \"String\",\r\n"
+ " \"termid\": \"Integer\",\r\n" + " \"villageid\": \"Integer\",\r\n"
+ " \"vitaminkBatchNo\": \"String\",\r\n" + " \"weightAtBirth\": \"Decimal\"\r\n" + " }\r\n"
+ " ]\r\n" + "}") @RequestBody String requestOBJ) {
public String syncDataToAmrit(@RequestBody String requestOBJ) {
OutputResponse response = new OutputResponse();
try {
if (requestOBJ != null) {
logger.info("request object with timestamp : " + new Timestamp(System.currentTimeMillis()) + " "
+ requestOBJ);
String s = rmnchDataSyncService.syncDataToAmrit(requestOBJ);
response.setResponse(s);
} else
response.setError(5000, "Invalid/NULL request obj");
} catch (Exception e) {
logger.error("Error in RMNCH mobile data sync : " + e);
logger.error("Error in RMNCH mobile data sync : {} " , e.getMessage());
response.setError(5000, "Error in RMNCH mobile data sync : " + e);
}
return response.toString();
Expand Down
6 changes: 4 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 @@ -21,12 +21,14 @@
*/
package com.iemr.common.identity.dto;

import java.util.List;

import lombok.Data;

@Data
public class SearchSyncDTO {

private Long lastModifDate;
private Integer blockID;
private Long lastModifiedDate;
private List<Integer> villageID;

}
15 changes: 9 additions & 6 deletions src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ 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);

List<MBeneficiarymapping> dynamicFilterSearch(IdentitySearchDTO searchDTO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public interface RMNCHBenDetailsRepo extends CrudRepository<RMNCHMBeneficiarydet
@Query(" SELECT t FROM RMNCHMBeneficiarydetail t WHERE t.id = :vanSerialNo AND t.VanID = :vanID")
public RMNCHMBeneficiarydetail getByIdAndVanID(@Param("vanSerialNo") BigInteger vanSerialNo,
@Param("vanID") int vanID);

@Query(" SELECT t FROM RMNCHMBeneficiarydetail t WHERE t.id = " +
"(SELECT m.benDetailsId from RMNCHMBeneficiarymapping m where m.benRegId = :beneficiaryRegID)")
public RMNCHMBeneficiarydetail getByBenRegID(@Param("beneficiaryRegID") BigInteger beneficiaryRegID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -505,28 +505,35 @@ 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<>();
try {
// find benmap ids
List<MBeneficiarymapping> benMappingsList = mappingRepo.findByBeneficiaryDetailsByBlockIDAndLastModifyDate(blockID, lastModDate);
if (benMappingsList == null || benMappingsList.isEmpty()){
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 {
beneficiaryCount = mappingRepo.getBeneficiaryCountsByVillageIDAndLastModifyDate(villageIDs,
lastModifiedDate);
} catch (Exception e) {
logger.error("error in getting beneficiary count to sync to CHO App with villageIDs: {},error :{} " , villageIDs ,e.getLocalizedMessage());
}
return beneficiaryCount;
}
public List<BeneficiariesDTO> searhBeneficiaryByGovIdentity(String identity)
throws NoResultException, QueryTimeoutException {
List<BeneficiariesDTO> beneficiaryList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public String syncDataToAmrit(String requestOBJ) throws Exception {
RMNCHBeneficiaryDetailsRmnch[] objArr = InputMapper.gson()
.fromJson(jsnOBJ.get("beneficiaryDetails"), RMNCHBeneficiaryDetailsRmnch[].class);
List<RMNCHBeneficiaryDetailsRmnch> benDetailsExtraList = Arrays.asList(objArr);

List<RMNCHMBeneficiarydetail> benDetailsList = new ArrayList<>();
if (benDetailsExtraList != null && benDetailsExtraList.size() > 0) {
// benRegID = rMNCHMBenRegIdMapRepo.getRegID(benDetailsExtraList.get(0).getBenficieryid());
//
Expand All @@ -166,16 +166,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<RMNCHBeneficiaryDetailsRmnch>) rMNCHBeneficiaryDetailsRmnchRepo
.saveAll(benDetailsExtraList);

benDetailsExtraList.forEach((n) -> beneficiaryDetailsIds.add(n.getId()));
// } else
// throw new Exception("invalid/empty beneficiary request data.");
// update beneficiary data in i_beneficiarydetails table
rMNCHBenDetailsRepo.saveAll(benDetailsList);

// born birth details
if (jsnOBJ != null && jsnOBJ.has("bornBirthDeatils")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ void testSearchBeneficiaryByBlockIdAndLastModDate() {
SearchSyncDTO searchSyncDTO = new SearchSyncDTO();
String req = new Gson().toJson(searchSyncDTO);
//when(svc.searchBeneficiaryByBlockIdAndLastModifyDate(any(), any())).thenReturn(bdList);
String resp = identityController.searchBeneficiaryByBlockIdAndLastModDate(req);

String resp = identityController.searchBeneficiaryByVillageIdAndLastModDate(req);

Assertions.assertNotNull(resp);
//Assertions.assertThrows(Exception.class, () ->
}
Expand Down
Loading