public Set<String> getBrandNamesByNameAndUnii(String name, String unii) throws IOException {
   UriComponentsBuilder builder =
       UriComponentsBuilder.fromHttpUrl(this.fdaDrugLabelUrl)
           .queryParam(
               "search",
               "(openfda.unii:"
                   + fixTerm.makeFdaSafe(unii)
                   + ")+AND+(openfda.brand_name:"
                   + fixTerm.makeFdaReady(fixTerm.makeFdaSafe(name))
                   + ")")
           .queryParam("count", "openfda.brand_name.exact");
   this.apiKey.addToUriComponentsBuilder(builder);
   try {
     String result = rest.getForObject(builder.build().toUri(), String.class);
     FieldFinder finder = new FieldFinder("term");
     return finder.find(result);
   } catch (HttpClientErrorException notFound) {
     if (notFound.getStatusCode() == HttpStatus.NOT_FOUND) {
       // server reported 404, handle it by returning no results
       log.warn("No brand name data found for search by name: " + name + " and unii " + unii);
       return Collections.emptySet();
     }
     throw notFound;
   }
 }
 public String getGenericNameByRxcui(Long rxcui) throws IOException {
   if (rxcui == null) {
     return "";
   }
   UriComponentsBuilder builder =
       UriComponentsBuilder.fromHttpUrl(this.nlmRxnavUrl + "/" + rxcui + "/allProperties.json")
           .queryParam("prop", "names");
   String result = rest.getForObject(builder.build().toUri(), String.class);
   FieldFinder finder = new FieldFinder("propValue");
   Set<String> generics = finder.find(result);
   if (generics.isEmpty()) {
     return "";
   } else {
     return generics.iterator().next();
   }
 }
 public Long getRxcuiByUnii(String unii) throws IOException {
   UriComponentsBuilder builder =
       UriComponentsBuilder.fromHttpUrl(this.nlmRxnavUrl + ".json")
           .queryParam("idtype", "UNII_CODE")
           .queryParam("id", URLEncoder.encode(unii, StandardCharsets.UTF_8.name()));
   String result = rest.getForObject(builder.build().toUri(), String.class);
   FieldFinder finder = new FieldFinder("rxnormId");
   for (String id : finder.find(result)) {
     try {
       return Long.parseLong(id);
     } catch (NumberFormatException nfe) {
       // ignore invalid ids
       log.warn("Got invalid rxnormId from Rxnav query on unii" + unii);
     }
   }
   return null;
 }
  @RequestMapping("/autocomplete")
  // TODO - Move this to the client side.
  public String autocomplete(@RequestParam(value = "name", defaultValue = "") String name)
      throws IOException {
    if (name == null) {
      name = "";
    }

    String result = "[{\"value\":\"" + name + "\"}]";
    if (name.length() >= 2) {
      ObjectMapper mapper = new ObjectMapper();
      String query = this.nlmDailymedAutocompleteUrl + "?key=search&returntype=json&term=" + name;
      JsonNode node = mapper.readTree(rest.getForObject(query, String.class));
      AutocompleteFilter myFilter = new AutocompleteFilter();
      List<String> values = myFilter.filter(node);
      result = mapper.writeValueAsString(values);
    }
    return result;
  }