Age is wrongly associated to subject in input files
authorDimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
Sat, 20 Jul 2013 16:43:54 +0200
changeset 355 c1672cba8805
parent 354 a16116e18bab
child 356 2a4cd09f9c66
Age is wrongly associated to subject in input files Keep age for later reference, do not make it a Subject attribute. Instead make it an Assessment attribute.
importers/localizer.py
--- a/importers/localizer.py	Thu Aug 01 12:44:00 2013 +0200
+++ b/importers/localizer.py	Sat Jul 20 16:43:54 2013 +0200
@@ -57,7 +57,9 @@
     data, score_values = {}, []
     info = json.load(open('%s/subject.json' % data_dir))
     data['identifier'] = info['nip']
-    data['age'] = info['age']
+    # age varies with time: it should not be stored as an attribute of Subject
+    # keep it for later use: store as an attribute of Assessment
+    age_for_assessment = info['age']
     data['gender'] = GENDER_MAP.get(info['sex'], GENDER_MAP['3'])
     data['age'] = info['age']
     data['handedness'] = HANDEDNESS_MAP.get(info['laterality'],
@@ -65,7 +67,7 @@
     for score in SCORE_TYPES:
         score_values.append({'name': score,
                              'value': info.get(score)})
-    return data, score_values
+    return data, age_for_assessment, score_values
 
 def import_study(data_dir):
     """Import a study from a data dir"""
@@ -108,12 +110,13 @@
         data['hosted_by'] = 'SHFJ'
     return data
 
-def import_assessment(data_dir, label, study_eid):
+def import_assessment(data_dir, age_for_assessment, label, study_eid):
     """Import an assessment"""
     info = json.load(open('%s/subject.json' % data_dir))
     data = {}
     data['identifier'] = u'%s_%s' % (info['nip'], label)
     data['protocol'] = info['protocol']
+    data['age_for_assessment'] = age_for_assessment
     data['timepoint'] = info['date']
     data['related_study'] = study_eid
     if info.get('date'):
@@ -404,7 +407,7 @@
             device_id = devices[device['name']]
 
         # Subject #############################################################
-        subject, score_values = import_subject(sid)
+        subject, age_for_assessment, score_values = import_subject(sid)
         subject = store.create_entity('Subject', **subject)
         store.relate(subject.eid, 'related_studies', study.eid)
         for score_val in score_values:
@@ -434,7 +437,7 @@
                                          start=root_dir)))
 
         # Genetics ############################################################
-        gen_assessment = import_assessment(sid, 'genetics', study.eid)
+        gen_assessment = import_assessment(sid, age_for_assessment, 'genetics', study.eid)
         gen_assessment = store.create_entity('Assessment', **gen_assessment)
         store.relate(subject.eid, 'concerned_by', gen_assessment.eid)
         measure = gen_measures[subject.identifier]
@@ -447,7 +450,7 @@
 
         # Anat & fMRI ############################################################
         # anat assessment
-        anat_assessment = import_assessment(sid, 'anat', study.eid)
+        anat_assessment = import_assessment(sid, age_for_assessment, 'anat', study.eid)
         anat_assessment = store.create_entity('Assessment', **anat_assessment)
         store.relate(center_eid, 'holds', anat_assessment.eid)
         store.relate(subject.eid, 'concerned_by', anat_assessment.eid)
@@ -463,7 +466,7 @@
             store.relate(scan_anat.eid, 'uses_device', device_id)
             store.relate(anat_assessment.eid, 'generates', scan_anat.eid, subjtype='Assessment')
         # fmri assessment
-        fmri_assessment = import_assessment(sid, 'fmri', study.eid)
+        fmri_assessment = import_assessment(sid, age_for_assessment, 'fmri', study.eid)
         fmri_assessment = store.create_entity('Assessment', **fmri_assessment)
         store.relate(center_eid, 'holds', fmri_assessment.eid)
         store.relate(subject.eid, 'concerned_by', fmri_assessment.eid)
@@ -481,7 +484,7 @@
 
         # c-maps & t-maps #####################################################
         for dtype, label in (('c', 'c_maps'), ('t', 't_maps')):
-            assessment = import_assessment(sid, label, study.eid)
+            assessment = import_assessment(sid, age_for_assessment, label, study.eid)
             assessment = store.create_entity('Assessment', **assessment)
             store.relate(center_eid, 'holds', assessment.eid)
             store.relate(subject.eid, 'concerned_by', assessment.eid)
@@ -503,7 +506,7 @@
                 store.relate(scan.eid, 'external_resources', dm_res.eid)
 
         # mask ################################################################
-        assessment = import_assessment(sid, 'mask', study.eid)
+        assessment = import_assessment(sid, age_for_assessment, 'mask', study.eid)
         assessment = store.create_entity('Assessment', **assessment)
         store.relate(center_eid, 'holds', assessment.eid)
         store.relate(subject.eid, 'concerned_by', assessment.eid)
@@ -519,7 +522,7 @@
         store.relate(assessment.eid, 'generates', scan.eid, subjtype='Assessment')
 
         # Questionnaire run ###################################################
-        assessment = import_assessment(sid, 'questionnaire', study.eid)
+        assessment = import_assessment(sid, age_for_assessment, 'questionnaire', study.eid)
         assessment = store.create_entity('Assessment', **assessment)
         store.relate(center_eid, 'holds', assessment.eid)
         store.relate(subject.eid, 'concerned_by', assessment.eid)