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