Search in sources :

Example 6 with ReportRequest

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

the class ReportSetup method scheduleBackupReports.

public static void scheduleBackupReports(Config config) {
    ReportService reportService = Context.getService(ReportService.class);
    ReportDefinitionService reportDefinitionService = Context.getService(ReportDefinitionService.class);
    // 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(ALL_PATIENTS_SCHEDULED_REPORT_REQUEST_UUID);
        if (allPatientsScheduledReportRequest == null) {
            allPatientsScheduledReportRequest = new ReportRequest();
        }
        ReportDefinition allPatientsReportDefinition = reportDefinitionService.getDefinitionByUuid(ALL_PATIENTS_WITH_IDS_REPORT_DEFINITION_UUID);
        allPatientsScheduledReportRequest.setUuid(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(APPOINTMENTS_SCHEDULED_REPORT_REQUEST_UUID);
        if (appointmentsScheduledReportRequest == null) {
            appointmentsScheduledReportRequest = new ReportRequest();
        }
        ReportDefinition appointmentsReportDefinition = reportDefinitionService.getDefinitionByUuid(APPOINTMENTS_REPORT_DEFINITION_UUID);
        appointmentsScheduledReportRequest.setUuid(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(CHECKINS_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        if (checkInsDataExportScheduledReportRequest == null) {
            checkInsDataExportScheduledReportRequest = new ReportRequest();
        }
        ReportDefinition checkInsDataExportReportDefinition = reportDefinitionService.getDefinitionByUuid(CHECKINS_DATA_EXPORT_REPORT_DEFINITION_UUID);
        checkInsDataExportScheduledReportRequest.setUuid(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(ALL_PATIENTS_SCHEDULED_REPORT_REQUEST_UUID);
        if (allPatientsScheduledReportRequest != null) {
            reportService.purgeReportRequest(allPatientsScheduledReportRequest);
        }
        ReportRequest appointmentsScheduledReportRequest = reportService.getReportRequestByUuid(APPOINTMENTS_SCHEDULED_REPORT_REQUEST_UUID);
        if (appointmentsScheduledReportRequest != null) {
            reportService.purgeReportRequest(appointmentsScheduledReportRequest);
        }
        ReportRequest checkInsDataExportScheduledReportRequest = reportService.getReportRequestByUuid(CHECKINS_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
        if (checkInsDataExportScheduledReportRequest != null) {
            reportService.purgeReportRequest(checkInsDataExportScheduledReportRequest);
        }
    }
}
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