Search in sources :

Example 1 with ReportDefinitionService

use of org.openmrs.module.reporting.report.definition.service.ReportDefinitionService in project openmrs-module-mirebalais by PIH.

the class MirebalaisHospitalActivator method started.

/**
 * @see ModuleActivator#started()
 */
public void started() {
    try {
        // currently only one of these
        Config config = Context.getRegisteredComponents(Config.class).get(0);
        AdministrationService administrationService = Context.getAdministrationService();
        ReportService reportService = Context.getService(ReportService.class);
        ReportDefinitionService reportDefinitionService = Context.getService(ReportDefinitionService.class);
        SerializedObjectDAO serializedObjectDAO = Context.getRegisteredComponents(SerializedObjectDAO.class).get(0);
        PrinterService printerService = Context.getService(PrinterService.class);
        DispositionService dispositionService = Context.getService(DispositionService.class);
        removeOldPrivileges();
        setDispositionConfig(config, dispositionService);
        // register our custom print handlers
        PrinterSetup.registerPrintHandlers(printerService);
        // set up html forms--this must happen *after* MDS packages are installed, so that forms defined in code/github
        // take precedent over any in MDS packages; therefore we still do this in the Mirebalais module, not PIH Core
        HtmlFormSetup.setupHtmlForms(config);
        // configure default dashboard in coreapps
        updateGlobalProperty(CoreAppsConstants.GP_DASHBOARD_URL, config.getDashboardUrl());
        // configure default visits page in coreapps
        updateGlobalProperty(CoreAppsConstants.GP_VISITS_PAGE_URL, config.getVisitPageUrl());
        // configure default specific visit detail page in coreapps
        updateGlobalProperty(CoreAppsConstants.GP_VISITS_PAGE_WITH_SPECIFIC_URL, config.getVisitsPageWithSpecificUrl());
        if (config.isComponentEnabled(Components.LEGACY_MPI)) {
            LegacyMasterPatientIndexSetup.setupConnectionToMasterPatientIndex(customProperties);
        }
        if (config.isComponentEnabled(Components.ARCHIVES)) {
            ArchivesSetup.setupCloseStaleCreateRequestsTask();
            ArchivesSetup.setupCloseStalePullRequestsTask();
        }
        if (config.isComponentEnabled(Components.APPOINTMENT_SCHEDULING)) {
            AppointmentSchedulingSetup.setupMarkAppointmentAsMissedOrCompletedTask();
            if (config.getCountry().equals(ConfigDescriptor.Country.HAITI)) {
                AppointmentSchedulingSetup.customizeDailyAppointmentsDataSet();
            }
        }
        if (config.isComponentEnabled(Components.RADIOLOGY) && config.getSite().equals(ConfigDescriptor.Site.MIREBALAIS)) {
            updateGlobalProperty(OpenmrsConstants.GP_ORDER_NUMBER_GENERATOR_BEAN_ID, MirebalaisConstants.RADIOLOGY_ORDER_NUMBER_GENERATOR_BEAN_ID);
        }
        if (!testMode) {
            if (config.isComponentEnabled(Components.OVERVIEW_REPORTS) || config.isComponentEnabled(Components.DATA_EXPORTS)) {
                // must happen after location tags have been configured
                ReportSetup.setupReports(reportService, reportDefinitionService, administrationService, serializedObjectDAO, config);
            }
            // do app and extension configuration
            Context.getRegisteredComponent("customAppLoaderFactory", CustomAppLoaderFactory.class).setReadyForRefresh(true);
            ModuleFactory.getStartedModuleById("appframework").getModuleActivator().contextRefreshed();
            // on first startup, these modules may not have been able to configure their global propertes correctly because
            // all metadata was not loaded; we call the started method here to complete setup
            ModuleFactory.getStartedModuleById("registrationapp").getModuleActivator().started();
        }
    } catch (Exception e) {
        Module mod = ModuleFactory.getModuleById(MirebalaisConstants.MIREBALAIS_MODULE_ID);
        ModuleFactory.stopModule(mod);
        throw new RuntimeException("failed to setup the required modules", e);
    }
    log.info("Mirebalais Hospital Module started");
}
Also used : DispositionService(org.openmrs.module.emrapi.disposition.DispositionService) ReportService(org.openmrs.module.reporting.report.service.ReportService) AdministrationService(org.openmrs.api.AdministrationService) ReportDefinitionService(org.openmrs.module.reporting.report.definition.service.ReportDefinitionService) CustomAppLoaderFactory(org.openmrs.module.mirebalais.apploader.CustomAppLoaderFactory) Config(org.openmrs.module.pihcore.config.Config) PrinterService(org.openmrs.module.printer.PrinterService) Module(org.openmrs.module.Module) SerializedObjectDAO(org.openmrs.api.db.SerializedObjectDAO)

Example 2 with ReportDefinitionService

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

Example 3 with ReportDefinitionService

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

ReportDefinitionService (org.openmrs.module.reporting.report.definition.service.ReportDefinitionService)3 ReportService (org.openmrs.module.reporting.report.service.ReportService)3 ReportRequest (org.openmrs.module.reporting.report.ReportRequest)2 ReportDefinition (org.openmrs.module.reporting.report.definition.ReportDefinition)2 AdministrationService (org.openmrs.api.AdministrationService)1 SerializedObjectDAO (org.openmrs.api.db.SerializedObjectDAO)1 Module (org.openmrs.module.Module)1 DispositionService (org.openmrs.module.emrapi.disposition.DispositionService)1 CustomAppLoaderFactory (org.openmrs.module.mirebalais.apploader.CustomAppLoaderFactory)1 Config (org.openmrs.module.pihcore.config.Config)1 PrinterService (org.openmrs.module.printer.PrinterService)1