def autofill(ctx, steps, metadata, fixed, study, environment, subject):
    """Request enterable data for a subject, generate data values and post back to Rave.
    Requires 'rwscmd_getdata' configurable dataset to be installed on the Rave URL."""

    if metadata is not None:  # Read metadata from file, if supplied
        odm_metadata = metadata.read()
        meta_v = etree.fromstring(odm_metadata).find('.//' + E_ODM.METADATA_VERSION.value).get(A_ODM.OID.value)
    else:
        odm_metadata = None
        meta_v = None

    fixed_values = {}
    if fixed is not None:  # Read fixed values from file, if supplied
        for f in fixed:
            oid, value = f.decode().split(',')
            fixed_values[oid] = value
            if ctx.obj['VERBOSE']:
                click.echo('Fixing {} to value: {}'.format(oid, value))

    try:
        for n in range(0, steps):
            if ctx.obj['VERBOSE']:
                click.echo('Step {}'.format(str(n + 1)))

            # Get currently enterable fields for this subject
            subject_data = get_data(ctx, study, environment, subject)

            subject_data_odm = etree.fromstring(subject_data)
            if subject_data_odm.find('.//' + E_ODM.CLINICAL_DATA.value) is None:
                if ctx.obj['VERBOSE']:
                    click.echo('No data found')
                break

            # Get the metadata version for the subject
            subject_meta_v = subject_data_odm.find('.//' + E_ODM.CLINICAL_DATA.value).get(
                A_ODM.METADATA_VERSION_OID.value)
            if subject_meta_v is None:
                if ctx.obj['VERBOSE']:
                    click.echo('Subject not found')
                break

            # If no metadata supplied, or versions don't match, retrieve metadata from RWS
            if meta_v != subject_meta_v:
                if ctx.obj['VERBOSE']:
                    click.echo('Getting metadata version {}'.format(subject_meta_v))
                ctx.obj['RWS'].send_request(StudyVersionRequest(study, subject_meta_v))
                odm_metadata = ctx.obj['RWS'].last_result.text
                meta_v = subject_meta_v

            # Generate data values to fill in empty fields
            if ctx.obj['VERBOSE']:
                click.echo('Generating data')

            scr = Scramble(odm_metadata)
            odm = scr.fill_empty(fixed_values, subject_data)

            # If new data values, post to RWS
            if etree.fromstring(odm).find('.//' + E_ODM.ITEM_DATA.value) is None:
                if ctx.obj['VERBOSE']:
                    click.echo('No data to send')
                break
            ctx.obj['RWS'].send_request(PostDataRequest(odm))
            if ctx.obj['RAW']:
                click.echo(ctx.obj['RWS'].last_result.text)

    except RWSException as e:
        click.echo(e.rws_error)

    except requests.exceptions.HTTPError as e:
        click.echo(e.strerror)
Request enterable data for a subject, generate data values and post back to Rave.
    Requires 'rwscmd_getdata' configurable dataset to be installed on the Rave URL.