source: trunk/grails-app/domain/dbnp/studycapturing/Study.groovy @ 754

Last change on this file since 754 was 754, checked in by keesvb, 11 years ago

big refactoring / change of the data model: implemented belongsTo everywhere where it should be, added comments to the domain classes, changed BootStrap? accordingly

  • Property svn:keywords set to Date Rev Author
File size: 3.5 KB
Line 
1package dbnp.studycapturing
2
3/**
4 * Domain class describing the basic entity in the study capture part: the Study class.
5 *
6 * Revision information:
7 * $Rev: 754 $
8 * $Author: keesvb $
9 * $Date: 2010-07-30 13:05:41 +0000 (vr, 30 jul 2010) $
10 */
11class Study extends TemplateEntity {
12        static searchable = {
13        [only: ['title', 'Description']]
14    }
15
16        nimble.User owner   // The owner of the study. A new study is automatically owned by its creator.
17        String title        // The title of the study
18        String code             // currently used as the external study ID, e.g. to reference a study in a SAM module
19        Date dateCreated
20        Date lastUpdated
21        Date startDate
22    List subjects
23        List events
24        List samplingEvents
25        List eventGroups
26        List samples
27        List assays
28
29        static hasMany = [
30                editors: nimble.User,   // Users with read/write access to the study
31                readers: nimble.User,   // Users with only read access to the study
32                subjects: Subject,
33                samplingEvents: SamplingEvent,
34                events: Event,
35                eventGroups: EventGroup,
36                samples: Sample,
37                assays: Assay,
38                persons: StudyPerson,
39                publications: Publication
40        ]
41
42        static constraints = {
43                owner(nullable: true, blank: true)
44                code(nullable:false, blank:true,unique:true) 
45        }
46
47        static mapping = {
48                researchQuestion type: 'text'
49                description type: 'text'
50                autoTimestamp true
51        }
52
53        // The external study ID is currently defined as the code of the study.
54        // It is used from within dbNP submodules to refer to particular study in this GSCF instance.
55        def getExternalStudyId() { code }
56
57        /**
58         * return the domain fields for this domain class
59         * @return List
60         */
61        static List<TemplateField> giveDomainFields() { return Study.domainFields }
62
63        static final List<TemplateField> domainFields = [
64                new TemplateField(
65                        name: 'title',
66                        type: TemplateFieldType.STRING),
67                new TemplateField(
68                        name: 'code',
69                        type: TemplateFieldType.STRING,
70                        preferredIdentifier:true,
71                        comment: 'Fill out the code by which many people will recognize your study'),
72                new TemplateField(
73                        name: 'startDate',
74                        type: TemplateFieldType.DATE,
75                        comment: 'Fill out the official start date or date of first action')
76        ]
77
78        /**
79         * return the title of this study
80         */
81        def String toString() {
82                return title
83        }
84
85        /**
86         * returns all events and sampling events that do not belong to a group
87         */
88        def Set<Event> getOrphanEvents() {
89                def orphans =   events.findAll { event -> !event.belongsToGroup(eventGroups) } +
90                                                samplingEvents.findAll { event -> !event.belongsToGroup(eventGroups) }
91
92                return orphans
93        }
94
95        /**
96         * Return the unique Subject templates that are used in this study
97         */
98        def Set<Template> giveSubjectTemplates() {
99                TemplateEntity.giveTemplates(subjects)
100        }
101
102        /**
103         * Return the unique Event and SamplingEvent templates that are used in this study
104         */
105        Set<Template> giveAllEventTemplates() {
106                // For some reason, giveAllEventTemplates() + giveAllSamplingEventTemplates()
107                // gives trouble when asking .size() to the result
108                // So we also use giveTemplates here
109                TemplateEntity.giveTemplates(events + samplingEvents)
110        }
111
112        /**
113         * Return the unique Event templates that are used in this study
114         */
115        Set<Template> giveEventTemplates() {
116                TemplateEntity.giveTemplates(events)
117        }
118
119        /**
120         * Return the unique SamplingEvent templates that are used in this study
121         */
122        Set<Template> giveSamplingEventTemplates() {
123                TemplateEntity.giveTemplates(samplingEvents)
124        }
125
126        /**
127         * Returns the unique Sample templates that are used in the study
128         */
129        Set<Template> giveSampleTemplates() {
130                TemplateEntity.giveTemplates(samples)
131        }
132        /**
133         * Returns the template of the study
134         */
135        Template giveStudyTemplate() {
136                return this.template
137        }
138}
Note: See TracBrowser for help on using the repository browser.