I’m trying to use parameter mappings with my custom dataset definition. I tried looking at how it’s done with CodedObsCohortDefinition.
I have a CohortCrossTabDataSetDefinition whose rows are CodedObsCohortDefinition. These CodedObsCohortDefinition have parameters onOrAfter and onOrBefore but what’s coming from the dataset definition is startDate and endDate. So we’re adding these to the dataset with parameter mappings defined as
Map<String,Object> parameterMappings = new HashMap<String, Object>();
parameterMappings.put("onOrAfter", "${startDate}");
parameterMappings.put("onOrBefore", "${endDate}");
After digging into the reporting codebase, I found this line
So I quickly assumed that, that’s how the values are passed from the dataset definition to the cohort definition. That a child context is created with the parameter values and used to by the cohort definitions evaluator. But that doesn’t seem to be what’s happening. CodedObsCohortDefinition has inherited properties onOrAfter and onOrBefore with setters and getters. When I look at this inherited coded from BaseObsCohortDefinitionEvaluator
I notice that the values of these passed parameters that were mapped to onOrAfter and onOrBefore are retrieved from the cohort definition using getters. Which means at some point these values where set on the definition even though from the report I only passed them as parameters. And I’m lost here.
I have a dataset definition, not a cohort definition and I would like to use parameter mappings like how it’s used with the cohort definition. My dataset definition doesn’t take any cohorts. It evaluates the data in it’s evaluator. Here’s my dataset definition and evaluator respectively ObsSummaryRowDataSetDefinition.java and ObsSummaryRowDataSetEvaluator.java
As far as I understand in order to provide parameter mappings to any dataset definition, you would have to wrap it into Mapped. For example, look at the API that enables this when adding a row to a CohortCrossTabDataSetDefinition, here:
public void addRow(String rowName, CohortDefinition row, Map<String, Object> mappings) {
getRows().put(rowName, new Mapped<CohortDefinition>(row, mappings));
}
In your specific development I believe that this is what needs to be changed. You don’t want to map ‘straight through’ from the parent to the child, you want to provide your own custom mapped version of the obs summary definition by doing something along the lines of
rd.addDataSetDefinition("Obs Summary", new Mapped<ObsSummaryRowDataSetDefinition>(obsSummaryDS, mappings));
I actually did this but I didn’t know how to extract the values of the parameters. I tried getting a child context but all parameter values in the child context where null
And I had sql errors. After placing breakpoints I observed that the parameter values in the evaluation context where all null. But now they seem to be working fine.