1 | import org.codehaus.groovy.grails.commons.GrailsApplication |
---|
2 | import grails.util.GrailsUtil |
---|
3 | import dbnp.studycapturing.* |
---|
4 | |
---|
5 | import dbnp.data.Ontology |
---|
6 | import dbnp.data.Term |
---|
7 | import java.text.SimpleDateFormat |
---|
8 | |
---|
9 | /** |
---|
10 | * Application Bootstrapper |
---|
11 | * @Author Jeroen Wesbeek |
---|
12 | * @Since 20091021 |
---|
13 | * |
---|
14 | * Revision information: |
---|
15 | * $Rev: 266 $ |
---|
16 | * $Author: keesvb $ |
---|
17 | * $Date: 2010-03-15 08:28:43 +0000 (ma, 15 mrt 2010) $ |
---|
18 | */ |
---|
19 | class BootStrap { |
---|
20 | def init = {servletContext -> |
---|
21 | // define timezone |
---|
22 | System.setProperty('user.timezone', 'CET') |
---|
23 | |
---|
24 | // we could also check if we are in development by GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT |
---|
25 | if (Study.count() == 0) { |
---|
26 | printf("development bootstrapping....\n\n"); |
---|
27 | |
---|
28 | // ontologies |
---|
29 | def speciesOntology = new Ontology( |
---|
30 | name: 'NCBI Taxonomy', |
---|
31 | shortName: 'Taxon', |
---|
32 | url: 'http://www.obofoundry.org/cgi-bin/detail.cgi?id=ncbi_taxonomy' |
---|
33 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
34 | |
---|
35 | def humanBodyOntology = new Ontology( |
---|
36 | name: 'Foundational Model of Anatomy', |
---|
37 | shortName: 'HumanBody', |
---|
38 | url: 'http://bioportal.bioontology.org/ontologies/39966' |
---|
39 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
40 | |
---|
41 | // terms |
---|
42 | def mouseTerm = new Term( |
---|
43 | name: 'Mus musculus', |
---|
44 | ontology: speciesOntology, |
---|
45 | accession: '10090' |
---|
46 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
47 | def humanTerm = new Term( |
---|
48 | name: 'Homo sapiens', |
---|
49 | ontology: speciesOntology, |
---|
50 | accession: '9606' |
---|
51 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
52 | |
---|
53 | def bloodTerm = new Term( |
---|
54 | name: 'Portion of blood', |
---|
55 | ontology: humanBodyOntology, |
---|
56 | accession: '9670' |
---|
57 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
58 | |
---|
59 | def madmaxOntology = new Ontology( |
---|
60 | name: 'Madmax ontology', |
---|
61 | shortName: 'MDMX', |
---|
62 | url: 'madmax.bioinformatics.nl' |
---|
63 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
64 | |
---|
65 | def treatmentTerm = new Term( |
---|
66 | name: 'ExperimentalProtocol', |
---|
67 | ontology: madmaxOntology, |
---|
68 | accession: 'P-MDMXGE-264' |
---|
69 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
70 | |
---|
71 | def dietProtocol = new Protocol( |
---|
72 | name: 'Diet treatment Protocol NuGO PPS3 leptin module', |
---|
73 | reference: treatmentTerm |
---|
74 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
75 | |
---|
76 | def boostProtocol = new Protocol( |
---|
77 | name: 'Boost treatment Protocol NuGO PPS3 leptin module', |
---|
78 | reference: treatmentTerm |
---|
79 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
80 | |
---|
81 | def fastingProtocol = new Protocol( |
---|
82 | name: 'Fasting', |
---|
83 | reference: treatmentTerm |
---|
84 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
85 | |
---|
86 | |
---|
87 | // ParameterStringListItems |
---|
88 | def oil10= new ParameterStringListItem( |
---|
89 | name: '10% fat (palm oil)' |
---|
90 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
91 | def oil45= new ParameterStringListItem( |
---|
92 | name: '45% fat (palm oil)' |
---|
93 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
94 | def vehicle= new ParameterStringListItem( |
---|
95 | name: 'Vehicle' |
---|
96 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
97 | def leptin= new ParameterStringListItem( |
---|
98 | name: 'Leptin' |
---|
99 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
100 | |
---|
101 | |
---|
102 | dietProtocol |
---|
103 | .addToParameters(new ProtocolParameter( |
---|
104 | name: 'Diet', |
---|
105 | type: ProtocolParameterType.STRINGLIST, |
---|
106 | listEntries: [oil10,oil45])) |
---|
107 | .save() |
---|
108 | |
---|
109 | boostProtocol |
---|
110 | .addToParameters(new ProtocolParameter( |
---|
111 | name: 'Compound', |
---|
112 | type: ProtocolParameterType.STRINGLIST, |
---|
113 | listEntries: [vehicle,leptin])) |
---|
114 | .save() |
---|
115 | |
---|
116 | fastingProtocol |
---|
117 | .addToParameters(new ProtocolParameter( |
---|
118 | name: 'Fasting period', |
---|
119 | type: ProtocolParameterType.STRING)) |
---|
120 | .save() |
---|
121 | |
---|
122 | |
---|
123 | // sampling event protocols |
---|
124 | |
---|
125 | def liverSamplingProtocol = new Protocol( |
---|
126 | name: 'Liver sampling' |
---|
127 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
128 | |
---|
129 | liverSamplingProtocol |
---|
130 | .addToParameters(new ProtocolParameter( |
---|
131 | name: 'Sample weight', |
---|
132 | unit: 'mg', |
---|
133 | type: ProtocolParameterType.FLOAT)) |
---|
134 | .save() |
---|
135 | |
---|
136 | def bloodSamplingProtocol = new Protocol( |
---|
137 | name: 'Blood sampling' |
---|
138 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
139 | |
---|
140 | bloodSamplingProtocol |
---|
141 | .addToParameters(new ProtocolParameter( |
---|
142 | name: 'Sample volume', |
---|
143 | unit: 'ml', |
---|
144 | type: ProtocolParameterType.FLOAT)) |
---|
145 | .save() |
---|
146 | |
---|
147 | // create system user |
---|
148 | |
---|
149 | /*def systemUser = userService.createUser(InstanceGenerator.user( |
---|
150 | username: 'system', |
---|
151 | pass: 'system', |
---|
152 | passConfirm: 'system', |
---|
153 | enabled: true |
---|
154 | ))*/ |
---|
155 | |
---|
156 | |
---|
157 | def genderField = new TemplateField( |
---|
158 | name: 'Gender',type: TemplateFieldType.STRINGLIST, |
---|
159 | listEntries: [new TemplateFieldListItem(name:'Male'),new TemplateFieldListItem(name: 'Female')]) |
---|
160 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
161 | |
---|
162 | def ageField = new TemplateField( |
---|
163 | name: 'Age',type: TemplateFieldType.INTEGER) |
---|
164 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
165 | |
---|
166 | // Nutritional study template |
---|
167 | |
---|
168 | def studyTemplate = new Template( |
---|
169 | name: 'Nutritional study', entity: dbnp.studycapturing.Study |
---|
170 | ).addToFields(new TemplateField( |
---|
171 | name: 'NuGO Code',type: TemplateFieldType.STRING) |
---|
172 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
173 | |
---|
174 | |
---|
175 | // Mouse template |
---|
176 | def mouseTemplate = new Template( |
---|
177 | name: 'Mouse', entity: dbnp.studycapturing.Subject |
---|
178 | ).addToFields(new TemplateField( |
---|
179 | name: 'Genotype',type: TemplateFieldType.STRINGLIST, |
---|
180 | listEntries: [new TemplateFieldListItem(name:'C57/Bl6j'),new TemplateFieldListItem(name:'wild type')])) |
---|
181 | .addToFields(genderField) |
---|
182 | .addToFields(ageField) |
---|
183 | .addToFields(new TemplateField( |
---|
184 | name: 'Cage',type: TemplateFieldType.INTEGER)) |
---|
185 | .addToFields(new TemplateField( |
---|
186 | name: 'SomeDouble', type: TemplateFieldType.DOUBLE)) |
---|
187 | .addToFields(new TemplateField( |
---|
188 | name: 'SomeOntology', type: TemplateFieldType.ONTOLOGYTERM)) |
---|
189 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
190 | |
---|
191 | // Human template |
---|
192 | def humanTemplate = new Template( |
---|
193 | name: 'Human', entity: dbnp.studycapturing.Subject) |
---|
194 | .addToFields(genderField) |
---|
195 | .addToFields(ageField) |
---|
196 | .addToFields(new TemplateField( |
---|
197 | name: 'DOB',type: TemplateFieldType.DATE)) |
---|
198 | .addToFields(new TemplateField( |
---|
199 | name: 'Height',type: TemplateFieldType.DOUBLE)) |
---|
200 | .addToFields(new TemplateField( |
---|
201 | name: 'Weight',type: TemplateFieldType.DOUBLE)) |
---|
202 | .addToFields(new TemplateField( |
---|
203 | name: 'BMI',type: TemplateFieldType.DOUBLE)) |
---|
204 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
205 | |
---|
206 | //events |
---|
207 | def eventDiet = new EventDescription( |
---|
208 | name: 'Diet treatment', |
---|
209 | description: 'Diet treatment (fat percentage)', |
---|
210 | classification: treatmentTerm, |
---|
211 | protocol: dietProtocol, |
---|
212 | isSamplingEvent: false |
---|
213 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
214 | |
---|
215 | def eventBoost = new EventDescription( |
---|
216 | name: 'Boost treatment', |
---|
217 | description: 'Boost treatment (leptin or vehicle)', |
---|
218 | classification: treatmentTerm, |
---|
219 | protocol: boostProtocol, |
---|
220 | isSamplingEvent: false |
---|
221 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
222 | |
---|
223 | def samplingEvent = new EventDescription( |
---|
224 | name: 'Liver extraction', |
---|
225 | description: 'Liver sampling for transcriptomics arrays', |
---|
226 | protocol: liverSamplingProtocol, |
---|
227 | isSamplingEvent: true |
---|
228 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
229 | |
---|
230 | def bloodSamplingEventDescription = new EventDescription( |
---|
231 | name: 'Blood extraction', |
---|
232 | description: 'Blood extraction targeted at lipid assays', |
---|
233 | protocol: bloodSamplingProtocol, |
---|
234 | isSamplingEvent: true |
---|
235 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
236 | |
---|
237 | |
---|
238 | def fastingTreatment = new EventDescription( |
---|
239 | name: 'Fasting treatment', |
---|
240 | description: 'Fasting Protocol NuGO PPSH', |
---|
241 | protocol: fastingProtocol, |
---|
242 | isSamplingEvent: false |
---|
243 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
244 | |
---|
245 | println('Adding PPS3 study...') |
---|
246 | |
---|
247 | // studies |
---|
248 | def exampleStudy = new Study( |
---|
249 | template: studyTemplate, |
---|
250 | title:"NuGO PPS3 mouse study leptin module", |
---|
251 | code:"PPS3_leptin_module", |
---|
252 | researchQuestion:"Leptin etc.", |
---|
253 | description:"C57Bl/6 mice were fed a high fat (45 en%) or low fat (10 en%) diet after a four week run-in on low fat diet. After 1 week 10 mice that received a low fat diet were given an IP leptin challenge and 10 mice of the low-fat group received placebo injections. The same procedure was performed with mice that were fed the high-fat diet. After 4 weeks the procedure was repeated. In total 80 mice were culled.", |
---|
254 | ecCode:"2007117.c", |
---|
255 | startDate: Date.parse('yyyy-MM-dd','2007-12-11') |
---|
256 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
257 | |
---|
258 | def evLF = new Event( |
---|
259 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
260 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
261 | eventDescription: eventDiet, |
---|
262 | parameterStringValues: ['Diet':'10% fat (palm oil)'] |
---|
263 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
264 | |
---|
265 | def evHF = new Event( |
---|
266 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
267 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
268 | eventDescription: eventDiet, |
---|
269 | parameterStringValues: ['Diet':'45% fat (palm oil)'] |
---|
270 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
271 | |
---|
272 | def evBV = new Event( |
---|
273 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
274 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
275 | eventDescription: eventBoost, |
---|
276 | parameterStringValues: ['Compound':'Vehicle'] |
---|
277 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
278 | |
---|
279 | def evBL = new Event( |
---|
280 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
281 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
282 | eventDescription: eventBoost, |
---|
283 | parameterStringValues: ['Compound':'Leptin'] |
---|
284 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
285 | |
---|
286 | def evLF4 = new Event( |
---|
287 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
288 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
289 | eventDescription: eventDiet, |
---|
290 | parameterStringValues: ['Diet':'10% fat (palm oil)'] |
---|
291 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
292 | |
---|
293 | def evHF4 = new Event( |
---|
294 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
295 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
296 | eventDescription: eventDiet, |
---|
297 | parameterStringValues: ['Diet':'45% fat (palm oil)'] |
---|
298 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
299 | |
---|
300 | def evBV4 = new Event( |
---|
301 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
302 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
303 | eventDescription: eventBoost, |
---|
304 | parameterStringValues: ['Compound':'Vehicle'] |
---|
305 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
306 | |
---|
307 | def evBL4 = new Event( |
---|
308 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
309 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
310 | eventDescription: eventBoost, |
---|
311 | parameterStringValues: ['Compound':'Leptin'] |
---|
312 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
313 | |
---|
314 | def evS = new SamplingEvent( |
---|
315 | startTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
316 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
317 | eventDescription: samplingEvent, |
---|
318 | parameterFloatValues: ['Sample weight':5F] |
---|
319 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
320 | |
---|
321 | def evS4 = new SamplingEvent( |
---|
322 | startTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
323 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
324 | eventDescription: samplingEvent, |
---|
325 | parameterFloatValues: ['Sample weight':5F] |
---|
326 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
327 | |
---|
328 | // Add events to study |
---|
329 | exampleStudy |
---|
330 | .addToEvents(evLF) |
---|
331 | .addToEvents(evHF) |
---|
332 | .addToEvents(evBV) |
---|
333 | .addToEvents(evBL) |
---|
334 | .addToEvents(evLF4) |
---|
335 | .addToEvents(evHF4) |
---|
336 | .addToEvents(evBV4) |
---|
337 | .addToEvents(evBL4) |
---|
338 | .addToSamplingEvents(evS) |
---|
339 | .addToSamplingEvents(evS4) |
---|
340 | .save() |
---|
341 | |
---|
342 | def LFBV1 = new EventGroup(name:"10% fat + vehicle for 1 week") |
---|
343 | .addToEvents(evLF) |
---|
344 | .addToEvents(evBV) |
---|
345 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
346 | |
---|
347 | def LFBL1 = new EventGroup(name:"10% fat + leptin for 1 week") |
---|
348 | .addToEvents(evLF) |
---|
349 | .addToEvents(evBL) |
---|
350 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
351 | |
---|
352 | def HFBV1 = new EventGroup(name:"45% fat + vehicle for 1 week") |
---|
353 | .addToEvents(evHF) |
---|
354 | .addToEvents(evBV) |
---|
355 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
356 | |
---|
357 | def HFBL1 = new EventGroup(name:"45% fat + leptin for 1 week") |
---|
358 | .addToEvents(evHF) |
---|
359 | .addToEvents(evBL) |
---|
360 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
361 | |
---|
362 | def LFBV4 = new EventGroup(name:"10% fat + vehicle for 4 weeks") |
---|
363 | .addToEvents(evLF4) |
---|
364 | .addToEvents(evBV4) |
---|
365 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
366 | |
---|
367 | def LFBL4 = new EventGroup(name:"10% fat + leptin for 4 weeks") |
---|
368 | .addToEvents(evLF4) |
---|
369 | .addToEvents(evBL4) |
---|
370 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
371 | |
---|
372 | def HFBV4 = new EventGroup(name:"45% fat + vehicle for 4 weeks") |
---|
373 | .addToEvents(evHF4) |
---|
374 | .addToEvents(evBV4) |
---|
375 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
376 | |
---|
377 | def HFBL4 = new EventGroup(name:"45% fat + leptin for 4 weeks") |
---|
378 | .addToEvents(evHF4) |
---|
379 | .addToEvents(evBL4) |
---|
380 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
381 | |
---|
382 | // Add subjects and samples and compose EventGroups |
---|
383 | |
---|
384 | def x=1 |
---|
385 | 80.times { |
---|
386 | def currentSubject = new Subject( |
---|
387 | name: "A" + x++, |
---|
388 | species: mouseTerm, |
---|
389 | template: mouseTemplate, |
---|
390 | ) |
---|
391 | .setFieldValue("Gender", "Male") |
---|
392 | .setFieldValue("Genotype", "C57/Bl6j") |
---|
393 | .setFieldValue("Age", 17) |
---|
394 | .setFieldValue("Cage", (int)(x/2)) |
---|
395 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
396 | |
---|
397 | exampleStudy.addToSubjects(currentSubject) |
---|
398 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
399 | |
---|
400 | // Add subject to appropriate EventGroup |
---|
401 | if (x > 70) { HFBL4.addToSubjects(currentSubject).save() } |
---|
402 | else if (x > 60) { HFBV4.addToSubjects(currentSubject).save() } |
---|
403 | else if (x > 50) { LFBL4.addToSubjects(currentSubject).save() } |
---|
404 | else if (x > 40) { LFBV4.addToSubjects(currentSubject).save() } |
---|
405 | else if (x > 30) { HFBL1.addToSubjects(currentSubject).save() } |
---|
406 | else if (x > 20) { HFBV1.addToSubjects(currentSubject).save() } |
---|
407 | else if (x > 10) { LFBL1.addToSubjects(currentSubject).save() } |
---|
408 | else { LFBV1.addToSubjects(currentSubject).save() } |
---|
409 | |
---|
410 | } |
---|
411 | |
---|
412 | // Add EventGroups to study |
---|
413 | exampleStudy |
---|
414 | .addToEventGroups(LFBV1) |
---|
415 | .addToEventGroups(LFBL1) |
---|
416 | .addToEventGroups(HFBV1) |
---|
417 | .addToEventGroups(HFBL1) |
---|
418 | .addToEventGroups(LFBV4) |
---|
419 | .addToEventGroups(LFBL4) |
---|
420 | .addToEventGroups(HFBV4) |
---|
421 | .addToEventGroups(HFBL4) |
---|
422 | .save() |
---|
423 | |
---|
424 | println 'Adding PPSH study' |
---|
425 | |
---|
426 | def humanStudy = new Study( |
---|
427 | template: studyTemplate, |
---|
428 | title:"NuGO PPS human study", |
---|
429 | code:"PPSH", |
---|
430 | researchQuestion:"How much are fasting plasma and urine metabolite levels affected by prolonged fasting ?", |
---|
431 | description:"Human study", |
---|
432 | ecCode:"unknown", |
---|
433 | startDate: Date.parse('yyyy-MM-dd','2009-01-01') |
---|
434 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
435 | |
---|
436 | def fastingEvent = new Event( |
---|
437 | startTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
438 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
439 | eventDescription: fastingTreatment, |
---|
440 | parameterStringValues: ['Fasting period':'8h']); |
---|
441 | |
---|
442 | def bloodSamplingEvent = new SamplingEvent( |
---|
443 | startTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
444 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
445 | eventDescription: bloodSamplingEventDescription, |
---|
446 | parameterFloatValues: ['Sample volume':4.5F]); |
---|
447 | |
---|
448 | def rootGroup = new EventGroup(name: 'Root group'); |
---|
449 | rootGroup.addToEvents fastingEvent |
---|
450 | rootGroup.addToEvents bloodSamplingEvent |
---|
451 | rootGroup.save() |
---|
452 | |
---|
453 | def y = 1 |
---|
454 | 11.times { |
---|
455 | def currentSubject = new Subject( |
---|
456 | name: "" + y++, |
---|
457 | species: humanTerm, |
---|
458 | template: humanTemplate).setFieldValue("Gender", (boolean) (x / 2) ? "Male" : "Female").setFieldValue("DOB", new java.text.SimpleDateFormat("dd-mm-yy").parse("01-02-19" + (10 + (int) (Math.random() * 80)))).setFieldValue("Age", 30).setFieldValue("Height", Math.random() * 2F).setFieldValue("Weight", Math.random() * 150F).setFieldValue("BMI", 20 + Math.random() * 10F).with { if (!validate()) { errors.each { println it} } else save()} |
---|
459 | |
---|
460 | rootGroup.addToSubjects currentSubject |
---|
461 | rootGroup.save() |
---|
462 | |
---|
463 | def currentSample = new Sample( |
---|
464 | name: currentSubject.name + '_B', |
---|
465 | material: bloodTerm, |
---|
466 | parentSubject: currentSubject, |
---|
467 | parentEvent: bloodSamplingEvent); |
---|
468 | |
---|
469 | |
---|
470 | humanStudy.addToSubjects(currentSubject).addToSamples(currentSample).with { if (!validate()) { errors.each { println it} } else save()} |
---|
471 | } |
---|
472 | |
---|
473 | humanStudy.addToEventGroups rootGroup |
---|
474 | humanStudy.save() |
---|
475 | |
---|
476 | // Add clinical data |
---|
477 | |
---|
478 | def lipidAssay = new dbnp.clinicaldata.ClinicalAssay( |
---|
479 | name: 'Lipid profile', |
---|
480 | approved: true |
---|
481 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
482 | |
---|
483 | def ldlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement( |
---|
484 | name: 'LDL', |
---|
485 | unit: 'mg/dL', |
---|
486 | type: dbnp.data.FeatureType.QUANTITATIVE, |
---|
487 | referenceValues: '100 mg/dL', |
---|
488 | detectableLimit: 250, |
---|
489 | isDrug: false, isIntake: true, inSerum: true |
---|
490 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
491 | |
---|
492 | def hdlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement( |
---|
493 | name: 'HDL', |
---|
494 | unit: 'mg/dL', |
---|
495 | type: dbnp.data.FeatureType.QUANTITATIVE, |
---|
496 | referenceValues: '50 mg/dL', |
---|
497 | detectableLimit: 100, |
---|
498 | isDrug: false, isIntake: true, inSerum: true |
---|
499 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
500 | |
---|
501 | lipidAssay.addToMeasurements ldlMeasurement |
---|
502 | lipidAssay.addToMeasurements hdlMeasurement |
---|
503 | |
---|
504 | def lipidAssayInstance = new dbnp.clinicaldata.ClinicalAssayInstance( |
---|
505 | assay: lipidAssay |
---|
506 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
507 | |
---|
508 | humanStudy.samples*.each { |
---|
509 | new dbnp.clinicaldata.ClinicalFloatData( |
---|
510 | assay: lipidAssayInstance, |
---|
511 | measurement: ldlMeasurement, |
---|
512 | sample: it.name, |
---|
513 | value: Math.round(Math.random()*ldlMeasurement.detectableLimit) |
---|
514 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
515 | |
---|
516 | new dbnp.clinicaldata.ClinicalFloatData( |
---|
517 | assay: lipidAssayInstance, |
---|
518 | measurement: hdlMeasurement, |
---|
519 | sample: it.name, |
---|
520 | value: Math.round(Math.random()*hdlMeasurement.detectableLimit) |
---|
521 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
522 | } |
---|
523 | |
---|
524 | // Add assay to study capture module |
---|
525 | |
---|
526 | def clinicalModule = new AssayModule( |
---|
527 | name: 'Clinical data', |
---|
528 | type: AssayType.CLINICAL_DATA, |
---|
529 | platform: 'clinical measurements', |
---|
530 | url: 'http://localhost:8080/gscf' |
---|
531 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
532 | |
---|
533 | def lipidAssayRef = new Assay( |
---|
534 | name: 'Lipid profiling', |
---|
535 | module: clinicalModule, |
---|
536 | externalAssayId: lipidAssayInstance.id |
---|
537 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
538 | |
---|
539 | humanStudy.samples*.each { |
---|
540 | lipidAssayRef.addToSamples(it) |
---|
541 | } |
---|
542 | lipidAssayRef.save() |
---|
543 | |
---|
544 | humanStudy.addToAssays(lipidAssayRef); |
---|
545 | humanStudy.save() |
---|
546 | |
---|
547 | } |
---|
548 | } |
---|
549 | |
---|
550 | def destroy = { |
---|
551 | } |
---|
552 | } |
---|