/** * @see org.openmrs.OpenmrsObject#getId() */ @Override public Integer getId() { return getLocationTagId(); }
/** * Extract locationTagIds from the list of LocationTag objects provided. * * @param tags * @return */ private List<Integer> getLocationTagIds(List<LocationTag> tags) { List<Integer> locationTagIds = new ArrayList<>(); for (LocationTag tag : tags) { locationTagIds.add(tag.getLocationTagId()); } return locationTagIds; } }
/** * @see LocationService#getLocationTagByUuid(String) */ @Test public void getLocationTagByUuid_shouldFindObjectGivenValidUuid() { Assert.assertEquals(Integer.valueOf(3), Context.getLocationService().getLocationTagByUuid( "0d0eaea2-47ed-11df-bc8b-001e378eb67e").getLocationTagId()); }
/** * You should be able to add a transient tag with an existing tag name. * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldOverwriteTransientTagIfTagWithSameNameExists() { LocationService ls = Context.getLocationService(); // First, create a new Location Location location = new Location(); location.setName("name"); location.setDescription("is a location"); // Add a transient tag with an existing name location.addTag(new LocationTag("General Hospital", null)); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); // Saved parent location should have exactly 1 tag assertEquals(1, newSavedLocation.getTags().size()); // Tag must be overwritten with tag with locationTagId == 1 assertNotNull("Location tag should have an ID now", newSavedLocation.getTags().iterator().next().getLocationTagId()); assertEquals(1, newSavedLocation.getTags().iterator().next().getLocationTagId().intValue()); }
/** * Make sure that purging a location tag removes the row from the database * * @see LocationService#purgeLocationTag(LocationTag) */ @Test public void purgeLocationTag_shouldDeleteLocationTag() { LocationService ls = Context.getLocationService(); // Fetch the encounter to delete from the db LocationTag tag = ls.getLocationTag(5); ls.purgeLocationTag(tag); // Try to refetch the location. should get a null object LocationTag t = ls.getLocationTag(tag.getLocationTagId()); assertNull("We shouldn't find the tag after deletion", t); }
/** * Test to make sure that a simple save to a new location tag gets persisted to the database * * @see LocationService#saveLocationTag(LocationTag) */ @Test public void saveLocationTag_shouldCreateLocationTagSuccessfully() { LocationTag tag = new LocationTag(); tag.setName("testing"); tag.setDescription("desc"); LocationService ls = Context.getLocationService(); ls.saveLocationTag(tag); LocationTag newSavedTag = ls.getLocationTag(tag.getLocationTagId()); assertNotNull("The saved tag should have an id now", tag.getLocationTagId()); assertNotNull("We should get back a tag", newSavedTag); assertTrue("The created tag needs to equal the pojo location", tag.equals(newSavedTag)); }
if (tag.getLocationTagId() == null) { if (!StringUtils.hasLength(tag.getName())) { throw new APIException("Location.tag.name.required", (Object[]) null);
LocationTag newestTag = ls.getLocationTag(tag.getLocationTagId());