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());
}
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);
}
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));
}
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"));
}
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);
}
}
}
Aggregations