/**
   * @return
   * @throws SQLException
   * @throws I2B2Exception
   */
  public HashMap calculateMaxPageInputList() throws SQLException, I2B2Exception {
    int maxIteration = getPagingMaxIteration();
    int i = 0;
    long pageSize = getPageSize();
    boolean fitPagingFlag = false;
    HashMap returnResultMap = new HashMap();
    returnResultMap.put("PAGING_REQUIRED_FLAG", true);
    long totalObservations = 0;
    // PatientListTypeHandler patientList = new PatientListTypeHandler(
    // dataSourceLookup, inputList.getPatientList());

    IInputOptionListHandler inputOptionListHandler =
        PDOFactory.buildInputListHandler(inputList, dataSourceLookup);

    int maxInputList = inputOptionListHandler.getMaxIndex();
    int minInputList = inputOptionListHandler.getMinIndex();
    int originalMaxInputList = maxInputList;
    int inputListCount = maxInputList - minInputList;
    while (i < maxIteration) {
      totalObservations = getTotal(inputListCount);
      log.debug("Total observations for [" + inputListCount + " ] is [" + totalObservations + " ]");
      //
      if (i == 0) {
        returnResultMap.put("TOTAL_OBSERVATION", totalObservations);
      }

      // if total < page size then set max patient break
      if (checkIfFitThePage(pageSize, totalObservations)) {
        log.debug(
            "Input list size of [" + inputListCount + "] fits the page size [" + pageSize + "]");
        fitPagingFlag = true;
        if (i == 0) {
          returnResultMap.put("PAGING_REQUIRED_FLAG", false);
        }
        break;
      }

      // call paging method with page size, total observation,..
      inputListCount = pageMethod.calculateListSize(inputListCount, totalObservations, pageSize);

      if (inputListCount < 1) {
        // need not continue the iteration if the list size is reduced
        // to < 1
        break;
      }
      i++;
    }

    if (fitPagingFlag) {
      returnResultMap.put("MAX_INPUT_LIST", inputListCount);
      return returnResultMap;
    } else {
      throw new I2B2Exception("Could not fit in a page after [" + maxIteration + "] iteration");
    }

    /*
     * // try with minimum percent of patient int minIndex =
     * patientList.getMinIndex(); int maxIndex = originalMaxInputList; int
     * listLength = maxIndex - minIndex; int minPercentInput =
     * getMinPercentInput(listLength);
     * log.debug("Trying with minimum input list percent of [ " +
     * minPercentInput + "]");
     *
     * if (minPercentInput > 0) { if (minPercentInput < maxInputList) {
     * totalObservations = getTotal(minPercentInput); log
     * .debug("Total observations for minimum input list percent  [" +
     * minPercentInput + " ] is [" + totalObservations + " ]"); if
     * (totalObservations > 0 && checkIfFitThePage(pageSize,
     * totalObservations)) { maxInputList = minIndex + minPercentInput;
     * returnResultMap.put("MAX_INPUT_LIST", maxInputList); return
     * returnResultMap; } } } else { log
     * .debug("Skipping minimum input list percent, since the value is 0");
     * }
     */

    // try with minimun of single patient
    // int minPagingSize = getPagingMinSize();
    // log.debug("Trying with minimum input list size of [" + minPagingSize
    // + "]");
    // if (minPagingSize < 1) {
    // throw new I2B2DAOException(
    // "Paging failed, minimum page size should not be less than 1");
    // }
    //
    // HashMap minMap = getMinPatientIndexAndTheTotal(originalMaxInputList);
    // int minDataIndex = (Integer) minMap.get("MIN_INDEX");
    // long minDataIndexTotal = (Long) minMap.get("MIN_INDEX_TOTAL");
    //
    // System.out.println("min index" + minMap.get("MIN_INDEX"));
    // System.out.println("min index total " +
    // minMap.get("MIN_INDEX_TOTAL"));
    //
    // // totalObservations = getTotal(minPagingSize);
    // log.debug("Total observation for first data index [" + minDataIndex
    // + " ] is [" + minDataIndexTotal + "]");
    //
    // if (!checkIfFitThePage(pageSize, minDataIndexTotal)) {
    // throw new I2B2DAOException(
    // "Paging failed, even the first patient index of ["
    // + minDataIndex + "] patient observations ["
    // + minDataIndexTotal
    // + "] could not fit the page size [" + pageSize
    // + "]");
    // } else {
    //
    // returnResultMap.put("MAX_INPUT_LIST", minDataIndex);
    // return returnResultMap;
    // }
  }