From 4ca7f7c288cfc5111849d69e5205bd309515a357 Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Mon, 25 Nov 2024 12:15:01 +0530 Subject: [PATCH 1/3] cumulative beneficiary. --- .../controller/UserController.java | 1 + .../dao/impl/KilkariCallReportDaoImpl.java | 29 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/controller/UserController.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/controller/UserController.java index f5ced1e9..5fc59089 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/controller/UserController.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/controller/UserController.java @@ -1444,6 +1444,7 @@ public ResponseEntity getCumulativeBeneficiaries(){ Long cumulativeJoinedSubscription = kilkariCallReportDao.getCumulativeJoinedSubscription(locationId, locationType, toDate); + LOGGER.info("cumulativecount:{},date:{},locationType:{},locationId:{}",cumulativeJoinedSubscription,toDate,locationType,locationId); return ResponseEntity.ok(cumulativeJoinedSubscription); // Long ashaStarted = 0L; // Long ashaCompleted = 0L; diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java index 6ee3b713..f11cb993 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java @@ -4,6 +4,7 @@ import com.beehyv.nmsreporting.dao.KilkariCallReportDao; import com.beehyv.nmsreporting.model.KilkariCalls; import org.hibernate.Criteria; +import org.hibernate.Query; import org.hibernate.criterion.Order; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; @@ -11,6 +12,7 @@ import java.util.Date; import java.util.List; +import java.util.logging.Logger; /** * Created by beehyv on 11/10/17. @@ -51,20 +53,29 @@ public KilkariCalls getKilkariCallreport(Integer locationId, String locationTyp @Override public Long getCumulativeJoinedSubscription(Long locationId, String locationType, Date toDate) { - Criteria criteria = createEntityCriteria(); + String hql; if (locationId == 0 && "State".equalsIgnoreCase(locationType)) { - criteria.add(Restrictions.eq("locationType", locationType)); + String sql = "SELECT COALESCE(SUM(CAST(total_beneficiaries AS SIGNED)), 0) " + + "FROM agg_kilkari_call_report " + + "WHERE location_type = :locationType AND date = (SELECT date FROM agg_kilkari_call_report ORDER BY date DESC LIMIT 1)"; + Query query = getSession().createSQLQuery(sql); + query.setParameter("locationType", locationType); +// query.setParameter("toDate", toDate); + Long result = ((Number) query.uniqueResult()).longValue(); + return result != null ? result : 0L; } else { - criteria.add(Restrictions.eq("locationId", locationId)); - criteria.add(Restrictions.eq("locationType", locationType)); + String sql = "SELECT COALESCE(SUM(CAST(total_beneficiaries AS SIGNED)), 0) " + + "FROM agg_kilkari_call_report " + + "WHERE location_id = :locationId AND location_type = :locationType AND date = (SELECT date FROM agg_kilkari_call_report ORDER BY date DESC LIMIT 1)"; + Query query = getSession().createSQLQuery(sql); + query.setParameter("locationId", locationId); + query.setParameter("locationType", locationType); +// query.setParameter("toDate", toDate); + Long result = ((Number) query.uniqueResult()).longValue(); + return result != null ? result : 0L; } - criteria.add(Restrictions.eq("date", toDate)); - criteria.setProjection(Projections.sum("uniqueBeneficiaries")); - - Long result = (Long) criteria.uniqueResult(); - return result != null ? result : 0L; } } From b072d4fd6b58e0206fd91a473ccefeb42d7d3c99 Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Mon, 25 Nov 2024 12:17:16 +0530 Subject: [PATCH 2/3] cumulative beneficiary. --- .../beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java index f11cb993..ae3ffb67 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java @@ -6,13 +6,11 @@ import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Order; -import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.springframework.stereotype.Repository; import java.util.Date; import java.util.List; -import java.util.logging.Logger; /** * Created by beehyv on 11/10/17. From 052c358cf73fca2fe38ce3d1125dadeda3e45fe3 Mon Sep 17 00:00:00 2001 From: Mandar-Beehyv Date: Mon, 25 Nov 2024 16:30:26 +0530 Subject: [PATCH 3/3] count fix for kilkari subscriber registration date report. --- .../dao/impl/BeneficiaryWithRegistrationDateBlockDaoImpl.java | 2 +- .../impl/BeneficiaryWithRegistrationDateDistrictDaoImpl.java | 2 +- .../dao/impl/BeneficiaryWithRegistrationDateStateDaoImpl.java | 2 +- .../impl/BeneficiaryWithRegistrationDateSubCentreDaoImpl.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateBlockDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateBlockDaoImpl.java index 11d0712a..b09aab83 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateBlockDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateBlockDaoImpl.java @@ -54,7 +54,7 @@ public List allCountOffReports(Integer dis "COUNT(Case when s.subscription_status = 'COMPLETED' THEN s.subscription_id END) AS subscriptions_completed, " + "0 AS subscriptions_rejected , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) BETWEEN -90 AND 168 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_PW , "+ - "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) BETWEEN 169 AND 504 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ + "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) >= 169 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) < -90 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Ineligible "+ "FROM Beneficiary b " + " INNER JOIN subscriptions s ON b.id = s.beneficiary_id AND s.subscription_id = (SELECT MAX(subscription_id) FROM subscriptions WHERE beneficiary_id = b.id) " + diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateDistrictDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateDistrictDaoImpl.java index 3f7fc0ad..e7491167 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateDistrictDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateDistrictDaoImpl.java @@ -56,7 +56,7 @@ public List allCountOffReports(Integer sta "COUNT(CASE WHEN s.subscription_status = 'COMPLETED' THEN s.subscription_id END) AS subscriptions_completed , " + "0 AS subscriptions_rejected , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) BETWEEN -90 AND 168 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_PW , "+ - "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) BETWEEN 169 AND 504 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ + "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) >= 169 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) < -90 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Ineligible "+ "FROM Beneficiary b " + " INNER JOIN subscriptions s ON b.id = s.beneficiary_id AND s.subscription_id = (SELECT MAX(subscription_id) FROM subscriptions WHERE beneficiary_id = b.id) " + diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateStateDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateStateDaoImpl.java index 2cac0044..c7434a75 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateStateDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateStateDaoImpl.java @@ -54,7 +54,7 @@ public List allCountOffReports(Date fromDa "COUNT(CASE WHEN s.subscription_status = 'COMPLETED' THEN s.subscription_id END) AS subscriptions_completed ," + "0 AS subscriptions_rejected , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) BETWEEN -90 AND 168 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_PW , "+ - "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) BETWEEN 169 AND 504 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child, "+ + "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) >= 169 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child, "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) < -90 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Ineligible "+ "FROM Beneficiary b " + " INNER JOIN subscriptions s ON b.id = s.beneficiary_id AND s.subscription_id = (SELECT MAX(subscription_id) FROM subscriptions WHERE beneficiary_id = b.id) " + diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateSubCentreDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateSubCentreDaoImpl.java index 24dd52cf..a1fa999a 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateSubCentreDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateSubCentreDaoImpl.java @@ -56,7 +56,7 @@ public List allCountOffReports(Integer blo "COUNT(CASE WHEN s.subscription_status = 'COMPLETED' THEN s.subscription_id END) AS subscriptions_completed , " + "0 AS subscriptions_rejected , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) BETWEEN -90 AND 168 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_PW , "+ - "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) BETWEEN 169 AND 504 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ + "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) >= 169 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) < -90 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Ineligible "+ "FROM Beneficiary b " + " INNER JOIN subscriptions s ON b.id = s.beneficiary_id AND s.subscription_id = (SELECT MAX(subscription_id) FROM subscriptions WHERE beneficiary_id = b.id) "+