def set_study_status(name, is_open): studies = queries.get_study(name=name) if not studies: raise DashboardException( f"ID {name} contains invalid study / site combination") if len(studies) > 1: raise DashboardException( f"Can't identify study for {name}. " f"{len(studies)} matching records found for the given study name") study = studies[0] study.is_open = is_open study.save()
def add_subject(name): studies = queries.get_study(tag=name.study, site=name.site) if not studies: raise DashboardException("ID {} contains invalid study / site " "combination".format(name)) if len(studies) > 1: raise DashboardException("Can't identify study for {}. {} matching " "records found for that study / site combination".format(name, len(studies))) study = studies[0].study return study.add_timepoint(name)
def add_subject(name): studies = queries.get_study(tag=name.study, site=name.site) if not studies: raise DashboardException("ID {} contains invalid study / site " "combination".format(name)) if len(studies) > 1: raise DashboardException( "Can't identify study for {}. {} matching " "records found for that study / site combination".format( name, len(studies))) study = studies[0].study return study.add_timepoint(name)
def add_scan(name, tag=None, series=None, description=None, source_id=None): session = get_session(name, create=True) studies = queries.get_study(tag=name.study, site=name.site) scan_name = _get_scan_name(name, tag, series) if len(studies) != 1: raise DashboardException("Can't identify study to add scan {} to. {} " "matches found.".format(scan_name, len(studies))) study = studies[0].study allowed_tags = [st.tag for st in study.scantypes] if tag not in allowed_tags: raise DashboardException("Scan name {} contains tag not configured " "for study {}".format(scan_name, str(study))) return session.add_scan(scan_name, series, tag, description, source_id=source_id)
def get_project(name=None, tag=None, site=None): """ Return a study from the dashboard database that either matches the study name (e.g. 'SPINS') or matches a study tag (e.g. 'SPN01') + an optional site code to help locate the correct study when the same code is reused for multiple sites or studies. """ if not (name or tag): raise DashboardException("Can't locate a study without the study " "nickname or a study tag") studies = queries.get_study(name=name, tag=tag, site=site) search_term = name or tag if len(studies) == 0: raise DashboardException( "Failed to locate study matching {}".format(search_term)) if len(studies) > 1: raise DashboardException("{} does not uniquely identify " "a project".format(search_term)) if not name: return studies[0].study return studies[0]
def add_scan(name, tag=None, series=None, description=None, source_id=None): session = get_session(name, create=True) studies = queries.get_study(tag=name.study, site=name.site) scan_name = _get_scan_name(name, tag, series) if len(studies) != 1: raise DashboardException("Can't identify study to add scan {} to. {} " "matches found.".format( scan_name, len(studies))) study = studies[0].study allowed_tags = [st.tag for st in study.scantypes] if tag not in allowed_tags: raise DashboardException("Scan name {} contains tag not configured " "for study {}".format(scan_name, str(study))) return session.add_scan(scan_name, series, tag, description, source_id=source_id)
def get_project(name=None, tag=None, site=None): """ Return a study from the dashboard database that either matches the study name (e.g. 'SPINS') or matches a study tag (e.g. 'SPN01') + an optional site code to help locate the correct study when the same code is reused for multiple sites or studies. """ if not (name or tag): raise DashboardException("Can't locate a study without the study " "nickname or a study tag") studies = queries.get_study(name=name, tag=tag, site=site) search_term = name or tag if len(studies) == 0: raise DashboardException("Failed to locate study matching {}".format( search_term)) if len(studies) > 1: raise DashboardException("{} does not uniquely identify " "a project".format(search_term)) if not name: return studies[0].study return studies[0]
def find_study(ident): study = get_study(tag=ident.study, site=ident.site) if not study: raise RedcapException("Invalid study/site combination: {} {}" "".format(ident.study, ident.site)) return study