Search in sources :

Example 1 with ReportRequest

use of org.openmrs.module.reporting.report.ReportRequest in project openmrs-module-mirebalais by PIH.

the class ReportSetup method cleanupOldReports.

private static void cleanupOldReports(ReportService reportingService) {
    // delete requests more than 6 months old, even if that have been saved--code adapted from deleteOldReportRequests from reporting module
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, -6);
    log.debug("Checking for saved reports older than six months Request date before " + cal.getTime());
    List<ReportRequest> oldRequests = reportingService.getReportRequests(null, null, cal.getTime(), null);
    log.debug("Found " + oldRequests.size() + " requests that qualify");
    for (ReportRequest request : oldRequests) {
        log.info("Request qualifies for deletion.  Deleting: " + request.getUuid());
        try {
            reportingService.purgeReportRequest(request);
        } catch (Exception e) {
            log.warn("Unable to delete old report request: " + request, e);
        }
    }
}
Also used : ReportRequest(org.openmrs.module.reporting.report.ReportRequest) Calendar(java.util.Calendar) IOException(java.io.IOException)

Example 2 with ReportRequest

use of org.openmrs.module.reporting.report.ReportRequest in project openmrs-module-mirebalais by PIH.

the class ReportSetup method scheduleBackupReports.

private static void scheduleBackupReports(ReportService reportService, ReportDefinitionService reportDefinitionService, Config config) {
    // sets up reports currently only used on Mirebalais production server (as a backup)
    if (config.shouldScheduleBackupReports()) {
        // schedule the all patients report to run at 4am and 4pm everyday
        ReportRequest allPatientsScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.ALL_PATIENTS_SCHEDULED_REPORT_REQUEST_UUID);
        if (allPatientsScheduledReportRequest == null) {
            allPatientsScheduledReportRequest = new ReportRequest();
        }
        ReportDefinition allPatientsReportDefinition = reportDefinitionService.getDefinitionByUuid(MirebalaisReportsProperties.ALL_PATIENTS_WITH_IDS_REPORT_DEFINITION_UUID);
        allPatientsScheduledReportRequest.setUuid(MirebalaisReportsProperties.ALL_PATIENTS_SCHEDULED_REPORT_REQUEST_UUID);
        allPatientsScheduledReportRequest.setReportDefinition(Mapped.noMappings(allPatientsReportDefinition));
        allPatientsScheduledReportRequest.setRenderingMode(getCsvReportRenderer(reportService, allPatientsReportDefinition));
        allPatientsScheduledReportRequest.setSchedule("0 0 4-23/12 * * ?");
        reportService.queueReport(allPatientsScheduledReportRequest);
        // schedule the appointments report to run  at 4am and 4pm everyday, retrieving all appointments for the next seven days
        ReportRequest appointmentsScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.APPOINTMENTS_SCHEDULED_REPORT_REQUEST_UUID);
        if (appointmentsScheduledReportRequest == null) {
            appointmentsScheduledReportRequest = new ReportRequest();
        }
        ReportDefinition appointmentsReportDefinition = reportDefinitionService.getDefinitionByUuid(MirebalaisReportsProperties.APPOINTMENTS_REPORT_DEFINITION_UUID);
        appointmentsScheduledReportRequest.setUuid(MirebalaisReportsProperties.APPOINTMENTS_SCHEDULED_REPORT_REQUEST_UUID);
        appointmentsScheduledReportRequest.setReportDefinition(Mapped.map(appointmentsReportDefinition, "startDate=${start_of_today},endDate=${start_of_today + 7d}"));
        appointmentsScheduledReportRequest.setRenderingMode(getCsvReportRenderer(reportService, appointmentsReportDefinition));
        appointmentsScheduledReportRequest.setSchedule("0 0 4-23/12 * * ?");
        reportService.queueReport(appointmentsScheduledReportRequest);
        // schedule the check-ins report to run  at 4am and 4pm everyday retrieving all check-ins for the past seven days
        ReportRequest checkInsDataExportScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.CHECKINS_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        if (checkInsDataExportScheduledReportRequest == null) {
            checkInsDataExportScheduledReportRequest = new ReportRequest();
        }
        ReportDefinition checkInsDataExportReportDefinition = reportDefinitionService.getDefinitionByUuid(MirebalaisReportsProperties.CHECKINS_DATA_EXPORT_REPORT_DEFINITION_UUID);
        checkInsDataExportScheduledReportRequest.setUuid(MirebalaisReportsProperties.CHECKINS_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        checkInsDataExportScheduledReportRequest.setReportDefinition(Mapped.map(checkInsDataExportReportDefinition, "startDate=${start_of_today - 7d},endDate=${now}"));
        checkInsDataExportScheduledReportRequest.setRenderingMode(getCsvReportRenderer(reportService, checkInsDataExportReportDefinition));
        checkInsDataExportScheduledReportRequest.setSchedule("0 0 4-23/12 * * ?");
        reportService.queueReport(checkInsDataExportScheduledReportRequest);
    } else {
        ReportRequest allPatientsScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.ALL_PATIENTS_SCHEDULED_REPORT_REQUEST_UUID);
        if (allPatientsScheduledReportRequest != null) {
            reportService.purgeReportRequest(allPatientsScheduledReportRequest);
        }
        ReportRequest appointmentsScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.APPOINTMENTS_SCHEDULED_REPORT_REQUEST_UUID);
        if (appointmentsScheduledReportRequest != null) {
            reportService.purgeReportRequest(appointmentsScheduledReportRequest);
        }
        ReportRequest checkInsDataExportScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.CHECKINS_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        if (checkInsDataExportScheduledReportRequest != null) {
            reportService.purgeReportRequest(checkInsDataExportScheduledReportRequest);
        }
    }
}
Also used : ReportRequest(org.openmrs.module.reporting.report.ReportRequest) ReportDefinition(org.openmrs.module.reporting.report.definition.ReportDefinition)

