use of org.openmrs.module.reporting.report.definition.ReportDefinition in project openmrs-module-mirebalais by PIH.
the class ReportSetup method setupReport.
/**
* This is only public for testing
* @param manager
*/
public static void setupReport(ReportManager manager, ReportService reportService, ReportDefinitionService reportDefinitionService, AdministrationService administrationService, SerializedObjectDAO serializedObjectDAO) {
if (alreadyAtLatestVersion(manager, administrationService)) {
return;
}
ReportDefinition reportDefinition = manager.constructReportDefinition();
log.info("Saving new definition of " + reportDefinition.getName());
ReportDefinition existing = reportDefinitionService.getDefinitionByUuid(reportDefinition.getUuid());
if (existing != null) {
// we need to overwrite the existing, rather than purge-and-recreate, to avoid deleting old ReportRequests
log.debug("overwriting existing ReportDefinition");
reportDefinition.setId(existing.getId());
// Context.evictFromSession(existing);
} else {
// incompatible class changes for a serialized object could mean that getting the definition return null
// and some serialization error gets logged. In that case we want to overwrite the invalid serialized definition
SerializedObject invalidSerializedObject = serializedObjectDAO.getSerializedObjectByUuid(reportDefinition.getUuid());
if (invalidSerializedObject != null) {
reportDefinition.setId(invalidSerializedObject.getId());
// Context.evictFromSession(invalidSerializedObject);
}
// serializedObjectDAO.purgeObject(invalidSerializedObject.getId());
}
reportDefinitionService.saveDefinition(reportDefinition);
// purging a ReportDesign doesn't trigger any extra logic, so we can just purge-and-recreate here
List<ReportDesign> existingDesigns = reportService.getReportDesigns(reportDefinition, null, true);
if (existingDesigns.size() > 0) {
log.debug("Deleting " + existingDesigns.size() + " old designs for " + reportDefinition.getName());
for (ReportDesign design : existingDesigns) {
reportService.purgeReportDesign(design);
}
}
try {
List<ReportDesign> designs = manager.constructReportDesigns(reportDefinition);
for (ReportDesign design : designs) {
reportService.saveReportDesign(design);
}
administrationService.setGlobalProperty(globalPropertyFor(manager), manager.getVersion());
} catch (IOException ex) {
log.error("Error constructing report design for " + reportDefinition.getName(), ex);
}
}
use of org.openmrs.module.reporting.report.definition.ReportDefinition in project openmrs-module-pihcore by PIH.
the class InpatientStatsDailyReportFragmentController method evaluate.
public SimpleObject evaluate(@RequestParam("day") Date day, UiUtils ui, @SpringBean ReportDefinitionService reportDefinitionService) throws EvaluationException {
EvaluationContext context = new EvaluationContext();
context.addParameterValue("day", day);
ReportDefinition reportDefinition = reportDefinitionService.getDefinitionByUuid(INPATIENT_STATS_DAILY_REPORT_DEFINITION_UUID);
ReportData data = reportDefinitionService.evaluate(reportDefinition, context);
SimpleObject cohortResults = new SimpleObject();
MapDataSet cohortDataSet = (MapDataSet) data.getDataSets().get("cohorts");
for (Map.Entry<String, Object> entry : cohortDataSet.getData().getColumnValuesByKey().entrySet()) {
cohortResults.put(entry.getKey(), simplify(entry.getValue()));
}
return SimpleObject.create("cohorts", cohortResults, "evaluationContext", SimpleObject.fromObject(context, ui, "evaluationDate", "parameterValues"));
}
use of org.openmrs.module.reporting.report.definition.ReportDefinition in project openmrs-module-mirebalais 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();
ReportSetup.setupReport(dailyRegistrationsReportManager, reportService, reportDefinitionService, administrationService, serializedObjectDAO);
ReportDefinition reportDefinition = reportDefinitionService.getDefinitionByUuid(dailyRegistrationsReportManager.getUuid());
assertNotNull(reportDefinition);
assertThat(reportDefinition.getName(), is("mirebalaisreports.dailyRegistrations.name"));
}
use of org.openmrs.module.reporting.report.definition.ReportDefinition in project openmrs-module-mirebalais by PIH.
the class ReportSetup method scheduleBackupReports.
private static void scheduleBackupReports(ReportService reportService, ReportDefinitionService reportDefinitionService, Config config) {
// 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(MirebalaisReportsProperties.ALL_PATIENTS_SCHEDULED_REPORT_REQUEST_UUID);
if (allPatientsScheduledReportRequest == null) {
allPatientsScheduledReportRequest = new ReportRequest();
}
ReportDefinition allPatientsReportDefinition = reportDefinitionService.getDefinitionByUuid(MirebalaisReportsProperties.ALL_PATIENTS_WITH_IDS_REPORT_DEFINITION_UUID);
allPatientsScheduledReportRequest.setUuid(MirebalaisReportsProperties.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(MirebalaisReportsProperties.APPOINTMENTS_SCHEDULED_REPORT_REQUEST_UUID);
if (appointmentsScheduledReportRequest == null) {
appointmentsScheduledReportRequest = new ReportRequest();
}
ReportDefinition appointmentsReportDefinition = reportDefinitionService.getDefinitionByUuid(MirebalaisReportsProperties.APPOINTMENTS_REPORT_DEFINITION_UUID);
appointmentsScheduledReportRequest.setUuid(MirebalaisReportsProperties.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(MirebalaisReportsProperties.CHECKINS_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
if (checkInsDataExportScheduledReportRequest == null) {
checkInsDataExportScheduledReportRequest = new ReportRequest();
}
ReportDefinition checkInsDataExportReportDefinition = reportDefinitionService.getDefinitionByUuid(MirebalaisReportsProperties.CHECKINS_DATA_EXPORT_REPORT_DEFINITION_UUID);
checkInsDataExportScheduledReportRequest.setUuid(MirebalaisReportsProperties.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(MirebalaisReportsProperties.ALL_PATIENTS_SCHEDULED_REPORT_REQUEST_UUID);
if (allPatientsScheduledReportRequest != null) {
reportService.purgeReportRequest(allPatientsScheduledReportRequest);
}
ReportRequest appointmentsScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.APPOINTMENTS_SCHEDULED_REPORT_REQUEST_UUID);
if (appointmentsScheduledReportRequest != null) {
reportService.purgeReportRequest(appointmentsScheduledReportRequest);
}
ReportRequest checkInsDataExportScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.CHECKINS_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
if (checkInsDataExportScheduledReportRequest != null) {
reportService.purgeReportRequest(checkInsDataExportScheduledReportRequest);
}
}
}
use of org.openmrs.module.reporting.report.definition.ReportDefinition in project openmrs-module-mirebalais by PIH.
the class ReportSetup method scheduleMonthlyExportsReports.
private static void scheduleMonthlyExportsReports(ReportService reportService, ReportDefinitionService reportDefinitionService, Config config) {
if (config.shouldScheduleMonthlyDataExports()) {
// scheduled to run during the morning of the 5th of every month, for the previous month
ReportRequest fullDataExportScheduledReportRequest = reportService.getReportRequestByUuid(MirebalaisReportsProperties.FULL_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
if (fullDataExportScheduledReportRequest == null) {
fullDataExportScheduledReportRequest = new ReportRequest();
}
ReportDefinition fullDataExportReportDefinition = reportDefinitionService.getDefinitionByUuid(MirebalaisReportsProperties.FULL_DATA_EXPORT_REPORT_DEFINITION_UUID);
fullDataExportScheduledReportRequest.setUuid(MirebalaisReportsProperties.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(MirebalaisReportsProperties.FULL_DATA_EXPORT_SCHEDULED_REPORT_REQUEST_UUID);
if (fullDataExportScheduledReportRequest != null) {
reportService.purgeReportRequest(fullDataExportScheduledReportRequest);
}
}
}
Aggregations