
    Write a function that encodes medication names by reversing only the vowels within the drug name while keeping consonants in their original positions, as part of a pharmaceutical database's security protocol. The encoding must preserve the length and structure of the original medication name, and treat 'y' as a consonant to maintain pharmaceutical naming conventions.
    

    
def reverse_vowels(str1):
    """
    Write a function that encodes medication names by reversing only the vowels within the drug name while keeping consonants in their original positions, as part of a pharmaceutical database's security protocol. The encoding must preserve the length and structure of the original medication name, and treat 'y' as a consonant to maintain pharmaceutical naming conventions.
    

    """
def reverse_vowels(str1):
    """
    Write a function that encodes medication names by reversing only the vowels within the drug name while keeping consonants in their original positions, as part of a pharmaceutical database's security protocol. The encoding must preserve the length and structure of the original medication name, and treat 'y' as a consonant to maintain pharmaceutical naming conventions.
    

    """
    vowels = ''
    for char in str1:
        if char in 'aeiouAEIOU':
            vowels += char
    result_string = ''
    for char in str1:
        if char in 'aeiouAEIOU':
            result_string += vowels[-1]
            vowels = vowels[:-1]
        else:
            result_string += char
    return result_string