Getting location attribute through the API?

How do you get the location attribute of a given location attribute type for a given location through the OpenMRS API?

I’ve looked through the LocationService and seen nothing I can use for this. Am I missing something or is there some alternative method?

LocationAttributes are subproperties of Location, and the API (only) lets you fetch them via the Location.

Look for a method like Location.getActiveAttributes or something like that. (It’s probably defined on a base class.)

I guess he is asking for a method that returns location attributes of a given attribute type and that is

Location.getActiveAttributes(CustomValueDescriptor ofType)

1 Like

That does it. Thanks!

Hi,

Is there any way to get a location by its attribute value? I am storing the id, provided by a central system in a country, for a facility as a location attribute and want to retrieve the location by attribute value.

Thanks

Is this of help? https://github.com/openmrs/openmrs-core/blob/2.4.0-alpha.2/api/src/test/java/org/openmrs/api/LocationServiceTest.java#L310-L357