Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public ResponseEntity<String> insertRecordsInOutboundCalls(@RequestBody Outbound
@ApiResponse(responseCode = CustomExceptionResponse.BAD_REQUEST_SC_V, description = CustomExceptionResponse.BAD_REQUEST_SC) })
public ResponseEntity<ResponseEligibleCallRecordsDTO> getEligibleRecordsLanguageInfo(@PathVariable int psmId,
@PathVariable String phoneNoType, @PathVariable String recordType, @PathVariable String fDate,
@PathVariable String tDate, @PathVariable String preferredLanguage) throws ECDException {
@PathVariable String tDate, @PathVariable String preferredLanguage,@PathVariable String role) throws ECDException {
return new ResponseEntity<>(
callAllocationImpl.getEligibleRecordsLanguageInfo(psmId, phoneNoType, recordType, fDate, tDate, preferredLanguage), HttpStatus.OK);
callAllocationImpl.getEligibleRecordsLanguageInfo(psmId, phoneNoType, recordType, fDate, tDate, preferredLanguage,role), HttpStatus.OK);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ Page<OutboundCalls> getMotherRecordsForANM(Pageable pageable, @Param("allocation

@Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN MotherRecord mv ON t.motherId = mv.ecdIdNo WHERE t.allocationStatus =:allocationStatus AND "
+ " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
+ " t.childId IS NULL AND t.motherId IS NOT NULL AND (t.isHighRisk = false OR t.isHighRisk IS NULL ) AND mv.preferredLanguage = :preferredLanguage AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL )")
+ " t.childId IS NULL AND t.motherId IS NOT NULL AND (t.isHighRisk = false OR t.isHighRisk IS NULL ) AND mv.preferredLanguage = :preferredLanguage AND "
+ " t.displayEcdCallType = 'introductory' AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL )")
Page<OutboundCalls> getMotherRecordsForAssociate(Pageable pageable,@Param("allocationStatus") String allocationStatus,
@Param("psmId") Integer psmId, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("preferredLanguage") String preferredLanguage);


@Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN ChildRecord cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocationStatus =:allocationStatus AND "
+ " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
+ " t.childId IS NOT NULL AND (t.isHrni = false OR t.isHrni IS NULL ) AND"
Expand All @@ -78,7 +80,8 @@ Page<OutboundCalls> getChildRecordsForANM(Pageable pageable, @Param("allocationS
@Param("psmId") Integer psmId, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("preferredLanguage") String preferredLanguage);
@Query(value = " SELECT t FROM OutboundCalls AS t INNER JOIN ChildRecord cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocationStatus =:allocationStatus AND "
+ " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
+ " t.childId IS NOT NULL AND (t.isHrni = false OR t.isHrni IS NULL ) AND cv.preferredLanguage = :preferredLanguage AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL )")
+ " t.childId IS NOT NULL AND (t.isHrni = false OR t.isHrni IS NULL ) AND cv.preferredLanguage = :preferredLanguage AND"
+ " t.displayEcdCallType = 'introductory' AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL )")
Page<OutboundCalls> getChildRecordsForAssociate(Pageable pageable, @Param("allocationStatus") String allocationStatus,
@Param("psmId") Integer psmId, @Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("preferredLanguage") String preferredLanguage);
@Query(value = " SELECT t FROM OutboundCalls AS t WHERE t.allocationStatus =:allocationStatus AND "
Expand Down Expand Up @@ -346,18 +349,38 @@ List<OutboundCalls> getIntroductoryRecordsUser(@Param("psmId") Integer psmId,
@Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN MotherRecord AS mv ON t.motherId = mv.ecdIdNo WHERE t.allocationStatus =:allocationStatus AND "
+ " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
+ " t.childId IS NULL AND t.motherId IS NOT NULL AND (t.isHighRisk = false OR t.isHighRisk IS NULL ) "
+ " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND mv.preferredLanguage = :preferredLanguage AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL ) ")
+ " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND mv.preferredLanguage = :preferredLanguage AND"
+ " t.displayEcdCallType != 'introductory' AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL ) ")
int getMotherUnAllocatedCountLRByLanguage(@Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId,
@Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneNoType") String phoneNoType, @Param("preferredLanguage") String preferredLanguage);

@Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN MotherRecord AS mv ON t.motherId = mv.ecdIdNo WHERE t.allocationStatus =:allocationStatus AND "
+ " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
+ " t.childId IS NULL AND t.motherId IS NOT NULL AND (t.isHighRisk = false OR t.isHighRisk IS NULL ) "
+ " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND mv.preferredLanguage = :preferredLanguage AND"
+ " t.displayEcdCallType = 'introductory' AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL ) ")
int getMotherUnAllocatedCountIntroductoryByLanguage(@Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId,
@Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneNoType") String phoneNoType, @Param("preferredLanguage") String preferredLanguage);

// un-allocated, child low risk,
@Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN ChildRecord AS cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocationStatus =:allocationStatus AND "
+ " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
+ " t.childId IS NOT NULL AND (t.isHrni = false OR t.isHrni IS NULL ) "
+ " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND cv.preferredLanguage = :preferredLanguage AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL )")
+ " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND cv.preferredLanguage = :preferredLanguage AND"
+ " t.displayEcdCallType != 'introductory' AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL )")
int getChildUnAllocatedCountLRByLanguage(@Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId,
@Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneNoType") String phoneNoType, @Param("preferredLanguage") String preferredLanguage);


@Query(value = " SELECT COUNT(1) FROM OutboundCalls AS t INNER JOIN ChildRecord AS cv ON t.childId = cv.ecdIdNoChildId WHERE t.allocationStatus =:allocationStatus AND "
+ " t.psmId=:psmId AND ((:fDate between t.callDateFrom AND t.callDateTo) OR (:tDate between t.callDateFrom AND t.callDateTo)) AND "
+ " t.childId IS NOT NULL AND (t.isHrni = false OR t.isHrni IS NULL ) "
+ " AND t.phoneNumberType=:phoneNoType AND t.deleted = false AND cv.preferredLanguage = :preferredLanguage AND"
+ " t.displayEcdCallType = 'introductory' AND (t.isFurtherCallRequired = true OR t.isFurtherCallRequired IS NULL )")
int getChildUnAllocatedCountIntroductoryByLanguage(@Param("allocationStatus") String allocationStatus, @Param("psmId") Integer psmId,
@Param("fDate") Timestamp fDate, @Param("tDate") Timestamp tDate, @Param("phoneNoType") String phoneNoType, @Param("preferredLanguage") String preferredLanguage);


@Modifying
@Transactional
@Query(" UPDATE OutboundCalls SET isFurtherCallRequired = :isFurtherCallRequired WHERE childId = :childId AND motherId IS NOT NULL AND callDateTo>current_date()")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,34 +1054,54 @@ public String insertRecordsInOutboundCalls(OutboundCallsDTO outboundCallsDTO) {
}
}

