@RequestMapping(value = "", method = RequestMethod.GET) @ApiOperation( value = "Get All LunchMenus.", notes = "Returns list of all existed LunchMenus by page.") @ApiResponses( value = { @ApiResponse(code = 401, message = "Only authenticated access allowed."), }) public Page<LunchMenu> getAllLunchMenus( @RequestParam(value = "page", required = true, defaultValue = DEFAULT_PAGE_NUM) @ApiParam(value = "Page number of LunchMenus list", required = false) Integer page, @ApiParam( value = "Size of Page of LunchMenus list. ", allowableValues = "range[1,1000]", required = false) @RequestParam(value = "size", required = true, defaultValue = DEFAULT_PAGE_SIZE) Integer size, @ApiParam(value = "", hidden = true) Authentication authentication) { SpringUser springUser = (SpringUser) authentication.getPrincipal(); LOGGER.debug( "Get all LunchMenu on page {} with size {} by {}", page, size, springUser.getUsername()); size = Math.min(1000, size); return lunchMenusService.getAllLunchMenus(page, size, springUser.getRole()); }
@RequestMapping("/drug") public String search( @RequestParam(value = "name", defaultValue = "") String name, @RequestParam(value = "limit", defaultValue = "10") int limit, @RequestParam(value = "skip", defaultValue = "0") int skip) throws IOException { name = fixTerm.makeFdaSafe(name); if (name.length() == 0) { return "[]"; } List<DrugSearchResult> rv = new LinkedList<DrugSearchResult>(); Set<String> uniis = this.getUniisByName(name); Map<String, Set<String>> brandNames = this.getBrandNamesByNameAndUniis(name, uniis); // create full list of drug search results for (String unii : uniis) { for (String brandName : brandNames.get(unii)) { DrugSearchResult res = new DrugSearchResult(); res.setUnii(unii); res.setBrandName(brandName); rv.add(res); } } // sort the list of drug search results by custom comparator Collections.sort(rv, new DrugSearchComparator(name)); // implement skip/limit if (rv.size() > 0) { rv = rv.subList(skip, Math.min(rv.size(), skip + limit)); } // fill in details for all the results we're returning for (DrugSearchResult res : rv) { res.setRxcui(this.getRxcuiByUnii(res.getUnii())); res.setGenericName(this.getGenericNameByRxcui(res.getRxcui())); if (res.getActiveIngredients().isEmpty() && res.getGenericName() != null) { res.setActiveIngredients( new TreeSet<String>(Arrays.asList(res.getGenericName().split(", ")))); } } ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(rv); }