/** * @see LocationService#getLocationsHavingAnyTag(List<QLocationTag;>) */ @Test public void getLocationsHavingAnyTag_shouldReturnEmptyListWhenNoLocationHasTheGivenTags() { LocationService ls = Context.getLocationService(); Assert.assertEquals(0, ls.getLocationsHavingAnyTag(Collections.singletonList(ls.getLocationTagByName("Retired"))) .size()); }
/** * Should be able to retrieve a single LocationTag by its name. * * @see LocationService#getLocationTagByName(String) */ @Test public void getLocationTagByName_shouldGetLocationTagByName() { LocationService ls = Context.getLocationService(); // Existing tag assertEquals(ls.getLocationTag(1), ls.getLocationTagByName("General Hospital")); // Nonexistant tag assertEquals(null, ls.getLocationTagByName("random")); }
/** * @see LocationService#getLocationTagByName(String) */ @Test public void getLocationTagByName_shouldReturnNullWhenNoLocationTagMatchGivenName() { Assert.assertNull(Context.getLocationService().getLocationTagByName("Hospital of the year 2222")); }
/** * @see LocationService#getLocationsByTag(LocationTag) */ @Test public void getLocationsByTag_shouldReturnEmptyListWhenNoLocationsHasTheGivenTag() { LocationService ls = Context.getLocationService(); Assert.assertEquals(0, ls.getLocationsByTag(ls.getLocationTagByName("Retired")).size()); }
LocationTag existing = Context.getLocationService().getLocationTagByName(tag.getName()); if (existing != null) { location.removeTag(tag);
/** * @see LocationService#unretireLocationTag(LocationTag) */ @Test public void unretireLocationTag_shouldUnretireRetiredLocationTag() { LocationService ls = Context.getLocationService(); LocationTag tag = ls.getLocationTagByName("Test Retired Tag"); Assert.assertTrue(tag.getRetired()); LocationTag newTag = ls.unretireLocationTag(tag); Assert.assertEquals(tag, newTag); Assert.assertFalse(tag.getRetired()); Assert.assertNull(tag.getRetiredBy()); Assert.assertNull(tag.getRetireReason()); }
/** * Fetches a location tag by name or id * (Will add support for uuid once we stop supporting OpenMRS 1.6, which doesn't a uuid on location tag) * * @param identifier * @return */ public static LocationTag getLocationTag(String identifier) { LocationTag tag = null; if (identifier != null) { identifier = identifier.trim(); // first try to fetch by id try { Integer id = Integer.valueOf(identifier); tag = Context.getLocationService().getLocationTag(id); if (tag != null) { return tag; } } catch (NumberFormatException e) {} // if not, try to fetch by name tag = Context.getLocationService().getLocationTagByName(identifier); if (tag != null) { return tag; } // TODO add ability to fetch by uuid once we are no longer worried about being compatible with OpenMRS 1.6 (since getLocationTagByUuid is not available in 1.6) } return null; }
/** * @see org.openmrs.module.webservices.rest.web.resource.api.SearchHandler#search(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public PageableResult search(RequestContext context) throws ResponseException { String tag = context.getRequest().getParameter("tag"); List<Location> locations = new ArrayList<Location>(); try { Context.addProxyPrivilege(VIEW_LOCATIONS); //Not using PrivilegeConstants.VIEW_LOCATIONS which was removed in platform 1.11+ Context.addProxyPrivilege("Get Locations"); //1.11+ LocationTag locationTag = Context.getLocationService().getLocationTagByUuid(tag); if (locationTag == null) { locationTag = Context.getLocationService().getLocationTagByName(tag); } if (locationTag != null) { locations = Context.getLocationService().getLocationsByTag(locationTag); } } finally { Context.removeProxyPrivilege(VIEW_LOCATIONS); //Not using PrivilegeConstants.VIEW_LOCATIONS which was removed in platform 1.11+ Context.removeProxyPrivilege("Get Locations"); //1.11+ } return new NeedsPaging<Location>(locations, context); } }