diff --git a/src/main/java/com/reporting/controller/ReportingController.java b/src/main/java/com/reporting/controller/ReportingController.java index 439a69d..161a868 100644 --- a/src/main/java/com/reporting/controller/ReportingController.java +++ b/src/main/java/com/reporting/controller/ReportingController.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.NoSuchFileException; +import java.sql.Time; import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.*; @@ -1207,6 +1208,106 @@ public class ReportingController { } } + @RequestMapping(value = {"/laporan-kunjungan-pasien-per-ruangan"}, method = {RequestMethod.GET}) + public void handleLaporanKunjunganPasienPerRuangan( + @RequestParam("tglAwal") Timestamp tglAwal, + @RequestParam("tglAkhir") Timestamp tglAkhir, + @RequestParam(value = "idInstalasi", required = false, defaultValue = "") Integer idInstalasi, + @RequestParam(value = "idUnit", required = false, defaultValue = "") Integer idUnit, + @RequestParam(value = "idRuangan", required = false, defaultValue = "") Integer idRuangan, + @RequestParam(value = "idKp", required = false, defaultValue = "") Integer idKp, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + @RequestParam(value = "printBy", required = false, defaultValue = "") String printBy, + HttpServletResponse response) throws Exception { + + JasperPrint jasperPrint = null; + try { + // Generate report (common for both PDF/Excel) + jasperPrint = this.reportingService.exportKunjunganPasienPerRuangan(tglAwal, tglAkhir, idInstalasi, idUnit, idRuangan, idKp, printBy); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Laporan_Kunjungan_Pasien_Per_Ruangan.xlsx"); + + JRXlsxExporter exporter = new JRXlsxExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + SimpleXlsxReportConfiguration config = new SimpleXlsxReportConfiguration(); + config.setOnePagePerSheet(false); + config.setDetectCellType(true); + config.setCollapseRowSpan(false); + config.setRemoveEmptySpaceBetweenRows(true); + config.setWhitePageBackground(false); + exporter.setConfiguration(config); + exporter.exportReport(); + + } else { + // Handle PDF preview + response.setContentType("application/pdf"); + response.setHeader("Content-Disposition", "inline; filename=Laporan_Kunjungan_Pasien_Per_Ruangan.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } finally { + jasperPrint = null; + } + } + + @RequestMapping(value = {"/laporan-rekap-resep-pasien"}, method = {RequestMethod.GET}) + public void handleLaporanRekapResepPasien( + @RequestParam("tglAwal") Timestamp tglAwal, + @RequestParam("tglAkhir") Timestamp tglAkhir, + @RequestParam(value = "idInstalasi", required = false, defaultValue = "") Integer idInstalasi, + @RequestParam(value = "idUnit", required = false, defaultValue = "") Integer idUnit, + @RequestParam(value = "idRuangan", required = false, defaultValue = "") Integer idRuangan, + @RequestParam(value = "idKp", required = false, defaultValue = "") Integer idKp, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + @RequestParam(value = "printBy", required = false, defaultValue = "") String printBy, + HttpServletResponse response) throws Exception { + + JasperPrint jasperPrint = null; + try { + // Generate report (common for both PDF/Excel) + jasperPrint = this.reportingService.exportRekapResepPasien(tglAwal, tglAkhir, idInstalasi, idUnit, idRuangan, idKp, printBy); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Laporan_Rekap_Resep_Pasien.xlsx"); + + JRXlsxExporter exporter = new JRXlsxExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + SimpleXlsxReportConfiguration config = new SimpleXlsxReportConfiguration(); + config.setOnePagePerSheet(false); + config.setDetectCellType(true); + config.setCollapseRowSpan(false); + config.setRemoveEmptySpaceBetweenRows(true); + config.setWhitePageBackground(false); + exporter.setConfiguration(config); + exporter.exportReport(); + + } else { + // Handle PDF preview + response.setContentType("application/pdf"); + response.setHeader("Content-Disposition", "inline; filename=Laporan_Rekap_Resep_Pasien.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } finally { + jasperPrint = null; + } + } + @RequestMapping(value = {"/laporan-pendaftaran-online"}, method = {RequestMethod.GET}) public void handleLpPendaftaranOnline( @RequestParam("tglAwal") String tglAwal, diff --git a/src/main/java/com/reporting/dao/ReportingDao.java b/src/main/java/com/reporting/dao/ReportingDao.java index 43573d4..f9c7cc6 100644 --- a/src/main/java/com/reporting/dao/ReportingDao.java +++ b/src/main/java/com/reporting/dao/ReportingDao.java @@ -1197,7 +1197,47 @@ public class ReportingDao { parameters.put("printBy", printBy); return JasperFillManager.fillReport(jasperReport, parameters, conn); } catch (Exception var15) { - LOG.error("Exception at exportVisit"); + LOG.error("Exception at exportKunjunganPasien"); + LOG.error(ReportingDao.class, var15); + } + return null; + } + + public JasperPrint exportKunjunganPasienPerRuangan(Timestamp tglAwal, Timestamp tglAkhir, Integer idInstalasi, Integer idUnit, Integer idRuangan, Integer idKp, String printBy) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "kunjungan_pasien_perruangan.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("idInstalasi", idInstalasi); + parameters.put("idUnit", idUnit); + parameters.put("idRuangan", idRuangan); + parameters.put("idKp", idKp); + parameters.put("printBy", printBy); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportKunjunganPasienPerRuangan"); + LOG.error(ReportingDao.class, var15); + } + return null; + } + + public JasperPrint exportRekapResepPasien(Timestamp tglAwal, Timestamp tglAkhir, Integer idInstalasi, Integer idUnit, Integer idRuangan, Integer idKp, String printBy) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "laporan_rekap_resep_pasien.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("idInstalasi", idInstalasi); + parameters.put("idUnit", idUnit); + parameters.put("idRuangan", idRuangan); + parameters.put("idKp", idKp); + parameters.put("printBy", printBy); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportRekapResepPasien"); LOG.error(ReportingDao.class, var15); } return null; diff --git a/src/main/java/com/reporting/service/ReportingService.java b/src/main/java/com/reporting/service/ReportingService.java index 730e609..9de9a60 100644 --- a/src/main/java/com/reporting/service/ReportingService.java +++ b/src/main/java/com/reporting/service/ReportingService.java @@ -390,6 +390,16 @@ public class ReportingService { return this.reportingDao.exportKunjunganPasien(tglAwal, tglAkhir, idInstalasi, idUnit, idRuangan, printBy); } + public JasperPrint exportKunjunganPasienPerRuangan(Timestamp tglAwal, Timestamp tglAkhir, Integer idInstalasi, Integer idUnit, Integer idRuangan, Integer idKp, String printBy) { + log.info("Starting exportKunjunganPasienPerRuangan with tglAwal: {}, tglAkhir: {}, idInstalasi: {}, idUnit: {}, idRuangan: {}, printBy: {}", tglAwal, tglAkhir, idInstalasi, idUnit, idRuangan, idKp, printBy); + return this.reportingDao.exportKunjunganPasienPerRuangan(tglAwal, tglAkhir, idInstalasi, idUnit, idRuangan, idKp, printBy); + } + + public JasperPrint exportRekapResepPasien(Timestamp tglAwal, Timestamp tglAkhir, Integer idInstalasi, Integer idUnit, Integer idRuangan, Integer idKp, String printBy) { + log.info("Starting exportRekapResepPasien with tglAwal: {}, tglAkhir: {}, idInstalasi: {}, idUnit: {}, idRuangan: {}, printBy: {}", tglAwal, tglAkhir, idInstalasi, idUnit, idRuangan, idKp, printBy); + return this.reportingDao.exportRekapResepPasien(tglAwal, tglAkhir, idInstalasi, idUnit, idRuangan, idKp, printBy); + } + public JasperPrint exportLpPendaftaranOnline(String tglAwal, String tglAkhir, Integer idUnit, Integer idRuangan, String printBy) { log.info("Starting exportLpPendaftaranOnline with tglAwal: {}, tglAkhir: {}, idUnit: {}, idRuangan: {}, printBy: {}", tglAwal, tglAkhir, idUnit, idRuangan, printBy); try {