Search in sources :

Example 6 with ReportDefinition

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

the class NonCodedDiagnosesPageController method post.

public void post(@SpringBean ReportDefinitionService reportDefinitionService, @SpringBean CoreAppsProperties coreAppsProperties, @RequestParam(required = false, value = "fromDate") Date fromDate, @RequestParam(required = false, value = "toDate") Date toDate, @RequestParam(required = false, value = "nonCoded") String nonCoded, @RequestParam(required = false, value = "provider") Provider provider, PageModel model) throws EvaluationException, IOException {
    if (fromDate == null) {
        fromDate = DateUtils.addDays(new Date(), -21);
    }
    if (toDate == null) {
        toDate = new Date();
    }
    fromDate = DateUtil.getStartOfDay(fromDate);
    toDate = DateUtil.getEndOfDay(toDate);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("fromDate", fromDate);
    params.put("toDate", toDate);
    if (StringUtils.isBlank(nonCoded)) {
        nonCoded = "";
    }
    params.put("nonCoded", nonCoded);
    model.addAttribute("nonCoded", nonCoded);
    Integer providerId = null;
    if (provider != null) {
        params.put("provider", provider);
        providerId = provider.getId();
    } else {
        params.put("provider", null);
    }
    model.addAttribute("providerId", providerId);
    EvaluationContext context = new EvaluationContext();
    context.setParameterValues(params);
    ReportDefinition reportDefinition = reportDefinitionService.getDefinitionByUuid(NON_CODED_DIAGNOSES_REPORT_DEFINITION_UUID);
    ReportData reportData = reportDefinitionService.evaluate(reportDefinition, context);
    model.addAttribute("nonCodedRows", reportData.getDataSets().get("data"));
    model.addAttribute("reportDefinition", reportDefinition);
    model.addAttribute("fromDate", fromDate);
    model.addAttribute("toDate", DateUtil.getStartOfDay(toDate));
    model.addAttribute("providers", getAllProviders());
    model.addAttribute("dashboardUrl", coreAppsProperties.getDashboardUrl());
}
Also used : HashMap(java.util.HashMap) ReportData(org.openmrs.module.reporting.report.ReportData) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Date(java.util.Date) ReportDefinition(org.openmrs.module.reporting.report.definition.ReportDefinition)

Example 7 with ReportDefinition

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

the class NonCodedDiagnosesPageController method get.

public void get(@SpringBean ReportDefinitionService reportDefinitionService, @RequestParam(required = false, value = "fromDate") Date fromDate, @RequestParam(required = false, value = "toDate") Date toDate, PageModel model) throws EvaluationException, IOException {
    if (fromDate == null) {
        fromDate = DateUtils.addDays(new Date(), -21);
    }
    if (toDate == null) {
        toDate = new Date();
    }
    fromDate = DateUtil.getStartOfDay(fromDate);
    toDate = DateUtil.getEndOfDay(toDate);
    ReportDefinition reportDefinition = reportDefinitionService.getDefinitionByUuid(NON_CODED_DIAGNOSES_REPORT_DEFINITION_UUID);
    model.addAttribute("nonCodedRows", null);
    model.addAttribute("providers", getAllProviders());
    model.addAttribute("reportDefinition", reportDefinition);
    model.addAttribute("fromDate", fromDate);
    model.addAttribute("toDate", toDate);
    model.addAttribute("nonCoded", "");
    model.addAttribute("providerId", null);
}
Also used : Date(java.util.Date) ReportDefinition(org.openmrs.module.reporting.report.definition.ReportDefinition)

Example 8 with ReportDefinition

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

the class DailyReportPageController method get.

public void get(@SpringBean ReportDefinitionService reportDefinitionService, @SpringBean CoreAppsProperties coreAppsProperties, @RequestParam("reportDefinition") String reportDefinitionUuid, PageModel model) throws Exception {
    ReportDefinition reportDefinition = reportDefinitionService.getDefinitionByUuid(reportDefinitionUuid);
    if (reportDefinition == null) {
        throw new IllegalArgumentException("No reportDefinition with the given uuid");
    }
    model.addAttribute("reportDefinition", reportDefinition);
    model.addAttribute("dashboardUrlWithoutQueryParams", coreAppsProperties.getDashboardUrlWithoutQueryParams());
    model.addAttribute("privilegePatientDashboard", PihEmrConfigConstants.PRIVILEGE_APP_COREAPPS_PATIENT_DASHBOARD);
    model.addAttribute("hideCounts", Context.getAdministrationService().getGlobalProperty(DAILY_CHECKINS_HIDE_COUNTS));
}
Also used : ReportDefinition(org.openmrs.module.reporting.report.definition.ReportDefinition)

Example 9 with ReportDefinition

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

the class ReportSetupComponentTest method testOverwritingInvalidSerializedReport.

/**
 * Tests the case where a persisted ReportDefinition is invalid (typically because of an incompatible change to a
 * definition class, while it is being developed)
 * @throws Exception
 */
@Test
public void testOverwritingInvalidSerializedReport() throws Exception {
    executeDataSet("org/openmrs/module/pihcore/coreMetadata.xml");
    executeDataSet("badReportDefinition.xml");
    authenticate();
    TestReportManager manager = new TestReportManager();
    ReportManagerUtil.setupReport(manager);
    ReportDefinition reportDefinition = reportDefinitionService.getDefinitionByUuid(manager.getUuid());
    assertNotNull(reportDefinition);
    assertThat(reportDefinition.getName(), is("dailyRegistrations"));
}
Also used : ReportDefinition(org.openmrs.module.reporting.report.definition.ReportDefinition) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 10 with ReportDefinition

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

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