List<PersonStub> users = new ArrayList<PersonStub>();
List<Option> providerUsers = new ArrayList<Option>();
// If the "role" attribute is passed in, limit to users with this role
if (parameters.get("role") != null) {
Role role = Context.getUserService().getRole((String) parameters.get("role"));
if (role == null) {
throw new RuntimeException("Cannot find role: " + parameters.get("role"));
} else {
users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole());
}
}
// Otherwise, use default options appropriate to the underlying OpenMRS version
else {
if (openmrsVersionDoesNotSupportProviders()) {
// limit to users with the default OpenMRS PROVIDER role,
String defaultRole = OpenmrsConstants.PROVIDER_ROLE;
Role role = Context.getUserService().getRole(defaultRole);
if (role != null) {
users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole());
}
// If this role isn't used, default to all Users
if (users.isEmpty()) {
users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(null);
}