private void fetchPatientList(
      String i2b2User, String i2b2Token, String i2b2Url, String i2b2Domain, String projectId)
      throws FhirServerException {
    status.markProcessing(projectId);
    try {
      logger.trace("fetching all Patients for project:" + projectId);
      String i2b2Xml = null;
      Bundle b = new Bundle();
      ArrayList<String> list = null;

      if (serverConfigs.GetString(ConfigParameter.patientFetchMin) != null
          && serverConfigs.GetString(ConfigParameter.patientFetchMin).equals("true")) {
        logger.debug("min call");
        i2b2Xml = I2b2Util.getAllPatientsMin(i2b2User, i2b2Token, i2b2Url, i2b2Domain, projectId);

        list = I2b2Util.getAllPatientsAsList(i2b2Xml);

        for (String id : list) {
          Patient p = new Patient();
          p = (Patient) FhirUtil.setId(p, id);
          BundleEntry be = new BundleEntry();
          be.setResource(FhirUtil.getResourceContainer(p));
          b.getEntry().add(be);
        }

      } else {
        logger.debug("max call");
        i2b2Xml = I2b2Util.getAllPatients(i2b2User, i2b2Token, i2b2Url, i2b2Domain, projectId);
        list = I2b2Util.getAllPatientsAsList(i2b2Xml);
        b = I2b2Util.getAllPatientsAsFhirBundle(i2b2Xml);
      }

      String bundleXml = JAXBUtil.toXml(b);
      service.put(projectId, list, bundleXml);
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new FhirServerException("Could not fetch patient list from i2b2 server");
    }
    status.markComplete(projectId);
  }
  public ProjectPatientMap getProjectPatientMap(
      String i2b2User, String i2b2Token, String i2b2Url, String i2b2Domain, String i2b2Project)
      throws FhirServerException {

    if (status.isComplete(i2b2Project)) {
      return getProjectPatientMapLocking(i2b2Project);
    }

    if (!(status.isProcessing(i2b2Project) || status.isComplete(i2b2Project))) {
      fetchPatientList(i2b2User, i2b2Token, i2b2Url, i2b2Domain, i2b2Project);
    }

    while (status.isProcessing(i2b2Project)) {
      logger.info("waiting on complete status");
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
      }
    }
    return getProjectPatientMap(i2b2User, i2b2Token, i2b2Url, i2b2Domain, i2b2Project);
  }