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;
   }
 }
 @RequestMapping("/drug/enforcements")
 @ResponseBody
 public JsonNode getDrugRecallsForUnii(
     @RequestParam(value = "unii", defaultValue = "") String unii,
     @RequestParam(value = "limit", defaultValue = "0") int limit)
     throws Exception {
   JsonNode node;
   HttpHeaders headers = new HttpHeaders();
   ObjectMapper mapper = new ObjectMapper();
   headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
   UriComponentsBuilder builder =
       UriComponentsBuilder.fromHttpUrl(searchDrugEnfrcmntUrl)
           .queryParam("limit", uniiRecallsLimit);
   this.apiKey.addToUriComponentsBuilder(builder);
   if (unii != null && unii.trim().length() > 0) {
     builder.queryParam("search", "openfda.unii:" + unii);
     try {
       node = mapper.readTree(rest.getForObject(builder.build().toUri(), String.class));
       ((ObjectNode) node).set("results", getSortedResults(node.get("results"), limit));
     } catch (HttpClientErrorException ex) {
       if (ex.getStatusCode().value() == 404) {
         node =
             new ObjectMapper()
                 .readTree(
                     "{\"error\":{\"code\":\"NOT_FOUND\", \"message\":\"No matches found!\"}}");
       } else {
         throw ex;
       }
     }
   } else {
     node = getDrugRecalls(limit == 0 ? 10 : limit, null, null);
   }
   return node;
 }
  @RequestMapping("/recalls")
  @ResponseBody
  public JsonNode getFDARecalls() throws IOException {
    JsonNode node = null;
    ObjectMapper mapper = new ObjectMapper();
    node = mapper.readTree(rest.getForObject(xml2JsonCnvrtrUrl + fdaRecallsRSSurl, String.class));

    return node;
  }
 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;
  }
  @RequestMapping("/drug/recalls")
  @ResponseBody
  public JsonNode getDrugRecalls(
      @RequestParam(value = "limit", defaultValue = "5") int limit,
      @RequestParam(value = "fromDt", defaultValue = "") String fromDt,
      @RequestParam(value = "toDt", defaultValue = "") String toDt)
      throws Exception {
    JsonNode node;
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
    UriComponentsBuilder builder =
        UriComponentsBuilder.fromHttpUrl(searchDrugEnfrcmntUrl)
            .queryParam("search", getDefaultReportDateQuery(fromDt, toDt))
            .queryParam("limit", mostRecentRecallsLimit);
    this.apiKey.addToUriComponentsBuilder(builder);
    ObjectMapper mapper = new ObjectMapper();
    String json = rest.getForObject(builder.build().toUri(), String.class);
    node = mapper.readTree(json);
    ((ObjectNode) node).set("results", getSortedResults(node.get("results"), limit));

    return node;
  }