SearchFragmentController { public SimpleObject[] locations(@RequestParam("q") String query, UiUtils ui) { LocationService svc = Context.getLocationService(); Set<Location> results = new TreeSet<Location>(new Comparator<Location>() { @Override public int compare(Location location1, Location location2) { return location1.getName().compareTo(location2.getName()); } }); if (StringUtils.isNumeric(query) && query.length() >= 5) { Location locationByMflCode = Context.getService(KenyaEmrService.class).getLocationByMflCode(query); if (locationByMflCode != null) { results.add(locationByMflCode); } } if (StringUtils.isNotBlank(query)) { results.addAll(svc.getLocations(query, true, 0, 20)); } return ui.simplifyCollection(results); }  SimpleObject patient(@RequestParam("id") Patient patient, UiUtils ui); List<SimpleObject> patients(@RequestParam(value = "q", required = false) String query,
									   @RequestParam(value = "which", required = false, defaultValue = "all") String which,
									   UiUtils ui); SimpleObject location(@RequestParam("id") Location location, UiUtils ui); SimpleObject[] locations(@RequestParam("q") String query, UiUtils ui); SimpleObject person(@RequestParam("id") Person person, UiUtils ui); SimpleObject[] persons(@RequestParam(value = "q", required = false) String query, UiUtils ui); SimpleObject provider(@RequestParam("id") Provider provider, UiUtils ui); SimpleObject[] providers(@RequestParam(value = "q", required = false) String query, UiUtils ui); List<SimpleObject> accounts(@RequestParam(value = "q", required = false) String query,
									   @RequestParam(value = "which", required = false, defaultValue = "all") String which,
									   HttpSession session,
									   UiUtils ui); SimpleObject concept(@RequestParam("id") Concept concept, UiUtils ui); List<SimpleObject> concepts(@RequestParam(value = "q", required = false) String query,
									   @RequestParam(value = "class", required = false) ConceptClass conceptClass,
									   @RequestParam(value = "answerTo", required = false) Concept answerTo,
									   @RequestParam(value = "size", required = false) Integer size,
									   UiUtils ui);  }
@Test public void locations_shouldMatchByPartialName() { SimpleObject[] result = controller.locations("Xan", ui); Assert.assertThat(result.length, is(1)); Assert.assertThat(result[0], hasEntry("id", (Object) new Integer(2))); Assert.assertThat(result[0], hasEntry("name", (Object) "Xanadu")); }
@Test public void locations_shouldMatchByCompleteMflCode() { LocationAttributeType mflCode = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.MASTER_FACILITY_CODE); Location xanadu = Context.getLocationService().getLocation(2); LocationAttribute attr = new LocationAttribute(); attr.setOwner(xanadu); attr.setAttributeType(mflCode); attr.setValue("15002"); xanadu.addAttribute(attr); Context.getLocationService().saveLocation(xanadu); SimpleObject[] result = controller.locations("15002", ui); Assert.assertThat(result.length, is(1)); Assert.assertThat(result[0], hasEntry("id", (Object) new Integer(2))); Assert.assertThat(result[0], hasEntry("name", (Object) "Xanadu")); Assert.assertThat(result[0], hasEntry("code", (Object) "15002")); }