private ResponseEntity<?> search(String name, int page, Locale locale, String actionMessageKey) {
    PatientListVO patientListVO = patientService.findByNameLike(page, maxResults, name);

    if (!StringUtils.isEmpty(actionMessageKey)) {
      addActionMessageToVO(patientListVO, locale, actionMessageKey, null);
    }

    Object[] args = {name};

    addSearchMessageToVO(patientListVO, locale, "message.search.for.active", args);

    return new ResponseEntity<PatientListVO>(patientListVO, HttpStatus.OK);
  }
  @RequestMapping(method = RequestMethod.POST, produces = "application/json")
  public ResponseEntity<?> create(
      @RequestBody Patient patient,
      @RequestParam(required = false) String searchFor,
      @RequestParam(required = false, defaultValue = DEFAULT_PAGE_DISPLAYED_TO_USER) int page,
      Locale locale) {
    patientService.save(patient);

    if (isSearchActivated(searchFor)) {
      return search(searchFor, page, locale, "message.create.success");
    }

    return createListAllResponse(page, locale, "message.create.success");
  }
  @RequestMapping(value = "/{id}", method = RequestMethod.PUT, produces = "application/json")
  public ResponseEntity<?> update(
      @PathVariable("id") int patientId,
      @RequestBody Patient patient,
      @RequestParam(required = false) String searchFor,
      @RequestParam(required = false, defaultValue = DEFAULT_PAGE_DISPLAYED_TO_USER) int page,
      Locale locale) {
    if (patientId != patient.getId()) {
      return new ResponseEntity<String>("Bad Request", HttpStatus.BAD_REQUEST);
    }

    patientService.save(patient);

    if (isSearchActivated(searchFor)) {
      return search(searchFor, page, locale, "message.update.success");
    }

    return createListAllResponse(page, locale, "message.update.success");
  }
  @RequestMapping(
      value = "/{patientId}",
      method = RequestMethod.DELETE,
      produces = "application/json")
  public ResponseEntity<?> delete(
      @PathVariable("patientId") int patientId,
      @RequestParam(required = false) String searchFor,
      @RequestParam(required = false, defaultValue = DEFAULT_PAGE_DISPLAYED_TO_USER) int page,
      Locale locale) {

    try {
      patientService.delete(patientId);
    } catch (AccessDeniedException e) {
      return new ResponseEntity<Object>(HttpStatus.FORBIDDEN);
    }

    if (isSearchActivated(searchFor)) {
      return search(searchFor, page, locale, "message.delete.success");
    }

    return createListAllResponse(page, locale, "message.delete.success");
  }
 private PatientListVO listAll(int page) {
   return patientService.findAll(page, maxResults);
 }