[importers] age from Psytools experiment ends up in Assessment
authorDimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
Sat, 27 Jul 2013 12:57:27 +0200
changeset 366 0518974bc7f4
parent 365 1cbe7540884d
child 371 e62367d9141a
[importers] age from Psytools experiment ends up in Assessment
importers/imagen.py
--- a/importers/imagen.py	Sat Jul 27 09:35:17 2013 +0200
+++ b/importers/imagen.py	Sat Jul 27 12:57:27 2013 +0200
@@ -360,7 +360,7 @@
     # Create assessment
     measure_eid = import_generic_test_run(store, experiment, study_eid, subject_eid,
                                           _type=u'genomics')
-    assessment_eid = create_assessment_for_experiment(store, experiment,
+    assessment_eid = create_assessment_for_experiment(store, experiment, None,
                                                       study_eid, subject_eid,
                                                       center_eid, measure_eid)
     # Create measure
@@ -557,7 +557,7 @@
 def import_neuroimaging(store, tree, experiment, study_eid, subject_eid, center_eid):
     """Import a neuroimaging assessment from an experiment node"""
     # Create assessment
-    assessment_eid = create_assessment_for_experiment(store, experiment,
+    assessment_eid = create_assessment_for_experiment(store, experiment, None, #TODO: None->age?
                                                       study_eid, subject_eid, center_eid)
     # Create device
     device_eid = import_device(store, tree, experiment, center_eid)
@@ -634,11 +634,11 @@
     """Import a behavioural (as a type of psytool experiment)
     """
     # Create behavioural data
-    behavioural_run_eid, behavioural_eid = import_pystool_experiment(store, tree,
-                                                                     experiment,
-                                                                     subject_eid,
-                                                                     'Questionnaire',
-                                                                     'QuestionnaireRun')
+    behavioural_run_eid, behavioural_eid, age = import_pystool_experiment(store, tree,
+                                                                          experiment,
+                                                                          subject_eid,
+                                                                          'Questionnaire',
+                                                                          'QuestionnaireRun')
     # Create questions/answers
     build_question_answer_infos(store, experiment, behavioural_eid, behavioural_run_eid)
     # Create trials file in a two steps procedure to merge possibly different keys
@@ -654,7 +654,7 @@
             extres_eid = store.create_entity('ExternalResource', **extres_infos).eid
             store.relate(behavioural_run_eid, 'external_resources', extres_eid)
     # Relate to an assessment
-    assessment_eid = create_assessment_for_experiment(store, experiment,
+    assessment_eid = create_assessment_for_experiment(store, experiment, age,
                                                       study_eid, subject_eid, center_eid,
                                                       behavioural_run_eid)
     return behavioural_run_eid
@@ -725,10 +725,9 @@
                                identifier=experiment_id,
                                iteration=iteration,
                                completed=completed,
-                               #age = age ### XXX modify the schema!
                                user_ident=user_ident,
                                concerns=subject_eid,
-                               instance_of=experiment_eid).eid
+                               instance_of=experiment_eid).eid, age
 
 def import_pystool_experiment(store, tree, experiment, subject_eid, exp_etype, etype_run):
     """Import all types of psytool experiments (questionnaire/behavioural)"""
@@ -737,9 +736,12 @@
     experiment_eid = build_psytool_experiment(store, tree, experiment, exp_etype)
     # Create experiment data specific to this experiment run, relate to
     # experiment metadata
-    experiment_run_eid = build_psytool_experiment_run(store, tree, experiment, etype_run,
-                                                      subject_eid, experiment_eid)
-    return experiment_run_eid, experiment_eid
+    # Retrieve the age of subject at the time of experiment
+    experiment_run_eid, age = build_psytool_experiment_run(store, tree, experiment,
+                                                           etype_run,
+                                                           subject_eid,
+                                                           experiment_eid)
+    return experiment_run_eid, experiment_eid, age
 
 def build_question_answer_infos(store, experiment, questionnaire_eid, questionnaire_run_eid):
     """Iterate over questions and answers for a questionnaire
@@ -790,11 +792,11 @@
 def import_questionnaire(store, tree, experiment, study_eid, subject_eid, center_eid):
     """Import a questionnaire (as a type of psytool experiment)"""
     # Create questionnaire
-    questionnaire_run_eid, questionnaire_eid = import_pystool_experiment(store, tree,
-                                                                         experiment,
-                                                                         subject_eid,
-                                                                         'Questionnaire',
-                                                                         'QuestionnaireRun')
+    questionnaire_run_eid, questionnaire_eid, age = import_pystool_experiment(store, tree,
+                                                                              experiment,
+                                                                              subject_eid,
+                                                                              'Questionnaire',
+                                                                              'QuestionnaireRun')
     # Create questions/answers
     build_question_answer_infos(store, experiment, questionnaire_eid, questionnaire_run_eid)
     # Create external resources
@@ -803,7 +805,7 @@
             extres_eid = store.create_entity('ExternalResource', **extres_infos).eid
             store.relate(questionnaire_run_eid, 'external_resources', extres_eid)
     # Relate to an assessment
-    assessment_eid = create_assessment_for_experiment(store, experiment,
+    assessment_eid = create_assessment_for_experiment(store, experiment, age,
                                                       study_eid, subject_eid, center_eid,
                                                       questionnaire_run_eid)
     # Files
@@ -844,13 +846,16 @@
         score_value_eid = store.create_entity('ScoreValue', **score_value_infos).eid
     return measure.eid
 
-def create_assessment_for_experiment(store, experiment, study_eid, subject_eid,
-                                     center_eid, measure_eid=None):
+def create_assessment_for_experiment(store, experiment, age, study_eid,
+                                     subject_eid, center_eid, measure_eid=None):
     """Create an assessment and required relations from and experiment
 
     Arguments:
     experiment -- XML node of the experiment
-    subject_eid -- current subject identifier
+    age -- age of subject at the time of expriment
+    study_eid -- identifier of the study this experiment is part of
+    subject_eid -- identifier of the subject
+    center_eid -- indentifier of the center where the expriment is conducted
     measure_eid -- ?
 
     Returns the identifier of the newly created Assessment
@@ -858,8 +863,9 @@
     # Create an assessment
     experiment_id = unicode(experiment.get('ID'))
     assessment_eid = store.create_entity('Assessment',
+                                         identifier=experiment_id,
+                                         age_for_assessment=age,
                                          protocol=unicode(experiment.get('%stype' % XSI)),
-                                         identifier=experiment_id,
                                          related_study=study_eid).eid
     # Create relations
     store.relate(subject_eid, 'concerned_by', assessment_eid)
@@ -886,7 +892,7 @@
     """Import the quality report assessment from an experiment node
     """
     measure_eid = import_generic_test_run(store, experiment, study_eid, subject_eid)
-    assessment_eid = create_assessment_for_experiment(store, experiment,
+    assessment_eid = create_assessment_for_experiment(store, experiment, None,  #TODO: None->age
                                                       study_eid, subject_eid,
                                                       center_eid, measure_eid)
     for _type in XNAT_TAGS_SUBJECT_INFOS:
@@ -1103,15 +1109,13 @@
         find = experiment.xpath('@xsi:type', namespaces=nsmap)
         experiment_type = find[0]
         if experiment_type == 'imagen:qualityReportData':
-            # Quality Report Data
             assessment_eid = import_quality_report(store, tree, experiment,
                                                    study_eid, subject_eid, center_eid)
         elif experiment_type in XNAT_TAGS_SUBJECT_ADDITIONAL_INFOS:
             assessment_eid = import_subject_additional_infos(store, experiment,
                                                              study_eid, subject_eid, center_eid)
         elif experiment_type in XNAT_TAGS_GENERIC_ASSESSMENT_RESOURCES_ONLY:
-            # Assessments for External Resources only
-            assessment_eid = create_assessment_for_experiment(store, experiment,
+            assessment_eid = create_assessment_for_experiment(store, experiment, None,
                                                               study_eid, subject_eid, center_eid)
         elif experiment_type in XNAT_TAGS_GENERIC_ASSESSMENT:
             testrun_eid = import_generic_subject_assessments(store, tree, experiment,