code: def get_paged(self, endpoint, params=None, page_size=50, merge=False):
          
          try:
              if not isinstance(page_size, (string_types, int)) or int(page_size) < 1:
                  raise ValueError
          except ValueError:
              raise ClientException("page_size must be > 1")
  
          params = {} if not params else params
          if 'paging' in params:
              raise ClientException("Can't set paging manually in `params` when using `get_paged`")
          params['pageSize'] = page_size
          params['page'] = 1
          params['totalPages'] = True
  
          collection = endpoint.split('/')[0]  # only use e.g. events when submitting events/query as endpoint
  
          def page_generator():
              """Yield pages"""
              page = self.get(endpoint=endpoint, file_type='json', params=params).json()
              page_count = page['pager']['pageCount']
              yield page
  
              while page['pager']['page'] < page_count:
                  params['page'] += 1
                  page = self.get(endpoint=endpoint, file_type='json', params=params).json()
                  yield page
  
          if not merge:
              return page_generator()
          else:
              data = []
              for p in page_generator():
                  data.append(p[collection])
              return {collection: list(chain.from_iterable(data))}
docs: GET with paging (for large payloads).
          :param page_size: how many objects per page
          :param endpoint: DHIS2 API endpoint
          :param params: HTTP parameters (dict), defaults to None
          :param merge: If true, return a list containing all pages instead of one page. Defaults to False.
          :return: generator OR a normal DHIS2 response dict, e.g. {"organisationUnits": [...]}