Exemple #1
0
    def get_loris_session_id(self):
        """
        Greps the LORIS session.ID corresponding to the BIDS visit. Note,
        if no BIDS visit are set, will use the default visit label value set
        in the config module

        :return: the session's ID in LORIS
         :rtype: int
        """

        # check if there are any visit label in BIDS structure, if not,
        # will use the default visit label set in the config module
        visit_label = self.bids_ses_id if self.bids_ses_id else self.default_vl

        session = Session(verbose=self.verbose,
                          cand_id=self.cand_id,
                          center_id=self.center_id,
                          visit_label=visit_label)
        loris_vl_info = session.get_session_info_from_loris(self.db)

        if not loris_vl_info:
            message = "ERROR: visit label " + visit_label + "does not exist in " + \
                      "the session table for candidate "  + self.cand_id         + \
                      "\nPlease make sure the visit label is created in the "    + \
                      "database or run bids_import.py with the -s option -s if " + \
                      "you wish that the insertion pipeline creates the visit "  + \
                      "label in the session table."
            print(message)
            exit(lib.exitcode.SELECT_FAILURE)

        return loris_vl_info['ID']
Exemple #2
0
def grep_or_create_visit_label_db_info(bids_id, cand_id, visit_label, db,
                                       createvisit, verbose, loris_bids_dir,
                                       center_id):
    """
    Greps (or creates if candidate does not exist and createcand is true) the
    BIDS candidate in the LORIS candidate's table and return a list of
    candidates with their related fields from the database.

    :parma bids_id       : BIDS ID of the candidate
     :type bids_id       : str
    :param cand_id       : CandID to use to create the session
     :type cand_id       : int
    :param visit_label   : Visit label to use to create the session
     :type visit_label   : str
    :param db            : database handler object
     :type db            : object
    :param createvisit   : if true, creates the candidate in LORIS
     :type createvisit   : bool
    :param verbose       : if true, prints out information while executing
     :type verbose       : bool
    :param loris_bids_dir: LORIS BIDS import root directory to copy data
     :type loris_bids_dir: str

    :return: session information grepped from LORIS for cand_id and visit_label
     :rtype: dict
    """

    session = Session(verbose,
                      cand_id=cand_id,
                      visit_label=visit_label,
                      center_id=center_id)
    loris_vl_info = session.get_session_info_from_loris(db)

    if not loris_vl_info and createvisit:
        loris_vl_info = session.create_session(db)

    # create the visit directory for in the candidate folder of the LORIS
    # BIDS import directory
    lib.utilities.create_dir(
        loris_bids_dir + "sub-" + bids_id + "/ses-" + visit_label, verbose)

    return loris_vl_info