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

Revision 1458, 4.8 KB (checked in by robert@…, 3 years ago)

- Implemented a cache for module rest calls, to increase performance (see moduleCommunicationService)
- Implemented searching in module data.

  • 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 java.util.List;
18
19import dbnp.studycapturing.*
20import org.dbnp.gdt.*
21
22class StudySearch extends Search {
23        public StudySearch() {
24                this.entity = "Study";
25        }
26
27        /**
28         * Searches for studies based on the given criteria. All criteria have to be satisfied and
29         * criteria for the different entities are satisfied as follows:
30         *
31         *              Study.title = 'abc'             
32         *                              All returned studies will have title 'abc'
33         *             
34         *              Subject.species = 'human'
35         *                              All returned studies will have one or more subjects with species = 'human' 
36         *
37         *              Sample.name = 'sample 1'
38         *                              All returned studies will have one or more samples with name = 'sample 1'
39         *
40         *              Event.startTime = '0s'
41         *                              All returned studies will have one or more events with start time = '0s' 
42         *
43         *              Assay.module = 'metagenomics'
44         *                              All returned studies will have one or more assays with module = 'metagenomics' 
45         *
46         * When searching the system doesn't look at the connections between different entities. This means,
47         * the system doesn't look for human subjects having a sample with name 'sample 1'. The sample 1 might
48         * as well belong to a mouse subject and still the study satisfies the criteria.
49         *
50         * When searching for more than one criterion per entity, these are taken combined. Searching for
51         *
52         *              Subject.species = 'human'
53         *              Subject.name = 'Jan'
54         *
55         *  will result in all studies having a human subject named 'Jan'. Studies with only a mouse subject
56         *  named 'Jan' or a human subject named 'Kees' won't satisfy the criteria.
57         *     
58         */
59        @Override
60        void execute() {
61                // TODO: check for authorization for these studies?
62                def studies = Study.list();
63
64                // If no criteria are found, return all studies
65                if( !criteria || criteria.size() == 0 ) {
66                        results = studies;
67                        return;
68                }
69
70                // Perform filters
71                studies = filterOnStudyCriteria( studies );
72                studies = filterOnSubjectCriteria( studies );
73                studies = filterOnSampleCriteria( studies );
74                studies = filterOnEventCriteria( studies );
75                studies = filterOnSamplingEventCriteria( studies );
76                studies = filterOnAssayCriteria( studies );
77
78                studies = filterOnModuleCriteria( studies );
79               
80                // Save matches
81                results = studies;
82        }
83       
84        /**
85         * Filters the given list of studies on the study criteria
86         * @param studies       Original list of studies
87         * @return                      List with all studies that match the Study criteria
88         */
89        protected List filterOnStudyCriteria( List studies ) {
90                return filterOnTemplateEntityCriteria(studies, "Study", { study, criterion -> return criterion.getFieldValue( study ) })
91        }
92
93        /**
94         * Filters the given list of studies on the subject criteria
95         * @param studies       Original list of studies
96         * @return                      List with all studies that match the Subject-criteria
97         */
98        protected List filterOnSubjectCriteria( List studies ) {
99                return filterOnTemplateEntityCriteria(studies, "Subject", { study, criterion ->
100                        return study.subjects?.collect { criterion.getFieldValue( it ); }
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 filterOnTemplateEntityCriteria(studies, "Sample", { study, criterion ->
111                        return study.samples?.collect { criterion.getFieldValue( it ); }
112                })
113        }
114
115        /**
116         * Filters the given list of studies on the event criteria
117         * @param studies       Original list of studies
118         * @return                      List with all studies that match the event-criteria
119         */
120        protected List filterOnEventCriteria( List studies ) {
121                return filterOnTemplateEntityCriteria(studies, "Event", { study, criterion ->
122                        return study.events?.collect { criterion.getFieldValue( it ); }
123                })
124        }
125       
126        /**
127        * Filters the given list of studies on the sampling event criteria
128        * @param studies        Original list of studies
129        * @return                       List with all studies that match the event-criteria
130        */
131   protected List filterOnSamplingEventCriteria( List studies ) {
132                return filterOnTemplateEntityCriteria(studies, "SamplingEvent", { study, criterion ->
133                        return study.samplingEvents?.collect { criterion.getFieldValue( it ); }
134                })
135   }
136       
137        /**
138         * Filters the given list of studies on the assay criteria
139         * @param studies       Original list of studies
140         * @return                      List with all studies that match the assay-criteria
141         */
142        protected List filterOnAssayCriteria( List studies ) {
143                return filterOnTemplateEntityCriteria(studies, "Assay", { study, criterion ->
144                        return study.assays?.collect { criterion.getFieldValue( it ); }
145                })
146        }
147}
Note: See TracBrowser for help on using the browser.