parameters: (source: message.Message, target: message.Message)
docstring: Adds all fields from source to target.
  
    Args:
      source: The FHIR Code instance to copy from.
      target: The target FHIR Code instance to copy to.
docstring_summary: Adds all fields from source to target.
docstring_tokens: Adds all fields from source to target .
function: def copy_code(source: message.Message, target: message.Message) -> None:
    """Adds all fields from source to target.
  
    Args:
      source: The FHIR Code instance to copy from.
      target: The target FHIR Code instance to copy to.
    """
    if not fhir_types.is_type_or_profile_of_code(source.DESCRIPTOR):
      raise fhir_errors.InvalidFhirError(f'Source: {source.DESCRIPTOR.full_name} '
                                         'is not type or profile of Code.')
  
    if not fhir_types.is_type_or_profile_of_code(target.DESCRIPTOR):
      raise fhir_errors.InvalidFhirError(f'Target: {target.DESCRIPTOR.full_name} '
                                         'is not type or profile of Code.')
  
    if proto_utils.are_same_message_type(source.DESCRIPTOR, target.DESCRIPTOR):
      target.CopyFrom(source)
      return
  
    source_value_field = source.DESCRIPTOR.fields_by_name.get('value')
    target_value_field = target.DESCRIPTOR.fields_by_name.get('value')
    if source_value_field is None or target_value_field is None:
      raise fhir_errors.InvalidFhirError('Unable to copy code from '
                                         f'{source.DESCRIPTOR.full_name} '
                                         f'to {target.DESCRIPTOR.full_name}.')
  
    proto_utils.copy_common_field(source, target, 'id')
    proto_utils.copy_common_field(source, target, 'extension')
  
    # Handle specialized codes
    if (source_value_field.type not in _CODE_TYPES or
        target_value_field.type not in _CODE_TYPES):
      raise ValueError(f'Unable to copy from {source.DESCRIPTOR.full_name} '
                       f'to {target.DESCRIPTOR.full_name}. Must have a field '
                       'of TYPE_ENUM or TYPE_STRING.')
  
    source_value = proto_utils.get_value_at_field(source, source_value_field)
    if source_value_field.type == target_value_field.type:
      # Perform a simple assignment if value_field types are equivalent
      proto_utils.set_value_at_field(target, target_value_field, source_value)
    else:
      # Otherwise, we need to transform the value prior to assignment...
      if source_value_field.type == descriptor.FieldDescriptor.TYPE_STRING:
        source_enum_value = code_string_to_enum_value_descriptor(
            source_value, target_value_field.enum_type)
        proto_utils.set_value_at_field(target, target_value_field,
                                       source_enum_value.number)
      elif source_value_field.type == descriptor.FieldDescriptor.TYPE_ENUM:
        source_string_value = enum_value_descriptor_to_code_string(
            source_value_field.enum_type.values_by_number[source_value])
        proto_utils.set_value_at_field(target, target_value_field,
                                       source_string_value)
      else:  # Should never hit
        raise ValueError('Unexpected generic value field type: '
                         f'{source_value_field.type}. Must be a field of '
                         'TYPE_ENUM or TYPE_STRING in order to copy.')
function_tokens: def copy_code ( source : message . Message , target : message . Message ) -> None : if not fhir_types . is_type_or_profile_of_code ( source . DESCRIPTOR ) : raise fhir_errors . InvalidFhirError ( f'Source: {source.DESCRIPTOR.full_name} ' 'is not type or profile of Code.' ) if not fhir_types . is_type_or_profile_of_code ( target . DESCRIPTOR ) : raise fhir_errors . InvalidFhirError ( f'Target: {target.DESCRIPTOR.full_name} ' 'is not type or profile of Code.' ) if proto_utils . are_same_message_type ( source . DESCRIPTOR , target . DESCRIPTOR ) : target . CopyFrom ( source ) return source_value_field = source . DESCRIPTOR . fields_by_name . get ( 'value' ) target_value_field = target . DESCRIPTOR . fields_by_name . get ( 'value' ) if source_value_field is None or target_value_field is None : raise fhir_errors . InvalidFhirError ( 'Unable to copy code from ' f'{source.DESCRIPTOR.full_name} ' f'to {target.DESCRIPTOR.full_name}.' ) proto_utils . copy_common_field ( source , target , 'id' ) proto_utils . copy_common_field ( source , target , 'extension' ) # Handle specialized codes if ( source_value_field . type not in _CODE_TYPES or target_value_field . type not in _CODE_TYPES ) : raise ValueError ( f'Unable to copy from {source.DESCRIPTOR.full_name} ' f'to {target.DESCRIPTOR.full_name}. Must have a field ' 'of TYPE_ENUM or TYPE_STRING.' ) source_value = proto_utils . get_value_at_field ( source , source_value_field ) if source_value_field . type == target_value_field . type : # Perform a simple assignment if value_field types are equivalent proto_utils . set_value_at_field ( target , target_value_field , source_value ) else : # Otherwise, we need to transform the value prior to assignment... if source_value_field . type == descriptor . FieldDescriptor . TYPE_STRING : source_enum_value = code_string_to_enum_value_descriptor ( source_value , target_value_field . enum_type ) proto_utils . set_value_at_field ( target , target_value_field , source_enum_value . number ) elif source_value_field . type == descriptor . FieldDescriptor . TYPE_ENUM : source_string_value = enum_value_descriptor_to_code_string ( source_value_field . enum_type . values_by_number [ source_value ] ) proto_utils . set_value_at_field ( target , target_value_field , source_string_value ) else : # Should never hit raise ValueError ( 'Unexpected generic value field type: ' f'{source_value_field.type}. Must be a field of ' 'TYPE_ENUM or TYPE_STRING in order to copy.' )