nodes: 0, module; 1, function_definition; 2, function_name:enrollments; 3, parameters; 4, block; 5, identifier:db; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, if_statement; 13, if_statement; 14, if_statement; 15, if_statement; 16, expression_statement; 17, with_statement; 18, return_statement; 19, identifier:uuid; 20, None; 21, identifier:organization; 22, None; 23, identifier:from_date; 24, None; 25, identifier:to_date; 26, None; 27, comment:"""List the enrollment information available in the registry.
  
      This function will return a list of enrollments. If 'uuid'
      parameter is set, it will return the enrollments related to that
      unique identity; if 'organization' parameter is given, it will
      return the enrollments related to that organization; if both
      parameters are set, the function will return the list of enrollments
      of 'uuid' on the 'organization'.
  
      Enrollments between a period can also be listed using 'from_date' and
      'to_date' parameters. When these are set, the function will return
      all those enrollments where Enrollment.start >= from_date AND
      Enrollment.end <= to_date. Defaults values for these dates are
      1900-01-01 and 2100-01-01.
  
      When either 'uuid' or 'organization' are not in the registry a
      'NotFoundError' exception will be raised.
  
      :param db: database manager
      :param uuid: unique identifier
      :param organization: name of the organization
      :param from_date: date when the enrollment starts
      :param to_date: date when the enrollment ends
  
      :returns: a list of enrollments sorted by uuid or by organization.
  
      :raises NotFoundError: when either 'uuid' or 'organization' are not
          found in the registry.
      :raises InvalidValeError: it is raised in two cases, when "from_date" < 1900-01-01 or
          "to_date" > 2100-01-01; when "from_date > to_date".
      """; 28, not_operator; 29, block; 30, not_operator; 31, block; 32, boolean_operator; 33, block; 34, boolean_operator; 35, block; 36, boolean_operator; 37, block; 38, assignment; 39, with_clause; 40, block; 41, identifier:enrollments; 42, identifier:from_date; 43, expression_statement; 44, identifier:to_date; 45, expression_statement; 46, comparison_operator:from_date < MIN_PERIOD_DATE; 47, comparison_operator:from_date > MAX_PERIOD_DATE; 48, raise_statement; 49, comparison_operator:to_date < MIN_PERIOD_DATE; 50, comparison_operator:to_date > MAX_PERIOD_DATE; 51, raise_statement; 52, boolean_operator; 53, comparison_operator:from_date > to_date; 54, raise_statement; 55, identifier:enrollments; 56, list; 57, with_item; 58, expression_statement; 59, comment:# Filter by uuid; 60, if_statement; 61, comment:# Filter by organization; 62, if_statement; 63, comment:# Get the results; 64, expression_statement; 65, comment:# Detach objects from the session; 66, expression_statement; 67, assignment; 68, assignment; 69, identifier:from_date; 70, identifier:MIN_PERIOD_DATE; 71, identifier:from_date; 72, identifier:MAX_PERIOD_DATE; 73, call; 74, identifier:to_date; 75, identifier:MIN_PERIOD_DATE; 76, identifier:to_date; 77, identifier:MAX_PERIOD_DATE; 78, call; 79, identifier:from_date; 80, identifier:to_date; 81, identifier:from_date; 82, identifier:to_date; 83, call; 84, as_pattern; 85, assignment; 86, identifier:uuid; 87, block; 88, identifier:organization; 89, block; 90, assignment; 91, call; 92, identifier:from_date; 93, identifier:MIN_PERIOD_DATE; 94, identifier:to_date; 95, identifier:MAX_PERIOD_DATE; 96, identifier:InvalidValueError; 97, argument_list; 98, identifier:InvalidValueError; 99, argument_list; 100, identifier:InvalidValueError; 101, argument_list; 102, call; 103, as_pattern_target; 104, identifier:query; 105, call; 106, expression_statement; 107, if_statement; 108, expression_statement; 109, expression_statement; 110, if_statement; 111, expression_statement; 112, identifier:enrollments; 113, call; 114, attribute; 115, argument_list; 116, binary_operator:"'from_date' %s is out of bounds" % str(from_date); 117, binary_operator:"'to_date' %s is out of bounds" % str(to_date); 118, binary_operator:"'from_date' %s cannot be greater than %s"
                                  % (from_date, to_date); 119, attribute; 120, argument_list; 121, identifier:session; 122, attribute; 123, argument_list; 124, assignment; 125, not_operator; 126, block; 127, assignment; 128, assignment; 129, not_operator; 130, block; 131, assignment; 132, attribute; 133, argument_list; 134, identifier:session; 135, identifier:expunge_all; 136, string:"'from_date' %s is out of bounds"; 137, call; 138, string:"'to_date' %s is out of bounds"; 139, call; 140, string:"'from_date' %s cannot be greater than %s"; 141, tuple; 142, identifier:db; 143, identifier:connect; 144, call; 145, line_continuation:\; 146, identifier:filter; 147, comparison_operator:Enrollment.start >= from_date; 148, comparison_operator:Enrollment.end <= to_date; 149, identifier:uidentity; 150, call; 151, identifier:uidentity; 152, raise_statement; 153, identifier:query; 154, call; 155, identifier:org; 156, call; 157, identifier:org; 158, raise_statement; 159, identifier:query; 160, call; 161, call; 162, identifier:all; 163, identifier:str; 164, argument_list; 165, identifier:str; 166, argument_list; 167, identifier:from_date; 168, identifier:to_date; 169, attribute; 170, argument_list; 171, attribute; 172, identifier:from_date; 173, attribute; 174, identifier:to_date; 175, identifier:find_unique_identity; 176, argument_list; 177, call; 178, attribute; 179, argument_list; 180, identifier:find_organization; 181, argument_list; 182, call; 183, attribute; 184, argument_list; 185, attribute; 186, argument_list; 187, identifier:from_date; 188, identifier:to_date; 189, call; 190, line_continuation:\; 191, identifier:join; 192, identifier:UniqueIdentity; 193, identifier:Organization; 194, identifier:Enrollment; 195, identifier:start; 196, identifier:Enrollment; 197, identifier:end; 198, identifier:session; 199, identifier:uuid; 200, identifier:NotFoundError; 201, argument_list; 202, identifier:query; 203, identifier:filter; 204, comparison_operator:Enrollment.uidentity == uidentity; 205, identifier:session; 206, identifier:organization; 207, identifier:NotFoundError; 208, argument_list; 209, identifier:query; 210, identifier:filter; 211, comparison_operator:Enrollment.organization == org; 212, identifier:query; 213, identifier:order_by; 214, attribute; 215, attribute; 216, attribute; 217, attribute; 218, attribute; 219, argument_list; 220, keyword_argument; 221, attribute; 222, identifier:uidentity; 223, keyword_argument; 224, attribute; 225, identifier:org; 226, identifier:UniqueIdentity; 227, identifier:uuid; 228, identifier:Organization; 229, identifier:name; 230, identifier:Enrollment; 231, identifier:start; 232, identifier:Enrollment; 233, identifier:end; 234, identifier:session; 235, identifier:query; 236, identifier:Enrollment; 237, identifier:entity; 238, identifier:uuid; 239, identifier:Enrollment; 240, identifier:uidentity; 241, identifier:entity; 242, identifier:organization; 243, identifier:Enrollment; 244, identifier:organization
