<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def visit(folder, provenance_id, step_name, previous_step_id=None, config=None, db_url=None, is_organised=True):
 """Record all files from a folder into the database. Note: If a file has been copied from a previous processing step without any transformation, it will be detected and (e.g. a DICOM file) contains some meta-data, those will be stored in the DB. Arguments: :param folder: folder path. :param provenance_id: provenance label. :param step_name: Name of the processing step that produced the folder to visit. :param previous_step_id: (optional) previous processing step ID. If not defined, we assume this is the first processing step. :param config: List of flags: - boost: (optional) When enabled, we consider that all the files from a same folder share the same meta-data. When enabled, the processing is (about 2 times) faster. This option is enabled by default. - session_id_by_patient: Rarely, a data set might use study IDs which are unique by patient (not for the whole study). E.g.: LREN data. In such a case, you have to enable this flag. This will use PatientID + StudyID as a session ID. - visit_id_in_patient_id: Rarely, a data set might mix patient IDs and visit IDs. E.g. : LREN data. In such a case, you have to enable this flag. This will try to split PatientID into VisitID and PatientID. - visit_id_from_path: Enable this flag to get the visit ID from the folder hierarchy instead of DICOM meta-data (e.g. can be useful for PPMI). - repetition_from_path: Enable this flag to get the repetition ID from the folder hierarchy instead of DICOM meta-data (e.g. can be useful for PPMI). :param db_url: (optional) Database URL. If not defined, it looks for an Airflow configuration file. :param is_organised: (optional) Disable this flag when scanning a folder that has not been organised yet (should only affect nifti files). :return: return processing step ID. """

    config = config if config else []

    logging.info("Visiting %s", folder)
    logging.info("-> is_organised=%s", str(is_organised))
    logging.info("-> config=%s", str(config))

    logging.info("Connecting to database...")
    db_conn = connection.Connection(db_url)

    step_id = _create_step(db_conn, step_name, provenance_id, previous_step_id)

    previous_files_hash = _get_files_hash_from_step(db_conn, previous_step_id)

    checked = dict()

    def process_file(file_path):
        logging.debug("Processing '%s'" % file_path)
        file_type = _find_type(file_path)
        if "DICOM" == file_type:
            is_copy = _hash_file(file_path) in previous_files_hash
            leaf_folder = os.path.split(file_path)[0]
            if leaf_folder not in checked or 'boost' not in config:
                ret = dicom_import.dicom2db(file_path, file_type, is_copy, step_id, db_conn,
                                            'session_id_by_patient' in config, 'visit_id_in_patient_id' in config,
                                            'visit_id_in_patient_id' in config, 'repetition_from_path' in config)
                try:
                    checked[leaf_folder] = ret['repetition_id']
                except KeyError:
                    # TODO: Remove it when dicom2db will be more stable
                    logging.warning("Cannot find repetition ID !")
            else:
                dicom_import.extract_dicom(
                    file_path, file_type, is_copy, checked[leaf_folder], step_id)
        elif "NIFTI" == file_type and is_organised:
            is_copy = _hash_file(file_path) in previous_files_hash
            nifti_import.nifti2db(file_path, file_type, is_copy, step_id, db_conn, 'session_id_by_patient' in config,
                                  'visit_id_in_patient_id' in config)
        elif file_type:
            is_copy = _hash_file(file_path) in previous_files_hash
            others_import.others2db(
                file_path, file_type, is_copy, step_id, db_conn)

    if sys.version_info.major == 3 and sys.version_info.minor < 5:
        matches = []
        for root, dirnames, filenames in os.walk(folder):
            for filename in fnmatch.filter(filenames, '*'):
                matches.append(os.path.join(root, filename))
        for file_path in matches:
            process_file(file_path)
    else:
        for file_path in glob.iglob(os.path.join(folder, "**/*"), recursive=True):
            process_file(file_path)

    logging.info("Closing database connection...")
    db_conn.close()

    return step_id