setting coded cohort queries properties as parameters

The page below is the working UI approach to map coded cohort query properties to parameters;

I need to do the same thing instead of setting such properties as for; on or after, on or before, observed at location with real values; here is what i have written; i want to instead of;

cd.setLocationList(locationList);
cd.setOnOrAfter(onOrAfter);
cd.setOnOrBefore(onOrBefore);

map these three properties to parameters, i have confirmed this to work from the UI although it was not straight forward finding out how it is done in the backend besides there lacking a unit test that handles this;

CC: @mseaton, @dkayiwa, @darius

@k.joseph, I’ll do my best to try to explain.

  1. All definitions can be parameterized on any property that has the @ConfigurationProperty annotation. In these cases, the name of the parameter must match exactly the name of the property. So in your case above, with a CodedObsCohortDefinition, you must parameterize it as follows:

cd.addParameter(new Parameter(“onOrAfter”, “On Or After”, Date.class)); cd.addParameter(new Parameter(“onOrBefore”, “On Or Before”, Date.class)); cd.addParameter(new Parameter(“locationList”, “Location”, Location.class));

Now, if you pass in parameters in your evaluation context named “onOrAfter”, “onOrBefore”, and “locationList”, things will work as you expect. But obviously this is rarely the case - you more commonly need to associate these with the actual parameter names/values coming in.

This is done via parameter Mapping. Specifically the use of the Mapped construct.

If you simply want to create a CohortDefinition that takes in startDate, endDate, and location parameters, you can use the adapter CohortDefinition called MappedParametersCohortDefinition. You can see an example of where we have done this here, in an attempt to standardize on “startDate”, “endDate”, and “location” parameters ourselves.

More commonly though, what you want to do is pass parameters from one definition to another - for example, from a ReportDefinition to a DataSetDefinition, a DataSetDefinition to an Indicator, or from an Indicator to a CohortDefinition. You’ll notice that most times one Definition includes other definitions, it does not include them directly. For example, the ReportDefinition does not have a Collection of DataSetDefinitions. Instead, the ReportDefinition has a Collection of Mapped. It is this Mapped construct that allows you to pass parameters through from one evaluation to another, and to change their names if necessary.

In your case, if you add your CohortDefinition to a DataSetDefinition, and this DataSetDefinition supports 3 parameters named “startDate”, “endDate”, and “location”, you would add your CohortDefinition to it as follows (pseudocode):

dsd.add(new Mapped(codedObsCohortDefinition, “onOrAfter=${startDate},onOrBefore=${endDate},locationList=${location}”);

You can see examples of this all throughout the reporting module unit tests. Have a look here specifically.

Hope this helps, Mike

1 Like