code: def enrollments(db, uuid=None, organization=None, from_date=None, to_date=None):
      """List the enrollment information available in the registry.
  
      This function will return a list of enrollments. If 'uuid'
      parameter is set, it will return the enrollments related to that
      unique identity; if 'organization' parameter is given, it will
      return the enrollments related to that organization; if both
      parameters are set, the function will return the list of enrollments
      of 'uuid' on the 'organization'.
  
      Enrollments between a period can also be listed using 'from_date' and
      'to_date' parameters. When these are set, the function will return
      all those enrollments where Enrollment.start >= from_date AND
      Enrollment.end <= to_date. Defaults values for these dates are
      1900-01-01 and 2100-01-01.
  
      When either 'uuid' or 'organization' are not in the registry a
      'NotFoundError' exception will be raised.
  
      :param db: database manager
      :param uuid: unique identifier
      :param organization: name of the organization
      :param from_date: date when the enrollment starts
      :param to_date: date when the enrollment ends
  
      :returns: a list of enrollments sorted by uuid or by organization.
  
      :raises NotFoundError: when either 'uuid' or 'organization' are not
          found in the registry.
      :raises InvalidValeError: it is raised in two cases, when "from_date" < 1900-01-01 or
          "to_date" > 2100-01-01; when "from_date > to_date".
      """
      if not from_date:
          from_date = MIN_PERIOD_DATE
      if not to_date:
          to_date = MAX_PERIOD_DATE
  
      if from_date < MIN_PERIOD_DATE or from_date > MAX_PERIOD_DATE:
          raise InvalidValueError("'from_date' %s is out of bounds" % str(from_date))
      if to_date < MIN_PERIOD_DATE or to_date > MAX_PERIOD_DATE:
          raise InvalidValueError("'to_date' %s is out of bounds" % str(to_date))
  
      if from_date and to_date and from_date > to_date:
          raise InvalidValueError("'from_date' %s cannot be greater than %s"
                                  % (from_date, to_date))
  
      enrollments = []
  
      with db.connect() as session:
          query = session.query(Enrollment).\
              join(UniqueIdentity, Organization).\
              filter(Enrollment.start >= from_date,
                     Enrollment.end <= to_date)
  
          # Filter by uuid
          if uuid:
              uidentity = find_unique_identity(session, uuid)
  
              if not uidentity:
                  raise NotFoundError(entity=uuid)
  
              query = query.filter(Enrollment.uidentity == uidentity)
  
          # Filter by organization
          if organization:
              org = find_organization(session, organization)
  
              if not org:
                  raise NotFoundError(entity=organization)
  
              query = query.filter(Enrollment.organization == org)
  
          # Get the results
          enrollments = query.order_by(UniqueIdentity.uuid,
                                       Organization.name,
                                       Enrollment.start,
                                       Enrollment.end).all()
  
          # Detach objects from the session
          session.expunge_all()
  
      return enrollments