Add the entries in defaults dict into input_dict if they don't exist in input_dict

    This is based on the accepted answer at
    http://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth

    :param dict input_dict: The dict to be updated
    :param dict defaults_dict: Dict containing the defaults for entries in input_dict
    :return: updated dict
    :rtype: dict

def _add_default_entries(input_dict, defaults_dict):
    """
    Add the entries in defaults dict into input_dict if they don't exist in input_dict

    This is based on the accepted answer at
    http://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth

    :param dict input_dict: The dict to be updated
    :param dict defaults_dict: Dict containing the defaults for entries in input_dict
    :return: updated dict
    :rtype: dict
    """
    for key, value in defaults_dict.iteritems():
        if key == 'patients':
            print('Cannot default `patients`.')
            continue
        if isinstance(value, dict):
            if key not in input_dict or input_dict[key] is None:
                # User didn't specify anython for the tool, but the entry was still in there so we
                # just copy over the whole defaults dict
                input_dict[key] = value
            else:
                r = _add_default_entries(input_dict.get(key, {}), value)
                input_dict[key] = r
        else:
            # Only write if not in input_dict
            if key not in input_dict or input_dict[key] is None:
                # Either the user didn't have the entry, or had it without a value
                input_dict[key] = value
    return input_dict