diff --git a/pom.xml b/pom.xml index 576c0cdf..b9c36ae8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.iemr.common.flw flw-api - 3.8.2 + 3.10.0 war FLW-API diff --git a/src/main/java/com/iemr/flw/domain/iemr/IncentiveActivity.java b/src/main/java/com/iemr/flw/domain/iemr/IncentiveActivity.java index a37f1501..a62d73b9 100644 --- a/src/main/java/com/iemr/flw/domain/iemr/IncentiveActivity.java +++ b/src/main/java/com/iemr/flw/domain/iemr/IncentiveActivity.java @@ -65,9 +65,4 @@ public class IncentiveActivity { - - @Column(name = "state_activity_code") - private Integer stateActivityCode; - - } diff --git a/src/main/java/com/iemr/flw/masterEnum/IncentiveApprovalStatus.java b/src/main/java/com/iemr/flw/masterEnum/IncentiveApprovalStatus.java index e40ecc98..4149cab0 100644 --- a/src/main/java/com/iemr/flw/masterEnum/IncentiveApprovalStatus.java +++ b/src/main/java/com/iemr/flw/masterEnum/IncentiveApprovalStatus.java @@ -5,7 +5,8 @@ public enum IncentiveApprovalStatus { VERIFIED(101, "Verified"), PENDING(102, "Pending"), REJECTED(103, "Rejected"), - OVERDUE(104, "Overdue"); + OVERDUE(104, "Overdue"), + APPROVED(105, "Approved"); private final int code; private final String label; diff --git a/src/main/java/com/iemr/flw/repo/iemr/AshaSupervisorLoginRepo.java b/src/main/java/com/iemr/flw/repo/iemr/AshaSupervisorLoginRepo.java index 78bb368b..3b52abe2 100644 --- a/src/main/java/com/iemr/flw/repo/iemr/AshaSupervisorLoginRepo.java +++ b/src/main/java/com/iemr/flw/repo/iemr/AshaSupervisorLoginRepo.java @@ -55,6 +55,70 @@ List getAshasAtFacility( @Param("endDate") Timestamp endDate); + @Query(value = "SELECT DISTINCT asm.ashaUserID, u.FirstName, u.LastName, " + + "COALESCE(u.AgentID,'') AS agentID, " + + "COALESCE(u.EmergencyContactNo,'') AS mobile, " + + "COALESCE(g.GenderName,'') AS gender " + + "FROM asha_supervisor_mapping asm " + + "JOIN m_User u ON u.UserID = asm.ashaUserID " + + "AND u.Deleted = false " + + "LEFT JOIN m_gender g ON g.GenderID = u.GenderID " + + "JOIN incentive_activity_record iar " + + "ON iar.asha_id = asm.ashaUserID " + + "WHERE asm.supervisorUserID = :supervisorUserID " + + "AND asm.facilityID = :facilityID " + + "AND asm.deleted = false " + + "AND iar.is_claimed = true " + + "AND iar.start_date >= :startDate " + + "AND iar.end_date < :endDate " + + "AND (" + + " :approvalStatus = 0 " + + " OR (:approvalStatus = 105 AND iar.approval_status IN (101,105)) " + + " OR (:approvalStatus = 106 AND iar.approval_status = 102) " + + " OR (:approvalStatus NOT IN (105,106) AND iar.approval_status = :approvalStatus)" + + ")", + nativeQuery = true) + List getAshasAtFacilityCg( + @Param("supervisorUserID") Integer supervisorUserID, + @Param("facilityID") Integer facilityID, + @Param("approvalStatus") Integer approvalStatus, + @Param("startDate") Timestamp startDate, + @Param("endDate") Timestamp endDate); + + + @Query(value = "SELECT DISTINCT asm.ashaUserID, u.FirstName, u.LastName, " + + "COALESCE(u.AgentID,'') AS agentID, " + + "COALESCE(u.EmergencyContactNo,'') AS mobile, " + + "COALESCE(g.GenderName,'') AS gender " + + "FROM asha_supervisor_mapping asm " + + "JOIN m_User u ON u.UserID = asm.ashaUserID " + + "AND u.Deleted = false " + + "LEFT JOIN m_gender g ON g.GenderID = u.GenderID " + + "JOIN incentive_activity_record iar " + + "ON iar.asha_id = asm.ashaUserID " + + "WHERE asm.supervisorUserID = :supervisorUserID " + + "AND asm.deleted = false " + + "AND (" + + " (:approvalStatus = 106 AND (iar.is_claimed = false OR iar.is_claimed IS NULL)) " + + " OR (:approvalStatus <> 106 AND iar.is_claimed = true)" + + ") " + + "AND iar.start_date >= :startDate " + + "AND iar.end_date < :endDate " + + "AND (" + + " :approvalStatus = 0 " + + " OR (:approvalStatus = 105 AND iar.approval_status IN (101,105)) " + + " OR (:approvalStatus = 106 AND iar.approval_status = 102) " + + " OR (:approvalStatus NOT IN (105,106) AND iar.approval_status = :approvalStatus)" + + ")", + nativeQuery = true) + List getAshasAtFacilityCg( + @Param("supervisorUserID") Integer supervisorUserID, + @Param("approvalStatus") Integer approvalStatus, + @Param("startDate") Timestamp startDate, + @Param("endDate") Timestamp endDate); + + + @Query(value = "SELECT DISTINCT asm.ashaUserID, " + "u.FirstName, " + "u.LastName, " diff --git a/src/main/java/com/iemr/flw/repo/iemr/IncentiveRecordRepo.java b/src/main/java/com/iemr/flw/repo/iemr/IncentiveRecordRepo.java index 81dc1865..fdda9847 100644 --- a/src/main/java/com/iemr/flw/repo/iemr/IncentiveRecordRepo.java +++ b/src/main/java/com/iemr/flw/repo/iemr/IncentiveRecordRepo.java @@ -72,7 +72,7 @@ IncentiveActivityRecord findRecordByActivityIdCreatedDateBenId( "SUM(CASE WHEN record.approvalStatus = 101 THEN 1 ELSE 0 END), " + "SUM(CASE WHEN record.approvalStatus = 102 THEN 1 ELSE 0 END), " + "SUM(CASE WHEN record.approvalStatus = 103 THEN 1 ELSE 0 END), " + - "SUM(CASE WHEN record.approvalStatus = 104 THEN 1 ELSE 0 END) " + + "SUM(CASE WHEN record.approvalStatus = 105 THEN 1 ELSE 0 END) " + "FROM IncentiveActivityRecord record " + "WHERE record.ashaId = :ashaId " + "AND record.isClaimed = true " + @@ -88,19 +88,54 @@ List getStatusCountByAshaId( "SUM(CASE WHEN record.approvalStatus = 101 THEN 1 ELSE 0 END), " + "SUM(CASE WHEN record.approvalStatus = 102 THEN 1 ELSE 0 END), " + "SUM(CASE WHEN record.approvalStatus = 103 THEN 1 ELSE 0 END), " + - "SUM(CASE WHEN record.approvalStatus = 104 THEN 1 ELSE 0 END) " + + "SUM(CASE WHEN record.approvalStatus IN (102,105) THEN 1 ELSE 0 END) " + "FROM IncentiveActivityRecord record " + "WHERE record.ashaId = :ashaId " + "AND record.isClaimed = true " + - "AND record.isDefaultActivity = true " + "AND record.createdDate >= :startDate " + "AND record.createdDate < :endDate") + List getStatusCountByAshaIdANM( + @Param("ashaId") Integer ashaId, + @Param("startDate") Timestamp startDate, + @Param("endDate") Timestamp endDate); + + @Query(""" +SELECT + SUM(CASE WHEN record.approvalStatus = 101 THEN 1 ELSE 0 END), + SUM(CASE WHEN record.approvalStatus = 102 THEN 1 ELSE 0 END), + SUM(CASE WHEN record.approvalStatus = 103 THEN 1 ELSE 0 END), + SUM(CASE WHEN record.approvalStatus IN (101,105) THEN 1 ELSE 0 END) +FROM IncentiveActivityRecord record +WHERE record.ashaId = :ashaId +AND record.isClaimed = true +AND record.isDefaultActivity = true +AND record.createdDate >= :startDate +AND record.createdDate < :endDate +""") List getStatusCountByAshaIdOfDefaultActivity( @Param("ashaId") Integer ashaId, @Param("startDate") Timestamp startDate, @Param("endDate") Timestamp endDate); + @Query(""" +SELECT + SUM(CASE WHEN record.approvalStatus = 101 THEN 1 ELSE 0 END), + SUM(CASE WHEN record.approvalStatus = 102 THEN 1 ELSE 0 END), + SUM(CASE WHEN record.approvalStatus = 103 THEN 1 ELSE 0 END), + SUM(CASE WHEN record.approvalStatus IN (101,105) THEN 1 ELSE 0 END) +FROM IncentiveActivityRecord record +WHERE record.ashaId = :ashaId +AND record.isClaimed = false +AND record.createdDate >= :startDate +AND record.createdDate < :endDate +""") + List getStatusUnclaimedCountByAshaId( + @Param("ashaId") Integer ashaId, + @Param("startDate") Timestamp startDate, + @Param("endDate") Timestamp endDate); + + @Query("SELECT COALESCE(SUM(record.amount), 0) " + "FROM IncentiveActivityRecord record " + @@ -118,6 +153,66 @@ Long getTotalAmountByAsha( @Param("approvalStatus") Integer approvalStatus, @Param("stateCode") Integer stateCode); + + @Query(""" + SELECT COALESCE(SUM(record.amount), 0) + FROM IncentiveActivityRecord record + JOIN IncentiveActivity master ON record.activityId = master.id + WHERE record.ashaId = :ashaId + AND master.state = :stateCode + AND record.isClaimed = true + AND record.startDate >= :fromDate + AND record.endDate <= :toDate + AND ( + :approvalStatus = 0 + OR ( + :approvalStatus = 102 + AND record.approvalStatus IN (102, 105) + ) + OR ( + :approvalStatus <> 102 + AND record.approvalStatus = :approvalStatus + ) + ) +""") + Long getTotalAmountByAshaANM( + @Param("ashaId") Integer ashaId, + @Param("fromDate") Timestamp fromDate, + @Param("toDate") Timestamp toDate, + @Param("approvalStatus") Integer approvalStatus, + @Param("stateCode") Integer stateCode + ); + + @Query(""" + SELECT COALESCE(SUM(record.amount), 0) + FROM IncentiveActivityRecord record + JOIN IncentiveActivity master ON record.activityId = master.id + WHERE record.ashaId = :ashaId + AND master.state = :stateCode + AND record.isClaimed = true + AND record.isDefaultActivity = false + AND record.startDate >= :fromDate + AND record.endDate <= :toDate + AND ( + :approvalStatus = 0 + OR ( + :approvalStatus = 102 + AND record.approvalStatus IN (102, 105) + ) + OR ( + :approvalStatus <> 102 + AND record.approvalStatus = :approvalStatus + ) + ) +""") + Long getTotalAmountByAshaANMbeforeClaimedHour( + @Param("ashaId") Integer ashaId, + @Param("fromDate") Timestamp fromDate, + @Param("toDate") Timestamp toDate, + @Param("approvalStatus") Integer approvalStatus, + @Param("stateCode") Integer stateCode + ); + @Query("SELECT COALESCE(SUM(record.amount), 0) " + "FROM IncentiveActivityRecord record " + "JOIN IncentiveActivity master ON record.activityId = master.id " + @@ -127,7 +222,11 @@ Long getTotalAmountByAsha( "AND record.isDefaultActivity = true " + "AND record.startDate >= :fromDate " + "AND record.endDate <= :toDate " + - "AND (:approvalStatus = 0 OR record.approvalStatus = :approvalStatus)") + "AND (" + + " :approvalStatus = 0 " + + " OR (:approvalStatus = 101 AND record.approvalStatus IN (101,105)) " + + " OR (:approvalStatus <> 101 AND record.approvalStatus = :approvalStatus)" + + ")") Long getDefaultActivityTotalAmountByAsha( @Param("ashaId") Integer ashaId, @Param("fromDate") Timestamp fromDate, @@ -188,31 +287,11 @@ int updateApprovalStatusByAshaAndDateRange( UPDATE IncentiveActivityRecord iar SET iar.approvalStatus = :approvalStatus, - - iar.verifiedByUserId = - CASE - WHEN iar.isDefaultActivity = false - THEN :ashaSupervisorUserId - ELSE iar.verifiedByUserId - END, - - iar.verifiedByUserName = - CASE - WHEN iar.isDefaultActivity = false - THEN :ashaSupervisorUserName - ELSE iar.verifiedByUserName - END, - - iar.approvalDate = - CASE - WHEN iar.isDefaultActivity = false - THEN :approvalDate - ELSE iar.approvalDate - END, - + iar.verifiedByUserId = :ashaSupervisorUserId, + iar.verifiedByUserName = :ashaSupervisorUserName, + iar.approvalDate = :approvalDate, iar.reason = NULL, iar.otherReason = NULL - WHERE iar.ashaId = :ashaId AND iar.isClaimed = true AND iar.createdDate >= :startDate @@ -238,9 +317,11 @@ int updateApprovalStatusByAshaAndDateRangeForDefaultActivity( + "iar.otherReason = :otherReason, " + "iar.approvalDate = :approvalDate, " + "iar.verifiedByUserName = :ashaSupervisorUserName " - + "WHERE iar.isClaimed = true") + + "WHERE iar.isClaimed = true " + + "AND iar.ashaId = :ashaId") int updateApprovalStatusById( @Param("status") Integer status, + @Param("ashaId") Integer ashaId, @Param("ashaSupervisorUserId") Integer ashaSupervisorUserId, @Param("ashaSupervisorUserName") String ashaSupervisorUserName, @Param("reason") String reason, diff --git a/src/main/java/com/iemr/flw/repo/iemr/SupervisorDashboardRepo.java b/src/main/java/com/iemr/flw/repo/iemr/SupervisorDashboardRepo.java index d1a1f661..071aeab0 100644 --- a/src/main/java/com/iemr/flw/repo/iemr/SupervisorDashboardRepo.java +++ b/src/main/java/com/iemr/flw/repo/iemr/SupervisorDashboardRepo.java @@ -80,6 +80,19 @@ List getUnclaimedCountByAshaIds( @Param("startDate") Timestamp startDate, @Param("endDate") Timestamp endDate); + + @Query(value = "SELECT COUNT(*) " + + "FROM incentive_activity_record iar " + + "WHERE iar.asha_id = :ashaId " + + "AND iar.created_date >= :startDate " + + "AND iar.created_date < :endDate " + + "AND (iar.is_claimed = false OR iar.is_claimed IS NULL)", + nativeQuery = true) + Long getUnclaimedCountByAshaId( + @Param("ashaId") Integer ashaId, + @Param("startDate") Timestamp startDate, + @Param("endDate") Timestamp endDate); + // Get facility details with geo names @Query(value = "SELECT DISTINCT f.FacilityID, f.FacilityName, " + "COALESCE(s.StateName,'') AS stateName, " @@ -107,7 +120,8 @@ List getUnclaimedCountByAshaIds( + "COUNT(*) AS totalRecords, " + "SUM(CASE WHEN iar.approval_status = 101 THEN 1 ELSE 0 END) AS verified, " + "SUM(CASE WHEN iar.approval_status = 103 THEN 1 ELSE 0 END) AS rejected, " - + "SUM(CASE WHEN iar.approval_status = 102 THEN 1 ELSE 0 END) AS pending " + + "SUM(CASE WHEN iar.approval_status = 102 THEN 1 ELSE 0 END) AS pending, " + + "SUM(CASE WHEN iar.approval_status IN (101, 105) THEN 1 ELSE 0 END) AS approved " + "FROM incentive_activity_record iar " + "WHERE iar.asha_id IN (:ashaIds) " + "AND iar.created_date >= :startDate " @@ -120,11 +134,32 @@ List getIncentiveStatusByAshaIds( @Param("startDate") Timestamp startDate, @Param("endDate") Timestamp endDate); + + + @Query(value = "SELECT iar.asha_id, " + + "COUNT(*) AS totalRecords, " + + "SUM(CASE WHEN iar.approval_status = 101 THEN 1 ELSE 0 END) AS verified, " + + "SUM(CASE WHEN iar.approval_status = 103 THEN 1 ELSE 0 END) AS rejected, " + + "SUM(CASE WHEN iar.approval_status = 102 THEN 1 ELSE 0 END) AS pending, " + + "SUM(CASE WHEN iar.approval_status IN (102,105) THEN 1 ELSE 0 END) AS approved " + + "FROM incentive_activity_record iar " + + "WHERE iar.asha_id IN (:ashaIds) " + + "AND iar.created_date >= :startDate " + + "AND iar.is_claimed = true " + + "AND iar.created_date < :endDate " + + "GROUP BY iar.asha_id", + nativeQuery = true) + List getIncentiveStatusByAshaIdsForAnm( + @Param("ashaIds") List ashaIds, + @Param("startDate") Timestamp startDate, + @Param("endDate") Timestamp endDate); + @Query(value = "SELECT iar.asha_id, " + "COUNT(*) AS totalRecords, " + "SUM(CASE WHEN iar.approval_status = 101 THEN 1 ELSE 0 END) AS verified, " + "SUM(CASE WHEN iar.approval_status = 103 THEN 1 ELSE 0 END) AS rejected, " - + "SUM(CASE WHEN iar.approval_status = 102 THEN 1 ELSE 0 END) AS pending " + + "SUM(CASE WHEN iar.approval_status = 102 THEN 1 ELSE 0 END) AS pending, " + + "SUM(CASE WHEN iar.approval_status IN (101, 105) THEN 1 ELSE 0 END) AS approved " + "FROM incentive_activity_record iar " + "WHERE iar.asha_id IN (:ashaIds) " + "AND iar.created_date >= :startDate " diff --git a/src/main/java/com/iemr/flw/service/impl/ChildCareServiceImpl.java b/src/main/java/com/iemr/flw/service/impl/ChildCareServiceImpl.java index e65e0f53..8a840f05 100644 --- a/src/main/java/com/iemr/flw/service/impl/ChildCareServiceImpl.java +++ b/src/main/java/com/iemr/flw/service/impl/ChildCareServiceImpl.java @@ -709,7 +709,8 @@ public List saveAllIfa(List dtoList, Intege savedList.forEach(data -> { Timestamp visitTimestamp = Timestamp.valueOf(data.getIfaProvisionDate().atStartOfDay()); - if(data.getIfaBottleCount().equals("10.0")){ + + if(data!=null){ incentiveLogicService.incentiveForGiveingIFA( data.getBeneficiaryId(), visitTimestamp, @@ -774,8 +775,10 @@ private IfaDistributionDTO mapToDTO(IfaDistribution entity) { fields.setIfa_provision_date(entity.getIfaProvisionDate().format(FORMATTER)); } fields.setMcp_card_upload(entity.getMcpCardUpload()); - fields.setIfa_bottle_count(Double.valueOf(entity.getIfaBottleCount())); + if(entity.getIfaBottleCount()!=null){ + fields.setIfa_bottle_count(Double.valueOf(entity.getIfaBottleCount())); + } dto.setFields(fields); return dto; } @@ -803,7 +806,10 @@ private IfaDistribution mapToEntity(IfaDistributionDTO dto, Integer userId) { entity.setIfaProvisionDate(null); } } - entity.setIfaBottleCount(dto.getFields().getIfa_bottle_count().toString()); + if(dto.getFields().getIfa_bottle_count()!=null){ + entity.setIfaBottleCount(dto.getFields().getIfa_bottle_count().toString()); + + } entity.setMcpCardUpload(dto.getFields().getMcp_card_upload()); } diff --git a/src/main/java/com/iemr/flw/service/impl/DeathReportsServiceImpl.java b/src/main/java/com/iemr/flw/service/impl/DeathReportsServiceImpl.java index b7eee7dd..cfc77214 100644 --- a/src/main/java/com/iemr/flw/service/impl/DeathReportsServiceImpl.java +++ b/src/main/java/com/iemr/flw/service/impl/DeathReportsServiceImpl.java @@ -81,37 +81,6 @@ public String registerCDR(List cdrDTOs) { } } - public String updateCDRUploadFiles(CdrDTO cdrDTOs, Long incentiveActivityId) { - try { - Optional cdrOptional = cdrRepo.findById(cdrDTOs.getId()); - CDR cdr = new CDR(); - if (cdrOptional.isPresent()) { - cdr = cdrOptional.get(); - if (cdrDTOs.getCdrImage() != null && !cdrDTOs.getCdrImage().isEmpty()) { - cdr.setCdrImage(cdrDTOs.getCdrImage()); - } - - if (cdrDTOs.getCdrImage2() != null && !cdrDTOs.getCdrImage2().isEmpty()) { - cdr.setCdrImage2(cdrDTOs.getCdrImage2()); - } - - if (cdrDTOs.getDeathCertImage1() != null && !cdrDTOs.getDeathCertImage1().isEmpty()) { - cdr.setDeathCertImage1(cdrDTOs.getDeathCertImage1()); - } - - if (cdrDTOs.getDeathCertImage2() != null && !cdrDTOs.getDeathCertImage2().isEmpty()) { - cdr.setDeathCertImage2(cdrDTOs.getDeathCertImage2()); - } - } - cdrRepo.save(cdr); - - pendindDocService.updateIncentive(incentiveActivityId); - - return "no of cdr details update: "; - } catch (Exception e) { - return "error while saving cdr details: " + e.getMessage(); - } - } @Override public String registerMDSR(List mdsrDTOs) { @@ -141,43 +110,6 @@ public String registerMDSR(List mdsrDTOs) { } } - public String updateMDSR(MdsrDTO mdsrDTO, Long incentiveActivityId) { - try { - - Optional mdsrOptional = mdsrRepo.findById(mdsrDTO.getId()); - MDSR mdsr = new MDSR(); - - if (mdsrOptional.isPresent()) { - - mdsr = mdsrOptional.get(); - - if (mdsrDTO.getMdsr1File() != null && !mdsrDTO.getMdsr1File().isEmpty()) { - mdsr.setMdsr1File(mdsrDTO.getMdsr1File()); - } - - if (mdsrDTO.getMdsr2File() != null && !mdsrDTO.getMdsr2File().isEmpty()) { - mdsr.setMdsr2File(mdsrDTO.getMdsr2File()); - } - - if (mdsrDTO.getMdsrDeathCertFile() != null && !mdsrDTO.getMdsrDeathCertFile().isEmpty()) { - mdsr.setMdsrDeathCertFile(mdsrDTO.getMdsrDeathCertFile()); - } - - } else { - return "MDSR record not found with id: " + mdsrDTO.getId(); - } - - mdsrRepo.save(mdsr); - - // incentive update - pendindDocService.updateIncentive(incentiveActivityId); - - return "MDSR updated successfully for id: " + mdsrDTO.getId(); - - } catch (Exception e) { - return "error while updating mdsr details: " + e.getMessage(); - } - } @Override public List getCdrRecords(GetBenRequestHandler dto) { diff --git a/src/main/java/com/iemr/flw/service/impl/DiseaseControlServiceImpl.java b/src/main/java/com/iemr/flw/service/impl/DiseaseControlServiceImpl.java index 35746b2f..64bc90cf 100644 --- a/src/main/java/com/iemr/flw/service/impl/DiseaseControlServiceImpl.java +++ b/src/main/java/com/iemr/flw/service/impl/DiseaseControlServiceImpl.java @@ -1269,6 +1269,26 @@ private void checkAndAddIncentives(ScreeningMalaria diseaseScreening) { } } + if (diseaseScreening.getCaseStatus().equals("Suspected")) { + if (!diseaseScreening.getMalariaTestType().isEmpty()) { + if (stateId.equals(StateCode.AM.getStateCode())) { + if (incentiveActivityForCollectSlideAM != null) { + addIncentive(incentiveActivityForCollectSlideAM, diseaseScreening); + + } + } + + if (stateId.equals(StateCode.CG.getStateCode())) { + if (incentiveActivityForCollectSlideCG != null) { + addIncentive(incentiveActivityForCollectSlideCG, diseaseScreening); + + } + } + + + } + + } } private void addIncentive(IncentiveActivity diseaseScreeningActivity, MosquitoNetEntity diseaseScreening) { diff --git a/src/main/java/com/iemr/flw/service/impl/IncentiveServiceImpl.java b/src/main/java/com/iemr/flw/service/impl/IncentiveServiceImpl.java index 8f814af2..cfdaaae2 100644 --- a/src/main/java/com/iemr/flw/service/impl/IncentiveServiceImpl.java +++ b/src/main/java/com/iemr/flw/service/impl/IncentiveServiceImpl.java @@ -370,10 +370,27 @@ public String getAllIncentivesGroupedSummary(GetBenRequestHandler request,Intege records = records.stream() .filter(r -> validActivityIds.contains(r.getActivityId()) && r.getIsDefaultActivity()) .collect(Collectors.toList()); - }else if("ANM".equalsIgnoreCase(roleName) || "CHO".equalsIgnoreCase(roleName) ){ - records = records.stream() - .filter(r -> validActivityIds.contains(r.getActivityId())) - .collect(Collectors.toList()); + }else if ("ANM".equalsIgnoreCase(roleName) || "CHO".equalsIgnoreCase(roleName)) { + if ("ANM".equalsIgnoreCase(roleName) || "CHO".equalsIgnoreCase(roleName)) { + records = records.stream() + .filter(r -> + validActivityIds.contains(r.getActivityId()) && + ( + r.getApprovalStatus() == 101 + || r.getApprovalStatus() == 103 + || r.getApprovalStatus() == 105 + || r.getApprovalStatus() == 104 + || ( + r.getApprovalStatus() == 102 + && ( + isAfter24Hours(r.getCalimedDate()) + || Boolean.FALSE.equals(r.getIsDefaultActivity()) + ) + ) + ) + ) + .collect(Collectors.toList()); + } } }else { @@ -396,6 +413,12 @@ public String getAllIncentivesGroupedSummary(GetBenRequestHandler request,Intege IncentiveActivity activity = incentivesRepo.findById(activityId).orElse(null); + Integer approvalStatus = list.stream() + .max(Comparator.comparing(IncentiveActivityRecord::getCreatedDate)) + .map(IncentiveActivityRecord::getApprovalStatus) + .orElse(0); + + if (activity == null) continue; long total = list.stream() @@ -408,6 +431,7 @@ public String getAllIncentivesGroupedSummary(GetBenRequestHandler request,Intege map.put("activityDec", activity.getDescription()); map.put("groupName", activity.getGroup()); map.put("isDefault", activity.getIsDefaultActivity()); + map.put("approvalStatus", approvalStatus); map.put("claimCount", list.size()); map.put("totalAmount", total); map.put("amount", activity.getRate()); @@ -431,6 +455,21 @@ public String getAllIncentivesGroupedSummary(GetBenRequestHandler request,Intege return new Gson().toJson(result); } + private boolean isAfter24Hours(Timestamp claimedDate) { + if (claimedDate == null) { + return false; + } + + long now = System.currentTimeMillis(); + long diff = now - claimedDate.getTime(); + + logger.info("Now: {}", new Timestamp(now)); + logger.info("ClaimedDate: {}", claimedDate); + logger.info("Diff(ms): {}", diff); + logger.info("Diff(hours): {}", diff / (1000 * 60 * 60.0)); + + return diff >= 24L * 60 * 60 * 1000; + } @Override public String getAllIncentivesGroupedActivity(GetBenRequestHandler request) { try { diff --git a/src/main/java/com/iemr/flw/service/impl/MaternalHealthServiceImpl.java b/src/main/java/com/iemr/flw/service/impl/MaternalHealthServiceImpl.java index 41849ee3..83d261ee 100644 --- a/src/main/java/com/iemr/flw/service/impl/MaternalHealthServiceImpl.java +++ b/src/main/java/com/iemr/flw/service/impl/MaternalHealthServiceImpl.java @@ -439,7 +439,8 @@ public String savePNCVisit(List pncVisitDTOs) { logger.info("PNC visit details saved"); return "no of pnc details saved: " + pncList.size(); } catch (Exception e) { - logger.info("Saving PNC visit details failed with error : " + e.getMessage()); + logger.error("Saving PNC visit details failed", e); + } return null; } @@ -591,7 +592,6 @@ private Boolean yesNoToBoolean(String value) { private void checkAndAddAntaraIncentive(PNCVisit ect) { Integer userId = userRepo.getUserIdByName(ect.getCreatedBy()); Integer stateId = userRepo.getUserRole(userId).get(0).getStateId(); - logger.info("ContraceptionMethod:" + ect.getContraceptionMethod()); // logic for assam if (stateId.equals(StateCode.AM.getStateCode())) { @@ -708,18 +708,20 @@ private void checkAndAddAntaraIncentive(PNCVisit ect) { } if (ect.getPncPeriod() == 1 || ect.getPncPeriod() == 3 || ect.getPncPeriod() == 7) { + if(ect.getContraceptionMethod()!=null){ + if ((ect.getContraceptionMethod().equals("POST PARTUM STERILIZATION (PPS)") + || ect.getContraceptionMethod().equals("MiniLap")) + && ect.getSterilisationDate() != null) { + IncentiveActivity ppsActivityCH = + incentivesRepo.findIncentiveMasterByNameAndGroup("FP_PPS", GroupName.ACTIVITY.getDisplayName()); + if (ppsActivityCH != null) { - if ((ect.getContraceptionMethod().equals("POST PARTUM STERILIZATION (PPS)") - || ect.getContraceptionMethod().equals("MiniLap")) - && ect.getSterilisationDate() != null) { - IncentiveActivity ppsActivityCH = - incentivesRepo.findIncentiveMasterByNameAndGroup("FP_PPS", GroupName.ACTIVITY.getDisplayName()); - if (ppsActivityCH != null) { + addIncenticeRecord(ect, userId, ppsActivityCH); - addIncenticeRecord(ect, userId, ppsActivityCH); + } + } + } - } - } } } @@ -850,7 +852,7 @@ private void checkAndAddIncentives(List ancList, Integer userId) { if (ancFullActivityCH != null && ancVisit.getAncVisit() != null && ancVisit.getAncVisit() == 4) { - recordAncRelatedIncentive(ancFullActivityCH, ancVisit); + recordFullAncIncentive(ancFullActivityCH, ancVisit); } @@ -872,12 +874,12 @@ private void recordAncRelatedIncentive(IncentiveActivity incentiveActivity, ANCV if (record == null) { record = new IncentiveActivityRecord(); record.setActivityId(incentiveActivity.getId()); - record.setCreatedDate(ancVisit.getCreatedDate()); + record.setCreatedDate(ancVisit.getAncDate()); record.setCreatedBy(ancVisit.getCreatedBy()); - record.setUpdatedDate(ancVisit.getCreatedDate()); + record.setUpdatedDate(ancVisit.getAncDate()); record.setUpdatedBy(ancVisit.getCreatedBy()); - record.setStartDate(ancVisit.getCreatedDate()); - record.setEndDate(ancVisit.getCreatedDate()); + record.setStartDate(ancVisit.getAncDate()); + record.setEndDate(ancVisit.getAncDate()); record.setBenId(ancVisit.getBenId()); record.setAshaId(userId); record.setAmount(Long.valueOf(incentiveActivity.getRate())); diff --git a/src/main/java/com/iemr/flw/service/impl/SupervisorDashboardServiceImpl.java b/src/main/java/com/iemr/flw/service/impl/SupervisorDashboardServiceImpl.java index bf164baa..b90b9f73 100644 --- a/src/main/java/com/iemr/flw/service/impl/SupervisorDashboardServiceImpl.java +++ b/src/main/java/com/iemr/flw/service/impl/SupervisorDashboardServiceImpl.java @@ -1,5 +1,6 @@ package com.iemr.flw.service.impl; +import java.math.BigDecimal; import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalDateTime; @@ -7,6 +8,7 @@ import java.util.*; import java.util.stream.Collectors; +import com.google.gson.Gson; import com.iemr.flw.domain.iemr.IncentiveActivityRecord; import com.iemr.flw.dto.iemr.UserServiceRoleDTO; import com.iemr.flw.masterEnum.IncentiveApprovalStatus; @@ -57,6 +59,9 @@ public String getSupervisorDashboard(Integer supervisorUserID, Integer month, In Integer stateId = userService.getUserDetail(supervisorUserID).getStateId(); String rollName = userService.getUserDetail(supervisorUserID).getRoleName(); + LocalDate today = LocalDate.now(); + + // 1. Supervisor user details List supervisorRows = dashboardRepo.getSupervisorUserDetails(supervisorUserID); if (supervisorRows != null && !supervisorRows.isEmpty()) { @@ -75,6 +80,14 @@ public String getSupervisorDashboard(Integer supervisorUserID, Integer month, In logger.info("Fetching ASHA details for supervisorUserID: {}", supervisorUserID); + LocalDate dueDate = LocalDate.of(year, month, 1) + .plusMonths(1) + .withDayOfMonth(5); + + boolean isOverDue = + rollName.equalsIgnoreCase("ANM") + && today.isAfter(dueDate); + List ashaRows; @@ -167,7 +180,7 @@ public String getSupervisorDashboard(Integer supervisorUserID, Integer month, In } // 5. Get incentive status per ASHA (verified, rejected, pending, totalAmount) - long overallVerified = 0, overallRejected = 0, overallPending = 0; + long overallVerified = 0, overallRejected = 0, overallPending = 0, overallOverDue =0; long overallUnclaimed = 0; try { @@ -209,26 +222,33 @@ public String getSupervisorDashboard(Integer supervisorUserID, Integer month, In List statusRows = dashboardRepo.getDefaultIncentiveStatusByAshaIds(ashaIDs, startDate, endDate); if (statusRows != null) { for (Object[] sRow : statusRows) { - long verified = ((Number) sRow[2]).longValue(); + long verified = ((Number) sRow[5]).longValue(); long rejected = ((Number) sRow[3]).longValue(); long pending = ((Number) sRow[4]).longValue(); + if (verified > 0) overallVerified += 1; if (rejected > 0) overallRejected += 1; if (pending > 0) overallPending += 1; } } }else if("ANM".equalsIgnoreCase(rollName)){ - List statusRows = dashboardRepo.getIncentiveStatusByAshaIds(ashaIDs, startDate, endDate); + List statusRows = dashboardRepo.getIncentiveStatusByAshaIdsForAnm(ashaIDs, startDate, endDate); if (statusRows != null) { for (Object[] sRow : statusRows) { long verified = ((Number) sRow[2]).longValue(); long rejected = ((Number) sRow[3]).longValue(); - long pending = ((Number) sRow[4]).longValue(); + long pending = ((Number) sRow[5]).longValue(); if (verified > 0) overallVerified += 1; if (rejected > 0) overallRejected += 1; - if (pending > 0) overallPending += 1; + if (pending > 0) { + if (isOverDue) { + overallOverDue++; + } else { + overallPending++; + } + } } } } @@ -255,7 +275,7 @@ public String getSupervisorDashboard(Integer supervisorUserID, Integer month, In overallSummary.put("verified", overallVerified); overallSummary.put("rejected", overallRejected); overallSummary.put("pending", overallPending); - overallSummary.put("overDue", 0); + overallSummary.put("overDue", overallOverDue); overallSummary.put("unclaimed", overallUnclaimed); result.put("incentiveSummary", overallSummary); @@ -315,7 +335,7 @@ public String getSupervisorDashboard(Integer supervisorUserID, Integer month, In public Map getAshasAtFacility(Integer supervisorId, Integer facilityId, Integer month, Integer year, Integer approvalStatusID) { Integer supervisorstateCode = userService.getUserDetail(supervisorId).getStateId(); - List rows; + List rows = null; LocalDate today = LocalDate.now(); @@ -324,6 +344,15 @@ public Map getAshasAtFacility(Integer supervisorId, Integer faci LocalDate currentMonthStartDate = LocalDate.of(year, month, 1); LocalDate currentMonthendLocalDate = currentMonthStartDate.plusMonths(1); + LocalDate dueDate = LocalDate.of(year, month, 1) + .plusMonths(1) + .withDayOfMonth(5); + + boolean isOverDue = + roleName.equalsIgnoreCase("ANM") + && today.isAfter(dueDate); + + logger.info("Login user role:"+ roleName); boolean isCurrentMonth = @@ -345,6 +374,7 @@ public Map getAshasAtFacility(Integer supervisorId, Integer faci if ("ANM".equalsIgnoreCase(roleName) || "CHO".equalsIgnoreCase(roleName)) { + logger.info("ANM:" + roleName); if (facilityId.equals(0)) { @@ -359,18 +389,36 @@ public Map getAshasAtFacility(Integer supervisorId, Integer faci } } else { + logger.info("Other:" + roleName); if (facilityId.equals(0)) { - rows = ashaSupervisorLoginRepo.getAshasAtFacility( - supervisorId, approvalStatusID, startDate, endDate); + if(supervisorstateCode.equals(StateCode.CG.getStateCode())){ + if("ASHA Supervisor".equalsIgnoreCase(roleName)){ + rows = ashaSupervisorLoginRepo.getAshasAtFacilityCg( + supervisorId, approvalStatusID, startDate, endDate); + } + }else if(supervisorstateCode.equals(StateCode.AM.getStateCode())){ + rows = ashaSupervisorLoginRepo.getAshasAtFacility( + supervisorId, approvalStatusID, startDate, endDate); + } } else { - rows = ashaSupervisorLoginRepo.getAshasAtFacility( - supervisorId, facilityId, approvalStatusID, startDate, endDate); + if(supervisorstateCode.equals(StateCode.CG.getStateCode())){ + if("ASHA Supervisor".equalsIgnoreCase(roleName)){ + rows = ashaSupervisorLoginRepo.getAshasAtFacilityCg( + supervisorId, facilityId, approvalStatusID, startDate, endDate); + } + }else if(supervisorstateCode.equals(StateCode.AM.getStateCode())){ + rows = ashaSupervisorLoginRepo.getAshasAtFacility( + supervisorId, facilityId, approvalStatusID, startDate, endDate); + } + + } } + logger.info("Other:" + rows); - long overallVerified = 0, overallRejected = 0, overallPending = 0 ,overallApproved =0; + long overallVerified = 0, overallRejected = 0, overallPending = 0 , overallUnclaimed=0 ,overallOverDue =0; String facilityName = ""; String facilityType = ""; @@ -392,13 +440,30 @@ public Map getAshasAtFacility(Integer supervisorId, Integer faci if(supervisorstateCode.equals(StateCode.CG.getStateCode())){ if("ASHA Supervisor".equalsIgnoreCase(roleName)){ - countList = incentiveRecordRepo.getStatusCountByAshaIdOfDefaultActivity(ashaId, startDate, endDate); + if(approvalStatusID.equals(106)){ + countList = incentiveRecordRepo.getStatusUnclaimedCountByAshaId(ashaId, startDate, endDate); + + }else { + countList = incentiveRecordRepo.getStatusCountByAshaIdOfDefaultActivity(ashaId, startDate, endDate); + + } + + logger.info("countList = {}", Arrays.deepToString(countList.toArray())); + + }else if(("ANM".equalsIgnoreCase(roleName) || "CHO".equalsIgnoreCase(roleName) )){ logger.info("ASHA_ID = {}", ashaId); logger.info("Role = {}", roleName); - countList = incentiveRecordRepo.getStatusCountByAshaId(ashaId, startDate, endDate); + if(approvalStatusID.equals(106)){ + countList = incentiveRecordRepo.getStatusUnclaimedCountByAshaId(ashaId, startDate, endDate); + + }else { + countList = incentiveRecordRepo.getStatusCountByAshaIdANM(ashaId, startDate, endDate); + + } + logger.info("Count List = {}", countList); @@ -417,12 +482,26 @@ public Map getAshasAtFacility(Integer supervisorId, Integer faci ashaId, startDate, endDate, approvalStatusID, stateCode); }else if(stateCode.equals(StateCode.CG.getStateCode())){ if("ASHA Supervisor".equalsIgnoreCase(roleName)){ + if(approvalStatusID.equals(105)){ + totalAmount = incentiveRecordRepo.getDefaultActivityTotalAmountByAsha( + ashaId, startDate, endDate, 101, stateCode); + }else { + totalAmount = incentiveRecordRepo.getDefaultActivityTotalAmountByAsha( + ashaId, startDate, endDate, approvalStatusID, stateCode); + } - totalAmount = incentiveRecordRepo.getDefaultActivityTotalAmountByAsha( - ashaId, startDate, endDate, approvalStatusID, stateCode); }else if("ANM".equalsIgnoreCase(roleName) || "CHO".equalsIgnoreCase(roleName) ){ - totalAmount = incentiveRecordRepo.getTotalAmountByAsha( - ashaId, startDate, endDate, approvalStatusID, stateCode); + if(approvalStatusID.equals(102)){ + totalAmount = incentiveRecordRepo.getTotalAmountByAshaANM( + ashaId, startDate, endDate, approvalStatusID, stateCode); + }else if(approvalStatusID.equals(104)){ + totalAmount = incentiveRecordRepo.getTotalAmountByAshaANM( + ashaId, startDate, endDate, 105, stateCode); + } else { + totalAmount = incentiveRecordRepo.getTotalAmountByAsha( + ashaId, startDate, endDate, approvalStatusID, stateCode); + } + } } @@ -445,21 +524,100 @@ public Map getAshasAtFacility(Integer supervisorId, Integer faci List dbRecords = incentiveRecordRepo.getRecordsByAsha(ashaId, startDate, endDate); if("ASHA Supervisor".equalsIgnoreCase(roleName)){ - incentiveActivityRecord = dbRecords.stream() - .filter(r -> approvalStatusID == 0 || - approvalStatusID.equals(r.getApprovalStatus()) && r.getIsDefaultActivity() && isWithin24Hours(r.getCalimedDate())) - .collect(Collectors.toList()); + if(approvalStatusID.equals(105)){ + incentiveActivityRecord = dbRecords.stream() + .filter(r -> (r.getApprovalStatus().equals(101) || r.getApprovalStatus().equals(105)) && r.getIsDefaultActivity()) + .collect(Collectors.toList()); + }else if(approvalStatusID.equals(106)){ + incentiveActivityRecord = dbRecords.stream() + .filter(r ->r.getApprovalStatus().equals(102) && r.getIsDefaultActivity() && !r.getIsClaimed()) + .collect(Collectors.toList()); + }else if(approvalStatusID.equals(0)){ + incentiveActivityRecord = dbRecords.stream() + .filter(r ->((r.getApprovalStatus().equals(102) && r.getIsClaimed()) ||(r.getApprovalStatus().equals(102) && !r.getIsClaimed())|| r.getApprovalStatus().equals(103) || r.getApprovalStatus().equals(105) || r.getApprovalStatus().equals(101) || r.getApprovalStatus().equals(104)) && r.getIsDefaultActivity()) + .collect(Collectors.toList()); + }else{ + incentiveActivityRecord = dbRecords.stream() + .filter(r ->( approvalStatusID == 0 || + approvalStatusID.equals(r.getApprovalStatus())) && r.getIsDefaultActivity() && isWithin24Hours(r.getCalimedDate())) + .collect(Collectors.toList()); + } + }else if ("ANM".equalsIgnoreCase(roleName) || "CHO".equalsIgnoreCase(roleName)) { - incentiveActivityRecord = dbRecords.stream() - .filter(r -> approvalStatusID == 0 || - approvalStatusID.equals(r.getApprovalStatus()) && isAfter24Hours(r.getCreatedDate())) + + if (approvalStatusID.equals(102)) { + + incentiveActivityRecord = dbRecords.stream() + .peek(r -> { + if (r.getApprovalStatus().equals(102) + && Boolean.FALSE.equals(r.getIsDefaultActivity()) + && r.getCalimedDate() != null + && isAfter24Hours(r.getCalimedDate())) { + + r.setApprovalStatus(105); + } + }) + .filter(r -> + r.getApprovalStatus().equals(105) + || (r.getApprovalStatus().equals(102) + && Boolean.FALSE.equals(r.getIsDefaultActivity()))) + .collect(Collectors.toList()); + totalAmount = incentiveActivityRecord.stream() + .mapToLong(r -> r.getAmount()) + .sum(); + incentiveActivityRecord.forEach(r -> logger.info( + "activityId={}, status={}, isDefaultActivity={}", + r.getActivityId(), + r.getApprovalStatus(), + r.getIsDefaultActivity() + )); + + }else if (approvalStatusID.equals(104)) { + if(isOverDue){ + incentiveActivityRecord = dbRecords.stream() + .filter(r -> + r.getApprovalStatus().equals(105) + || (r.getApprovalStatus().equals(104))) + .peek(r -> { + if (r.getApprovalStatus().equals(102) || r.getApprovalStatus().equals(105)) { + r.setApprovalStatus(104); + } + }) + .collect(Collectors.toList()); + } + + }else if(approvalStatusID.equals(106)){ + incentiveActivityRecord = dbRecords.stream() + .filter(r->!r.getIsClaimed() && r.getApprovalStatus().equals(102)).collect(Collectors.toList()); + }else if(approvalStatusID.equals(0)){ + incentiveActivityRecord = dbRecords.stream() + .filter(r->((r.getApprovalStatus().equals(102) && r.getIsClaimed()) ||(r.getApprovalStatus().equals(102) && !r.getIsClaimed()) || r.getApprovalStatus().equals(103) || r.getApprovalStatus().equals(105) || r.getApprovalStatus().equals(101) || r.getApprovalStatus().equals(104))).collect(Collectors.toList()); + } else{ + incentiveActivityRecord = dbRecords.stream() + .filter(r -> { + + if (approvalStatusID != 0 + && !approvalStatusID.equals(r.getApprovalStatus())) { + return false; + } + + // 102 should be visible only after 24 hours + if (r.getApprovalStatus().equals(102)) { + return true; + } + + // 105 should always be visible + return true; + }) .peek(r -> { - if (isAfter24Hours(r.getCreatedDate()) - && r.getApprovalStatus().equals(102)) { - r.setApprovalStatus(104); + if (r.getApprovalStatus().equals(102) + && isAfter24Hours(r.getCalimedDate())) { + r.setApprovalStatus(105); } }) .collect(Collectors.toList()); + } + } @@ -467,6 +625,9 @@ public Map getAshasAtFacility(Integer supervisorId, Integer faci } logger.info("Final incentiveActivityRecord count: {}", incentiveActivityRecord.size()); + logger.info("Final incentiveActivityRecord: {}", + new Gson().toJson(incentiveActivityRecord)); + List> activityList = new ArrayList<>(); for (IncentiveActivityRecord record : incentiveActivityRecord) { Map activity = new HashMap<>(); @@ -495,37 +656,104 @@ public Map getAshasAtFacility(Integer supervisorId, Integer faci asha.put("facilityType", facilityType); asha.put("userId", row[0]); asha.put("fullName", fullName(row[1], row[2])); - asha.put("employeeId", str(row[3]).isEmpty() ? null : str(row[3])); + asha.put("employeeId", row[0]); asha.put("mobile", str(row[4]).isEmpty() ? null : str(row[4])); asha.put("gender", str(row[5]).isEmpty() ? null : str(row[5])); asha.put("totalAmount", totalAmount); asha.put("activities", activityList); - long pending = 0, verified = 0, rejected = 0 ,approved =0; + + + long pending = 0, verified = 0, rejected = 0 , unclaimedCount = 0 ; + + if (countList != null && !countList.isEmpty()) { Object[] counts = countList.get(0); - verified = counts[0] != null ? ((Number) counts[0]).longValue() : 0; - pending = counts[1] != null ? ((Number) counts[1]).longValue() : 0; - rejected = counts[2] != null ? ((Number) counts[2]).longValue() : 0; - approved = counts[3] != null ? ((Number) counts[3]).longValue() : 0; + logger.info("Count List = {}", Arrays.deepToString(countList.toArray())); + logger.info("101={}, 102={}, 103={}, 101+105={}", + counts[0], counts[1], counts[2], counts[3]); + + if(stateCode.equals(StateCode.CG.getStateCode())){ + if(roleName.equalsIgnoreCase("ANM")){ + verified = counts[0] != null ? ((Number) counts[0]).longValue() : 0; + rejected = counts[2] != null ? ((Number) counts[2]).longValue() : 0; + if(approvalStatusID.equals(106)){ + unclaimedCount = counts[1] != null ? ((Number) counts[1]).longValue() : 0; + + }else if(approvalStatusID.equals(0)){ + unclaimedCount = counts[1] != null ? ((Number) counts[1]).longValue() : 0; + pending = counts[3] != null ? ((Number) counts[3]).longValue() : 0; + + }else{ + + pending = counts[3] != null ? ((Number) counts[3]).longValue() : 0; + + } + + + }else if(roleName.equalsIgnoreCase("ASHA Supervisor")) { + if (approvalStatusID.equals(105)) { + // 101 + 105 + verified = counts[3] != null ? ((Number) counts[3]).longValue() : 0; + } else { + // only 101 + verified = counts[0] != null ? ((Number) counts[0]).longValue() : 0; + } + if(approvalStatusID.equals(106)){ + unclaimedCount = counts[1] != null ? ((Number) counts[1]).longValue() : 0; + + }else if(approvalStatusID.equals(0)){ + unclaimedCount = counts[1] != null ? ((Number) counts[1]).longValue() : 0; + pending = counts[1] != null ? ((Number) counts[1]).longValue() : 0; + + }else{ + pending = counts[1] != null ? ((Number) counts[1]).longValue() : 0; + + } + rejected = counts[2] != null ? ((Number) counts[2]).longValue() : 0; + + + } + }else { + verified = counts[0] != null ? ((Number) counts[0]).longValue() : 0; + pending = counts[1] != null ? ((Number) counts[1]).longValue() : 0; + rejected = counts[2] != null ? ((Number) counts[2]).longValue() : 0; + } + } + + if (verified > 0) overallVerified += 1; if (rejected > 0) overallRejected += 1; - if (pending > 0) overallPending += 1; - if (approved > 0) overallApproved += 1; + if (pending > 0) { + if (isOverDue) { + overallOverDue++; + } else { + overallPending++; + } + } + + if (unclaimedCount > 0) overallUnclaimed += 1; asha.put("pending", pending); asha.put("verified", verified); asha.put("rejected", rejected); - asha.put("approved", approved); + asha.put("unClaimed", unclaimedCount); int approvalStatus = 0; if (!activityList.isEmpty()) { approvalStatus = (int) activityList.get(0).get("approvalStatus"); } - if (pending == 0 && verified == 0 && rejected == 0) continue; + if(!approvalStatusID.equals(106)){ + if (totalAmount == null || totalAmount <= 0) continue; + + } + + + if (pending == 0 && verified == 0 && rejected == 0 && unclaimedCount == 0) continue; + if (approvalStatusID.equals(0)) { asha.put("approvalStatus", approvalStatus); @@ -543,7 +771,7 @@ public Map getAshasAtFacility(Integer supervisorId, Integer faci approvalStatus.put("verified", overallVerified); approvalStatus.put("pending", overallPending); approvalStatus.put("rejected", overallRejected); - approvalStatus.put("approved", overallApproved); + approvalStatus.put("unClaimed", overallUnclaimed); response.put("approvalStatus", approvalStatus); response.put("data", ashaList); @@ -557,8 +785,15 @@ private boolean isAfter24Hours(Timestamp claimedDate) { return false; } - long diff = System.currentTimeMillis() - claimedDate.getTime(); - return diff >= 24 * 60 * 60 * 1000L; + long now = System.currentTimeMillis(); + long diff = now - claimedDate.getTime(); + + logger.info("Now: {}", new Timestamp(now)); + logger.info("ClaimedDate: {}", claimedDate); + logger.info("Diff(ms): {}", diff); + logger.info("Diff(hours): {}", diff / (1000 * 60 * 60.0)); + + return diff >= 24L * 60 * 60 * 1000; } private boolean isWithin24Hours(Timestamp claimedDate) { if (claimedDate == null) { @@ -608,6 +843,7 @@ public int updateApprovalStatus(Integer ashaId, if (approvalStatus.equals(IncentiveApprovalStatus.REJECTED.getCode())) { updatedCount = incentiveRecordRepo.updateApprovalStatusById( approvalStatus, + ashaId, ashaSupervisorUserId, ashaSupervisorDetails.getUserName(), reason, @@ -628,11 +864,11 @@ public int updateApprovalStatus(Integer ashaId, if ("ASHA Supervisor".equalsIgnoreCase(ashaSupervisorDetails.getRoleName())) { updatedCount = incentiveRecordRepo.updateApprovalStatusByAshaAndDateRange( - ashaId, 104, startDate, endDate, + ashaId, 105, startDate, endDate, approvalDate, ashaSupervisorUserId, ashaSupervisorDetails.getUserName()); - } else { + } else if("ANM".equalsIgnoreCase(ashaSupervisorDetails.getRoleName())){ updatedCount = incentiveRecordRepo.updateApprovalStatusByAshaAndDateRangeForDefaultActivity( ashaId, approvalStatus, startDate, endDate,