cni / nims

Legacy version of NIMS. All new development at @scitran
14 stars 12 forks source link

mis-classified sessions #34

Closed rfdougherty closed 11 years ago

rfdougherty commented 11 years ago

When a user has multiple experiments with the same name but under different research groups, a session can get mis-classified. E.g., if a user has access to smcclure/gaba and cni/gaba, their sessions with patient id "smcclure/gaba' may end up in 'cni/gaba'. (I think the subject names would have to also match for this error to occur.) It seems that the problem is in the Subject class method from_mrfile, which does a query for any matching experiment name regardless of the ResearchGroup. E.g.:

subj_code, group_name, exp_name = nimsutil.parse_patient_id('smcclure/gaba', ResearchGroup.all_ids())
print(subj_code, group_name, exp_name)
    (u'', u'smcclure', u'gaba')
query = Subject.query.join(Experiment, Subject.experiment).filter(Experiment.name==exp_name)
subject = query.filter(Subject.firstname=='Mrs').filter(Subject.lastname=='Gaba').filter(Subject.dob==None).first()
subject.experiment
    <Experiment: cni/gaba>
gsfr commented 11 years ago

The bug is actually not limited to what a user might have access to. If a matching subject exists in an identically named experiment, we mistakenly use that experiment. Scary!

I have added another line to the query. Seems to work. Testing now...

query = query.join(ResearchGroup, Experiment.owner).filter(ResearchGroup.gid == group_name)