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

AMM-1076 and AMM-1078 #146

Merged
merged 15 commits into from
Jan 7, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public void detailedCallReport() {
for (DetailedCallReport detailedCallReport : findByCallStartTimeBetween) {
String phoneNo = detailedCallReport.getPHONE();
String sessionID = detailedCallReport.getSession_ID();
if(null != phoneNo && phoneNo.length()>10) {
phoneNo = phoneNo.replaceFirst("^0+", "");
}
BeneficiaryCall existRecord = callReportRepo.getBenCallDetailsBySessionIDAndPhone(sessionID,phoneNo);
if (existRecord != null) {
logger.info("Record already present in t_bencall table with sessionID : " + sessionID
Expand Down Expand Up @@ -150,7 +153,10 @@ private Integer getCallTypeId(Boolean isOutbound, Integer calledServiceId, Detai
private BeneficiaryCall getCallDetail(DetailedCallReport detailedCallReport) {
BeneficiaryCall beneficiaryCall = new BeneficiaryCall();
beneficiaryCall.setCallID(detailedCallReport.getSession_ID());
beneficiaryCall.setPhoneNo(detailedCallReport.getPHONE());
String phoneNo = detailedCallReport.getPHONE();
if(null != phoneNo && phoneNo.length()>10)
phoneNo = phoneNo.replaceFirst("^0+", "");
beneficiaryCall.setPhoneNo(phoneNo);
beneficiaryCall.setCalledServiceID(null);
beneficiaryCall.setRemarks("missed records - Failure");
beneficiaryCall.setIs1097(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public class CommonIdentityDTO {
@Expose
private Boolean beneficiaryConsent;
private String otherFields;
private String religionName;

// private Object otherFields;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,16 @@ public class BeneficiaryModel implements Comparable<BeneficiaryModel> {
@Expose
private String occupationName;
@Expose
private String occupation;
@Expose
private String incomeStatus;
@Expose
private BigInteger religionId;
@Expose
private String religion;
@Expose
private String education;
@Expose
private Integer providerServiceMapID;

@Expose
Expand Down Expand Up @@ -285,6 +289,8 @@ public class BeneficiaryModel implements Comparable<BeneficiaryModel> {
@Expose
private Boolean passToNurse = false;
private String otherFields;
@Expose
private String religionName;

// private Object otherFields;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface CallReportRepo extends CrudRepository<BeneficiaryCall, Integer>
+ "and report.createdDate >= :startDate and report.createdDate <= :endDate ")
public List<BeneficiaryCall> getAllBenCallIDetails(@Param("startDate") Timestamp startDate, @Param("endDate") Timestamp endDate);//start date and end date as param for x days.

@Query("SELECT call FROM BeneficiaryCall call WHERE call.callID = :sessionID and call.phoneNo = :phoneNo")
@Query("SELECT call FROM BeneficiaryCall call WHERE call.callID = :sessionID and call.phoneNo like %:phoneNo%")
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 2, 2025

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Consider clarifying matching requirements and potential performance trade-offs.

Switching from = to LIKE broadens the match criteria, which may risk unintended matches or degrade performance if the underlying column lacks an appropriate index. Evaluate whether partial matches are truly desired, and if so, ensure that phone numbers are sanitized and indexed appropriately to mitigate performance and accuracy concerns.

Copy link
Member Author

Choose a reason for hiding this comment

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

CTI server is maintaining 0 before the phone number resulting false for every search from our server Hence using like operator to match phonenumber
@coderabbitai

Copy link
Contributor

Choose a reason for hiding this comment

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

@ravishanigarapu I understand now - the LIKE operator is necessary to handle the phone number format discrepancy between the CTI server (which prepends zeros) and your server. Thank you for the clarification.


✏️ Learnings added
Learnt from: ravishanigarapu
PR: PSMRI/Common-API#146
File: src/main/java/com/iemr/common/repository/report/CallReportRepo.java:45-45
Timestamp: 2025-01-07T11:10:32.956Z
Learning: The CTI server prepends '0' to phone numbers, requiring the use of LIKE operator instead of exact matching (=) when comparing phone numbers between CTI server and application server data.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

public BeneficiaryCall getBenCallDetailsBySessionIDAndPhone(@Param("sessionID") String sessionID,@Param("phoneNo") String phoneNo);

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,15 @@ public List<BeneficiaryModel> getBeneficiaryListFromMapper(List<BeneficiariesDTO
benDetailForOutboundDTOList.forEach(beneficiaryModel -> {

BeneficiaryModel beneficiary = benCompleteMapper.benDetailForOutboundDTOToIBeneficiary(beneficiaryModel);
if(null != beneficiaryModel.getBeneficiaryDetails() && null != beneficiaryModel.getBeneficiaryDetails().getCommunity())
if(null != beneficiaryModel && null != beneficiaryModel.getBeneficiaryDetails()) {
beneficiary.setCommunityName(beneficiaryModel.getBeneficiaryDetails().getCommunity());
beneficiary.setReligion(beneficiaryModel.getBeneficiaryDetails().getReligion());
beneficiary.setReligionName(beneficiaryModel.getBeneficiaryDetails().getReligion());
beneficiary.setOccupationName(beneficiaryModel.getBeneficiaryDetails().getOccupation());
beneficiary.setOccupation(beneficiaryModel.getBeneficiaryDetails().getOccupation());
beneficiary.setEducation(beneficiaryModel.getBeneficiaryDetails().getEducation());
beneficiary.setIncomeStatus(beneficiaryModel.getBeneficiaryDetails().getIncomeStatus());
}
if (beneficiary.getAge() == null) {
beneficiary.setAge(beneficiary.getActualAge());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ public Integer updateBenificiary(BeneficiaryModel benificiaryDetails, String aut
Integer updatedRows = 0;

IdentityEditDTO identityEditDTO = identityBenEditMapper.BenToIdentityEditMapper(benificiaryDetails);
if(null != benificiaryDetails.getI_bendemographics()) {
identityEditDTO.setCommunity(benificiaryDetails.getI_bendemographics().getCommunityName());
identityEditDTO.setCommunityName(benificiaryDetails.getI_bendemographics().getCommunityName());
}
setDemographicDetails(identityEditDTO,benificiaryDetails);

if (benificiaryDetails.getBeneficiaryIdentities() != null
&& benificiaryDetails.getBeneficiaryIdentities().size() > 0) {
identityEditDTO.setIdentities(Identity.createIdentity(benificiaryDetails.getBeneficiaryIdentities(),
Expand All @@ -132,6 +130,29 @@ public Integer updateBenificiary(BeneficiaryModel benificiaryDetails, String aut
return updatedRows;
}

private void setDemographicDetails(IdentityEditDTO identityEditDTO, BeneficiaryModel benificiaryDetails) {
if(null != benificiaryDetails.getI_bendemographics()) {
identityEditDTO.setCommunity(benificiaryDetails.getI_bendemographics().getCommunityName());
identityEditDTO.setCommunityName(benificiaryDetails.getI_bendemographics().getCommunityName());
if(null != benificiaryDetails.getReligion())
identityEditDTO.setReligion(benificiaryDetails.getReligion());
else if(null != benificiaryDetails.getI_bendemographics().getReligion())
identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligion());
else
identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligionName());
if(null != benificiaryDetails.getOccupation())
identityEditDTO.setOccupationName(benificiaryDetails.getOccupation());
else
identityEditDTO.setOccupationName(benificiaryDetails.getI_bendemographics().getOccupation());
identityEditDTO.setEducation(benificiaryDetails.getI_bendemographics().getEducationName());
if(null != benificiaryDetails.getIncomeStatus())
identityEditDTO.setIncomeStatus(benificiaryDetails.getIncomeStatus());
else
identityEditDTO.setIncomeStatus(benificiaryDetails.getI_bendemographics().getIncomeStatus());
}

}
Comment on lines +133 to +154
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add consistent null checks to prevent NPEs.

The method has several potential null pointer issues:

  1. Missing null check for educationName on line 147
  2. Complex nested logic for religion field could be simplified

Consider this safer implementation:

 private void setDemographicDetails(IdentityEditDTO identityEditDTO, BeneficiaryModel benificiaryDetails) {
     if(null != benificiaryDetails.getI_bendemographics()) {
         BeneficiaryDemographicsModel demographics = benificiaryDetails.getI_bendemographics();
         
         String communityName = demographics.getCommunityName();
         if(communityName != null) {
             identityEditDTO.setCommunity(communityName);
             identityEditDTO.setCommunityName(communityName);
         }
         
         // Simplified religion logic
         String religion = benificiaryDetails.getReligion();
         if(religion == null) {
             religion = demographics.getReligion();
             if(religion == null) {
                 religion = demographics.getReligionName();
             }
         }
         identityEditDTO.setReligion(religion);
         
         String occupation = benificiaryDetails.getOccupation();
         identityEditDTO.setOccupationName(occupation != null ? occupation : demographics.getOccupation());
         
         String education = demographics.getEducationName();
         if(education != null) {
             identityEditDTO.setEducation(education);
         }
         
         String incomeStatus = benificiaryDetails.getIncomeStatus();
         identityEditDTO.setIncomeStatus(incomeStatus != null ? incomeStatus : demographics.getIncomeStatus());
     }
 }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private void setDemographicDetails(IdentityEditDTO identityEditDTO, BeneficiaryModel benificiaryDetails) {
if(null != benificiaryDetails.getI_bendemographics()) {
identityEditDTO.setCommunity(benificiaryDetails.getI_bendemographics().getCommunityName());
identityEditDTO.setCommunityName(benificiaryDetails.getI_bendemographics().getCommunityName());
if(null != benificiaryDetails.getReligion())
identityEditDTO.setReligion(benificiaryDetails.getReligion());
else if(null != benificiaryDetails.getI_bendemographics().getReligion())
identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligion());
else
identityEditDTO.setReligion(benificiaryDetails.getI_bendemographics().getReligionName());
if(null != benificiaryDetails.getOccupation())
identityEditDTO.setOccupationName(benificiaryDetails.getOccupation());
else
identityEditDTO.setOccupationName(benificiaryDetails.getI_bendemographics().getOccupation());
identityEditDTO.setEducation(benificiaryDetails.getI_bendemographics().getEducationName());
if(null != benificiaryDetails.getIncomeStatus())
identityEditDTO.setIncomeStatus(benificiaryDetails.getIncomeStatus());
else
identityEditDTO.setIncomeStatus(benificiaryDetails.getI_bendemographics().getIncomeStatus());
}
}
private void setDemographicDetails(IdentityEditDTO identityEditDTO, BeneficiaryModel benificiaryDetails) {
if(null != benificiaryDetails.getI_bendemographics()) {
BeneficiaryDemographicsModel demographics = benificiaryDetails.getI_bendemographics();
String communityName = demographics.getCommunityName();
if(communityName != null) {
identityEditDTO.setCommunity(communityName);
identityEditDTO.setCommunityName(communityName);
}
// Simplified religion logic
String religion = benificiaryDetails.getReligion();
if(religion == null) {
religion = demographics.getReligion();
if(religion == null) {
religion = demographics.getReligionName();
}
}
identityEditDTO.setReligion(religion);
String occupation = benificiaryDetails.getOccupation();
identityEditDTO.setOccupationName(occupation != null ? occupation : demographics.getOccupation());
String education = demographics.getEducationName();
if(education != null) {
identityEditDTO.setEducation(education);
}
String incomeStatus = benificiaryDetails.getIncomeStatus();
identityEditDTO.setIncomeStatus(incomeStatus != null ? incomeStatus : demographics.getIncomeStatus());
}
}


private int updateDemographics(BeneficiaryDemographicsModel i_BenDemographics) {
int updatedRows = 0;
System.out.println(i_BenDemographics);
Expand All @@ -145,9 +166,7 @@ public String save(BeneficiaryModel beneficiaryModel, HttpServletRequest servlet
// logger.info("benificiaryDetails: " + beneficiaryModel);

CommonIdentityDTO identityDTO = identityMapper.beneficiaryModelCommonIdentityDTO(beneficiaryModel);
if(null != beneficiaryModel.getI_bendemographics()) {
identityDTO.setCommunity(beneficiaryModel.getI_bendemographics().getCommunityName());
}
setSaveDemographicDetails(identityDTO,beneficiaryModel);
// identityDTO.setOtherFields(beneficiaryModel.getOtherFields());
identityDTO.setFaceEmbedding(beneficiaryModel.getFaceEmbedding());
identityDTO.setEmergencyRegistration(beneficiaryModel.isEmergencyRegistration());
Expand Down Expand Up @@ -178,6 +197,29 @@ public String save(BeneficiaryModel beneficiaryModel, HttpServletRequest servlet
return OutputMapper.gson().toJson(beneficiary);
}

private void setSaveDemographicDetails(CommonIdentityDTO identityDTO, BeneficiaryModel beneficiaryModel) {
if(null != beneficiaryModel.getI_bendemographics()) {
identityDTO.setCommunity(beneficiaryModel.getI_bendemographics().getCommunityName());
if(null != beneficiaryModel.getReligion())
identityDTO.setReligion(beneficiaryModel.getReligion());
else if(null != beneficiaryModel.getI_bendemographics().getReligion())
identityDTO.setReligion(beneficiaryModel.getI_bendemographics().getReligion());
else
identityDTO.setReligion(beneficiaryModel.getI_bendemographics().getReligionName());
if(null != beneficiaryModel.getOccupation())
identityDTO.setOccupationName(beneficiaryModel.getOccupation());
else
identityDTO.setOccupationName(beneficiaryModel.getI_bendemographics().getOccupation());
if(null != beneficiaryModel.getI_bendemographics().getEducationName())
identityDTO.setEducation(beneficiaryModel.getI_bendemographics().getEducationName());
if(null != beneficiaryModel.getIncomeStatus())
identityDTO.setIncomeStatus(beneficiaryModel.getIncomeStatus());
else
identityDTO.setIncomeStatus(beneficiaryModel.getI_bendemographics().getIncomeStatus());
}

}

@Override
public Integer updateCommunityorEducation(BeneficiaryModel benificiaryDetails, String auth) throws IEMRException {
IdentityEditDTO identityEditDTO = new IdentityEditDTO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
case "doAgentLogout":
case "userLogout":
case "swagger-ui.html":
case "index.html":
case "swagger-initializer.js":
case "swagger-config":
case "ui":
case "swagger-resources":
case "api-docs":
Expand Down
Loading