/** * You should be able to remove a tag from a location. * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldRemoveLocationTagFromLocation() { LocationService ls = Context.getLocationService(); // Loading location with exactly 3 tags from the initialData.xml file Location location = ls.getLocation(1); // Removing a tag location.removeTag(location.getTags().iterator().next()); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); // Saved location should have 2 tag now assertEquals(2, newSavedLocation.getTags().size()); }
/** * @see org.openmrs.customdatatype.SerializingCustomDatatype#deserialize(String) * @override */ @Override public Location deserialize(String uuid) { if (StringUtils.isBlank(uuid)) { return null; } return Context.getLocationService().getLocationByUuid(uuid); } }
/** * @see org.openmrs.Attributable#getPossibleValues() */ @Override public List<Location> getPossibleValues() { try { return Context.getLocationService().getAllLocations(); } catch (Exception e) { return Collections.emptyList(); } }
/** * Get locations that have a specified tag among its child tags. * * @see LocationService#getLocationsByTag(LocationTag) */ @Test public void getLocationsByTag_shouldGetLocationsByTag() { LocationService ls = Context.getLocationService(); assertEquals(1, ls.getLocationsByTag(ls.getLocationTag(1)).size()); assertEquals(2, ls.getLocationsByTag(ls.getLocationTag(3)).size()); assertEquals(4, ls.getLocationsByTag(ls.getLocationTag(4)).size()); }
@Test public void getLocationsHavingAllTags_shouldGetLocationsHavingAllTags() { LocationService ls = Context.getLocationService(); List<LocationTag> list1 = new ArrayList<>(); list1.add(ls.getLocationTag(1)); list1.add(ls.getLocationTag(2)); assertEquals(1, ls.getLocationsHavingAllTags(list1).size()); }
/** * Get locations that have any of specified set of tags among its child tags. * * @see LocationService#getLocationsHavingAnyTag(List<LocationTag;>) */ @Test public void getLocationsHavingAnyTag_shouldGetLocationsHavingAnyTag() { LocationService ls = Context.getLocationService(); List<LocationTag> list1 = new ArrayList<>(); list1.add(ls.getLocationTag(1)); list1.add(ls.getLocationTag(2)); List<LocationTag> list2 = new ArrayList<>(); list2.add(ls.getLocationTag(3)); list2.add(ls.getLocationTag(4)); List<LocationTag> list3 = new ArrayList<>(); list3.add(ls.getLocationTag(1)); list3.add(ls.getLocationTag(2)); list3.add(ls.getLocationTag(3)); assertEquals(1, ls.getLocationsHavingAnyTag(list1).size()); assertEquals(4, ls.getLocationsHavingAnyTag(list2).size()); assertEquals(3, ls.getLocationsHavingAnyTag(list3).size()); }
@Test public void shouldOverwriteAListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); location.addChildLocation(service.getLocation(2)); service.saveLocation(location); String json = "{ \"childLocations\": [] }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); Location updatedLocation = service.getLocationByUuid(getUuid()); Assert.assertNotNull(updatedLocation); Assert.assertTrue(updatedLocation.getChildLocations().isEmpty()); }
/** * @return current location for this user context if any is set * @since 1.9 */ public Location getLocation() { if (locationId == null) { return null; } return Context.getLocationService().getLocation(locationId); }
phoneAttrType.setMaxOccurs(1); phoneAttrType.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype"); Context.getLocationService().saveLocationAttributeType(phoneAttrType); emailAttrType.setMaxOccurs(1); emailAttrType.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype"); Context.getLocationService().saveLocationAttributeType(emailAttrType); Location location1 = Context.getLocationService().getLocation(1); LocationAttribute la1a = new LocationAttribute(); la1a.setAttributeType(phoneAttrType); la1b.setValue("admin@facility.com"); location1.addAttribute(la1b); Context.getLocationService().saveLocation(location1); Location location2 = Context.getLocationService().getLocation(2); LocationAttribute la2 = new LocationAttribute(); la2.setAttributeType(phoneAttrType); la2.setValue("0123456789"); location2.addAttribute(la2); Context.getLocationService().saveLocation(location2); List<Location> locations = Context.getLocationService().getLocations(null, null, attrValues, false, null, null); Assert.assertEquals(1, locations.size()); Assert.assertEquals(location1, locations.get(0));
List<Location> locationsBeforeRetired = ls.getAllLocations(true); List<Location> locationsNotRetiredBefore = ls.getAllLocations(false); Location location = ls.getLocation(1); Location retiredLoc = ls.retireLocation(location, "Just Testing"); List<Location> locationsAfterRetired = ls.getAllLocations(true); List<Location> locationsNotRetiredAfter = ls.getAllLocations(false);
Location location = new Location(); if (facilityId != null) { location = locationService.getLocation(Integer.parseInt(facilityId)); } else { final List<Location> locationsWithSameName = locationService.getLocations(facility.getName()); final List<Location> matchedLocation = Lambda.select(locationsWithSameName, having(on(Location.class), locationMatcher(facility))); if (CollectionUtils.isNotEmpty(matchedLocation)) { location.setCountyDistrict(facility.getCountyDistrict()); Location savedLocation = this.locationService.saveLocation(location); MRSFacility facilityInst = convertLocationToFacility(savedLocation); if (facilityId == null) {
@Test public void shouldUnretireALocation() throws Exception { Location location = service.getLocation(3); Assert.assertTrue(location.isRetired()); String json = "{ \"retired\": false }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); Location updatedLocation = service.getLocationByUuid(getUuid()); Assert.assertTrue(!updatedLocation.isRetired()); }
/** * @verifies return location by tag uuid * @see LocationSearchHandler#getSearchConfig() */ @Test public void getSearchConfig_shouldReturnLocationByTagUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("tag", "0940c6d4-47ed-11df-bc8b-001e378eb67e"); SimpleObject result = deserialize(handle(req)); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(2, hits.size()); List<Location> locations = service.getAllLocations(); Assert.assertEquals(service.getLocation(1).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); Assert.assertEquals(service.getLocation(2).getUuid(), PropertyUtils.getProperty(hits.get(1), "uuid")); }
/** * @see org.openmrs.api.LocationService#unretireLocation(org.openmrs.Location) */ @Override public Location unretireLocation(Location location) throws APIException { location.setRetired(false); return Context.getLocationService().saveLocation(location); }
Location exist = Context.getLocationService().getLocation(location.getName()); if (exist != null && !exist.getRetired() && !OpenmrsUtil.nullSafeEquals(location.getUuid(), exist.getUuid())) { errors.rejectValue("name", "location.duplicate.name"); "address3", "address4", "address5", "address6", "address7", "address8", "address9", "address10", "address11", "address12", "address13", "address14", "address15", "retireReason"); super.validateAttributes(location, errors, Context.getLocationService().getAllLocationAttributeTypes());
/** * @see LocationService#saveLocationAttributeType(LocationAttributeType) */ @Test public void saveLocationAttributeType_shouldEditAnExistingLocationAttributeType() { executeDataSet(LOC_ATTRIBUTE_DATA_XML); LocationService service = Context.getLocationService(); Assert.assertEquals(2, service.getAllLocationAttributeTypes().size()); LocationAttributeType lat = service.getLocationAttributeType(1); lat.setName("A new name"); service.saveLocationAttributeType(lat); Assert.assertEquals(2, service.getAllLocationAttributeTypes().size()); Assert.assertEquals("A new name", service.getLocationAttributeType(1).getName()); }
/** * @see org.openmrs.Attributable#findPossibleValues(java.lang.String) */ @Override public List<Location> findPossibleValues(String searchText) { try { return Context.getLocationService().getLocations(searchText); } catch (Exception e) { return Collections.emptyList(); } }
/** * @see LocationService#purgeLocationAttributeType(LocationAttributeType) */ @Test public void purgeLocationAttributeType_shouldCompletelyRemoveALocationAttributeType() { executeDataSet(LOC_ATTRIBUTE_DATA_XML); Assert.assertEquals(2, Context.getLocationService().getAllLocationAttributeTypes().size()); Context.getLocationService().purgeLocationAttributeType(Context.getLocationService().getLocationAttributeType(2)); Assert.assertEquals(1, Context.getLocationService().getAllLocationAttributeTypes().size()); }
LocationTag locationTag = locationService.getLocationTagByUuid(tagUuid); locationsByTag = locationService.getLocationsByTag(locationTag); locationsByQuery = locationService.getLocations(query);
/** * 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")); }