diff --git a/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java b/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java index 34670c6..4cb5d45 100644 --- a/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java +++ b/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java @@ -95,4 +95,18 @@ public class DataSourceConfig { dataSource.setPassword("FAS"); return dataSource; } + + + ////////////////////////////// Health Camp //////////////////////// + @Bean(name = "mysqlHealthCampDataSource") + public DataSource mysqlHealthCampDataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://" + host + "/gcc_health_camp"); + dataSource.setUsername("root"); + dataSource.setPassword(dbpassword); + return dataSource; + } + + } diff --git a/src/main/java/com/gcc/commissionerreview/controller/HealthCampController.java b/src/main/java/com/gcc/commissionerreview/controller/HealthCampController.java new file mode 100644 index 0000000..dbb8e78 --- /dev/null +++ b/src/main/java/com/gcc/commissionerreview/controller/HealthCampController.java @@ -0,0 +1,70 @@ +package com.gcc.commissionerreview.controller; + + +import com.gcc.commissionerreview.service.HealthCampService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/commissionerreview/api") +public class HealthCampController { + + + @Autowired + private HealthCampService healthCampService ; + + + @GetMapping("/zonewise") + public ResponseEntity> getHealthCampAbstract( + @RequestParam(value = "date", required = false) String date, + @RequestParam(value = "zone", required = false) String zone) { + + List> data = + healthCampService.getZoneWiseHealthCampReport(date, zone); + + return ResponseEntity.ok(Map.of( + "status", "success", + "data", data + )); + } + + + + @GetMapping("/wardwise") + public ResponseEntity> getWardWiseReport( + @RequestParam (value = "date", required = false)String date, + @RequestParam (value = "zone", required = false) String zone + ) { + + List> data = + healthCampService.getWardWiseHealthCampReport(date, zone); + + return ResponseEntity.ok(Map.of( + "status", "success", + "data", data + )); + } + + + + @GetMapping("/patientdetails") + public ResponseEntity> getPatientDetails( + + @RequestParam String ward, + @RequestParam String date + ) { + return ResponseEntity.ok(Map.of( + "status", "success", + "data", healthCampService.getPatientDetailsByWard(ward, date) + )); + } + + +} diff --git a/src/main/java/com/gcc/commissionerreview/service/HealthCampService.java b/src/main/java/com/gcc/commissionerreview/service/HealthCampService.java new file mode 100644 index 0000000..22c09f0 --- /dev/null +++ b/src/main/java/com/gcc/commissionerreview/service/HealthCampService.java @@ -0,0 +1,279 @@ +package com.gcc.commissionerreview.service; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Service +public class HealthCampService { + + @Autowired + private JdbcTemplate jdbcTemplate; + + + @Autowired + public void setFeedbackDataSource(@Qualifier("mysqlHealthCampDataSource") DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + + + public List> getZoneWiseHealthCampReport(String date, String zone) { + + StringBuilder sql = new StringBuilder(""" + SELECT + cd.zone, + + COUNT(DISTINCT cd.id) AS no_of_camps, + + /* Camp type counts */ + SUM(cd.camp_type_id = 1) AS monsoon_standard_camp_count, + SUM(cd.camp_type_id = 2) AS special_medical_camp_count, + SUM(cd.camp_type_id = 3) AS outreach_camp_count, + + /* Age & Gender counts */ + SUM(pd.pt_age > 0 AND pd.pt_age <= 10 AND pd.pt_gender_id = 1) AS age_0_10_male, + SUM(pd.pt_age > 0 AND pd.pt_age <= 10 AND pd.pt_gender_id = 2) AS age_0_10_female, + SUM(pd.pt_age > 0 AND pd.pt_age <= 10 AND pd.pt_gender_id = 3) AS age_0_10_transgender, + + SUM(pd.pt_age > 10 AND pd.pt_age <= 40 AND pd.pt_gender_id = 1) AS age_11_40_male, + SUM(pd.pt_age > 10 AND pd.pt_age <= 40 AND pd.pt_gender_id = 2) AS age_11_40_female, + SUM(pd.pt_age > 10 AND pd.pt_age <= 40 AND pd.pt_gender_id = 3) AS age_11_40_transgender, + + SUM(pd.pt_age > 40 AND pd.pt_age <= 60 AND pd.pt_gender_id = 1) AS age_41_60_male, + SUM(pd.pt_age > 40 AND pd.pt_age <= 60 AND pd.pt_gender_id = 2) AS age_41_60_female, + SUM(pd.pt_age > 40 AND pd.pt_age <= 60 AND pd.pt_gender_id = 3) AS age_41_60_transgender, + + SUM(pd.pt_age > 60 AND pd.pt_gender_id = 1) AS age_61_above_male, + SUM(pd.pt_age > 60 AND pd.pt_gender_id = 2) AS age_61_above_female, + SUM(pd.pt_age > 60 AND pd.pt_gender_id = 3) AS age_61_above_transgender, + + COUNT(pd.id) AS total_beneficiaries, + + /* Disease counts (pre-aggregated per patient) */ + SUM(IFNULL(dd.ANC, 0)) AS ANC, + SUM(IFNULL(dd.PN, 0)) AS PN, + SUM(IFNULL(dd.FEVER, 0)) AS FEVER, + SUM(IFNULL(dd.Cough_Cold, 0)) AS Cough_Cold, + SUM(IFNULL(dd.ILI, 0)) AS ILI, + SUM(IFNULL(dd.ADD_, 0)) AS ADD_, + SUM(IFNULL(dd.Skin_Infections, 0)) AS Skin_Infections, + SUM(IFNULL(dd.DM, 0)) AS DM, + SUM(IFNULL(dd.HTN, 0)) AS HTN, + SUM(IFNULL(dd.DM_HTN, 0)) AS DM_HTN, + SUM(IFNULL(dd.Animal_Insect_Bite, 0)) AS Animal_Insect_Bite, + SUM(IFNULL(dd.Injuries, 0)) AS Injuries, + SUM(IFNULL(dd.Other_Cases, 0)) AS Other_Cases + + FROM camp_details cd + + LEFT JOIN patient_details pd + ON cd.id = pd.camp_id + + LEFT JOIN ( + SELECT + patient_id, + SUM(disease_id = 1) AS ANC, + SUM(disease_id = 2) AS PN, + SUM(disease_id = 3) AS FEVER, + SUM(disease_id = 4) AS Cough_Cold, + SUM(disease_id = 5) AS ILI, + SUM(disease_id = 6) AS ADD_, + SUM(disease_id = 7) AS Skin_Infections, + SUM(disease_id = 8) AS DM, + SUM(disease_id = 9) AS HTN, + SUM(disease_id = 10) AS DM_HTN, + SUM(disease_id = 11) AS Animal_Insect_Bite, + SUM(disease_id = 12) AS Injuries, + SUM(disease_id = 13) AS Other_Cases + FROM diseases_details + GROUP BY patient_id + ) dd + ON pd.patient_id = dd.patient_id + + WHERE 1 = 1 + """); + + List params = new ArrayList<>(); + + + if (date != null && !date.isBlank()) { + sql.append(""" + AND cd.cdate >= ? + AND cd.cdate < DATE_ADD(?, INTERVAL 1 DAY) + """); + params.add(date); + params.add(date); + } + + + if (zone != null && !zone.isBlank()) { + sql.append(" AND cd.zone = ? "); + params.add(zone); + } + + sql.append(""" + GROUP BY cd.zone + ORDER BY cd.zone + """); + + return jdbcTemplate.queryForList(sql.toString(), params.toArray()); + } + + + + public List> getWardWiseHealthCampReport(String date, String zone) { + + StringBuilder sql = new StringBuilder(""" + SELECT + cd.ward,cd.zone, + + /* Camps */ + COUNT(DISTINCT cd.id) AS no_of_camps, + + SUM(cd.camp_type_id = 1) AS monsoon_standard_camp_count, + SUM(cd.camp_type_id = 2) AS special_medical_camp_count, + SUM(cd.camp_type_id = 3) AS outreach_camp_count, + + /* AGE 0–10 */ + SUM(pd.pt_age BETWEEN 1 AND 10 AND pd.pt_gender_id = 1) AS age_0_10_male, + SUM(pd.pt_age BETWEEN 1 AND 10 AND pd.pt_gender_id = 2) AS age_0_10_female, + SUM(pd.pt_age BETWEEN 1 AND 10 AND pd.pt_gender_id = 3) AS age_0_10_transgender, + + /* AGE 11–40 */ + SUM(pd.pt_age BETWEEN 11 AND 40 AND pd.pt_gender_id = 1) AS age_11_40_male, + SUM(pd.pt_age BETWEEN 11 AND 40 AND pd.pt_gender_id = 2) AS age_11_40_female, + SUM(pd.pt_age BETWEEN 11 AND 40 AND pd.pt_gender_id = 3) AS age_11_40_transgender, + + /* AGE 41–60 */ + SUM(pd.pt_age BETWEEN 41 AND 60 AND pd.pt_gender_id = 1) AS age_41_60_male, + SUM(pd.pt_age BETWEEN 41 AND 60 AND pd.pt_gender_id = 2) AS age_41_60_female, + SUM(pd.pt_age BETWEEN 41 AND 60 AND pd.pt_gender_id = 3) AS age_41_60_transgender, + + /* AGE 61+ */ + SUM(pd.pt_age >= 61 AND pd.pt_gender_id = 1) AS age_61_above_male, + SUM(pd.pt_age >= 61 AND pd.pt_gender_id = 2) AS age_61_above_female, + SUM(pd.pt_age >= 61 AND pd.pt_gender_id = 3) AS age_61_above_transgender, + + /* Beneficiaries */ + COUNT(DISTINCT pd.id) AS total_beneficiaries, + + /* Diseases (pre-aggregated per patient) */ + SUM(IFNULL(dd.ANC,0)) AS ANC, + SUM(IFNULL(dd.PN,0)) AS PN, + SUM(IFNULL(dd.FEVER,0)) AS FEVER, + SUM(IFNULL(dd.Cough_Cold,0)) AS Cough_Cold, + SUM(IFNULL(dd.ILI,0)) AS ILI, + SUM(IFNULL(dd.ADD_,0)) AS ADD_, + SUM(IFNULL(dd.Skin_Infections,0)) AS Skin_Infections, + SUM(IFNULL(dd.DM,0)) AS DM, + SUM(IFNULL(dd.HTN,0)) AS HTN, + SUM(IFNULL(dd.DM_HTN,0)) AS DM_HTN, + SUM(IFNULL(dd.Animal_Insect_Bite,0)) AS Animal_Insect_Bite, + SUM(IFNULL(dd.Injuries,0)) AS Injuries, + SUM(IFNULL(dd.others,0)) AS others + + FROM camp_details cd + + LEFT JOIN patient_details pd + ON pd.camp_id = cd.id + + LEFT JOIN ( + SELECT + patient_id, + SUM(disease_id = 1) AS ANC, + SUM(disease_id = 2) AS PN, + SUM(disease_id = 3) AS FEVER, + SUM(disease_id = 4) AS Cough_Cold, + SUM(disease_id = 5) AS ILI, + SUM(disease_id = 6) AS ADD_, + SUM(disease_id = 7) AS Skin_Infections, + SUM(disease_id = 8) AS DM, + SUM(disease_id = 9) AS HTN, + SUM(disease_id = 10) AS DM_HTN, + SUM(disease_id = 11) AS Animal_Insect_Bite, + SUM(disease_id = 12) AS Injuries, + SUM(disease_id = 13) AS others + FROM diseases_details + GROUP BY patient_id + ) dd ON dd.patient_id = pd.patient_id + + WHERE 1 = 1 + """); + + List params = new ArrayList<>(); + + /* ZONE FILTER */ + if (zone != null && !zone.isBlank()) { + sql.append(" AND cd.zone = ? "); + params.add(zone); + } + + /* DATE FILTER (works for DATETIME column) */ + if (date != null && !date.isBlank()) { + sql.append(""" + AND cd.cdate >= ? + AND cd.cdate < DATE_ADD(?, INTERVAL 1 DAY) + """); + params.add(date); + params.add(date); + } + + sql.append(""" + GROUP BY cd.ward + ORDER BY cd.ward + """); + + return jdbcTemplate.queryForList(sql.toString(), params.toArray()); + } + + + + public List> getPatientDetailsByWard( + String ward, + String date + ) { + + String sql = """ + SELECT + cd.zone, + cd.ward, + DATE_FORMAT(cd.cdate, '%d-%m-%Y') AS cdate, + pd.pt_name, + pd.pt_age, + pd.pt_mob_no, + pd.pt_address, + pd.remarks, + gm.gender + + FROM camp_details cd + LEFT JOIN patient_details pd + ON pd.camp_id = cd.id + LEFT JOIN gender_master gm + ON gm.id=pd.pt_gender_id + + WHERE cd.ward = ? + AND cd.cdate >= ? + AND cd.cdate < DATE_ADD(?, INTERVAL 1 DAY) + + ORDER BY pd.pt_name + """; + + return jdbcTemplate.queryForList( + sql, + ward, + date, + date + ); + } + + + +} diff --git a/src/main/resources/templates/modules/health_camp/foodschemereport.html b/src/main/resources/templates/modules/health_camp/foodschemereport.html deleted file mode 100644 index b198fdf..0000000 --- a/src/main/resources/templates/modules/health_camp/foodschemereport.html +++ /dev/null @@ -1,1274 +0,0 @@ - - - - - - - - Food Distribution Operations Dashboard - - - - - - - - - - - - - - -
-

