parameters: (self, json_value: Any, field: descriptor.FieldDescriptor,
                     parent: message.Message)
docstring: Merges the json_value into the provided field of the parent Message.
  
      Args:
        json_value: The JSON value to set.
        field: The FieldDescriptor of the field to set in parent.
        parent: The parent Message to set the value on.
  
      Raises:
        ValueError: In the event that a non-primitive field has already been set.
        ValueError: In the event that a oneof field has already been set.
docstring_summary: Merges the json_value into the provided field of the parent Message.
docstring_tokens: Merges the json_value into the provided field of the parent Message .
function: def _merge_field(self, json_value: Any, field: descriptor.FieldDescriptor,
                     parent: message.Message) -> None:
      """Merges the json_value into the provided field of the parent Message.
  
      Args:
        json_value: The JSON value to set.
        field: The FieldDescriptor of the field to set in parent.
        parent: The parent Message to set the value on.
  
      Raises:
        ValueError: In the event that a non-primitive field has already been set.
        ValueError: In the event that a oneof field has already been set.
      """
      # If the field is non-primitive, ensure that it hasn't been set yet. Note
      # that we allow primitive types to be set already, because FHIR represents
      # extensions to primitives as separate, subsequent JSON elements, with the
      # field prepended by an underscore
      if (not annotation_utils.is_primitive_type(field.message_type) and
          proto_utils.field_is_set(parent, field)):
        raise ValueError(f'Target field {field.full_name} is already set.')
  
      # Consider it an error if a oneof field is already set.
      #
      # Exception: When a primitive in a choice type has a value and an extension,
      # it will get set twice, once by the value (e.g. valueString) and once by an
      # extension (e.g., _valueString)
      if field.containing_oneof is not None:
        oneof_field = parent.DESCRIPTOR.oneofs_by_name[
            field.containing_oneof.name]
        if (annotation_utils.is_primitive_type(field.message_type) and
            oneof_field.full_name == field.full_name):
          raise ValueError(
              f'Cannot set field {field.full_name} since oneof field '
              f'{oneof_field.full_name} is already set.')
  
      # Ensure that repeated fields get proper list assignment
      existing_field_size = proto_utils.field_content_length(parent, field)
      if proto_utils.field_is_repeated(field):
        if not isinstance(json_value, list):
          raise ValueError(
              f'Attempted to merge a repeated field, {field.name}, a json_value '
              f'with type {type(json_value)} instead of a list.')
  
        if existing_field_size != 0 and existing_field_size != len(json_value):
          raise ValueError(
              'Repeated primitive list length does not match extension list for '
              'field: {field.full_name!r}.')
  
      # Set the JSON values, taking care to clear the PRIMITIVE_HAS_NO_VALUE_URL
      # if we've already visited the field before.
      json_value = (
          json_value if proto_utils.field_is_repeated(field) else [json_value])
      for (i, value) in enumerate(json_value):
        parsed_value = self._parse_field_value(field, value)
        if existing_field_size > 0:
          field_value = proto_utils.get_value_at_field_index(parent, field, i)
          field_value.MergeFrom(parsed_value)
          extensions.clear_fhir_extensions_with_url(
              field_value, extensions.PRIMITIVE_HAS_NO_VALUE_URL)
        else:
          field_value = proto_utils.set_in_parent_or_add(parent, field)
          field_value.MergeFrom(parsed_value)
function_tokens: def _merge_field ( self , json_value : Any , field : descriptor . FieldDescriptor , parent : message . Message ) -> None : # If the field is non-primitive, ensure that it hasn't been set yet. Note # that we allow primitive types to be set already, because FHIR represents # extensions to primitives as separate, subsequent JSON elements, with the # field prepended by an underscore if ( not annotation_utils . is_primitive_type ( field . message_type ) and proto_utils . field_is_set ( parent , field ) ) : raise ValueError ( f'Target field {field.full_name} is already set.' ) # Consider it an error if a oneof field is already set. # # Exception: When a primitive in a choice type has a value and an extension, # it will get set twice, once by the value (e.g. valueString) and once by an # extension (e.g., _valueString) if field . containing_oneof is not None : oneof_field = parent . DESCRIPTOR . oneofs_by_name [ field . containing_oneof . name ] if ( annotation_utils . is_primitive_type ( field . message_type ) and oneof_field . full_name == field . full_name ) : raise ValueError ( f'Cannot set field {field.full_name} since oneof field ' f'{oneof_field.full_name} is already set.' ) # Ensure that repeated fields get proper list assignment existing_field_size = proto_utils . field_content_length ( parent , field ) if proto_utils . field_is_repeated ( field ) : if not isinstance ( json_value , list ) : raise ValueError ( f'Attempted to merge a repeated field, {field.name}, a json_value ' f'with type {type(json_value)} instead of a list.' ) if existing_field_size != 0 and existing_field_size != len ( json_value ) : raise ValueError ( 'Repeated primitive list length does not match extension list for ' 'field: {field.full_name!r}.' ) # Set the JSON values, taking care to clear the PRIMITIVE_HAS_NO_VALUE_URL # if we've already visited the field before. json_value = ( json_value if proto_utils . field_is_repeated ( field ) else [ json_value ] ) for ( i , value ) in enumerate ( json_value ) : parsed_value = self . _parse_field_value ( field , value ) if existing_field_size > 0 : field_value = proto_utils . get_value_at_field_index ( parent , field , i ) field_value . MergeFrom ( parsed_value ) extensions . clear_fhir_extensions_with_url ( field_value , extensions . PRIMITIVE_HAS_NO_VALUE_URL ) else : field_value = proto_utils . set_in_parent_or_add ( parent , field ) field_value . MergeFrom ( parsed_value )