Search in sources :

Example 1 with MapDataSet

use of org.openmrs.module.reporting.dataset.MapDataSet in project openmrs-module-pihcore by PIH.

the class InpatientStatsDailyDataSetManagerTest method testRunningReport.

@Test
public void testRunningReport() throws Exception {
    EvaluationContext context = new EvaluationContext();
    context.addParameterValue("day", DateUtil.parseDate("2013-10-03", "yyyy-MM-dd"));
    DataSetDescriptor descriptor = new DataSetDescriptor();
    DataSetDefinition dsd = manager.constructDataSetDefinition(descriptor, null);
    MapDataSet mds = (MapDataSet) dataSetDefinitionService.evaluate(dsd, context);
    Map<String, Integer> results = new HashMap<>();
    for (DataSetColumn column : mds.getMetaData().getColumns()) {
        CohortIndicatorAndDimensionResult val = (CohortIndicatorAndDimensionResult) mds.getData(column);
        results.put(column.getName(), val.getValue().intValue());
    }
    // Men's Internal Medicine
    assertAndRemove(results, "censusAtStart:e5db0599-89e8-44fa-bfa2-07e47d63546f", 1);
    assertAndRemove(results, "admissions:e5db0599-89e8-44fa-bfa2-07e47d63546f", 1);
    assertAndRemove(results, "discharged:e5db0599-89e8-44fa-bfa2-07e47d63546f", 1);
    assertAndRemove(results, "censusAtEnd:e5db0599-89e8-44fa-bfa2-07e47d63546f", 1);
    // Surgical Ward
    assertAndRemove(results, "transfersIn:7d6cc39d-a600-496f-a320-fd4985f07f0b", 1);
    assertAndRemove(results, "censusAtEnd:7d6cc39d-a600-496f-a320-fd4985f07f0b", 1);
    // Women's Internal Medicine
    assertAndRemove(results, "censusAtStart:2c93919d-7fc6-406d-a057-c0b640104790", 2);
    assertAndRemove(results, "transfersOut:2c93919d-7fc6-406d-a057-c0b640104790", 1);
    assertAndRemove(results, "censusAtEnd:2c93919d-7fc6-406d-a057-c0b640104790", 1);
    assertAndRemove(results, "edcheckin", 1);
    assertAndRemove(results, "orvolume", 1);
    assertAndRemove(results, "possiblereadmission", 1);
    // everything else should be 0
    for (Integer actual : results.values()) {
        assertThat(actual, is(0));
    }
}
Also used : DataSetColumn(org.openmrs.module.reporting.dataset.DataSetColumn) DataSetDescriptor(org.openmrs.module.reporting.config.DataSetDescriptor) HashMap(java.util.HashMap) MapDataSet(org.openmrs.module.reporting.dataset.MapDataSet) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) DataSetDefinition(org.openmrs.module.reporting.dataset.definition.DataSetDefinition) CohortIndicatorAndDimensionResult(org.openmrs.module.reporting.indicator.dimension.CohortIndicatorAndDimensionResult) BaseInpatientReportTest(org.openmrs.module.pihcore.reporting.BaseInpatientReportTest) Test(org.junit.Test)

Example 2 with MapDataSet

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

Aggregations

MapDataSet (org.openmrs.module.reporting.dataset.MapDataSet)2 EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 BaseInpatientReportTest (org.openmrs.module.pihcore.reporting.BaseInpatientReportTest)1 DataSetDescriptor (org.openmrs.module.reporting.config.DataSetDescriptor)1 DataSetColumn (org.openmrs.module.reporting.dataset.DataSetColumn)1 DataSetDefinition (org.openmrs.module.reporting.dataset.definition.DataSetDefinition)1 CohortIndicatorAndDimensionResult (org.openmrs.module.reporting.indicator.dimension.CohortIndicatorAndDimensionResult)1 ReportData (org.openmrs.module.reporting.report.ReportData)1 ReportDefinition (org.openmrs.module.reporting.report.definition.ReportDefinition)1 SimpleObject (org.openmrs.ui.framework.SimpleObject)1