Food Distribution Report

-
- - - -
- - - - - - - - -
-
- - - -
-
-
-
Zone wise Overallview
- -
-
- - -
- - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
S.NoZoneNo of CampsNo of Mobile CampNo of Static CampChildAdultANCPNNo of Fever CasesNumber of cases with Cough and Cold Indentified among the - screened - No of ILI CasesNo of ADD CasesSkin InfectionDMHTNBoth DM & HTNAnimal / Insect BiteInjuriesOther casesNo of Pamplets issued
MaleFemaleTotalMaleFemaleTotal
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/templates/modules/healthcamp/abstractreport.html b/src/main/resources/templates/modules/healthcamp/abstractreport.html new file mode 100644 index 0000000..53adfea --- /dev/null +++ b/src/main/resources/templates/modules/healthcamp/abstractreport.html @@ -0,0 +1,928 @@ + + + + + + + + Health Camp Dashboard + + + + + + + + + + + + + + + +
+

Health Camp Report

+
+ +
+
+ +
+
+
+ + +
+
Zone wise Overallview
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + + +
+ +
+ + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
S.NoZoneNo of CampsMonsoon Standard CampSpecial Medical CampOutreach CampAge 0–10Age 11–40Age 41–60Age 61+Total BeneficiariesANCPNFeverCough/ColdILIADDSkin InfectionDMHTNDM & HTNAnimal/Insect BiteInjuriesOther Cases
MaleFemaleTransgenderMaleFemaleTransgenderMaleFemaleTransgenderMaleFemaleTransgender
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file