root/trunk/grails-app/domain/dbnp/studycapturing/SamplingEvent.groovy @ 959

Revision 959, 2.9 KB (checked in by j.a.m.wesbeek@…, 4 years ago)

- set keyword expansion

  • Property svn:keywords set to Author Date Rev
Line 
1package dbnp.studycapturing
2
3/**
4 * The SamplingEvent class describes a sampling event, an event that also results in one or more samples.
5 *
6 * NOTE: according to Grails documentation, super classes and subclasses share the same table.
7 *       thus, we could merge the sampling with the Event super class and include a boolean
8 *       However, using a separate class makes it more clear in the code that Event and SamplingEvent are treated differently
9 *
10 * Revision information:
11 * $Rev$
12 * $Author$
13 * $Date$
14 */
15class SamplingEvent extends TemplateEntity {
16        // A SamplingEvent always belongs to one study.
17        // Although this is technically inherited from Event, we have to specify it here again.
18        // Otherwise, Grails expects the SamplingEvent to be referenced in Study.events,
19        // where it is actually referenced in Study.samplingEvents
20        static belongsTo = [parent : Study]
21        static hasMany = [samples : Sample]
22
23        /** Start time of the event, relative to the start time of the study */
24        long startTime
25
26        /** Duration of the sampling event, if it has any (default is 0) */
27        long duration
28
29        // define what template samples should have
30        Template sampleTemplate
31
32        // define domain constraints
33        static constraints = {
34                duration(default: 0L)
35                sampleTemplate(nullable: false, blank: false)
36        }
37
38        /**
39         * return the domain fields for this domain class
40         * @return List<TemplateField>
41         */
42        static List<TemplateField> giveDomainFields() { return SamplingEvent.domainFields }
43
44        // To improve performance, the domain fields list is stored as a static final variable in the class.
45        static final List<TemplateField> domainFields = [
46                new TemplateField(
47                        name: 'startTime',
48                        type: TemplateFieldType.RELTIME,
49                        comment: "Please enter the start time as a relative time from study start date."+RelTime.getHelpText(),
50                        required: true),
51                new TemplateField(
52                        name: 'duration',
53                        type: TemplateFieldType.RELTIME,
54                        comment: "Please enter the duration of the sampling action, if applicable. "+RelTime.getHelpText(),
55                        required: true),
56                new TemplateField(
57                        name: 'sampleTemplate',
58                        type: TemplateFieldType.TEMPLATE,
59                        entity: dbnp.studycapturing.Sample,
60                        comment: "Please select the template of the resulting samples",
61                        required: true)
62        ]
63
64         /**
65          * Return the start time of the event, which should be relative to the start of the study
66          * @return String a human readable representation of the start time of the event
67         */
68        def getStartTimeString() {
69                return new RelTime(startTime).toPrettyString();
70        }
71
72        /**
73         * Checks whether this Event is part of one or more of the given EventGroups
74         * @param groups
75         * @return
76         */
77        def belongsToGroup(Collection<EventGroup> groups) {
78                def eventFound = false;
79                def that = this;
80                groups.each { eventgroup ->
81                        if (!eventFound && eventgroup.samplingEvents) {
82                                eventFound = (that.id in eventgroup.samplingEvents.id);
83                        }
84                }
85
86                return eventFound;
87        }
88
89        def String toString() {
90                return fieldExists('Description') ? getFieldValue('Description') : ""
91        }
92       
93}
Note: See TracBrowser for help on using the browser.