Example 3 with ReportRequest

use of org.openmrs.module.reporting.report.ReportRequest in project openmrs-module-mirebalais by PIH.

the class ReportSetup method scheduleMonthlyExportsReports.

private static void scheduleMonthlyExportsReports(ReportService reportService, ReportDefinitionService reportDefinitionService, Config config) {
    if (config.shouldScheduleMonthlyDataExports()) {
        // scheduled to run during the morning of the 5th of every month, for the previous month
        ReportRequest fullDataExportScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.FULL_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        if (fullDataExportScheduledReportRequest == null) {
            fullDataExportScheduledReportRequest = new ReportRequest();
        }
        ReportDefinition fullDataExportReportDefinition = reportDefinitionService.getDefinitionByUuid(MirebalaisReportsProperties.FULL_DATA_EXPORT_REPORT_DEFINITION_UUID);
        fullDataExportScheduledReportRequest.setUuid(MirebalaisReportsProperties.FULL_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        fullDataExportScheduledReportRequest.setReportDefinition(Mapped.map(fullDataExportReportDefinition, "startDate=${start_of_last_month},endDate=${end_of_last_month}"));
        fullDataExportScheduledReportRequest.setRenderingMode(getCsvReportRenderer(reportService, fullDataExportReportDefinition));
        // 4am on the 5th of the month
        fullDataExportScheduledReportRequest.setSchedule("0 0 4 5 * ?");
        reportService.queueReport(fullDataExportScheduledReportRequest);
    } else {
        ReportRequest fullDataExportScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.FULL_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        if (fullDataExportScheduledReportRequest != null) {
            reportService.purgeReportRequest(fullDataExportScheduledReportRequest);
        }
    }
}
Also used : ReportRequest(org.openmrs.module.reporting.report.ReportRequest) ReportDefinition(org.openmrs.module.reporting.report.definition.ReportDefinition)

Example 4 with ReportRequest

use of org.openmrs.module.reporting.report.ReportRequest in project openmrs-module-pihcore by PIH.

the class ReportSetup method cleanupOldReports.

public static void cleanupOldReports() {
    // delete requests more than 6 months old, even if that have been saved--code adapted from deleteOldReportRequests from reporting module
    ReportService reportService = Context.getService(ReportService.class);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, -6);
    log.debug("Checking for saved reports older than six months Request date before " + cal.getTime());
    List<ReportRequest> oldRequests = reportService.getReportRequests(null, null, cal.getTime(), null);
    log.debug("Found " + oldRequests.size() + " requests that qualify");
    for (ReportRequest request : oldRequests) {
        log.info("Request qualifies for deletion.  Deleting: " + request.getUuid());
        try {
            reportService.purgeReportRequest(request);
        } catch (Exception e) {
            log.warn("Unable to delete old report request: " + request, e);
        }
    }
}
Also used : ReportService(org.openmrs.module.reporting.report.service.ReportService) ReportRequest(org.openmrs.module.reporting.report.ReportRequest) Calendar(java.util.Calendar)

Example 5 with ReportRequest

use of org.openmrs.module.reporting.report.ReportRequest in project openmrs-module-pihcore by PIH.

the class ReportSetup method scheduleMonthlyExportsReports.

public static void scheduleMonthlyExportsReports(Config config) {
    ReportService reportService = Context.getService(ReportService.class);
    ReportDefinitionService reportDefinitionService = Context.getService(ReportDefinitionService.class);
    if (config.shouldScheduleMonthlyDataExports()) {
        // scheduled to run during the morning of the 5th of every month, for the previous month
        ReportRequest fullDataExportScheduledReportRequest = reportService.getReportRequestByUuid(FULL_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        if (fullDataExportScheduledReportRequest == null) {
            fullDataExportScheduledReportRequest = new ReportRequest();
        }
        ReportDefinition fullDataExportReportDefinition = reportDefinitionService.getDefinitionByUuid(FULL_DATA_EXPORT_REPORT_DEFINITION_UUID);
        fullDataExportScheduledReportRequest.setUuid(FULL_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        fullDataExportScheduledReportRequest.setReportDefinition(Mapped.map(fullDataExportReportDefinition, "startDate=${start_of_last_month},endDate=${end_of_last_month}"));
        fullDataExportScheduledReportRequest.setRenderingMode(getCsvReportRenderer(reportService, fullDataExportReportDefinition));
        // 4am on the 5th of the month
        fullDataExportScheduledReportRequest.setSchedule("0 0 4 5 * ?");
        reportService.queueReport(fullDataExportScheduledReportRequest);
    } else {
        ReportRequest fullDataExportScheduledReportRequest = reportService.getReportRequestByUuid(FULL_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        if (fullDataExportScheduledReportRequest != null) {
            reportService.purgeReportRequest(fullDataExportScheduledReportRequest);
        }
    }
}
Also used : ReportService(org.openmrs.module.reporting.report.service.ReportService) ReportDefinitionService(org.openmrs.module.reporting.report.definition.service.ReportDefinitionService) ReportRequest(org.openmrs.module.reporting.report.ReportRequest) ReportDefinition(org.openmrs.module.reporting.report.definition.ReportDefinition)

Aggregations

ReportRequest (org.openmrs.module.reporting.report.ReportRequest)6 ReportDefinition (org.openmrs.module.reporting.report.definition.ReportDefinition)4 ReportService (org.openmrs.module.reporting.report.service.ReportService)3 Calendar (java.util.Calendar)2 ReportDefinitionService (org.openmrs.module.reporting.report.definition.service.ReportDefinitionService)2 IOException (java.io.IOException)1