schema.py
author Vincent Michel <vincent.michel@logilab.fr>
Thu, 17 Jan 2013 14:17:22 +0100
changeset 35 1f80416802da
parent 26 e9f7ffbd5b50
child 66 bd1eec6c4d01
child 69 dc9cfb29e775
child 154 63acf059a3fe
permissions -rw-r--r--
preparing 0.1.0

# -*- coding: utf-8 -*-
# copyright 2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr -- mailto:contact@logilab.fr
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

"""cubicweb-brainomics schema"""
from yams.buildobjs import (EntityType, RelationDefinition, SubjectRelation, String, RichString,
                            Int, Float, Boolean)

from cubes.questionnaire.schema import QuestionnaireRun, Questionnaire, Question
from cubes.neuroimaging.schema import Scan, AnatomicalRegion
from cubes.genomics.schema import GenomicMeasure, ColumnRef
from cubes.medicalexp.schema  import Assessment, ProcessingRun, ScoreDef, ScoreValue

ALL_MEASURES = ('GenericMeasure', 'QuestionnaireRun', 'GenericTestRun', 'Scan', 'GenomicMeasure')


# ProcessingRun -> Measure
ProcessingRun.add_relation(SubjectRelation('QuestionnaireRun', cardinality='**'), name='inputs')
ProcessingRun.add_relation(SubjectRelation('Scan', cardinality='**'), name='inputs')
ProcessingRun.add_relation(SubjectRelation('GenomicMeasure', cardinality='**'), name='inputs')

ProcessingRun.add_relation(SubjectRelation('QuestionnaireRun', cardinality='**'), name='outputs')
ProcessingRun.add_relation(SubjectRelation('Scan', cardinality='**'), name='outputs')
ProcessingRun.add_relation(SubjectRelation('GenomicMeasure', cardinality='**'), name='outputs')

# Maesure -> Subject
QuestionnaireRun.add_relation(SubjectRelation(('Subject', 'Group'), cardinality='1*', inlined=True), name='concerns')
Scan.add_relation(SubjectRelation(('Subject', 'Group'), cardinality='1*', inlined=True), name='concerns')
GenomicMeasure.add_relation(SubjectRelation(('Subject', 'Group'), cardinality='1*', inlined=True), name='concerns')

# Assessment -> Measure
Assessment.add_relation(SubjectRelation('QuestionnaireRun', cardinality='**'), name='uses')
Assessment.add_relation(SubjectRelation('Scan', cardinality='**'), name='uses')
Assessment.add_relation(SubjectRelation('GenomicMeasure', cardinality='**'), name='uses')

Assessment.add_relation(SubjectRelation('QuestionnaireRun', cardinality='?*', inlined=True), name='generates')
Assessment.add_relation(SubjectRelation('Scan', cardinality='?*', inlined=True), name='generates')
Assessment.add_relation(SubjectRelation('GenomicMeasure', cardinality='?*', inlined=True), name='generates')

# Score -> Measure
ScoreValue.add_relation(SubjectRelation('QuestionnaireRun', cardinality='?*', inlined=True), name='measure')
ScoreValue.add_relation(SubjectRelation('Scan', cardinality='?*', inlined=True), name='measure')
ScoreValue.add_relation(SubjectRelation('GenomicMeasure', cardinality='?*', inlined=True), name='measure')

# Use for filepath computation
QuestionnaireRun.add_relation(SubjectRelation('Study', cardinality='1*', inlined=True), name='related_study')
Scan.add_relation(SubjectRelation('Study', cardinality='1*', inlined=True), name='related_study')
GenomicMeasure.add_relation(SubjectRelation('Study', cardinality='1*', inlined=True), name='related_study')
QuestionnaireRun.add_relation(SubjectRelation('Study', cardinality='**'), name='other_studies')
Scan.add_relation(SubjectRelation('Study', cardinality='**'), name='other_studies')
GenomicMeasure.add_relation(SubjectRelation('Study', cardinality='**'), name='other_studies')

# Device -> Measure
QuestionnaireRun.add_relation(SubjectRelation('Device', cardinality='?*', inlined=True), name='uses_device')
Scan.add_relation(SubjectRelation('Device', cardinality='?*', inlined=True), name='uses_device')
GenomicMeasure.add_relation(SubjectRelation('Device', cardinality='?*', inlined=True), name='uses_device')

# Measure -> ExternalResources
Questionnaire.add_relation(SubjectRelation('ExternalResource', cardinality='*1'), name='external_resources')
Scan.add_relation(SubjectRelation('ExternalResource', cardinality='*1'), name='external_resources')
GenomicMeasure.add_relation(SubjectRelation('ExternalResource', cardinality='*1'), name='external_resources')

# Various relations
Questionnaire.add_relation(SubjectRelation('ScoreDef', cardinality='*?'), name='definitions')
ScoreDef.add_relation(SubjectRelation('Question', cardinality='**'), name='used_by')
AnatomicalRegion.add_relation(SubjectRelation('ScoreValue', cardinality='**'), name='concerned_by')
ColumnRef.add_relation(SubjectRelation('Assessment', cardinality='1*', inlined=True), name='assessment')