root/trunk/src/groovy/dbnp/query/StudySearch.groovy @ 1456

Revision 1456, 4.9 KB (checked in by business@…, 3 years ago)

moved gdt package to org.dbnp, moved tests for RelTime?, TemplateEntity?, Template etc. to gdt plugin

  • Property svn:keywords set to Rev Author Date
Line 
1/**
2 * StudySearch Domain Class
3 *
4 * This class provides querying capabilities for searching for studies
5 *
6 * @author  Robert Horlings (robert@isdat.nl)
7 * @since       20110118
8 * @package     dbnp.query
9 *
10 * Revision information:
11 * $Rev$
12 * $Author$
13 * $Date$
14 */
15package dbnp.query
16
17import dbnp.studycapturing.*
18
19class StudySearch extends Search {
20        public StudySearch() {
21                this.entity = "Study";
22        }
23
24        /**
25         * Searches for studies based on the given criteria. All criteria have to be satisfied and
26         * criteria for the different entities are satisfied as follows:
27         *
28         *              Study.title = 'abc'             
29         *                              All returned studies will have title 'abc'
30         *             
31         *              Subject.species = 'human'
32         *                              All returned studies will have one or more subjects with species = 'human' 
33         *
34         *              Sample.name = 'sample 1'
35         *                              All returned studies will have one or more samples with name = 'sample 1'
36         *
37         *              Event.startTime = '0s'
38         *                              All returned studies will have one or more events with start time = '0s' 
39         *
40         *              Assay.module = 'metagenomics'
41         *                              All returned studies will have one or more assays with module = 'metagenomics' 
42         *
43         * When searching the system doesn't look at the connections between different entities. This means,
44         * the system doesn't look for human subjects having a sample with name 'sample 1'. The sample 1 might
45         * as well belong to a mouse subject and still the study satisfies the criteria.
46         *
47         * When searching for more than one criterion per entity, these are taken combined. Searching for
48         *
49         *              Subject.species = 'human'
50         *              Subject.name = 'Jan'
51         *
52         *  will result in all studies having a human subject named 'Jan'. Studies with only a mouse subject
53         *  named 'Jan' or a human subject named 'Kees' won't satisfy the criteria.
54         *     
55         */
56        @Override
57        void execute() {
58                // TODO: check for authorization for these studies?
59                def studies = Study.list();
60
61                // If no criteria are found, return all studies
62                if( !criteria || criteria.size() == 0 ) {
63                        results = studies;
64                        return;
65                }
66
67                // Perform filters
68                studies = filterOnStudyCriteria( studies );
69                studies = filterOnSubjectCriteria( studies );
70                studies = filterOnSampleCriteria( studies );
71                studies = filterOnEventCriteria( studies );
72                studies = filterOnSamplingEventCriteria( studies );
73                studies = filterOnAssayCriteria( studies );
74
75                // Save matches
76                results = studies;
77        }
78
79        /**
80         * Filters the given list of studies on the study criteria
81         * @param studies       Original list of studies
82         * @return                      List with all studies that match the Study-criteria
83         */
84        protected List filterOnStudyCriteria( List studies ) {
85                return filterEntityList( studies, getEntityCriteria( 'Study' ), { study, criterion ->
86                        return criterion.matchOne( study );
87                });
88        }
89
90        /**
91         * Filters the given list of studies on the subject criteria
92         * @param studies       Original list of studies
93         * @return                      List with all studies that match the Subject-criteria
94         */
95        protected List filterOnSubjectCriteria( List studies ) {
96                return filterEntityList( studies, getEntityCriteria( 'Subject' ), { study, criterion ->
97                        if( !study.subjects?.size() )
98                                return false
99
100                        return criterion.matchAny( study.subjects );
101                });
102        }
103
104        /**
105         * Filters the given list of studies on the sample criteria
106         * @param studies       Original list of studies
107         * @return                      List with all studies that match the sample-criteria
108         */
109        protected List filterOnSampleCriteria( List studies ) {
110                return filterEntityList( studies, getEntityCriteria( 'Sample' ), { study, criterion ->
111                        if( !study.samples?.size() )
112                                return false
113
114                        return criterion.matchAny( study.samples );
115                });
116        }
117
118        /**
119         * Filters the given list of studies on the event criteria
120         * @param studies       Original list of studies
121         * @return                      List with all studies that match the event-criteria
122         */
123        protected List filterOnEventCriteria( List studies ) {
124                return filterEntityList( studies, getEntityCriteria( 'Event' ), { study, criterion ->
125                        if( !study.events?.size() )
126                                return false
127
128                        return criterion.matchAny( study.events );
129                });
130        }
131       
132        /**
133        * Filters the given list of studies on the sampling event criteria
134        * @param studies        Original list of studies
135        * @return                       List with all studies that match the event-criteria
136        */
137   protected List filterOnSamplingEventCriteria( List studies ) {
138           return filterEntityList( studies, getEntityCriteria( 'SamplingEvent' ), { study, criterion ->
139                   if( !study.samplingEvents?.size() )
140                           return false
141
142                        return criterion.matchAny( study.samplingEvents );
143           });
144   }
145
146       
147        /**
148         * Filters the given list of studies on the assay criteria
149         * @param studies       Original list of studies
150         * @return                      List with all studies that match the assay-criteria
151         */
152        protected List filterOnAssayCriteria( List studies ) {
153                return filterEntityList( studies, getEntityCriteria( 'Assay' ), { study, criterion ->
154                        if( !study.assays?.size() )
155                                return false
156
157                        return criterion.matchAny( study.assays );
158                });
159        }
160}
Note: See TracBrowser for help on using the browser.