root/trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy @ 822

Revision 822, 2.5 KB (checked in by duh, 4 years ago)

- added revision information to the header

  • Property svn:keywords set to Author Rev Date
Line 
1package dbnp.studycapturing
2
3import dbnp.data.Term
4
5/**
6 * The Sample class describes an actual sample which results from a SamplingEvent.
7 *
8 * Revision information:
9 * $Rev$
10 * $Author$
11 * $Date$
12 */
13class Sample extends TemplateEntity {
14        // uncommented due to searchable issue
15        // @see http://jira.codehaus.org/browse/GRAILSPLUGINS-1577
16        //static searchable = { [only: ['name']] }
17
18        // A Sample always belongs to one study.
19        static belongsTo = [parent : Study, parentSubject : Subject, parentEvent : SamplingEvent]
20
21        // A Sample optionally has a parent Subject from which it was taken, this Subject should be in the same parent study.
22        //long parentSubject
23
24        // Also, it has a parent SamplingEvent describing the actual sampling, also within the same parent study.
25        // Strange enough, we need to define parentEvent as a long here, otherwise the SamplingEvent gets serialized into the database (?!!)
26        //long parentEvent
27
28        String name             // should be unique with respect to the parent study (which can be inferred)
29        Term material           // material of the sample (should normally be bound to the BRENDA ontology)
30
31        def getExternalSampleId() { name }
32
33        /**
34         * return the domain fields for this domain class
35         * @return List
36         */
37        static List<TemplateField> giveDomainFields() { return Sample.domainFields }
38
39        // We have to specify an ontology list for the material property. However, at compile time, this ontology does of course not exist.
40        // Therefore, the ontology is added at runtime in the bootstrap, possibly downloading the ontology properties if it is not present in the database yet.
41        static List<TemplateField> domainFields = [
42                new TemplateField(
43                        name: 'name',
44                        type: TemplateFieldType.STRING,
45                        preferredIdentifier: true,
46                        required: true
47                ),
48                new TemplateField(
49                        name: 'material',
50                        type: TemplateFieldType.ONTOLOGYTERM
51                )
52        ]
53
54        static constraints = {
55                // The parent subject is optional, e.g. in a biobank of samples the subject could be unknown or non-existing.
56                parentSubject(nullable:true)
57
58                // The material domain field is optional
59                material(nullable: true)
60
61                // Check if the externalSampleId (currently defined as name) is really unique within each parent study of this sample.
62                // This feature is tested by integration test SampleTests.testSampleUniqueNameConstraint
63                name(unique:['parent'])
64        }
65
66        static getSamplesFor( event ) {
67                return  Sample.findAll( 'from Sample s where s.parentEvent =:event', [event:event] )
68        }
69
70        def String toString() {
71                return name
72        }
73}
Note: See TracBrowser for help on using the browser.