cubes.piws.importer.questionnaires.Questionnaires

class cubes.piws.importer.questionnaires.Questionnaires(session, project_name, center_name, questionnaires, questionnaire_type, can_read=True, can_update=True, data_filepath=None, use_store=True, piws_security_model=True, use_openanswer=False)[source]

This class enables us to load the questionnaire to CW.

__init__(session, project_name, center_name, questionnaires, questionnaire_type, can_read=True, can_update=True, data_filepath=None, use_store=True, piws_security_model=True, use_openanswer=False)[source]

Initialize the ‘Questionnaires’ class.

Parameters:

session: Session (mandatory) :

a cubicweb session.

project_name: str (mandatory) :

the name of the project

center_name: str (mandatory) :

the center name

questionnaires: dict of list of dict (mandatory) :

the scan description: the first dictionary contains the subject name as keys and then a list of dictionaries with four keys (Scans - (Scan - TypeData - FileSet - ExternalResource - ScoreValues) - Assessment) that contains the entities parameter decriptions.

questionnaire_type: str (mandatory) :

a questionnaire type used to gather together similar questionnaires.

can_read: bool (optional, default True) :

set the read permission to the imported data.

can_update: bool (optional, default True) :

set the update permission to the imported data.

data_filepath: str (optional, default None) :

the path to folder containing the current study dataset.

use_store: bool (optional, default True) :

if True use an SQLGenObjectStore, otherwise the session.

piws_security_model: bool (optional, default True) :

if True apply the PIWS security model.

use_openanswer : bool (optional, default False)

if True insert questionnaires using the OpenAnswer entity, else using the File entity.

Notes

Here is an example of the definition of the ‘questionnaires’ parameter:

questionnaires = {
    "subject1": [
        {
            "Questionnaires": {
                "Personal": {u"mood": 5}
                "ID": {u"gender": u"male", u"age": 27,
                       u"handedness": u"right"}
            }
            "Assessment": {
                "age_of_subject": 27,
                "identifier": u"toy_V1_subject1",
                "timepoint": u"V1'"
            }
        },
        {
            "Questionnaires": {
                "Personal": {u"mood": 5}
                "ID": {u"gender": u"male", u"age": 27,
                       u"handedness": u"right"}
            }
            "Assessment": {
                "age_of_subject": 27,
                "identifier": u"toy_V0_subject1",
                "timepoint": u"V0"
            }
        }
    ]
}

Methods

__init__(session, project_name, center_name, ...) Initialize the ‘Questionnaires’ class.
cleanup() Method to cleanup temporary items and to commit changes.
import_data() Method that import some questionnaires in the db.
schema(outfname[, text_font, node_text_size]) Create a view of the schema described in a python structure.

Attributes

assessment_relations
device_relations
fileset_relations
relations
__module__ = 'cubes.piws.importer.questionnaires'
_create_questionnaire(questionnaire_name, q_items, identifier_prefix, subject_id, subject_eid, study_eid, assessment_eid, questionnaire_eids, question_eids)[source]

Create a scans and its associated relations.

import_data()[source]

Method that import some questionnaires in the db.

Note

Below the schema used to insert the questionnaires:


schema

Warning

This method assumes that all the subjects and groups have already been inserted in the database.

relations = [('Assessment', 'study', 'Study'), ('Study', 'assessments', 'Assessment'), ('Subject', 'assessments', 'Assessment'), ('Assessment', 'subjects', 'Subject'), ('Center', 'assessments', 'Assessment'), ('Assessment', 'center', 'Center'), ('CWGroup', 'can_read', 'Assessment'), ('CWGroup', 'can_update', 'Assessment'), ('Assessment', 'device', 'Device'), ('Device', 'device_assessments', 'Assessment'), ('Question', 'questionnaire', 'Questionnaire'), ('Questionnaire', 'questions', 'Question'), ('QuestionnaireRun', 'questionnaire', 'Questionnaire'), ('Questionnaire', 'questionnaire_questionnaire_runs', 'QuestionnaireRun'), ('Assessment', 'questionnaire_runs', 'QuestionnaireRun'), ('QuestionnaireRun', 'in_assessment', 'Assessment'), ('QuestionnaireRun', 'study', 'Study'), ('Study', 'study_questionnaire_runs', 'QuestionnaireRun'), ('QuestionnaireRun', 'subject', 'Subject'), ('Subject', 'subject_questionnaire_runs', 'QuestionnaireRun'), ('OpenAnswer', 'question', 'Question'), ('Question', 'question_open_answers', 'OpenAnswer'), ('OpenAnswer', 'questionnaire_run', 'QuestionnaireRun'), ('QuestionnaireRun', 'open_answers', 'OpenAnswer'), ('OpenAnswer', 'in_assessment', 'Assessment'), ('QuestionnaireRun', 'file', 'RestrictedFile')]