Search in sources :

Example 1 with ReportData

use of org.openmrs.module.reporting.report.ReportData 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"));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ReportData(org.openmrs.module.reporting.report.ReportData) MapDataSet(org.openmrs.module.reporting.dataset.MapDataSet) SimpleObject(org.openmrs.ui.framework.SimpleObject) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Map(java.util.Map) ReportDefinition(org.openmrs.module.reporting.report.definition.ReportDefinition)

Example 2 with ReportData

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

Aggregations

EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)2 ReportData (org.openmrs.module.reporting.report.ReportData)2 ReportDefinition (org.openmrs.module.reporting.report.definition.ReportDefinition)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MapDataSet (org.openmrs.module.reporting.dataset.MapDataSet)1 SimpleObject (org.openmrs.ui.framework.SimpleObject)1