public static JSONArray generateAllCategoriesJSON() {
    JSONArray jsonArray = new JSONArray();
    List<ChartSearchCategoryDisplayName> allDisplayNames =
        chartSearchService.getAllCategoryDisplayNames();
    List<CategoryFilter> allCats = chartSearchService.getAllCategoryFilters();

    for (CategoryFilter cat : allCats) {
      JSONObject json = new JSONObject();
      String name = cat.getCategoryName();
      String description = cat.getCategoryDescription();
      String displayName = "";
      String uuid = cat.getCategoryUuid();

      for (ChartSearchCategoryDisplayName catName : allDisplayNames) {

        if (Context.getAuthenticatedUser()
                .getUserId()
                .equals(catName.getPreference().getPreferenceOwner().getUserId())
            && catName.getCategoryFilter().getCategoryName().equals(name)) {
          displayName = catName.getDisplayName();
          uuid = catName.getUuid();
        }
      }

      json.put("name", name);
      json.put("uuid", uuid);
      json.put("displayName", displayName);
      json.put("description", description);

      jsonArray.add(json);
    }

    return jsonArray;
  }
  public static JSONArray getAllGlobalNotesOnASearch(String searchPhrase, Integer patientId) {
    JSONArray jsonArr = new JSONArray();
    List<ChartSearchNote> allNotes = chartSearchService.getAllSearchNotes();
    List<ChartSearchNote> allGlobalNotes = new ArrayList<ChartSearchNote>();

    for (ChartSearchNote note : allNotes) {
      if (note.getPatient().getPatientId().equals(patientId)
          && note.getSearchPhrase().equals(searchPhrase)
          && note.getPriority().equals("HIGH")) {
        allGlobalNotes.add(note);
      }
    }

    if (!allGlobalNotes.isEmpty()) {
      for (ChartSearchNote note : allGlobalNotes) {
        JSONObject json = new JSONObject();
        String userName = note.getNoteOwner().getUsername();
        String systemId = note.getNoteOwner().getSystemId();

        json.put("uuid", note.getUuid());
        json.put("createdOrLastModifiedAt", note.getCreatedOrLastModifiedAt().getTime());
        json.put(
            "formatedCreatedOrLastModifiedAt",
            Context.getDateFormat().format(note.getCreatedOrLastModifiedAt()));
        json.put("backgroundColor", note.getDisplayColor());

        addPhraseAndCommentNotesAttributes(note, json);

        json.put("noteOwner", null == userName ? systemId : userName);

        jsonArr.add(json);
      }
    }
    return jsonArr;
  }
 private static String[] getAllPossibleSuggestionsAsArray() {
   List<String> allPossibleSuggestions =
       chartSearchService.getAllPossibleSearchSuggestions(SearchAPI.getPatientId());
   String[] searchSuggestions = new String[allPossibleSuggestions.size()];
   searchSuggestions = (String[]) allPossibleSuggestions.toArray(searchSuggestions);
   return searchSuggestions;
 }
  public static JSONArray getAllSearchHistoriesToSendToTheUI() {
    JSONArray histories = new JSONArray();
    List<ChartSearchHistory> allHistory = chartSearchService.getAllSearchHistory();

    for (ChartSearchHistory history : allHistory) {
      JSONObject json = null;
      if (Context.getAuthenticatedUser().getUserId().equals(history.getHistoryOwner().getUserId())
          && history.getPatient().getPatientId().equals(SearchAPI.getInstance().getPatientId())) {
        json = generateHistoryJSON(history);
      }
      if (json != null) {
        histories.add(json);
      }
    }

    return histories;
  }
  public static JSONArray getAllSearchBookmarksToReturnTomanagerUI() {
    JSONArray bookmarks = new JSONArray();
    List<ChartSearchBookmark> allBookmarks = chartSearchService.getAllSearchBookmarks();

    for (ChartSearchBookmark curBookmark : allBookmarks) {
      JSONObject json = null;

      if (Context.getAuthenticatedUser()
          .getUserId()
          .equals(curBookmark.getBookmarkOwner().getUserId())) {
        json = generateBookmarksJSON(curBookmark);
      }

      if (json != null) {
        bookmarks.add(json);
      }
    }
    return bookmarks;
  }
 public static JSONObject generateRightMatchedPreferencesJSON() {
   return generatePreferencesJSON(chartSearchService.getRightMatchedPreferences());
 }
 public static JSONObject generateDaemonPreferencesJSON() {
   return generatePreferencesJSON(chartSearchService.getChartSearchPreferenceOfAUser(2));
 }