Reporting Module: How to set a List<Location> report parameter

Hi guys!

(@mseaton)

I would like to configure an OpenMRS Report where the user can select multiple locations against which the report is run. But I am not sure what is the correct Java syntax to use in my Report Manager class…

For instance, the following instructions will correctly set a Location parameter to my Report and Visit query filter:

Report parameter configuration:

ReportDefinition rd = new ReportDefinition();
rd.setParameters(Arrays.asList(new Parameter("locationList", "Visit Location", Location.class)));

Query filter configuration:

BasicVisitQuery query = new BasicVisitQuery();
Parameter location = new Parameter("locationList", "Visit Location", Location.class);
query.setParameters(Arrays.asList(location));

But this won’t allow to pass a list of Locations. This will let the user select only one location:

See how it shows in the UI:

Screenshot from 2018-05-24 15-50-58


However, I would prefer to be able to select multiple locations.

I know that the Query filter I am using can handle this just fine but it is only a matter of getting the right Java syntax to declare the parameters:

For instance, this won’t work:

new Parameter("locationList", "Visit Location", List.class)

Neither will this:

new Parameter("locationList", "Visit Location", List<Location>.class)

I haven’t been able to find an similar use case in Malawi PIH module.

Btw, I actually have found confusing info in the Malawi reports, such as this:

q.addParameter(new Parameter("locationList", "Locations", Date.class));

I know that this is supported by the OpenMRS Reports module because I can manually change the parameter type in the UI:

Screenshot from 2018-05-24 16-00-37

Screenshot from 2018-05-24 16-00-09

Thanks!

Romain

(cc: @ouiliam, @mksd)

@mksrom, the link you referred to in the pihmalawi module looks to be a bug, which is why it is confusing.

For how to construct a Parameter that takes a List of Locations, see the example in the definition library here:

Mike

2 Likes

Thanks @mseaton, it works just fine.

new Parameter("locationList", "Visit Location", Location.class, List.class, null);