Skip to content
Open
Show file tree
Hide file tree
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 @@ -70,4 +70,5 @@ public class TBConfirmedCase {
@Column(name = "updated_at")
private LocalDate updatedAt;


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface BeneficiaryRepo extends JpaRepository<RMNCHBeneficiaryDetailsRm
Optional<RMNCHBeneficiaryDetailsRmnch> findById(Long benID);

List<RMNCHBeneficiaryDetailsRmnch> findByHouseoldId(Long houseHoldId);
Optional<RMNCHBeneficiaryDetailsRmnch> findByBenficieryid(Long benID);
List<RMNCHBeneficiaryDetailsRmnch> findByBenficieryid(Long benID);

@Query(value = "SELECT beneficiaryRegID FROM db_identity.i_beneficiarydetails_rmnch WHERE BeneficiaryId = :benId", nativeQuery = true)
Long getBenRegIdFromBenId(@Param("benId") Long benId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface DiseaseLeprosyRepository extends JpaRepository<ScreeningLeprosy
// Custom queries can be added here if needed
@Query("SELECT s FROM ScreeningLeprosy s WHERE s.createdBy = :createdBy")
List<ScreeningLeprosy> getByCreatedBy(@Param("createdBy") String createdBy);


}
5 changes: 3 additions & 2 deletions src/main/java/com/iemr/flw/repo/iemr/HbncVisitRepo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.iemr.flw.repo.iemr;

import com.iemr.flw.domain.iemr.HbncVisit;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -20,6 +22,5 @@ public interface HbncVisitRepo extends JpaRepository<HbncVisit, Long> {
HbncVisit findByBeneficiaryIdAndVisit_day(@Param("beneficiaryId") Long beneficiaryId,
@Param("visitDay") String visitDay);

List<HbncVisit> findByAshaId(Integer ashaId);

Page<HbncVisit> findByAshaId(Integer ashaId, Pageable pageable);
}
56 changes: 34 additions & 22 deletions src/main/java/com/iemr/flw/repo/iemr/IncentiveRecordRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import com.iemr.flw.domain.iemr.IncentiveActivityRecord;
import jakarta.persistence.Column;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -18,41 +20,51 @@
public interface IncentiveRecordRepo extends JpaRepository<IncentiveActivityRecord, Long> {

@Query(value = """
SELECT *
FROM db_iemr.incentive_activity_record r
WHERE r.activity_id = :id
AND r.ben_id = :benId
AND MONTH(r.created_date) = MONTH(:createdDate)
AND YEAR(r.created_date) = YEAR(:createdDate)
LIMIT 1
""", nativeQuery = true)
IncentiveActivityRecord findRecordByActivityIdCreatedDateBenId(@Param("id") Long id, @Param("createdDate") Timestamp createdDate, @Param("benId") Long benId);
SELECT *
FROM db_iemr.incentive_activity_record r
WHERE r.activity_id = :id
AND r.ben_id = :benId
AND r.asha_id = :ashaId
AND MONTH(r.start_date) = MONTH(:createdDate)
AND YEAR(r.start_date) = YEAR(:createdDate)
LIMIT 1
""", nativeQuery = true)
IncentiveActivityRecord findRecordByActivityIdCreatedDateBenId(
@Param("id") Long id,
@Param("createdDate") Timestamp createdDate,
@Param("benId") Long benId,
@Param("ashaId") Integer ashaId);
Comment on lines +23 to +36

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚑ Quick win

Month-based dedup changes the lookup granularity across many incentive flows. This overload is used from multiple event-specific callers, so replacing exact createdDate matching with MONTH(...)/YEAR(...) will treat any prior record for the same activity+ben+asha in that calendar month as a duplicate. That can suppress legitimately separate incentives; if this is intentional, the callers need to be updated to pass a month-scoped key.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/com/iemr/flw/repo/iemr/IncentiveRecordRepo.java` around lines
23 - 36, The lookup in
IncentiveRecordRepo.findRecordByActivityIdCreatedDateBenId now matches by
MONTH/YEAR instead of exact createdDate, which changes deduplication scope
across all callers. Update this repository method to preserve the intended
granularity, or if month-scoped dedup is desired, adjust the event-specific
callers that use findRecordByActivityIdCreatedDateBenId to pass and document a
month-based key consistently so they don’t treat separate incentives as
duplicates.



Optional<IncentiveActivityRecord> findById(Long id);


@Query("select record from IncentiveActivityRecord record where record.activityId = :id and record.createdDate = :createdDate and record.benId = :benId and record.ashaId = :ashaId")
IncentiveActivityRecord findRecordByActivityIdCreatedDateBenId(@Param("id") Long id, @Param("createdDate") Timestamp createdDate, @Param("benId") Long benId, @Param("ashaId") Integer ashaId);


@Query("SELECT record FROM IncentiveActivityRecord record " +
"WHERE record.activityId = :id " +
"AND record.createdDate BETWEEN :startDate AND :endDate " +
"AND record.benId = :benId " + // ← space added here
"AND record.ashaId = :ashaId")
@Query(value = """
SELECT *
FROM incentive_activity_record
WHERE activity_id = :activityId
AND ben_id = :benId
AND asha_id = :ashaId
AND created_date >= :startOfMonth
AND created_date < :startOfNextMonth
ORDER BY created_date DESC
LIMIT 1
""", nativeQuery = true)
IncentiveActivityRecord findRecordByActivityIdCreatedDateBenId(
@Param("id") Long id,
@Param("startDate") Timestamp startDate,
@Param("endDate") Timestamp endDate,
@Param("activityId") Long activityId,
@Param("benId") Long benId,
@Param("ashaId") Integer ashaId
@Param("ashaId") Integer ashaId,
@Param("startOfMonth") Timestamp startOfMonth,
@Param("startOfNextMonth") Timestamp startOfNextMonth
);

@Query("select record from IncentiveActivityRecord record where record.ashaId = :ashaId and record.startDate >= :fromDate and record.startDate <= :toDate and record.endDate >= :fromDate and record.endDate <= :toDate ")
List<IncentiveActivityRecord> findRecordsByAsha(@Param("ashaId") Integer ashaId, @Param("fromDate") Timestamp fromDate, @Param("toDate") Timestamp toDate);


@Query("SELECT DISTINCT record FROM IncentiveActivityRecord record WHERE record.ashaId = :ashaId")
Page<IncentiveActivityRecord> findRecordsByAsha(@Param("ashaId") Integer ashaId, Pageable pageable);

@Query("SELECT DISTINCT record FROM IncentiveActivityRecord record WHERE record.ashaId = :ashaId")
List<IncentiveActivityRecord> findRecordsByAsha(@Param("ashaId") Integer ashaId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Repository
public interface LeprosyFollowUpRepository extends JpaRepository<LeprosyFollowUp, Long> {
Optional<LeprosyFollowUp> findByBenId(Long benId);
List<LeprosyFollowUp> findByBenId(Long benId);

// Custom queries can be added here if needed
@Query("SELECT s FROM LeprosyFollowUp s WHERE s.createdBy = :createdBy")
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/com/iemr/flw/service/MaaMeetingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,23 @@ record = new IncentiveActivityRecord();
record.setBenId(0L);
record.setAshaId(meeting.getAshaId());
record.setAmount(Long.valueOf(incentiveActivity.getRate()));
record.setIsEligible(true);
recordRepo.save(record);

if (meeting.getMeetingImagesJson() != null) {
record.setIsEligible(true);
recordRepo.save(record);

} else {
record.setIsEligible(false);
IncentiveActivityRecord activityRecord = recordRepo.save(record);
if (activityRecord != null) {
updatePendingActivity(meeting.getAshaId(), meeting.getId(), activityRecord.getId(), incentiveActivity.getId());

}

}
// if (meeting.getMeetingImagesJson() != null) {
// record.setIsEligible(true);
// recordRepo.save(record);
//
// } else {
// record.setIsEligible(false);
// IncentiveActivityRecord activityRecord = recordRepo.save(record);
// if (activityRecord != null) {
// updatePendingActivity(meeting.getAshaId(), meeting.getId(), activityRecord.getId(), incentiveActivity.getId());
//
// }
//
// }
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void checkAndAddIncentives(AdolescentHealth adolescentHealth) {

if (sellingSanitaryActivity != null) {
IncentiveActivityRecord record = recordRepo
.findRecordByActivityIdCreatedDateBenId(sellingSanitaryActivity.getId(), adolescentHealth.getCreatedDate(), adolescentHealth.getBenId().longValue());
.findRecordByActivityIdCreatedDateBenId(sellingSanitaryActivity.getId(), adolescentHealth.getCreatedDate(), adolescentHealth.getBenId().longValue(),adolescentHealth.getUserId());
if (record == null) {
record = new IncentiveActivityRecord();
record.setActivityId(sellingSanitaryActivity.getId());
Expand All @@ -151,7 +151,7 @@ record = new IncentiveActivityRecord();

if (mobilizingADHActivity != null) {
IncentiveActivityRecord record = recordRepo
.findRecordByActivityIdCreatedDateBenId(mobilizingADHActivity.getId(), adolescentHealth.getCreatedDate(), adolescentHealth.getBenId().longValue());
.findRecordByActivityIdCreatedDateBenId(mobilizingADHActivity.getId(), adolescentHealth.getCreatedDate(), adolescentHealth.getBenId().longValue(),adolescentHealth.getUserId());
if (record == null) {
record = new IncentiveActivityRecord();
record.setActivityId(mobilizingADHActivity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private List<String> parseBase64Json(String jsonString) {

private void checkMonthlyPulsePolioIncentive(Integer ashaId,LocalDate startDate,LocalDate endDate) {

IncentiveActivity CHILD_MOBILIZATION_SESSIONS = incentivesRepo.findIncentiveMasterByNameAndGroup("CHILD_MOBILIZATION_SESSIONS", GroupName.ACTIVITY.getDisplayName());
IncentiveActivity CHILD_MOBILIZATION_SESSIONS = incentivesRepo.findIncentiveMasterByNameAndGroup("PULSE_POLIO_SUPPORT", GroupName.ACTIVITY.getDisplayName());
if (CHILD_MOBILIZATION_SESSIONS != null) {
addAshaIncentiveRecord(CHILD_MOBILIZATION_SESSIONS, ashaId,startDate,endDate);
}
Expand Down Expand Up @@ -480,10 +480,10 @@ private void addAshaIncentiveRecord(IncentiveActivity incentiveActivity, Integer

IncentiveActivityRecord record = recordRepo.findRecordByActivityIdCreatedDateBenId(
incentiveActivity.getId(),
startOfMonth,
endOfMonth,
0L,
ashaId
ashaId,
startOfMonth,
endOfMonth
);


Expand Down
Loading