Search in sources :

Example 11 with ReportDefinition

use of org.openmrs.module.reporting.report.definition.ReportDefinition 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

ReportDefinition (org.openmrs.module.reporting.report.definition.ReportDefinition)11 ReportRequest (org.openmrs.module.reporting.report.ReportRequest)4 Date (java.util.Date)2 Test (org.junit.Test)2 EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)2 ReportData (org.openmrs.module.reporting.report.ReportData)2 ReportDefinitionService (org.openmrs.module.reporting.report.definition.service.ReportDefinitionService)2 ReportService (org.openmrs.module.reporting.report.service.ReportService)2 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SerializedObject (org.openmrs.api.db.SerializedObject)1 MapDataSet (org.openmrs.module.reporting.dataset.MapDataSet)1 ReportDesign (org.openmrs.module.reporting.report.ReportDesign)1 SimpleObject (org.openmrs.ui.framework.SimpleObject)1