Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.iemr.common.utils.mapper.InputMapper;
import com.iemr.common.utils.mapper.OutputMapper;
import com.iemr.common.utils.response.OutputResponse;
import org.springframework.beans.factory.annotation.Value;

@Service
public class IdentityBeneficiaryServiceImpl implements IdentityBeneficiaryService {
Expand All @@ -52,7 +51,6 @@ public class IdentityBeneficiaryServiceImpl implements IdentityBeneficiaryServic
Logger logger = LoggerFactory.getLogger(this.getClass().getName());
private static HttpUtils httpUtils = new HttpUtils();
private InputMapper inputMapper = new InputMapper();

@Value("${identity-api-url}")
private String identityBaseURL;
@Value("${identity-1097-api-url}")
Expand Down Expand Up @@ -153,6 +151,9 @@ public List<BeneficiariesPartialDTO> getPartialBeneficiaryListByIDs(HashSet benI
// search beneficiaries by phone number
public List<BeneficiariesDTO> getBeneficiaryListByPhone(String phoneNo, String auth, Boolean is1097)
throws IEMRException {
logger.info("Phone no from getBeneficiaryListByPhone: " + phoneNo);
String cleanedPhoneNo = cleanPhoneNumber(phoneNo);
logger.info("Cleaned phone no: " + cleanedPhoneNo);

List<BeneficiariesDTO> listBenDetailForOutboundDTO = new ArrayList<>();

Expand All @@ -164,8 +165,12 @@ public List<BeneficiariesDTO> getBeneficiaryListByPhone(String phoneNo, String a
if (auth != null) {
header.put("Authorization", auth);
}

logger.info("Result="+(ConfigProperties.getPropertyByName("identity-api-url-getByPhoneNum")
.replace(IDENTITY_BASE_URL, (is1097 ? identity1097BaseURL : identityBaseURL))) + cleanedPhoneNo);

result = httpUtils.post((ConfigProperties.getPropertyByName("identity-api-url-getByPhoneNum")
.replace(IDENTITY_BASE_URL, (is1097 ? identity1097BaseURL : identityBaseURL))) + phoneNo, "", header);
.replace(IDENTITY_BASE_URL, (is1097 ? identity1097BaseURL : identityBaseURL))) + cleanedPhoneNo, "", header);

OutputResponse identityResponse = InputMapper.gson().fromJson(result, OutputResponse.class);
if (identityResponse.getStatusCode() == OutputResponse.USERID_FAILURE) {
Expand All @@ -185,6 +190,25 @@ public List<BeneficiariesDTO> getBeneficiaryListByPhone(String phoneNo, String a
return listBenDetailForOutboundDTO;
}

private String cleanPhoneNumber(String phoneNumber) {
if (phoneNumber == null || phoneNumber.trim().isEmpty()) {
return phoneNumber;
}

String cleaned = phoneNumber.trim();

// Remove +91 prefix
if (cleaned.startsWith("+91")) {
cleaned = cleaned.substring(3);
}
// Remove 91 prefix if it's a 12-digit number (91 + 10 digit mobile)
else if (cleaned.startsWith("91") && cleaned.length() == 12) {
cleaned = cleaned.substring(2);
}

return cleaned.trim();
}

@Override
// search beneficiary by beneficiary id
public List<BeneficiariesDTO> getBeneficiaryListByBenID(String benId, String auth, Boolean is1097)
Expand Down Expand Up @@ -557,4 +581,4 @@ public List<BeneficiaryGenModel> generateBeneficiaryIDs(String request, String a
return listBen;
}

}
}
Loading