Search in sources :

Example 1 with LocationDescriptor

use of org.openmrs.module.metadatadeploy.descriptor.LocationDescriptor in project openmrs-module-pihcore by PIH.

the class LocationTagSetup method setLocationTagsFor.

private static void setLocationTagsFor(LocationService service, LocationTagDescriptor locationTag, Collection<LocationDescriptor> locationsThatGetTag) {
    LocationTag tag = service.getLocationTagByUuid(locationTag.uuid());
    for (Location candidate : service.getAllLocations()) {
        boolean expected = false;
        if (locationsThatGetTag != null) {
            for (LocationDescriptor d : locationsThatGetTag) {
                if (d != null && d.uuid().equals(candidate.getUuid())) {
                    expected = true;
                }
            }
        }
        boolean actual = candidate.hasTag(tag.getName());
        if (actual && !expected) {
            candidate.removeTag(tag);
            service.saveLocation(candidate);
        } else if (!actual && expected) {
            candidate.addTag(tag);
            service.saveLocation(candidate);
        }
    }
}
Also used : LocationTag(org.openmrs.LocationTag) LocationDescriptor(org.openmrs.module.metadatadeploy.descriptor.LocationDescriptor) Location(org.openmrs.Location)

Aggregations

Location (org.openmrs.Location)1 LocationTag (org.openmrs.LocationTag)1 LocationDescriptor (org.openmrs.module.metadatadeploy.descriptor.LocationDescriptor)1