original_docstring: Generates target labels in the case of having missing label in the entityset.
  
          Args:
              es: fhir entityset.
  
          Returns:
              Updated entityset with the generated label.
  
          Raises:
              ValueError: An error occurs if the target label cannot be generated.
          
docstring: Generates target labels in the case of having missing label in the entityset.
docstring_tokens: Generates target labels in the case of having missing label in the entityset .
code: def generate_target_label(self, es):
          """Generates target labels in the case of having missing label in the entityset.
  
          Args:
              es: fhir entityset.
  
          Returns:
              Updated entityset with the generated label.
  
          Raises:
              ValueError: An error occurs if the target label cannot be generated.
          """
          generate_from = 'Period'
          end = 'end'
          if (DataLoader().check_column_existence(
              es,
              generate_from,
              end)) and (DataLoader().check_column_existence(es,
                                                             self.target_entity,
                                                             'period')):
  
              if not DataLoader().check_for_missing_values(
                      es,
                      generate_from, end):
  
                  entity_set_df = es[self.target_entity].df
                  generated_df = es[generate_from].df
                  merged_df = pd.merge(entity_set_df, generated_df, how='left',
                                       left_on='period', right_on='object_id')
  
                  generated_target_label = []
                  encounter_identifier = []
  
                  for patient in set(merged_df['subject']):
                      patient_visits = merged_df[merged_df['subject'] == patient]
                      inital_date = patient_visits[end].iloc[0]
  
                      encounter_identifier.append(patient_visits['identifier'].iloc[0])
                      generated_target_label.append(False)  # first visit
  
                      if len(patient_visits) != 1:
                          for visit_date, encounter_id in zip(patient_visits[end][1:],
                                                              patient_visits['identifier'][1:]):
  
                              visit_range = visit_date - inital_date
                              inital_date = visit_date
  
                              if visit_range.days <= self.readmission_threshold:
                                  generated_target_label.append(True)
                                  encounter_identifier.append(encounter_id)
  
                              else:
                                  generated_target_label.append(False)
                                  encounter_identifier.append(encounter_id)
  
                  generated_labels = pd.DataFrame(
                      {self.target_label_column_name: generated_target_label,
                       'identifier': encounter_identifier})
                  updated_target_entity = pd.merge(entity_set_df,
                                                   generated_labels,
                                                   on='identifier')
  
                  es = es.entity_from_dataframe(entity_id=self.target_entity,
                                                dataframe=updated_target_entity,
                                                index='identifier')
  
                  return es
  
              else:
                  raise ValueError(
                      'Can not generate target label {} in table {} beacuse end label in \
                       table {} contains missing value.'.format(
                          self.target_label_column_name, self. target_entity, generate_from))
  
          else:
              raise ValueError(
                  'Can not generate target label {} in table {}.'.format(
                      self.target_label_column_name,
                      self.target_entity))
code_tokens: def generate_target_label ( self , es ) : generate_from = 'Period' end = 'end' if ( DataLoader ( ) . check_column_existence ( es , generate_from , end ) ) and ( DataLoader ( ) . check_column_existence ( es , self . target_entity , 'period' ) ) : if not DataLoader ( ) . check_for_missing_values ( es , generate_from , end ) : entity_set_df = es [ self . target_entity ] . df generated_df = es [ generate_from ] . df merged_df = pd . merge ( entity_set_df , generated_df , how = 'left' , left_on = 'period' , right_on = 'object_id' ) generated_target_label = [ ] encounter_identifier = [ ] for patient in set ( merged_df [ 'subject' ] ) : patient_visits = merged_df [ merged_df [ 'subject' ] == patient ] inital_date = patient_visits [ end ] . iloc [ 0 ] encounter_identifier . append ( patient_visits [ 'identifier' ] . iloc [ 0 ] ) generated_target_label . append ( False ) if len ( patient_visits ) != 1 : for visit_date , encounter_id in zip ( patient_visits [ end ] [ 1 : ] , patient_visits [ 'identifier' ] [ 1 : ] ) : visit_range = visit_date - inital_date inital_date = visit_date if visit_range . days <= self . readmission_threshold : generated_target_label . append ( True ) encounter_identifier . append ( encounter_id ) else : generated_target_label . append ( False ) encounter_identifier . append ( encounter_id ) generated_labels = pd . DataFrame ( { self . target_label_column_name : generated_target_label , 'identifier' : encounter_identifier } ) updated_target_entity = pd . merge ( entity_set_df , generated_labels , on = 'identifier' ) es = es . entity_from_dataframe ( entity_id = self . target_entity , dataframe = updated_target_entity , index = 'identifier' ) return es else : raise ValueError ( 'Can not generate target label {} in table {} beacuse end label in \
                       table {} contains missing value.' . format ( self . target_label_column_name , self . target_entity , generate_from ) ) else : raise ValueError ( 'Can not generate target label {} in table {}.' . format ( self . target_label_column_name , self . target_entity ) )
short_docstring: Generates target labels in the case of having missing label in the entityset.
short_docstring_tokens: Generates target labels in the case of having missing label in the entityset .
comment: """Generates target labels in the case of having missing label in the entityset.
  
          Args:
              es: fhir entityset.
  
          Returns:
              Updated entityset with the generated label.
  
          Raises:
              ValueError: An error occurs if the target label cannot be generated.
          """$SEP$# first visit