source: trunk/src/groovy/dbnp/query/StudySearch.groovy @ 1426

Last change on this file since 1426 was 1426, checked in by work@…, 10 years ago
  • Resolved part of improvement #225
  • refactored the template model out of GSCF into the GDT (Grails Domain Templates) plugin version 0.0.1
  • still work needs to be done (move template editor into gdt, etcetera)
  • fix template owner
  • some methods are missing from Template, but most of it works
File size: 4.9 KB
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.*
18import nl.grails.plugins.gdt.*
19
20class StudySearch extends Search {
21        public StudySearch() {
22                this.entity = "Study";
23        }
24
25        /**
26         * Searches for studies based on the given criteria. All criteria have to be satisfied and
27         * criteria for the different entities are satisfied as follows:
28         *
29         *              Study.title = 'abc'             
30         *                              All returned studies will have title 'abc'
31         *             
32         *              Subject.species = 'human'
33         *                              All returned studies will have one or more subjects with species = 'human' 
34         *
35         *              Sample.name = 'sample 1'
36         *                              All returned studies will have one or more samples with name = 'sample 1'
37         *
38         *              Event.startTime = '0s'
39         *                              All returned studies will have one or more events with start time = '0s' 
40         *
41         *              Assay.module = 'metagenomics'
42         *                              All returned studies will have one or more assays with module = 'metagenomics' 
43         *
44         * When searching the system doesn't look at the connections between different entities. This means,
45         * the system doesn't look for human subjects having a sample with name 'sample 1'. The sample 1 might
46         * as well belong to a mouse subject and still the study satisfies the criteria.
47         *
48         * When searching for more than one criterion per entity, these are taken combined. Searching for
49         *
50         *              Subject.species = 'human'
51         *              Subject.name = 'Jan'
52         *
53         *  will result in all studies having a human subject named 'Jan'. Studies with only a mouse subject
54         *  named 'Jan' or a human subject named 'Kees' won't satisfy the criteria.
55         *     
56         */
57        @Override
58        void execute() {
59                // TODO: check for authorization for these studies?
60                def studies = Study.list();
61
62                // If no criteria are found, return all studies
63                if( !criteria || criteria.size() == 0 ) {
64                        results = studies;
65                        return;
66                }
67
68                // Perform filters
69                studies = filterOnStudyCriteria( studies );
70                studies = filterOnSubjectCriteria( studies );
71                studies = filterOnSampleCriteria( studies );
72                studies = filterOnEventCriteria( studies );
73                studies = filterOnSamplingEventCriteria( studies );
74                studies = filterOnAssayCriteria( studies );
75
76                // Save matches
77                results = studies;
78        }
79
80        /**
81         * Filters the given list of studies on the study criteria
82         * @param studies       Original list of studies
83         * @return                      List with all studies that match the Study-criteria
84         */
85        protected List filterOnStudyCriteria( List studies ) {
86                return filterEntityList( studies, getEntityCriteria( 'Study' ), { study, criterion ->
87                        return criterion.matchOne( study );
88                });
89        }
90
91        /**
92         * Filters the given list of studies on the subject criteria
93         * @param studies       Original list of studies
94         * @return                      List with all studies that match the Subject-criteria
95         */
96        protected List filterOnSubjectCriteria( List studies ) {
97                return filterEntityList( studies, getEntityCriteria( 'Subject' ), { study, criterion ->
98                        if( !study.subjects?.size() )
99                                return false
100
101                        return criterion.matchAny( study.subjects );
102                });
103        }
104
105        /**
106         * Filters the given list of studies on the sample criteria
107         * @param studies       Original list of studies
108         * @return                      List with all studies that match the sample-criteria
109         */
110        protected List filterOnSampleCriteria( List studies ) {
111                return filterEntityList( studies, getEntityCriteria( 'Sample' ), { study, criterion ->
112                        if( !study.samples?.size() )
113                                return false
114
115                        return criterion.matchAny( study.samples );
116                });
117        }
118
119        /**
120         * Filters the given list of studies on the event criteria
121         * @param studies       Original list of studies
122         * @return                      List with all studies that match the event-criteria
123         */
124        protected List filterOnEventCriteria( List studies ) {
125                return filterEntityList( studies, getEntityCriteria( 'Event' ), { study, criterion ->
126                        if( !study.events?.size() )
127                                return false
128
129                        return criterion.matchAny( study.events );
130                });
131        }
132       
133        /**
134        * Filters the given list of studies on the sampling event criteria
135        * @param studies        Original list of studies
136        * @return                       List with all studies that match the event-criteria
137        */
138   protected List filterOnSamplingEventCriteria( List studies ) {
139           return filterEntityList( studies, getEntityCriteria( 'SamplingEvent' ), { study, criterion ->
140                   if( !study.samplingEvents?.size() )
141                           return false
142
143                        return criterion.matchAny( study.samplingEvents );
144           });
145   }
146
147       
148        /**
149         * Filters the given list of studies on the assay criteria
150         * @param studies       Original list of studies
151         * @return                      List with all studies that match the assay-criteria
152         */
153        protected List filterOnAssayCriteria( List studies ) {
154                return filterEntityList( studies, getEntityCriteria( 'Assay' ), { study, criterion ->
155                        if( !study.assays?.size() )
156                                return false
157
158                        return criterion.matchAny( study.assays );
159                });
160        }
161}
Note: See TracBrowser for help on using the repository browser.