@RequestMapping(value = "", method = RequestMethod.GET)
  public @ResponseBody RootNode getEnrollments(
      @RequestParam(required = false) String ou,
      @RequestParam(required = false) OrganisationUnitSelectionMode ouMode,
      @RequestParam(required = false) String program,
      @RequestParam(required = false) ProgramStatus programStatus,
      @RequestParam(required = false) Boolean followUp,
      @RequestParam(required = false) Date lastUpdated,
      @RequestParam(required = false) Date programStartDate,
      @RequestParam(required = false) Date programEndDate,
      @RequestParam(required = false) String trackedEntity,
      @RequestParam(required = false) String trackedEntityInstance,
      @RequestParam(required = false) Integer page,
      @RequestParam(required = false) Integer pageSize,
      @RequestParam(required = false) boolean totalPages,
      @RequestParam(required = false) boolean skipPaging) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));

    if (fields.isEmpty()) {
      fields.add(
          "enrollment,created,lastUpdated,trackedEntity,trackedEntityInstance,program,status,orgUnit,enrollmentDate,incidentDate,followup");
    }

    Set<String> orgUnits = TextUtils.splitToArray(ou, TextUtils.SEMICOLON);

    ProgramInstanceQueryParams params =
        programInstanceService.getFromUrl(
            orgUnits,
            ouMode,
            lastUpdated,
            program,
            programStatus,
            programStartDate,
            programEndDate,
            trackedEntity,
            trackedEntityInstance,
            followUp,
            page,
            pageSize,
            totalPages,
            skipPaging);

    List<Enrollment> enrollments =
        new ArrayList<>(
            enrollmentService.getEnrollments(programInstanceService.getProgramInstances(params)));

    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(Enrollment.class, enrollments, fields));

    return rootNode;
  }
  @Override
  public Optional<String> getPopulateTempTableStatement() {
    String sql =
        "insert into "
            + getTempTableName()
            + " "
            + "select coc.categoryoptioncomboid as cocid, coc.name as cocname, ";

    for (DataElementCategory category : objects) {
      sql +=
          "("
              + "select co.name from categoryoptioncombos_categoryoptions cocco "
              + "inner join dataelementcategoryoption co on cocco.categoryoptionid = co.categoryoptionid "
              + "inner join categories_categoryoptions cco on co.categoryoptionid = cco.categoryoptionid "
              + "where coc.categoryoptioncomboid = cocco.categoryoptioncomboid "
              + "and cco.categoryid = "
              + category.getId()
              + " "
              + "limit 1) as "
              + columnQuote
              + category.getName()
              + columnQuote
              + ", ";

      sql +=
          "("
              + "select co.uid from categoryoptioncombos_categoryoptions cocco "
              + "inner join dataelementcategoryoption co on cocco.categoryoptionid = co.categoryoptionid "
              + "inner join categories_categoryoptions cco on co.categoryoptionid = cco.categoryoptionid "
              + "where coc.categoryoptioncomboid = cocco.categoryoptioncomboid "
              + "and cco.categoryid = "
              + category.getId()
              + " "
              + "limit 1) as "
              + columnQuote
              + category.getUid()
              + columnQuote
              + ", ";
    }

    sql = TextUtils.removeLastComma(sql) + " ";
    sql += "from categoryoptioncombo coc ";

    return Optional.of(sql);
  }