Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
// the supervisor is bound to the provider variable
def supervisor = provider    

// get all providers in the system, excluding retired providers
List providers = providerService.getAllProviders(false)

// initialize the set we are going to pass back as a result
// (note that it is a list of persons, not providers)
Set results = new HashSet<org.openmrs.Person>()

// iterate through the list of providers we have fetched
for (org.openmrs.Provider p : providers) {

	// if the provider has the same city/village as the supervisor, add the *person* associated with this provider to the results list
	if (p.getPerson() && p.getPerson().getPersonAddress()?.getCityVillage().equals(supervisor.getPersonAddress()?.getCityVillage())) {
    		results.add(p.getPerson())
	}


}

// return the results
return results

Note that the result will still be filtered to exclude any providers who do not have a role that the selected provider is able to supervise.