source: trunk/grails-app/domain/dbnp/studycapturing/Event.groovy @ 1922

Last change on this file since 1922 was 1922, checked in by work@…, 9 years ago
  • removed all default instance configuration in favor of just one default.properties file. Instance configuration should be on the server side, not within the code. The setup wizard will help you generate a configuration file...
  • removed obsolete references to searchable
  • removed obsolete references to grails melody
  • Property svn:keywords set to Rev Author Date
File size: 3.4 KB
Line 
1package dbnp.studycapturing
2import org.dbnp.gdt.*
3
4/**
5 * The Event class describes an actual event, as it has happened to a certain subject. Often, the same event occurs
6 * to multiple subjects at the same time. That is why the actual description of the event is factored out into a more
7 * general EventDescription class. Events that also lead to sample(s) should be instantiated as SamplingEvents.
8 *
9 * Revision information:
10 * $Rev: 1922 $
11 * $Author: work@osx.eu $
12 * $Date: 2011-06-09 12:10:44 +0000 (do, 09 jun 2011) $
13 */
14class Event extends TemplateEntity {
15        static belongsTo = [parent : Study]
16
17        /** Start time of the event, relative to the start time of the study */
18        long startTime
19        /** end time of the event, relative to the start time of the study */
20        long endTime
21
22        /**
23         * Constraints
24         */
25        static constraints = {
26                endTime(validator: { fields, obj, errors ->
27                        def error = false
28
29                        // endTime must be >= the startTime
30                        if (fields && fields.compareTo(obj.startTime) < 0) {
31                                error = true
32                                errors.rejectValue(
33                                        'endTime',
34                                        'event.endTime.greaterThanStartTime',
35                                        ['endTime', fields] as Object[],
36                                        'End time should be greater than or equal to the Start Time'
37                                )
38                        }
39
40                        return (!error)
41                })
42        }
43
44        /**
45         * return the domain fields for this domain class
46         * @return List<TemplateField>
47         */
48        static List<TemplateField> giveDomainFields() { return Event.domainFields }
49
50        // To improve performance, the domain fields list is stored as a static final variable in the class.
51        static final List<TemplateField> domainFields = [
52                new TemplateField(
53                        name: 'startTime',
54                        type: TemplateFieldType.RELTIME,
55                        comment: "Please enter the start time as a relative time from study start date. "+RelTime.getHelpText(),
56                        required: true),
57                new TemplateField(
58                        name: 'endTime',
59                        type: TemplateFieldType.RELTIME,
60                        comment: "Please enter the end time as a relative time from study start date. "+RelTime.getHelpText(),
61                        required: true)
62        ]
63
64    static mapping = {
65        sort "startTime"
66
67        // Workaround for bug http://jira.codehaus.org/browse/GRAILS-6754
68        templateTextFields type: 'text'
69    }
70
71        /**
72         * Get the duration of the event as RelTime
73         * @return RelTime
74         */
75        def getDuration() {
76                return new RelTime(startTime, endTime)
77        }
78
79         /**
80          * Return the start time of the event, which should be relative to the start of the study
81          * @return String a human readable representation of the start time of the event
82         */
83        def getStartTimeString() {
84                return new RelTime(startTime).toPrettyString();
85        }
86
87        /**
88         * Get extended, human readable string representing the duration between startTime and endTime
89     *
90         * @return String
91         */
92        def getDurationString() {
93                return new RelTime(startTime, endTime).toPrettyString();
94        }
95
96        /**
97         * Get human readable string representing the duration between startTime and endTime, rounded to one unit (weeks/days/hours etc.)
98     *
99         * @return String
100         */
101        def getRoundedDuration() {
102                return new RelTime(startTime, endTime).toPrettyRoundedString();
103        }
104
105        /**
106         * Checks whether this Event is part of one or more of the given EventGroups
107         * @param groups
108         * @return
109         */
110        def belongsToGroup(Collection<EventGroup> groups) {
111                def eventFound = false;
112                def that = this;
113                groups.each { eventgroup ->
114                        if (!eventFound && eventgroup.events) {
115                                eventFound = (that.id in eventgroup.events.id);
116                        }
117                }
118
119                return eventFound;
120        }
121
122        def String toString() {
123                return fieldExists('Description') ? getFieldValue('Description') : ""
124        }
125}
Note: See TracBrowser for help on using the repository browser.