/**
   * Searches for locations by name of MFL code
   *
   * @param term the search term
   * @return the list of locations as simple objects
   */
  public List<SimpleObject> locations(
      @RequestParam("term") String term, UiUtils ui, @SpringBean KenyaEmrUiUtils kenyaUi) {
    LocationService svc = Context.getLocationService();
    LocationAttributeType mflCodeAttrType =
        Metadata.getLocationAttributeType(Metadata.MASTER_FACILITY_CODE_LOCATION_ATTRIBUTE_TYPE);

    // Results will be sorted by name
    Set<Location> results =
        new TreeSet<Location>(
            new Comparator<Location>() {
              @Override
              public int compare(Location location1, Location location2) {
                return location1.getName().compareTo(location2.getName());
              }
            });

    // If term looks like an MFL code, add location with that code
    if (StringUtils.isNumeric(term) && term.length() >= 5) {
      Location locationByMflCode =
          Context.getService(KenyaEmrService.class).getLocationByMflCode(term);
      if (locationByMflCode != null) {
        results.add(locationByMflCode);
      }
    }

    // Add first 20 results of search by name
    if (StringUtils.isNotBlank(term)) {
      results.addAll(svc.getLocations(term, true, 0, 20));
    }

    // Convert to simple objects
    List<SimpleObject> ret = new ArrayList<SimpleObject>();
    for (Location l : results) {
      ret.add(kenyaUi.simpleLocation(l, mflCodeAttrType, ui));
    }
    return ret;
  }
 /**
  * Gets a location by it's id
  *
  * @param location the location
  * @param ui
  * @param kenyaUi
  * @return the simplified location
  */
 public SimpleObject location(
     @RequestParam("id") Location location, UiUtils ui, @SpringBean KenyaEmrUiUtils kenyaUi) {
   LocationAttributeType mflCodeAttrType =
       Metadata.getLocationAttributeType(Metadata.MASTER_FACILITY_CODE_LOCATION_ATTRIBUTE_TYPE);
   return kenyaUi.simpleLocation(location, mflCodeAttrType, ui);
 }