public ResponseEligibleCallRecordsDTO getEligibleRecordsLanguageInfo(int psmId, String phoneNoType, String recordType, String fDate,
String tDate, String preferredLanguage) {
public ResponseEligibleCallRecordsDTO getEligibleRecordsLanguageInfo(int psmId, String phoneNoType,
String recordType, String fDate, String tDate, String preferredLanguage, String role) {
Comment on lines +1057 to +1058
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Add input validation for the role parameter.

The method should validate that the role parameter is not null or empty before proceeding with the logic.

Add validation at the beginning of the method:

public ResponseEligibleCallRecordsDTO getEligibleRecordsLanguageInfo(int psmId, String phoneNoType,
		String recordType, String fDate, String tDate, String preferredLanguage, String role) {
	try {
+		if (role == null || role.trim().isEmpty()) {
+			throw new InvalidRequestException("role is required");
+		}
		if (preferredLanguage == null || preferredLanguage.trim().isEmpty()) {
			throw new InvalidRequestException("preferred language is required");
		}
πŸ“ 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
public ResponseEligibleCallRecordsDTO getEligibleRecordsLanguageInfo(int psmId, String phoneNoType,
String recordType, String fDate, String tDate, String preferredLanguage, String role) {
public ResponseEligibleCallRecordsDTO getEligibleRecordsLanguageInfo(int psmId, String phoneNoType,
String recordType, String fDate, String tDate, String preferredLanguage, String role) {
try {
if (role == null || role.trim().isEmpty()) {
throw new InvalidRequestException("role is required");
}
if (preferredLanguage == null || preferredLanguage.trim().isEmpty()) {
throw new InvalidRequestException("preferred language is required");
}
// ... rest of existing logic ...
} catch (Exception e) {
// existing exception handling
}
}
πŸ€– Prompt for AI Agents
In
src/main/java/com/iemr/ecd/service/call_conf_allocation/CallAllocationImpl.java
around lines 1057 to 1058, add input validation for the role parameter by
checking if it is null or empty at the start of the
getEligibleRecordsLanguageInfo method. If the role is invalid, handle it
appropriately, such as returning an error response or throwing an exception,
before proceeding with the rest of the method logic.

try {
if (preferredLanguage == null || preferredLanguage.trim().isEmpty()) {
throw new InvalidRequestException("preferred language is required");
}
Timestamp tempFDateStamp = null;
Timestamp tempTDateStamp = null;
if (fDate != null && tDate != null) {
tempFDateStamp = getTimestampFromString(fDate.split(Constants.T)[0].concat(Constants.TIME_FORMAT_START_TIME));
tempTDateStamp = getTimestampFromString(tDate.split(Constants.T)[0].concat(Constants.TIME_FORMAT_END_TIME));
tempFDateStamp = getTimestampFromString(
fDate.split(Constants.T)[0].concat(Constants.TIME_FORMAT_START_TIME));
tempTDateStamp = getTimestampFromString(
tDate.split(Constants.T)[0].concat(Constants.TIME_FORMAT_END_TIME));
} else
throw new InvalidRequestException(Constants.FROM_DATE_TO_DATE_IS_NULL);

ResponseEligibleCallRecordsDTO responseEligibleCallRecordsDTO = new ResponseEligibleCallRecordsDTO();
int totalLowRisk = 0;
if (recordType != null && recordType.equalsIgnoreCase(Constants.MOTHER)) {
totalLowRisk = outboundCallsRepo.getMotherUnAllocatedCountLRByLanguage(Constants.UNALLOCATED, psmId, tempFDateStamp,
tempTDateStamp, phoneNoType, preferredLanguage);
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.CHILD)) {
totalLowRisk = outboundCallsRepo.getChildUnAllocatedCountLRByLanguage(Constants.UNALLOCATED, psmId, tempFDateStamp,
tempTDateStamp, phoneNoType, preferredLanguage);
int totalIntroductoryCount = 0;
if (recordType != null && recordType.equalsIgnoreCase(Constants.MOTHER)
&& role.equalsIgnoreCase(Constants.ANM)) {
totalLowRisk = outboundCallsRepo.getMotherUnAllocatedCountLRByLanguage(Constants.UNALLOCATED, psmId,
tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalLowRiskRecord(totalLowRisk);
return responseEligibleCallRecordsDTO;
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.CHILD)
&& role.equalsIgnoreCase(Constants.ANM)) {
totalLowRisk = outboundCallsRepo.getChildUnAllocatedCountLRByLanguage(Constants.UNALLOCATED, psmId,
tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalLowRiskRecord(totalLowRisk);
return responseEligibleCallRecordsDTO;
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.MOTHER)
&& role.equalsIgnoreCase(Constants.ASSOCIATE)) {
totalIntroductoryCount = outboundCallsRepo.getMotherUnAllocatedCountIntroductoryByLanguage(
Constants.UNALLOCATED, psmId, tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalIntroductoryRecord(totalIntroductoryCount);
return responseEligibleCallRecordsDTO;
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.CHILD)
&& role.equalsIgnoreCase(Constants.ASSOCIATE)) {
totalIntroductoryCount = outboundCallsRepo.getChildUnAllocatedCountIntroductoryByLanguage(
Constants.UNALLOCATED, psmId, tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalIntroductoryRecord(totalIntroductoryCount);
return responseEligibleCallRecordsDTO;
}
Comment on lines +1076 to 1100
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Improve error handling for unsupported role and record type combinations.

The method returns null for unsupported role and record type combinations, which could lead to unexpected behavior. Consider throwing a descriptive exception instead.

Replace the implicit null return with explicit exception handling:

		} else if (recordType != null && recordType.equalsIgnoreCase(Constants.CHILD)
				&& role.equalsIgnoreCase(Constants.ASSOCIATE)) {
			totalIntroductoryCount = outboundCallsRepo.getChildUnAllocatedCountIntroductoryByLanguage(
					Constants.UNALLOCATED, psmId, tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
			responseEligibleCallRecordsDTO.setTotalIntroductoryRecord(totalIntroductoryCount);
			return responseEligibleCallRecordsDTO;
+		} else {
+			throw new InvalidRequestException("Unsupported combination of role '" + role + "' and recordType '" + recordType + "'");
		}
-
πŸ“ 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
if (recordType != null && recordType.equalsIgnoreCase(Constants.MOTHER)
&& role.equalsIgnoreCase(Constants.ANM)) {
totalLowRisk = outboundCallsRepo.getMotherUnAllocatedCountLRByLanguage(Constants.UNALLOCATED, psmId,
tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalLowRiskRecord(totalLowRisk);
return responseEligibleCallRecordsDTO;
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.CHILD)
&& role.equalsIgnoreCase(Constants.ANM)) {
totalLowRisk = outboundCallsRepo.getChildUnAllocatedCountLRByLanguage(Constants.UNALLOCATED, psmId,
tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalLowRiskRecord(totalLowRisk);
return responseEligibleCallRecordsDTO;
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.MOTHER)
&& role.equalsIgnoreCase(Constants.ASSOCIATE)) {
totalIntroductoryCount = outboundCallsRepo.getMotherUnAllocatedCountIntroductoryByLanguage(
Constants.UNALLOCATED, psmId, tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalIntroductoryRecord(totalIntroductoryCount);
return responseEligibleCallRecordsDTO;
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.CHILD)
&& role.equalsIgnoreCase(Constants.ASSOCIATE)) {
totalIntroductoryCount = outboundCallsRepo.getChildUnAllocatedCountIntroductoryByLanguage(
Constants.UNALLOCATED, psmId, tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalIntroductoryRecord(totalIntroductoryCount);
return responseEligibleCallRecordsDTO;
}
if (recordType != null && recordType.equalsIgnoreCase(Constants.MOTHER)
&& role.equalsIgnoreCase(Constants.ANM)) {
totalLowRisk = outboundCallsRepo.getMotherUnAllocatedCountLRByLanguage(Constants.UNALLOCATED, psmId,
tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalLowRiskRecord(totalLowRisk);
return responseEligibleCallRecordsDTO;
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.CHILD)
&& role.equalsIgnoreCase(Constants.ANM)) {
totalLowRisk = outboundCallsRepo.getChildUnAllocatedCountLRByLanguage(Constants.UNALLOCATED, psmId,
tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalLowRiskRecord(totalLowRisk);
return responseEligibleCallRecordsDTO;
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.MOTHER)
&& role.equalsIgnoreCase(Constants.ASSOCIATE)) {
totalIntroductoryCount = outboundCallsRepo.getMotherUnAllocatedCountIntroductoryByLanguage(
Constants.UNALLOCATED, psmId, tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalIntroductoryRecord(totalIntroductoryCount);
return responseEligibleCallRecordsDTO;
} else if (recordType != null && recordType.equalsIgnoreCase(Constants.CHILD)
&& role.equalsIgnoreCase(Constants.ASSOCIATE)) {
totalIntroductoryCount = outboundCallsRepo.getChildUnAllocatedCountIntroductoryByLanguage(
Constants.UNALLOCATED, psmId, tempFDateStamp, tempTDateStamp, phoneNoType, preferredLanguage);
responseEligibleCallRecordsDTO.setTotalIntroductoryRecord(totalIntroductoryCount);
return responseEligibleCallRecordsDTO;
} else {
throw new InvalidRequestException(
"Unsupported combination of role '" + role + "' and recordType '" + recordType + "'");
}
πŸ€– Prompt for AI Agents
In
src/main/java/com/iemr/ecd/service/call_conf_allocation/CallAllocationImpl.java
around lines 1076 to 1100, the method currently returns null for unsupported
combinations of role and recordType, which can cause unexpected behavior. To fix
this, add explicit error handling by throwing a descriptive exception when the
role and recordType combination is not supported, instead of returning null.
This will make the method's behavior clearer and safer.

responseEligibleCallRecordsDTO.setTotalLowRiskRecord(totalLowRisk);
return responseEligibleCallRecordsDTO;

} catch (Exception e) {
throw new ECDException(e);
}

return null;
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Remove unreachable null return statement.

With the suggested exception handling above, this null return becomes unreachable and should be removed.

		} catch (Exception e) {
			throw new ECDException(e);
		}
-		return null;
	}
πŸ“ 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
return null;
} catch (Exception e) {
throw new ECDException(e);
}
}
πŸ€– Prompt for AI Agents
In
src/main/java/com/iemr/ecd/service/call_conf_allocation/CallAllocationImpl.java
at line 1105, remove the return null statement because with the updated
exception handling it is unreachable and unnecessary.

}
}
Loading