/** * Checks whether 'location' is a member of the tree starting at 'root'. * * @param location The location to be tested. * @param root Location node from which to start the testing (down in the hierarchy). * @since 1.5 * @should return false given any null parameter * @should return true given same object in both parameters * @should return true given location that is already somewhere in hierarchy * @should return false given location that is not in hierarchy * @should should find location in hierarchy */ public static Boolean isInHierarchy(Location location, Location root) { if (root == null) { return false; } while (true) { if (location == null) { return false; } else if (root.equals(location)) { return true; } location = location.getParentLocation(); } }
if (child.equals(this)) { throw new APIException("Location.cannot.be.its.own.child", (Object[]) null);
while (root.getParentLocation() != null) { root = root.getParentLocation(); if (root.equals(location)) { // Have gone in a circle errors.rejectValue("parentLocation", "Location.parentLocation.error"); break;
/** * @see Encounter#addObs(Obs) */ @Test public void addObs_shouldAddEncounterAttrsToObsIfAttributesAreNull() { /// an encounter that will hav the date/location/patient on it Encounter encounter = new Encounter(); Date date = new Date(); encounter.setEncounterDatetime(date); Location location = new Location(1); encounter.setLocation(location); Patient patient = new Patient(1); encounter.setPatient(patient); // add an obs that doesn't have date/location/patient set on it. Obs obs = new Obs(123); encounter.addObs(obs); // make sure it was added assertEquals(1, encounter.getAllObs(true).size()); // check the values of the obs attrs to see if they were added assertTrue(obs.getObsDatetime().equals(date)); assertTrue(obs.getLocation().equals(location)); assertTrue(obs.getPerson().equals(patient)); }
if (!OpenmrsUtil.nullSafeEquals(newLocation, originalLocation) && obs.getLocation().equals(originalLocation)) { obs.setLocation(newLocation);
assertFalse("The location should be different", origLocation.equals(loc2)); assertTrue("The location should be different", newestEnc.getLocation().equals(loc2)); assertFalse("The enc should have changed", origEncType.equals(encType2)); assertTrue("The enc type needs to have been set", newestEnc.getEncounterType().equals(encType2));
/** * Test to make sure that a simple save to a new location gets persisted to the database * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldCreateLocationSuccessfully() { Location location = new Location(); location.setName("testing"); location.setDescription("desc"); location.setAddress1("123"); location.setAddress1("456"); location.setCityVillage("city"); location.setStateProvince("state"); location.setCountry("country"); location.setPostalCode("post"); location.setLatitude("lat"); location.setLongitude("lon"); LocationService ls = Context.getLocationService(); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); assertNotNull("The saved location should have an id now", location.getLocationId()); assertNotNull("We should get back a location", newSavedLocation); assertTrue("The created location needs to equal the pojo location", location.equals(newSavedLocation)); }
for (Location l : useLocations) { sb.append("\n<option"); if (location != null && location.equals(l)) sb.append(" selected=\"true\""); sb.append(" value=\"" + l.getLocationId() + "\">").append(HtmlFormEntryUtil.format(l)).append("</option>");
Option option = new Option(label, location.getId().toString(), location.equals(defaultLocation)); locationOptions.add(option);
Option option = new Option(location.getName(), location.getId().toString(), location.equals(defaultLocation)); locationOptions.add(option);