import logging


def get_spiro_vals(key: str, rec: dict) -> tuple:
    """
    Takes a spirometry test (eg FEV1, FVC, etc) as key and returns an 8-tuple
    with pre then post measured, %predicted, SR as well as predicted and percent change
    Fills tuple position with None if value doesn't exist
    """
    if not key in rec:
        logging.error('Lung function, get_spiro_vals() - no data found')
        return (None, None, None, None, None, None, None, None)

    pre = rec[key]['Measured_pre']
    pred = rec[key]['Predicted']
    pre_percent_pred = rec[key]['Percent_pred_pre']
    pre_SR = (rec[key]['SR_pre'] if 'SR_pre' in rec[key] else None)

    post = (rec[key]['Measured_post'] if 'Measured_post' in rec[key] else None)
    post_percent_pred = (rec[key]['Percent_pred_post'] if 'Percent_pred_post' in rec[key] else None)
    percent_change = (rec[key]['Percent_change'] if 'Percent_change' in rec[key] else None)
    post_SR = (rec[key]['SR_post'] if 'SR_post' in rec[key] else None)

    return (pre, pred, pre_percent_pred, pre_SR, post, percent_change, post_percent_pred, post_SR)